Reviewers: Sven Panne,

Message:
plz review :)

the tests pass locally in ia32.debug

Description:
Change cctest/test-lockers to not copy persistent handles around.

Instead, create Local handles to pass them around. This also means that the
code needs to be shifted around a bit such that a handle scope exists when
creating threads.

Please review this at https://codereview.chromium.org/14150017/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M test/cctest/test-lockers.cc


Index: test/cctest/test-lockers.cc
diff --git a/test/cctest/test-lockers.cc b/test/cctest/test-lockers.cc
index a54390bf4e92a6cd133aa22cdd67581e2b7113a5..99e6c950249300a4f200bcee029cd7c5d8d5ba94 100644
--- a/test/cctest/test-lockers.cc
+++ b/test/cctest/test-lockers.cc
@@ -33,6 +33,7 @@
 #include "isolate.h"
 #include "compilation-cache.h"
 #include "execution.h"
+#include "smart-pointers.h"
 #include "snapshot.h"
 #include "platform.h"
 #include "utils.h"
@@ -58,11 +59,10 @@ using ::v8::V8;
 // Migrating an isolate
 class KangarooThread : public v8::internal::Thread {
  public:
-  KangarooThread(v8::Isolate* isolate,
-                 v8::Handle<v8::Context> context)
+  KangarooThread(v8::Isolate* isolate, v8::Handle<v8::Context> context)
       : Thread("KangarooThread"),
-        isolate_(isolate), context_(context) {
-  }
+        isolate_(isolate),
+        context_(v8::Persistent<v8::Context>::New(isolate, context)) {}

   void Run() {
     {
@@ -95,19 +95,19 @@ class KangarooThread : public v8::internal::Thread {
 // Migrates an isolate from one thread to another
 TEST(KangarooIsolates) {
   v8::Isolate* isolate = v8::Isolate::New();
-  Persistent<v8::Context> context;
+  v8::internal::SmartPointer<KangarooThread> thread1;
   {
     v8::Locker locker(isolate);
     v8::Isolate::Scope isolate_scope(isolate);
     v8::HandleScope handle_scope(isolate);
-    context = v8::Context::New();
+    v8::Local<v8::Context> context = v8::Context::New(isolate);
     v8::Context::Scope context_scope(context);
     CHECK_EQ(isolate, v8::internal::Isolate::Current());
     CompileRun("function getValue() { return 30; }");
+    thread1.Reset(new KangarooThread(isolate, context));
   }
-  KangarooThread thread1(isolate, context);
-  thread1.Start();
-  thread1.Join();
+  thread1->Start();
+  thread1->Join();
 }

 static void CalcFibAndCheck() {
@@ -342,7 +342,7 @@ class LockIsolateAndCalculateFibSharedContextThread : public JoinableThread {
       v8::Isolate* isolate, v8::Handle<v8::Context> context)
     : JoinableThread("LockIsolateAndCalculateFibThread"),
       isolate_(isolate),
-      context_(context) {
+      context_(v8::Persistent<v8::Context>::New(isolate, context)) {
   }

   virtual void Run() {
@@ -368,15 +368,15 @@ class LockerUnlockerThread : public JoinableThread {
     v8::Locker lock(isolate_);
     v8::Isolate::Scope isolate_scope(isolate_);
     v8::HandleScope handle_scope(isolate_);
-    v8::Handle<v8::Context> context = v8::Context::New();
+    v8::Local<v8::Context> context = v8::Context::New(isolate_);
     {
       v8::Context::Scope context_scope(context);
       CalcFibAndCheck();
     }
     {
+ LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
       isolate_->Exit();
       v8::Unlocker unlocker(isolate_);
- LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
       thread.Start();
       thread.Join();
     }
@@ -418,7 +418,7 @@ class LockTwiceAndUnlockThread : public JoinableThread {
     v8::Locker lock(isolate_);
     v8::Isolate::Scope isolate_scope(isolate_);
     v8::HandleScope handle_scope(isolate_);
-    v8::Handle<v8::Context> context = v8::Context::New();
+    v8::Local<v8::Context> context = v8::Context::New(isolate_);
     {
       v8::Context::Scope context_scope(context);
       CalcFibAndCheck();
@@ -426,9 +426,9 @@ class LockTwiceAndUnlockThread : public JoinableThread {
     {
       v8::Locker second_lock(isolate_);
       {
+ LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
         isolate_->Exit();
         v8::Unlocker unlocker(isolate_);
- LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
         thread.Start();
         thread.Join();
       }
@@ -497,16 +497,24 @@ class LockAndUnlockDifferentIsolatesThread : public JoinableThread {
       }
     }
     {
+ v8::internal::SmartPointer<LockIsolateAndCalculateFibSharedContextThread>
+      thread;
+      {
+        CHECK(v8::Locker::IsLocked(isolate1_));
+        v8::Isolate::Scope isolate_scope(isolate1_);
+        v8::HandleScope handle_scope(isolate1_);
+        thread.Reset(new LockIsolateAndCalculateFibSharedContextThread(
+            isolate1_, v8::Local<v8::Context>::New(isolate1_, context1)));
+      }
       v8::Unlocker unlock1(isolate1_);
       CHECK(!v8::Locker::IsLocked(isolate1_));
       CHECK(v8::Locker::IsLocked(isolate2_));
       v8::Isolate::Scope isolate_scope(isolate2_);
       v8::HandleScope handle_scope(isolate2_);
       v8::Context::Scope context_scope(context2);
- LockIsolateAndCalculateFibSharedContextThread thread(isolate1_, context1);
-      thread.Start();
+      thread->Start();
       CalcFibAndCheck();
-      thread.Join();
+      thread->Join();
     }
   }

@@ -528,10 +536,10 @@ TEST(LockAndUnlockDifferentIsolates) {

 class LockUnlockLockThread : public JoinableThread {
  public:
- LockUnlockLockThread(v8::Isolate* isolate, v8::Handle<v8::Context> context) + LockUnlockLockThread(v8::Isolate* isolate, v8::Local<v8::Context> context)
     : JoinableThread("LockUnlockLockThread"),
       isolate_(isolate),
-      context_(context) {
+      context_(v8::Persistent<v8::Context>::New(isolate, context)) {
   }

   virtual void Run() {
@@ -574,15 +582,16 @@ TEST(LockUnlockLockMultithreaded) {
 #endif
   v8::Isolate* isolate = v8::Isolate::New();
   Persistent<v8::Context> context;
+  i::List<JoinableThread*> threads(kNThreads);
   {
     v8::Locker locker_(isolate);
     v8::Isolate::Scope isolate_scope(isolate);
     v8::HandleScope handle_scope(isolate);
     context = v8::Context::New();
-  }
-  i::List<JoinableThread*> threads(kNThreads);
-  for (int i = 0; i < kNThreads; i++) {
-    threads.Add(new LockUnlockLockThread(isolate, context));
+    for (int i = 0; i < kNThreads; i++) {
+      threads.Add(new LockUnlockLockThread(
+          isolate, v8::Local<v8::Context>::New(isolate, context)));
+    }
   }
   StartJoinAndDeleteThreads(threads);
   isolate->Dispose();
@@ -590,10 +599,10 @@ TEST(LockUnlockLockMultithreaded) {

 class LockUnlockLockDefaultIsolateThread : public JoinableThread {
  public:
- explicit LockUnlockLockDefaultIsolateThread(v8::Handle<v8::Context> context)
-    : JoinableThread("LockUnlockLockDefaultIsolateThread"),
-      context_(context) {
-  }
+ explicit LockUnlockLockDefaultIsolateThread(v8::Local<v8::Context> context)
+      : JoinableThread("LockUnlockLockDefaultIsolateThread"),
+ context_(v8::Persistent<v8::Context>::New(CcTest::default_isolate(),
+                                                  context)) {}

   virtual void Run() {
     v8::Locker lock1(CcTest::default_isolate());
@@ -625,14 +634,15 @@ TEST(LockUnlockLockDefaultIsolateMultithreaded) {
   const int kNThreads = 100;
 #endif
   Persistent<v8::Context> context;
+  i::List<JoinableThread*> threads(kNThreads);
   {
     v8::Locker locker_(CcTest::default_isolate());
     v8::HandleScope handle_scope(CcTest::default_isolate());
     context = v8::Context::New();
-  }
-  i::List<JoinableThread*> threads(kNThreads);
-  for (int i = 0; i < kNThreads; i++) {
-    threads.Add(new LockUnlockLockDefaultIsolateThread(context));
+    for (int i = 0; i < kNThreads; i++) {
+      threads.Add(new LockUnlockLockDefaultIsolateThread(
+ v8::Local<v8::Context>::New(CcTest::default_isolate(), context)));
+    }
   }
   StartJoinAndDeleteThreads(threads);
 }


--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to