Revision: 5578
Author: [email protected]
Date: Fri Oct  1 11:01:30 2010
Log: [Isolates] Avoid isolate lookup in HandleScope destructor.

This has a nice side effect that we can assert the isolate stayed the
same. I had to update one of our new tests to satisfy this assert.

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

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

=======================================
--- /branches/experimental/isolates/include/v8.h        Fri Sep 24 17:27:22 2010
+++ /branches/experimental/isolates/include/v8.h        Fri Oct  1 11:01:30 2010
@@ -470,9 +470,11 @@
     int extensions;
     internal::Object** next;
     internal::Object** limit;
-    inline void Initialize() {
+    internal::Isolate* isolate;
+    inline void Initialize(internal::Isolate* i) {
       extensions = -1;
       next = limit = NULL;
+      isolate = i;
     }
   };

=======================================
--- /branches/experimental/isolates/src/api.cc  Mon Sep 27 09:58:02 2010
+++ /branches/experimental/isolates/src/api.cc  Fri Oct  1 11:01:30 2010
@@ -4837,13 +4837,14 @@


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

   ResetAfterArchive();
-  current->Initialize();
+  current->Initialize(isolate);

   return storage + ArchiveSpacePerThread();
 }
=======================================
--- /branches/experimental/isolates/src/handles-inl.h Tue Sep 28 07:20:01 2010 +++ /branches/experimental/isolates/src/handles-inl.h Fri Oct 1 11:01:30 2010
@@ -127,7 +127,8 @@

 void HandleScope::Leave(
     const v8::ImplementationUtilities::HandleScopeData* previous) {
-  Isolate* isolate = Isolate::Current();
+  Isolate* isolate = previous->isolate;
+  ASSERT(isolate == Isolate::Current());
   v8::ImplementationUtilities::HandleScopeData* current =
       isolate->handle_scope_data();
   if (current->extensions > 0) {
=======================================
--- /branches/experimental/isolates/src/isolate.cc      Fri Sep  3 05:50:01 2010
+++ /branches/experimental/isolates/src/isolate.cc      Fri Oct  1 11:01:30 2010
@@ -375,7 +375,7 @@
   producer_heap_profile_ = NULL;
 #endif

-  handle_scope_data_.Initialize();
+  handle_scope_data_.Initialize(this);

#define ISOLATE_INIT_EXECUTE(type, name, initial_value) \
   name##_ = (initial_value);
=======================================
--- /branches/experimental/isolates/test/cctest/test-api.cc Fri Sep 24 17:27:22 2010 +++ /branches/experimental/isolates/test/cctest/test-api.cc Fri Oct 1 11:01:30 2010
@@ -11479,56 +11479,81 @@
   // Run isolate 1.
   v8::Isolate* isolate1 = v8::Isolate::New();
   isolate1->Enter();
-  v8::HandleScope scope1;
-  LocalContext context1;
-
-  // Run something in new isolate.
-  CompileRun("var foo = 'isolate 1';");
-  ExpectString("function f() { return foo; }; f()", "isolate 1");
+  v8::Persistent<v8::Context> context1 = v8::Context::New();
+
+  {
+    v8::Context::Scope cscope(context1);
+    v8::HandleScope scope;
+    // Run something in new isolate.
+    CompileRun("var foo = 'isolate 1';");
+    ExpectString("function f() { return foo; }; f()", "isolate 1");
+  }

   // Run isolate 2.
   v8::Isolate* isolate2 = v8::Isolate::New();
-  isolate2->Enter();
-  v8::HandleScope scope2;
-  LocalContext context2;
-
-  // Run something in new isolate.
-  CompileRun("var foo = 'isolate 2';");
-  ExpectString("function f() { return foo; }; f()", "isolate 2");
-
-  isolate2->Exit();
-
-  // Now again in isolate 1
-
-  ExpectString("function f() { return foo; }; f()", "isolate 1");
+  v8::Persistent<v8::Context> context2;
+
+  {
+    v8::Isolate::Scope iscope(isolate2);
+    context2 = v8::Context::New();
+    v8::Context::Scope cscope(context2);
+    v8::HandleScope scope;
+
+    // Run something in new isolate.
+    CompileRun("var foo = 'isolate 2';");
+    ExpectString("function f() { return foo; }; f()", "isolate 2");
+  }
+
+  {
+    v8::Context::Scope cscope(context1);
+    v8::HandleScope scope;
+    // Now again in isolate 1
+    ExpectString("function f() { return foo; }; f()", "isolate 1");
+  }

   isolate1->Exit();

   // Run some stuff in default isolate.
-  v8::HandleScope scope_default;
-  LocalContext context_default;
-
-  // Variables in other isolates should be not available, verify there
-  // is an exception.
-  ExpectTrue("function f() {"
-             "  try {"
-             "    foo;"
-             "    return false;"
-             "  } catch(e) {"
-             "    return true;"
-             "  }"
-             "};"
-             "var isDefaultIsolate = true;"
-             "f()");
+  v8::Persistent<v8::Context> context_default = v8::Context::New();
+
+  {
+    v8::Context::Scope cscope(context_default);
+    v8::HandleScope scope;
+    // Variables in other isolates should be not available, verify there
+    // is an exception.
+    ExpectTrue("function f() {"
+               "  try {"
+               "    foo;"
+               "    return false;"
+               "  } catch(e) {"
+               "    return true;"
+               "  }"
+               "};"
+               "var isDefaultIsolate = true;"
+               "f()");
+  }

   isolate1->Enter();

   {
-    v8::Isolate::Scope isolate_scope(isolate2);
+    v8::Isolate::Scope iscope(isolate2);
+    v8::Context::Scope cscope(context2);
+    v8::HandleScope scope;
     ExpectString("function f() { return foo; }; f()", "isolate 2");
   }

-  ExpectString("function f() { return foo; }; f()", "isolate 1");
+  {
+    v8::Context::Scope cscope(context1);
+    v8::HandleScope scope;
+    ExpectString("function f() { return foo; }; f()", "isolate 1");
+  }
+
+  {
+    v8::Isolate::Scope iscope(isolate2);
+    context2.Dispose();
+  }
+
+  context1.Dispose();
   isolate1->Exit();

   v8::V8::SetFatalErrorHandler(StoringErrorCallback);
@@ -11543,7 +11568,11 @@
   CHECK_EQ(last_message, NULL);

   // Check that default isolate still runs.
-  ExpectTrue("function f() { return isDefaultIsolate; }; f()");
+  {
+    v8::Context::Scope cscope(context_default);
+    v8::HandleScope scope;
+    ExpectTrue("function f() { return isDefaultIsolate; }; f()");
+  }
 }

 static int CalcFibonacci(v8::Isolate* isolate, int limit) {

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

Reply via email to