Revision: 4788
Author: [email protected]
Date: Wed Jun  2 08:08:09 2010
Log: Current HandleScope moving to Isolate.
This is first part. HandleScopeImplementor is still global.

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

Modified:
 /branches/experimental/isolates/src/api.cc
 /branches/experimental/isolates/src/apiutils.h
 /branches/experimental/isolates/src/handles-inl.h
 /branches/experimental/isolates/src/handles.cc
 /branches/experimental/isolates/src/handles.h
 /branches/experimental/isolates/src/isolate.cc
 /branches/experimental/isolates/src/isolate.h
 /branches/experimental/isolates/test/cctest/test-serialize.cc

=======================================
--- /branches/experimental/isolates/src/api.cc  Wed Jun  2 00:42:37 2010
+++ /branches/experimental/isolates/src/api.cc  Wed Jun  2 08:08:09 2010
@@ -263,12 +263,6 @@
   }
   return ApiCheck(v8::V8::Initialize(), location, "Error initializing V8");
 }
-
-
-ImplementationUtilities::HandleScopeData*
-    ImplementationUtilities::CurrentHandleScope() {
-  return &i::HandleScope::current_;
-}


 #ifdef DEBUG
@@ -449,6 +443,9 @@

 HandleScope::HandleScope() : is_closed_(false) {
   API_ENTRY_CHECK("HandleScope::HandleScope");
+  // Handle scope is per-isolate so we need to initialize the current one
+  // if it wasn't already.
+  EnsureInitialized("HandleScope::HandleScope");
   i::HandleScope::Enter(&previous_);
 }

@@ -3053,8 +3050,7 @@
 bool v8::V8::Initialize() {
   if (i::V8::IsRunning()) return true;
   ENTER_V8;
-  HandleScope scope;
-  if (i::Snapshot::Initialize()) return true;
+  if(i::Snapshot::Initialize()) return true;
   return i::V8::Initialize(NULL);
 }

