* still JavaScript frames on the stack and the termination
* exception is still active.
*/
- static bool IsExecutionTerminating(Isolate* isolate = NULL);
+ static bool IsExecutionTerminating();
/**
* Releases any resources used by v8 and stops any utility threads
class IsolateThread : public v8::internal::Thread {
public:
explicit IsolateThread(SourceGroup* group)
- : v8::internal::Thread(GetThreadOptions()), group_(group) {}
+ : v8::internal::Thread(NULL, GetThreadOptions()), group_(group) {}
virtual void Run() {
group_->ExecuteInThread();
}
-bool V8::IsExecutionTerminating(Isolate* isolate) {
- i::Isolate* i_isolate = isolate != NULL ?
- reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current();
- return IsExecutionTerminatingCheck(i_isolate);
+bool V8::IsExecutionTerminating() {
+ i::Isolate* isolate = i::Isolate::Current();
+ return IsExecutionTerminatingCheck(isolate);
}
static const int kTickSamplesBufferChunksCount = 16;
-ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator)
- : Thread("v8:ProfEvntProc"),
+ProfilerEventsProcessor::ProfilerEventsProcessor(Isolate* isolate,
+ ProfileGenerator* generator)
+ : Thread(isolate, "v8:ProfEvntProc"),
generator_(generator),
running_(true),
ticks_buffer_(sizeof(TickSampleEventRecord),
saved_logging_nesting_ = isolate->logger()->logging_nesting_;
isolate->logger()->logging_nesting_ = 0;
generator_ = new ProfileGenerator(profiles_);
- processor_ = new ProfilerEventsProcessor(generator_);
+ processor_ = new ProfilerEventsProcessor(isolate, generator_);
NoBarrier_Store(&is_profiling_, true);
processor_->Start();
// Enumerate stuff we already have in the heap.
// methods called by event producers: VM and stack sampler threads.
class ProfilerEventsProcessor : public Thread {
public:
- explicit ProfilerEventsProcessor(ProfileGenerator* generator);
+ ProfilerEventsProcessor(Isolate* isolate,
+ ProfileGenerator* generator);
virtual ~ProfilerEventsProcessor() {}
// Thread control.
}
// Create a new session and hook up the debug message handler.
- session_ = new DebuggerAgentSession(this, client);
+ session_ = new DebuggerAgentSession(isolate(), this, client);
v8::Debug::SetMessageHandler2(DebuggerAgentMessageHandler);
session_->Start();
}
// handles connection from a remote debugger.
class DebuggerAgent: public Thread {
public:
- DebuggerAgent(const char* name, int port)
- : Thread(name),
+ DebuggerAgent(Isolate* isolate, const char* name, int port)
+ : Thread(isolate, name),
name_(StrDup(name)), port_(port),
server_(OS::CreateSocket()), terminate_(false),
session_access_(OS::CreateMutex()), session_(NULL),
// debugger and sends debugger events/responses to the remote debugger.
class DebuggerAgentSession: public Thread {
public:
- DebuggerAgentSession(DebuggerAgent* agent, Socket* client)
- : Thread("v8:DbgAgntSessn"),
+ DebuggerAgentSession(Isolate* isolate, DebuggerAgent* agent, Socket* client)
+ : Thread(isolate, "v8:DbgAgntSessn"),
agent_(agent), client_(client) {}
void DebuggerMessage(Vector<uint16_t> message);
if (Socket::Setup()) {
if (agent_ == NULL) {
- agent_ = new DebuggerAgent(name, port);
+ agent_ = new DebuggerAgent(isolate_, name, port);
agent_->Start();
}
return true;
MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate)
- : Thread("v8:MsgDispHelpr"),
+ : Thread(isolate, "v8:MsgDispHelpr"),
sem_(OS::CreateSemaphore(0)), mutex_(OS::CreateMutex()),
already_signalled_(false) {
}
private:
- PreallocatedMemoryThread()
- : Thread("v8:PreallocMem"),
+ explicit PreallocatedMemoryThread(Isolate* isolate)
+ : Thread(isolate, "v8:PreallocMem"),
keep_running_(true),
wait_for_ever_semaphore_(OS::CreateSemaphore(0)),
data_ready_semaphore_(OS::CreateSemaphore(0)),
void Isolate::PreallocatedMemoryThreadStart() {
if (preallocated_memory_thread_ != NULL) return;
- preallocated_memory_thread_ = new PreallocatedMemoryThread();
+ preallocated_memory_thread_ = new PreallocatedMemoryThread(this);
preallocated_memory_thread_->Start();
}
//
class Profiler: public Thread {
public:
- Profiler();
+ explicit Profiler(Isolate* isolate);
void Engage();
void Disengage();
//
// Profiler implementation.
//
-Profiler::Profiler()
- : Thread("v8:Profiler"),
+Profiler::Profiler(Isolate* isolate)
+ : Thread(isolate, "v8:Profiler"),
head_(0),
tail_(0),
overflow_(false),
}
if (FLAG_prof) {
- profiler_ = new Profiler();
+ profiler_ = new Profiler(isolate);
if (!FLAG_prof_auto) {
profiler_->pause();
} else {
pthread_t thread_; // Thread handle for pthread.
};
-Thread::Thread(const Options& options)
+Thread::Thread(Isolate* isolate, const Options& options)
: data_(new PlatformData()),
+ isolate_(isolate),
stack_size_(options.stack_size) {
set_name(options.name);
}
-Thread::Thread(const char* name)
+Thread::Thread(Isolate* isolate, const char* name)
: data_(new PlatformData()),
+ isolate_(isolate),
stack_size_(0) {
set_name(name);
}
0, 0, 0);
thread->data()->thread_ = pthread_self();
ASSERT(thread->data()->thread_ != kNoThread);
+ Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
thread->Run();
return NULL;
}
};
explicit SignalSender(int interval)
- : Thread("SignalSender"),
+ : Thread(NULL, "SignalSender"),
vm_tgid_(getpid()),
interval_(interval) {}
int stack_size;
};
- // Create new thread.
- explicit Thread(const Options& options);
- explicit Thread(const char* name);
+ // Create new thread (with a value for storing in the TLS isolate field).
+ Thread(Isolate* isolate, const Options& options);
+ Thread(Isolate* isolate, const char* name);
virtual ~Thread();
// Start new thread by calling the Run() method in the new thread.
// A hint to the scheduler to let another thread run.
static void YieldCPU();
+ Isolate* isolate() const { return isolate_; }
// The thread name length is limited to 16 based on Linux's implementation of
// prctl().
PlatformData* data_;
+ Isolate* isolate_;
char name_[kMaxThreadNameLength];
int stack_size_;
ContextSwitcher::ContextSwitcher(Isolate* isolate, int every_n_ms)
- : Thread("v8:CtxtSwitcher"),
+ : Thread(isolate, "v8:CtxtSwitcher"),
keep_going_(true),
- sleep_ms_(every_n_ms),
- isolate_(isolate) {
+ sleep_ms_(every_n_ms) {
}
// Preempted thread needs to call back to the ContextSwitcher to acknowledge
// the handling of a preemption request.
static void PreemptionReceived();
-
- private:
- ContextSwitcher(Isolate* isolate, int every_n_ms);
- Isolate* isolate() const { return isolate_; }
+ private:
+ explicit ContextSwitcher(Isolate* isolate, int every_n_ms);
void Run();
bool keep_going_;
int sleep_ms_;
- Isolate* isolate_;
};
} } // namespace v8::internal
class ApiTestFuzzer: public v8::internal::Thread {
public:
void CallTest();
- explicit ApiTestFuzzer(int num)
- : Thread("ApiTestFuzzer"),
+ explicit ApiTestFuzzer(v8::internal::Isolate* isolate, int num)
+ : Thread(isolate, "ApiTestFuzzer"),
test_number_(num),
gate_(v8::internal::OS::CreateSemaphore(0)),
active_(true) {
int end = (count * (part + 1) / (LAST_PART + 1)) - 1;
active_tests_ = tests_being_run_ = end - start + 1;
for (int i = 0; i < tests_being_run_; i++) {
- RegisterThreadedTest::nth(i)->fuzzer_ = new ApiTestFuzzer(i + start);
+ RegisterThreadedTest::nth(i)->fuzzer_ = new ApiTestFuzzer(
+ i::Isolate::Current(), i + start);
}
for (int i = 0; i < active_tests_; i++) {
RegisterThreadedTest::nth(i)->fuzzer_->Start();
gc_during_regexp_ = 0;
regexp_success_ = false;
gc_success_ = false;
- GCThread gc_thread(this);
+ GCThread gc_thread(i::Isolate::Current(), this);
gc_thread.Start();
v8::Locker::StartPreemption(1);
class GCThread : public i::Thread {
public:
- GCThread(RegExpInterruptTest* test)
- : Thread("GCThread"), test_(test) {}
+ explicit GCThread(i::Isolate* isolate, RegExpInterruptTest* test)
+ : Thread(isolate, "GCThread"), test_(test) {}
virtual void Run() {
test_->CollectGarbage();
}
gc_during_apply_ = 0;
apply_success_ = false;
gc_success_ = false;
- GCThread gc_thread(this);
+ GCThread gc_thread(i::Isolate::Current(), this);
gc_thread.Start();
v8::Locker::StartPreemption(1);
class GCThread : public i::Thread {
public:
- explicit GCThread(ApplyInterruptTest* test)
- : Thread("GCThread"), test_(test) {}
+ explicit GCThread(i::Isolate* isolate, ApplyInterruptTest* test)
+ : Thread(isolate, "GCThread"), test_(test) {}
virtual void Run() {
test_->CollectGarbage();
}
NONE,
i::kNonStrictMode)->ToObjectChecked();
- MorphThread morph_thread(this);
+ MorphThread morph_thread(i::Isolate::Current(), this);
morph_thread.Start();
v8::Locker::StartPreemption(1);
LongRunningRegExp();
class MorphThread : public i::Thread {
public:
- explicit MorphThread(RegExpStringModificationTest* test)
- : Thread("MorphThread"), test_(test) {}
+ explicit MorphThread(i::Isolate* isolate,
+ RegExpStringModificationTest* test)
+ : Thread(isolate, "MorphThread"), test_(test) {}
virtual void Run() {
test_->MorphString();
}
class IsolateThread : public v8::internal::Thread {
public:
- IsolateThread(v8::Isolate* isolate, int fib_limit)
- : Thread("IsolateThread"),
+ explicit IsolateThread(v8::Isolate* isolate, int fib_limit)
+ : Thread(NULL, "IsolateThread"),
isolate_(isolate),
fib_limit_(fib_limit),
result_(0) { }
};
explicit InitDefaultIsolateThread(TestCase testCase)
- : Thread("InitDefaultIsolateThread"),
+ : Thread(NULL, "InitDefaultIsolateThread"),
testCase_(testCase),
result_(false) { }
public:
typedef SamplingCircularQueue::Cell Record;
- ProducerThread(SamplingCircularQueue* scq,
+ ProducerThread(i::Isolate* isolate,
+ SamplingCircularQueue* scq,
int records_per_chunk,
Record value,
i::Semaphore* finished)
- : Thread("producer"),
+ : Thread(isolate, "producer"),
scq_(scq),
records_per_chunk_(records_per_chunk),
value_(value),
// Check that we are using non-reserved values.
CHECK_NE(SamplingCircularQueue::kClear, 1);
CHECK_NE(SamplingCircularQueue::kEnd, 1);
- ProducerThread producer1(&scq, kRecordsPerChunk, 1, semaphore);
- ProducerThread producer2(&scq, kRecordsPerChunk, 10, semaphore);
- ProducerThread producer3(&scq, kRecordsPerChunk, 20, semaphore);
+ i::Isolate* isolate = i::Isolate::Current();
+ ProducerThread producer1(isolate, &scq, kRecordsPerChunk, 1, semaphore);
+ ProducerThread producer2(isolate, &scq, kRecordsPerChunk, 10, semaphore);
+ ProducerThread producer3(isolate, &scq, kRecordsPerChunk, 20, semaphore);
CHECK_EQ(NULL, scq.StartDequeue());
producer1.Start();
TEST(StartStop) {
CpuProfilesCollection profiles;
ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(&generator);
+ ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
processor.Start();
processor.Stop();
processor.Join();
CpuProfilesCollection profiles;
profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(&generator);
+ ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
processor.Start();
// Enqueue code creation events.
CpuProfilesCollection profiles;
profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(&generator);
+ ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
processor.Start();
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
CpuProfilesCollection profiles;
profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(&generator);
+ ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
processor.Start();
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
// placing JSON debugger commands in the queue.
class MessageQueueDebuggerThread : public v8::internal::Thread {
public:
- MessageQueueDebuggerThread()
- : Thread("MessageQueueDebuggerThread") { }
+ explicit MessageQueueDebuggerThread(v8::internal::Isolate* isolate)
+ : Thread(isolate, "MessageQueueDebuggerThread") { }
void Run();
};
// This thread runs the v8 engine.
TEST(MessageQueues) {
- MessageQueueDebuggerThread message_queue_debugger_thread;
+ MessageQueueDebuggerThread message_queue_debugger_thread(
+ i::Isolate::Current());
// Create a V8 environment
v8::HandleScope scope;
class V8Thread : public v8::internal::Thread {
public:
- V8Thread() : Thread("V8Thread") { }
+ explicit V8Thread(v8::internal::Isolate* isolate)
+ : Thread(isolate, "V8Thread") { }
void Run();
};
class DebuggerThread : public v8::internal::Thread {
public:
- DebuggerThread() : Thread("DebuggerThread") { }
+ explicit DebuggerThread(v8::internal::Isolate* isolate)
+ : Thread(isolate, "DebuggerThread") { }
void Run();
};
TEST(ThreadedDebugging) {
- DebuggerThread debugger_thread;
- V8Thread v8_thread;
+ DebuggerThread debugger_thread(i::Isolate::Current());
+ V8Thread v8_thread(i::Isolate::Current());
// Create a V8 environment
threaded_debugging_barriers.Initialize();
class BreakpointsV8Thread : public v8::internal::Thread {
public:
- BreakpointsV8Thread() : Thread("BreakpointsV8Thread") { }
+ explicit BreakpointsV8Thread(v8::internal::Isolate* isolate)
+ : Thread(isolate, "BreakpointsV8Thread") { }
void Run();
};
class BreakpointsDebuggerThread : public v8::internal::Thread {
public:
- explicit BreakpointsDebuggerThread(bool global_evaluate)
- : Thread("BreakpointsDebuggerThread"),
+ explicit BreakpointsDebuggerThread(v8::internal::Isolate* isolate,
+ bool global_evaluate)
+ : Thread(isolate, "BreakpointsDebuggerThread"),
global_evaluate_(global_evaluate) {}
void Run();
void TestRecursiveBreakpointsGeneric(bool global_evaluate) {
i::FLAG_debugger_auto_break = true;
- BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate);
- BreakpointsV8Thread breakpoints_v8_thread;
+ BreakpointsDebuggerThread breakpoints_debugger_thread(i::Isolate::Current(),
+ global_evaluate);
+ BreakpointsV8Thread breakpoints_v8_thread(i::Isolate::Current());
// Create a V8 environment
Barriers stack_allocated_breakpoints_barriers;
class HostDispatchV8Thread : public v8::internal::Thread {
public:
- HostDispatchV8Thread() : Thread("HostDispatchV8Thread") { }
+ explicit HostDispatchV8Thread(v8::internal::Isolate* isolate)
+ : Thread(isolate, "HostDispatchV8Thread") { }
void Run();
};
class HostDispatchDebuggerThread : public v8::internal::Thread {
public:
- HostDispatchDebuggerThread() : Thread("HostDispatchDebuggerThread") { }
+ explicit HostDispatchDebuggerThread(v8::internal::Isolate* isolate)
+ : Thread(isolate, "HostDispatchDebuggerThread") { }
void Run();
};
TEST(DebuggerHostDispatch) {
- HostDispatchDebuggerThread host_dispatch_debugger_thread;
- HostDispatchV8Thread host_dispatch_v8_thread;
+ HostDispatchDebuggerThread host_dispatch_debugger_thread(
+ i::Isolate::Current());
+ HostDispatchV8Thread host_dispatch_v8_thread(i::Isolate::Current());
i::FLAG_debugger_auto_break = true;
// Create a V8 environment
class DebugMessageDispatchV8Thread : public v8::internal::Thread {
public:
- DebugMessageDispatchV8Thread() : Thread("DebugMessageDispatchV8Thread") { }
+ explicit DebugMessageDispatchV8Thread(v8::internal::Isolate* isolate)
+ : Thread(isolate, "DebugMessageDispatchV8Thread") { }
void Run();
};
class DebugMessageDispatchDebuggerThread : public v8::internal::Thread {
public:
- DebugMessageDispatchDebuggerThread()
- : Thread("DebugMessageDispatchDebuggerThread") { }
+ explicit DebugMessageDispatchDebuggerThread(v8::internal::Isolate* isolate)
+ : Thread(isolate, "DebugMessageDispatchDebuggerThread") { }
void Run();
};
TEST(DebuggerDebugMessageDispatch) {
- DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread;
- DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread;
+ DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread(
+ i::Isolate::Current());
+ DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread(
+ i::Isolate::Current());
i::FLAG_debugger_auto_break = true;
class DebuggerAgentProtocolServerThread : public i::Thread {
public:
- explicit DebuggerAgentProtocolServerThread(int port)
- : Thread("DebuggerAgentProtocolServerThread"),
+ explicit DebuggerAgentProtocolServerThread(i::Isolate* isolate, int port)
+ : Thread(isolate, "DebuggerAgentProtocolServerThread"),
port_(port),
server_(NULL),
client_(NULL),
// Create a socket server to receive a debugger agent message.
DebuggerAgentProtocolServerThread* server =
- new DebuggerAgentProtocolServerThread(kPort);
+ new DebuggerAgentProtocolServerThread(i::Isolate::Current(), kPort);
server->Start();
server->WaitForListening();
public:
KangarooThread(v8::Isolate* isolate,
v8::Handle<v8::Context> context, int value)
- : Thread("KangarooThread"),
+ : Thread(NULL, "KangarooThread"),
isolate_(isolate), context_(context), value_(value) {
}
private:
class ThreadWithSemaphore : public i::Thread {
public:
- ThreadWithSemaphore(JoinableThread* joinable_thread)
- : Thread(joinable_thread->name_),
+ explicit ThreadWithSemaphore(JoinableThread* joinable_thread)
+ : Thread(NULL, joinable_thread->name_),
joinable_thread_(joinable_thread) {
}
class TestThread : public Thread {
public:
- TestThread() : Thread("TestThread") {}
+ TestThread() : Thread(NULL, "TestThread") {}
virtual void Run() {
DoTest();
class SocketListenerThread : public Thread {
public:
- SocketListenerThread(int port, int data_size)
- : Thread("SocketListenerThread"),
+ explicit SocketListenerThread(Isolate* isolate, int port, int data_size)
+ : Thread(isolate, "SocketListenerThread"),
port_(port),
data_size_(data_size),
server_(NULL),
OS::SNPrintF(Vector<char>(port_str, kPortBuferLen), "%d", port);
// Create a socket listener.
- SocketListenerThread* listener = new SocketListenerThread(port, len);
+ SocketListenerThread* listener = new SocketListenerThread(Isolate::Current(),
+ port, len);
listener->Start();
listener->WaitForListening();
class TerminatorThread : public v8::internal::Thread {
public:
explicit TerminatorThread(i::Isolate* isolate)
- : Thread("TerminatorThread"),
- isolate_(reinterpret_cast<v8::Isolate*>(isolate)) { }
+ : Thread(isolate, "TerminatorThread") { }
void Run() {
semaphore->Wait();
- CHECK(!v8::V8::IsExecutionTerminating(isolate_));
- v8::V8::TerminateExecution(isolate_);
+ CHECK(!v8::V8::IsExecutionTerminating());
+ v8::V8::TerminateExecution();
}
-
- private:
- v8::Isolate* isolate_;
};
class LoopingThread : public v8::internal::Thread {
public:
- LoopingThread() : Thread("LoopingThread") { }
+ explicit LoopingThread(i::Isolate* isolate)
+ : Thread(isolate, "LoopingThread") { }
void Run() {
v8::Locker locker;
v8::HandleScope scope;
const int kThreads = 2;
i::List<LoopingThread*> threads(kThreads);
for (int i = 0; i < kThreads; i++) {
- threads.Add(new LoopingThread());
+ threads.Add(new LoopingThread(i::Isolate::Current()));
}
for (int i = 0; i < kThreads; i++) {
threads[i]->Start();
class ThreadA: public v8::internal::Thread {
public:
- ThreadA() : Thread("ThreadA") { }
+ explicit ThreadA(i::Isolate* isolate) : Thread(isolate, "ThreadA") { }
void Run() {
v8::Locker locker;
v8::HandleScope scope;
class ThreadB: public v8::internal::Thread {
public:
- ThreadB() : Thread("ThreadB") { }
+ explicit ThreadB(i::Isolate* isolate) : Thread(isolate, "ThreadB") { }
void Run() {
do {
{
TEST(JSFunctionResultCachesInTwoThreads) {
v8::V8::Initialize();
- ThreadA threadA;
- ThreadB threadB;
+ ThreadA threadA(i::Isolate::Current());
+ ThreadB threadB(i::Isolate::Current());
threadA.Start();
threadB.Start();
i::List<i::ThreadId>* refs,
unsigned int thread_no,
i::Semaphore* semaphore)
- : Thread("ThreadRefValidationThread"),
+ : Thread(NULL, "ThreadRefValidationThread"),
refs_(refs), thread_no_(thread_no), thread_to_start_(thread_to_start),
semaphore_(semaphore) {
}