Revision: 4758
Author: lukezarko
Date: Mon May 31 05:47:33 2010
Log: Create a new class v8::internal::Isolate in isolate.h/isolate.cc.
Add isolate.cc to the build system.
Move code from v8::internal::V8::Initialize to Isolate::Initialize.

V8::Initialize now calls Isolate::Initialize to do almost
all of its work. From here, statics from the rest of the V8 code will
gradually move into an Isolate object (created on the first call to
Isolate::current() and initialized in V8::initialize). Once the statics have
been moved, the API will be extended to allow for the creation and use of
multiple isolates. Backward compatibility can be maintained using a single
isolate (similar to how this changelist operates).

Review URL: http://codereview.chromium.org/2310003
http://code.google.com/p/v8/source/detail?r=4758

Added:
 /branches/experimental/isolates/src/isolate.cc
 /branches/experimental/isolates/src/isolate.h
Modified:
 /branches/experimental/isolates/src/SConscript
 /branches/experimental/isolates/src/v8.cc

=======================================
--- /dev/null
+++ /branches/experimental/isolates/src/isolate.cc      Mon May 31 05:47:33 2010
@@ -0,0 +1,153 @@
+// Copyright 2006-2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include <stdlib.h>
+
+#include "v8.h"
+
+#include "bootstrapper.h"
+#include "debug.h"
+#include "log.h"
+#include "isolate.h"
+#include "serialize.h"
+#include "simulator.h"
+#include "stub-cache.h"
+#include "oprofile-agent.h"
+
+namespace v8 {
+namespace internal {
+
+
+Isolate* Isolate::global_isolate = NULL;
+
+
+void Isolate::InitOnce() {
+}
+
+
+Isolate* Isolate::Create(Deserializer* des) {
+  // While we're still building out support for isolates, only support
+  // one single global isolate.
+  ASSERT(global_isolate == NULL);
+  Isolate* new_isolate = new Isolate();
+  if (new_isolate->Init(des)) {
+    global_isolate = new_isolate;
+    return new_isolate;
+  } else {
+    delete new_isolate;
+    return NULL;
+  }
+}
+
+
+Isolate::Isolate() {
+}
+
+
+Isolate::~Isolate() {
+}
+
+bool Isolate::Init(Deserializer* des) {
+  bool create_heap_objects = des == NULL;
+
+#ifdef DEBUG
+  // The initialization process does not handle memory exhaustion.
+  DisallowAllocationFailure disallow_allocation_failure;
+#endif
+
+  // Enable logging before setting up the heap
+  Logger::Setup();
+
+  CpuProfiler::Setup();
+
+  // Setup the platform OS support.
+  OS::Setup();
+
+  // Initialize other runtime facilities
+#if !V8_HOST_ARCH_ARM && V8_TARGET_ARCH_ARM
+  ::assembler::arm::Simulator::Initialize();
+#endif
+
+  { // NOLINT
+ // Ensure that the thread has a valid stack guard. The v8::Locker object + // will ensure this too, but we don't have to use lockers if we are only
+    // using one thread.
+    ExecutionAccess lock;
+    StackGuard::InitThread(lock);
+  }
+
+  // Setup the object heap
+  ASSERT(!Heap::HasBeenSetup());
+  if (!Heap::Setup(create_heap_objects)) {
+    V8::SetFatalError();
+    return false;
+  }
+
+  Bootstrapper::Initialize(create_heap_objects);
+  Builtins::Setup(create_heap_objects);
+  Top::Initialize();
+
+  if (FLAG_preemption) {
+    v8::Locker locker;
+    v8::Locker::StartPreemption(100);
+  }
+
+#ifdef ENABLE_DEBUGGER_SUPPORT
+  Debug::Setup(create_heap_objects);
+#endif
+  StubCache::Initialize(create_heap_objects);
+
+  // If we are deserializing, read the state into the now-empty heap.
+  if (des != NULL) {
+    des->Deserialize();
+    StubCache::Clear();
+  }
+
+  // Deserializing may put strange things in the root array's copy of the
+  // stack guard.
+  Heap::SetStackLimits();
+
+  // Setup the CPU support. Must be done after heap setup and after
+  // any deserialization because we have to have the initial heap
+  // objects in place for creating the code object used for probing.
+  CPU::Setup();
+
+  OProfileAgent::Initialize();
+
+  // If we are deserializing, log non-function code objects and compiled
+  // functions found in the snapshot.
+  if (des != NULL && FLAG_log_code) {
+    HandleScope scope;
+    LOG(LogCodeObjects());
+    LOG(LogCompiledFunctions());
+  }
+
+  return true;
+}
+
+
+} }  // namespace v8::internal
=======================================
--- /dev/null
+++ /branches/experimental/isolates/src/isolate.h       Mon May 31 05:47:33 2010
@@ -0,0 +1,66 @@
+// Copyright 2010 the V8 project authors. All rights reserved.
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are
+// met:
+//
+//     * Redistributions of source code must retain the above copyright
+//       notice, this list of conditions and the following disclaimer.
+//     * Redistributions in binary form must reproduce the above
+//       copyright notice, this list of conditions and the following
+//       disclaimer in the documentation and/or other materials provided
+//       with the distribution.
+//     * Neither the name of Google Inc. nor the names of its
+//       contributors may be used to endorse or promote products derived
+//       from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#ifndef V8_ISOLATE_H_
+#define V8_ISOLATE_H_
+
+namespace v8 {
+namespace internal {
+
+class Deserializer;
+
+class Isolate {
+ public:
+  // Returns the single global isolate.
+  static inline Isolate* Current() {
+    ASSERT(global_isolate != NULL);
+    return global_isolate;
+  }
+
+  // Creates a new isolate (perhaps using a deserializer). Returns null
+  // on failure.
+  static Isolate* Create(Deserializer* des);
+
+  // Initialize process-wide state.
+  static void InitOnce();
+
+  ~Isolate();
+
+ private:
+  Isolate();
+
+  static Isolate* global_isolate;
+
+  bool Init(Deserializer* des);
+
+  DISALLOW_COPY_AND_ASSIGN(Isolate);
+};
+
+
+} }  // namespace v8::internal
+
+#endif  // V8_ISOLATE_H_
=======================================
--- /branches/experimental/isolates/src/SConscript      Fri May 21 02:23:33 2010
+++ /branches/experimental/isolates/src/SConscript      Mon May 31 05:47:33 2010
@@ -76,6 +76,7 @@
     heap.cc
     ic.cc
     interpreter-irregexp.cc
