Revision: 14420
Author: [email protected]
Date: Wed Apr 24 07:23:46 2013
Log: 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.
Review URL: https://codereview.chromium.org/14150017
Patch from Jochen Eisinger <[email protected]>.
http://code.google.com/p/v8/source/detail?r=14420
Modified:
/branches/bleeding_edge/include/v8.h
/branches/bleeding_edge/test/cctest/test-lockers.cc
=======================================
--- /branches/bleeding_edge/include/v8.h Mon Apr 22 08:20:28 2013
+++ /branches/bleeding_edge/include/v8.h Wed Apr 24 07:23:46 2013
@@ -375,6 +375,14 @@
}
template <class S> V8_INLINE(Persistent(S* that)) : Handle<T>(that) { }
+
+ /**
+ * A constructor that creates a new global cell pointing to that. In
contrast
+ * to the copy constructor, this creates a new persistent handle which
needs
+ * to be separately disposed.
+ */
+ template <class S> V8_INLINE(Persistent(Isolate* isolate, Handle<S>
that))
+ : Handle<T>(New(isolate, that)) { }
/**
* "Casts" a plain handle which is known to be a persistent handle
=======================================
--- /branches/bleeding_edge/test/cctest/test-lockers.cc Fri Mar 15 05:06:53
2013
+++ /branches/bleeding_edge/test/cctest/test-lockers.cc Wed Apr 24 07:23:46
2013
@@ -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 @@
// 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_(isolate, context) {}
void Run() {
{
@@ -95,19 +95,19 @@
// Migrates an isolate from one thread to another
TEST(KangarooIsolates) {
v8::Isolate* isolate = v8::Isolate::New();
- Persistent<v8::Context> context;
+ i::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 @@
v8::Isolate* isolate, v8::Handle<v8::Context> context)
: JoinableThread("LockIsolateAndCalculateFibThread"),
isolate_(isolate),
- context_(context) {
+ context_(isolate, context) {
}
virtual void Run() {
@@ -368,15 +368,15 @@
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 @@
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 @@
{
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,23 @@
}
}
{
+ i::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 +535,10 @@
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_(isolate, context) {
}
virtual void Run() {
@@ -574,15 +581,16 @@
#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 +598,9 @@
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_(CcTest::default_isolate(), context) {}
virtual void Run() {
v8::Locker lock1(CcTest::default_isolate());
@@ -625,14 +632,15 @@
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.