@@ -4381,7 +4377,7 @@

 char* HandleScopeImplementer::ArchiveThreadHelper(char* storage) {
   v8::ImplementationUtilities::HandleScopeData* current =
-      v8::ImplementationUtilities::CurrentHandleScope();
+      Isolate::Current()->handle_scope_data();
   handle_scope_data_ = *current;
   memcpy(storage, this, sizeof(*this));

@@ -4404,7 +4400,7 @@

 char* HandleScopeImplementer::RestoreThreadHelper(char* storage) {
   memcpy(this, storage, sizeof(*this));
-  *v8::ImplementationUtilities::CurrentHandleScope() = handle_scope_data_;
+  *Isolate::Current()->handle_scope_data() = handle_scope_data_;
   return storage + ArchiveSpacePerThread();
 }

@@ -4430,7 +4426,7 @@

 void HandleScopeImplementer::Iterate(ObjectVisitor* v) {
   v8::ImplementationUtilities::HandleScopeData* current =
-      v8::ImplementationUtilities::CurrentHandleScope();
+      Isolate::Current()->handle_scope_data();
   thread_local.handle_scope_data_ = *current;
   thread_local.IterateThis(v);
 }
=======================================
--- /branches/experimental/isolates/src/apiutils.h      Wed Sep  9 03:49:40 2009
+++ /branches/experimental/isolates/src/apiutils.h      Wed Jun  2 08:08:09 2010
@@ -57,8 +57,6 @@
   // to access the HandleScope data.
   typedef v8::HandleScope::Data HandleScopeData;

-  static HandleScopeData* CurrentHandleScope();
-
 #ifdef DEBUG
static void ZapHandleRange(internal::Object** begin, internal::Object** end);
 #endif
=======================================
--- /branches/experimental/isolates/src/handles-inl.h Fri Aug 14 10:19:51 2009 +++ /branches/experimental/isolates/src/handles-inl.h Wed Jun 2 08:08:09 2010
@@ -54,7 +54,7 @@
 #ifdef DEBUG
 inline NoHandleAllocation::NoHandleAllocation() {
   v8::ImplementationUtilities::HandleScopeData* current =
-      v8::ImplementationUtilities::CurrentHandleScope();
+      Isolate::Current()->handle_scope_data();
   extensions_ = current->extensions;
   // Shrink the current handle scope to make it impossible to do
   // handle allocations without an explicit handle scope.
@@ -66,7 +66,7 @@
 inline NoHandleAllocation::~NoHandleAllocation() {
   // Restore state in current handle scope to re-enable handle
   // allocations.
- v8::ImplementationUtilities::CurrentHandleScope()->extensions = extensions_;
+  Isolate::Current()->handle_scope_data()->extensions = extensions_;
 }
 #endif

=======================================
--- /branches/experimental/isolates/src/handles.cc      Wed Jun  2 02:13:42 2010
+++ /branches/experimental/isolates/src/handles.cc      Wed Jun  2 08:08:09 2010
@@ -44,25 +44,25 @@
 namespace internal {


-v8::ImplementationUtilities::HandleScopeData HandleScope::current_ =
-    { -1, NULL, NULL };
-
-
 int HandleScope::NumberOfHandles() {
   int n = HandleScopeImplementer::instance()->blocks()->length();
   if (n == 0) return 0;
   return ((n - 1) * kHandleBlockSize) + static_cast<int>(
- (current_.next - HandleScopeImplementer::instance()->blocks()->last()));
+      (Isolate::Current()->handle_scope_data()->next -
+          HandleScopeImplementer::instance()->blocks()->last()));
 }


 Object** HandleScope::Extend() {
-  Object** result = current_.next;
-
-  ASSERT(result == current_.limit);
+  v8::ImplementationUtilities::HandleScopeData* current =
+      Isolate::Current()->handle_scope_data();
+
+  Object** result = current->next;
+
+  ASSERT(result == current->limit);
   // Make sure there's at least one scope on the stack and that the
   // top of the scope stack isn't a barrier.
-  if (current_.extensions < 0) {
+  if (current->extensions < 0) {
     Utils::ReportApiFailure("v8::HandleScope::CreateHandle()",
"Cannot create a handle without a HandleScope");
     return NULL;
@@ -72,21 +72,21 @@
   // for fast creation of scopes after scope barriers.
   if (!impl->blocks()->is_empty()) {
     Object** limit = &impl->blocks()->last()[kHandleBlockSize];
-    if (current_.limit != limit) {
-      current_.limit = limit;
+    if (current->limit != limit) {
+      current->limit = limit;
     }
   }

   // If we still haven't found a slot for the handle, we extend the
   // current handle scope by allocating a new handle block.
-  if (result == current_.limit) {
+  if (result == current->limit) {
     // If there's a spare block, use it for growing the current scope.
     result = impl->GetSpareOrNewBlock();
     // Add the extension to the global list of blocks, but count the
     // extension as part of the current scope.
     impl->blocks()->Add(result);
-    current_.extensions++;
-    current_.limit = &result[kHandleBlockSize];
+    current->extensions++;
+    current->limit = &result[kHandleBlockSize];
   }

   return result;
@@ -94,8 +94,11 @@


 void HandleScope::DeleteExtensions() {
-  ASSERT(current_.extensions != 0);
- HandleScopeImplementer::instance()->DeleteExtensions(current_.extensions);
+  v8::ImplementationUtilities::HandleScopeData* current =
+      Isolate::Current()->handle_scope_data();
+
+  ASSERT(current->extensions != 0);
+ HandleScopeImplementer::instance()->DeleteExtensions(current->extensions);
 }


@@ -108,17 +111,20 @@


 Address HandleScope::current_extensions_address() {
-  return reinterpret_cast<Address>(&current_.extensions);
+  return reinterpret_cast<Address>(
+      &Isolate::Current()->handle_scope_data()->extensions);
 }


 Address HandleScope::current_next_address() {
-  return reinterpret_cast<Address>(&current_.next);
+  return reinterpret_cast<Address>(
+      &Isolate::Current()->handle_scope_data()->next);
 }


 Address HandleScope::current_limit_address() {
-  return reinterpret_cast<Address>(&current_.limit);
+  return reinterpret_cast<Address>(
+      &Isolate::Current()->handle_scope_data()->limit);
 }


=======================================
--- /branches/experimental/isolates/src/handles.h       Tue May 25 05:14:49 2010
+++ /branches/experimental/isolates/src/handles.h       Wed Jun  2 08:08:09 2010
@@ -107,8 +107,8 @@
 // for which the handle scope has been deleted is undefined.
 class HandleScope {
  public:
-  HandleScope() : previous_(current_) {
-    current_.extensions = 0;
+  HandleScope() : previous_(*Isolate::Current()->handle_scope_data()) {
+    Isolate::Current()->handle_scope_data()->extensions = 0;
   }

   ~HandleScope() {
@@ -121,12 +121,15 @@
   // Creates a new handle with the given value.
   template <typename T>
   static inline T** CreateHandle(T* value) {
-    internal::Object** cur = current_.next;
-    if (cur == current_.limit) cur = Extend();
+    v8::ImplementationUtilities::HandleScopeData* current =
+        Isolate::Current()->handle_scope_data();
+
+    internal::Object** cur = current->next;
+    if (cur == current->limit) cur = Extend();
     // Update the current next field, set the value in the created
     // handle, and return the result.
-    ASSERT(cur < current_.limit);
-    current_.next = cur + 1;
+    ASSERT(cur < current->limit);
+    current->next = cur + 1;

     T** result = reinterpret_cast<T**>(cur);
     *result = value;
@@ -147,26 +150,29 @@
   void* operator new(size_t size);
   void operator delete(void* size_t);

-  static v8::ImplementationUtilities::HandleScopeData current_;
   const v8::ImplementationUtilities::HandleScopeData previous_;

   // Pushes a fresh handle scope to be used when allocating new handles.
   static void Enter(
       v8::ImplementationUtilities::HandleScopeData* previous) {
-    *previous = current_;
-    current_.extensions = 0;
+    v8::ImplementationUtilities::HandleScopeData* current =
+        Isolate::Current()->handle_scope_data();
+    *previous = *current;
+    current->extensions = 0;
   }

   // Re-establishes the previous scope state. Should be called only
   // once, and only for the current scope.
   static void Leave(
       const v8::ImplementationUtilities::HandleScopeData* previous) {
-    if (current_.extensions > 0) {
+    v8::ImplementationUtilities::HandleScopeData* current =
+        Isolate::Current()->handle_scope_data();
+    if (current->extensions > 0) {
       DeleteExtensions();
     }
-    current_ = *previous;
+    *current = *previous;
 #ifdef DEBUG
-    ZapRange(current_.next, current_.limit);
+    ZapRange(current->next, current->limit);
 #endif
   }

=======================================
--- /branches/experimental/isolates/src/isolate.cc      Wed Jun  2 00:51:31 2010
+++ /branches/experimental/isolates/src/isolate.cc      Wed Jun  2 08:08:09 2010
@@ -67,6 +67,7 @@
 Isolate::Isolate()
     : bootstrapper_(NULL),
       stub_cache_(NULL) {
+  handle_scope_data_.Initialize();
 }


=======================================
--- /branches/experimental/isolates/src/isolate.h       Wed Jun  2 02:13:42 2010
+++ /branches/experimental/isolates/src/isolate.h       Wed Jun  2 08:08:09 2010
@@ -28,6 +28,7 @@
 #ifndef V8_ISOLATE_H_
 #define V8_ISOLATE_H_

+#include "apiutils.h"
 #include "heap.h"

 namespace v8 {
@@ -58,7 +59,10 @@
   Bootstrapper* bootstrapper() { return bootstrapper_; }
   Heap* heap() { return &heap_; }
   StubCache* stub_cache() { return stub_cache_; }
-
+  v8::ImplementationUtilities::HandleScopeData* handle_scope_data() {
+    return &handle_scope_data_;
+  }
+
  private:
   Isolate();

@@ -69,6 +73,7 @@
   Bootstrapper* bootstrapper_;
   Heap heap_;
   StubCache* stub_cache_;
+  v8::ImplementationUtilities::HandleScopeData handle_scope_data_;

   DISALLOW_COPY_AND_ASSIGN(Isolate);
 };
=======================================
--- /branches/experimental/isolates/test/cctest/test-serialize.cc Tue Jun 1 03:51:42 2010 +++ /branches/experimental/isolates/test/cctest/test-serialize.cc Wed Jun 2 08:08:09 2010
@@ -293,7 +293,6 @@
   // serialization.  That doesn't matter.  We don't need to be able to
   // serialize a snapshot in a VM that is booted from a snapshot.
   if (!Snapshot::IsEnabled()) {
-    v8::HandleScope scope;

     Deserialize();

@@ -307,7 +306,6 @@

 DEPENDENT_TEST(DeserializeFromSecondSerialization, SerializeTwice) {
   if (!Snapshot::IsEnabled()) {
-    v8::HandleScope scope;

     Deserialize();

@@ -321,13 +319,13 @@

 DEPENDENT_TEST(DeserializeAndRunScript2, Serialize) {
   if (!Snapshot::IsEnabled()) {
-    v8::HandleScope scope;

     Deserialize();

     v8::Persistent<v8::Context> env = v8::Context::New();
     env->Enter();

+    v8::HandleScope scope;
     const char* c_source = "\"1234\".length";
     v8::Local<v8::String> source = v8::String::New(c_source);
     v8::Local<v8::Script> script = v8::Script::Compile(source);
@@ -339,13 +337,13 @@
 DEPENDENT_TEST(DeserializeFromSecondSerializationAndRunScript2,
                SerializeTwice) {
   if (!Snapshot::IsEnabled()) {
-    v8::HandleScope scope;

     Deserialize();

     v8::Persistent<v8::Context> env = v8::Context::New();
     env->Enter();

+    v8::HandleScope scope;
     const char* c_source = "\"1234\".length";
     v8::Local<v8::String> source = v8::String::New(c_source);
     v8::Local<v8::Script> script = v8::Script::Compile(source);

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

Reply via email to