#include "isolate.h"
#include "compilation-cache.h"
#include "execution.h"
+#include "smart-pointers.h"
#include "snapshot.h"
#include "platform.h"
#include "utils.h"
// 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() {
{
// 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() {
v8::Isolate* isolate, v8::Handle<v8::Context> context)
: JoinableThread("LockIsolateAndCalculateFibThread"),
isolate_(isolate),
- context_(context) {
+ context_(isolate, context) {
}
virtual void Run() {
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();
}
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();
{
v8::Locker second_lock(isolate_);
{
+ LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
isolate_->Exit();
v8::Unlocker unlocker(isolate_);
- LockIsolateAndCalculateFibSharedContextThread thread(isolate_, context);
thread.Start();
thread.Join();
}
}
}
{
+ 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();
}
}
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() {
#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();
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());
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);
}