+    isolate.cc
     jsregexp.cc
     jump-target.cc
     liveedit.cc
=======================================
--- /branches/experimental/isolates/src/v8.cc   Fri May 21 22:27:19 2010
+++ /branches/experimental/isolates/src/v8.cc   Mon May 31 05:47:33 2010
@@ -29,6 +29,7 @@

 #include "bootstrapper.h"
 #include "debug.h"
+#include "isolate.h"
 #include "serialize.h"
 #include "simulator.h"
 #include "stub-cache.h"
@@ -44,7 +45,6 @@
 bool V8::has_fatal_error_ = false;

 bool V8::Initialize(Deserializer* des) {
-  bool create_heap_objects = des == NULL;
   if (has_been_disposed_ || has_fatal_error_) return false;
   if (IsRunning()) return true;

@@ -52,79 +52,9 @@
   has_been_setup_ = true;
   has_fatal_error_ = false;
   has_been_disposed_ = false;
-#ifdef DEBUG
-  // The initialization process does not handle memory exhaustion.
-  DisallowAllocationFailure disallow_allocation_failure;
-#endif
-
-  // Enable logging before setting up the heap
-  Logger::Setup();
-
-  CpuProfiler::Setup();
-
-  // Setup the platform OS support.
-  OS::Setup();
-
-  // Initialize other runtime facilities
-#if !V8_HOST_ARCH_ARM && V8_TARGET_ARCH_ARM
-  ::assembler::arm::Simulator::Initialize();
-#endif
-
-  { // NOLINT
- // Ensure that the thread has a valid stack guard. The v8::Locker object - // will ensure this too, but we don't have to use lockers if we are only
-    // using one thread.
-    ExecutionAccess lock;
-    StackGuard::InitThread(lock);
-  }
-
-  // Setup the object heap
-  ASSERT(!Heap::HasBeenSetup());
-  if (!Heap::Setup(create_heap_objects)) {
-    SetFatalError();
-    return false;
-  }
-
-  Bootstrapper::Initialize(create_heap_objects);
-  Builtins::Setup(create_heap_objects);
-  Top::Initialize();
-
-  if (FLAG_preemption) {
-    v8::Locker locker;
-    v8::Locker::StartPreemption(100);
-  }
-
-#ifdef ENABLE_DEBUGGER_SUPPORT
-  Debug::Setup(create_heap_objects);
-#endif
-  StubCache::Initialize(create_heap_objects);
-
-  // If we are deserializing, read the state into the now-empty heap.
-  if (des != NULL) {
-    des->Deserialize();
-    StubCache::Clear();
-  }
-
-  // Deserializing may put strange things in the root array's copy of the
-  // stack guard.
-  Heap::SetStackLimits();
-
-  // Setup the CPU support. Must be done after heap setup and after
-  // any deserialization because we have to have the initial heap
-  // objects in place for creating the code object used for probing.
-  CPU::Setup();
-
-  OProfileAgent::Initialize();
-
-  // If we are deserializing, log non-function code objects and compiled
-  // functions found in the snapshot.
-  if (des != NULL && FLAG_log_code) {
-    HandleScope scope;
-    LOG(LogCodeObjects());
-    LOG(LogCompiledFunctions());
-  }
-
-  return true;
+
+  Isolate::InitOnce();
+  return (Isolate::Create(des) != NULL);
 }


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to