* because of a call to TerminateExecution. In that case there are
* still JavaScript frames on the stack and the termination
* exception is still active.
+ *
+ * \param isolate The isolate in which to check.
*/
- static bool IsExecutionTerminating();
+ static bool IsExecutionTerminating(Isolate* isolate = NULL);
/**
* 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(NULL, GetThreadOptions()), group_(group) {}
+ : v8::internal::Thread(GetThreadOptions()), group_(group) {}
virtual void Run() {
group_->ExecuteInThread();
}
-bool V8::IsExecutionTerminating() {
- i::Isolate* isolate = i::Isolate::Current();
- return IsExecutionTerminatingCheck(isolate);
+bool V8::IsExecutionTerminating(Isolate* isolate) {
+ i::Isolate* i_isolate = isolate != NULL ?
+ reinterpret_cast<i::Isolate*>(isolate) : i::Isolate::Current();
+ return IsExecutionTerminatingCheck(i_isolate);
}
static const int kTickSamplesBufferChunksCount = 16;
-ProfilerEventsProcessor::ProfilerEventsProcessor(Isolate* isolate,
- ProfileGenerator* generator)
- : Thread(isolate, "v8:ProfEvntProc"),
+ProfilerEventsProcessor::ProfilerEventsProcessor(ProfileGenerator* generator)
+ : Thread("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(isolate, generator_);
+ processor_ = new ProfilerEventsProcessor(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:
- ProfilerEventsProcessor(Isolate* isolate,
- ProfileGenerator* generator);
+ explicit ProfilerEventsProcessor(ProfileGenerator* generator);
virtual ~ProfilerEventsProcessor() {}
// Thread control.
}
// Create a new session and hook up the debug message handler.
- session_ = new DebuggerAgentSession(isolate(), this, client);
- v8::Debug::SetMessageHandler2(DebuggerAgentMessageHandler);
+ session_ = new DebuggerAgentSession(this, client);
+ isolate_->debugger()->SetMessageHandler(DebuggerAgentMessageHandler);
session_->Start();
}
// Send the request received to the debugger.
v8::Debug::SendCommand(reinterpret_cast<const uint16_t *>(temp.start()),
- len);
+ len,
+ NULL,
+ reinterpret_cast<v8::Isolate*>(agent_->isolate()));
if (is_closing_session) {
// Session is closed.
// handles connection from a remote debugger.
class DebuggerAgent: public Thread {
public:
- DebuggerAgent(Isolate* isolate, const char* name, int port)
- : Thread(isolate, name),
+ DebuggerAgent(const char* name, int port)
+ : Thread(name),
+ isolate_(Isolate::Current()),
name_(StrDup(name)), port_(port),
server_(OS::CreateSocket()), terminate_(false),
session_access_(OS::CreateMutex()), session_(NULL),
terminate_now_(OS::CreateSemaphore(0)),
listening_(OS::CreateSemaphore(0)) {
- ASSERT(Isolate::Current()->debugger_agent_instance() == NULL);
- Isolate::Current()->set_debugger_agent_instance(this);
+ ASSERT(isolate_->debugger_agent_instance() == NULL);
+ isolate_->set_debugger_agent_instance(this);
}
~DebuggerAgent() {
- Isolate::Current()->set_debugger_agent_instance(NULL);
+ isolate_->set_debugger_agent_instance(NULL);
delete server_;
}
void Shutdown();
void WaitUntilListening();
+ Isolate* isolate() { return isolate_; }
+
private:
void Run();
void CreateSession(Socket* socket);
void CloseSession();
void OnSessionClosed(DebuggerAgentSession* session);
+ Isolate* isolate_;
SmartPointer<const char> name_; // Name of the embedding application.
int port_; // Port to use for the agent.
Socket* server_; // Server socket for listen/accept.
// debugger and sends debugger events/responses to the remote debugger.
class DebuggerAgentSession: public Thread {
public:
- DebuggerAgentSession(Isolate* isolate, DebuggerAgent* agent, Socket* client)
- : Thread(isolate, "v8:DbgAgntSessn"),
+ DebuggerAgentSession(DebuggerAgent* agent, Socket* client)
+ : Thread("v8:DbgAgntSessn"),
agent_(agent), client_(client) {}
void DebuggerMessage(Vector<uint16_t> message);
// Return if debugger is already loaded.
if (IsLoaded()) return true;
- ASSERT(Isolate::Current() == isolate_);
Debugger* debugger = isolate_->debugger();
// Bail out if we're already in the process of compiling the native
// Check whether a single break point object is triggered.
bool Debug::CheckBreakPoint(Handle<Object> break_point_object) {
- ASSERT(Isolate::Current() == isolate_);
Factory* factory = isolate_->factory();
HandleScope scope(isolate_);
void Debug::PrepareStep(StepAction step_action, int step_count) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
ASSERT(Debug::InDebugger());
void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
// Get the executing function in which the debug break occurred.
void Debug::ClearMirrorCache() {
- ASSERT(Isolate::Current() == isolate_);
PostponeInterruptsScope postpone(isolate_);
HandleScope scope(isolate_);
ASSERT(isolate_->context() == *Debug::debug_context());
void Debug::CreateScriptCache() {
- ASSERT(Isolate::Current() == isolate_);
Heap* heap = isolate_->heap();
HandleScope scope(isolate_);
Handle<FixedArray> Debug::GetLoadedScripts() {
- ASSERT(Isolate::Current() == isolate_);
// Create and fill the script cache when the loaded scripts is requested for
// the first time.
if (script_cache_ == NULL) {
}
-Debugger::Debugger()
+Debugger::Debugger(Isolate* isolate)
: debugger_access_(OS::CreateMutex()),
event_listener_(Handle<Object>()),
event_listener_data_(Handle<Object>()),
message_dispatch_helper_thread_(NULL),
host_dispatch_micros_(100 * 1000),
agent_(NULL),
- command_queue_(kQueueInitialSize),
+ command_queue_(isolate->logger(), kQueueInitialSize),
command_received_(OS::CreateSemaphore(0)),
- event_command_queue_(kQueueInitialSize) {
+ event_command_queue_(isolate->logger(), kQueueInitialSize),
+ isolate_(isolate) {
}
Handle<Object> Debugger::MakeJSObject(Vector<const char> constructor_name,
int argc, Object*** argv,
bool* caught_exception) {
- ASSERT(Isolate::Current() == isolate_);
ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
// Create the execution state object.
Handle<Object> Debugger::MakeExecutionState(bool* caught_exception) {
- ASSERT(Isolate::Current() == isolate_);
// Create the execution state object.
Handle<Object> break_id = isolate_->factory()->NewNumberFromInt(
isolate_->debug()->break_id());
Handle<Object> Debugger::MakeBreakEvent(Handle<Object> exec_state,
Handle<Object> break_points_hit,
bool* caught_exception) {
- ASSERT(Isolate::Current() == isolate_);
// Create the new break event object.
const int argc = 2;
Object** argv[argc] = { exec_state.location(),
Handle<Object> exception,
bool uncaught,
bool* caught_exception) {
- ASSERT(Isolate::Current() == isolate_);
Factory* factory = isolate_->factory();
// Create the new exception event object.
const int argc = 3;
Handle<Object> Debugger::MakeNewFunctionEvent(Handle<Object> function,
bool* caught_exception) {
- ASSERT(Isolate::Current() == isolate_);
// Create the new function event object.
const int argc = 1;
Object** argv[argc] = { function.location() };
Handle<Object> Debugger::MakeCompileEvent(Handle<Script> script,
bool before,
bool* caught_exception) {
- ASSERT(Isolate::Current() == isolate_);
Factory* factory = isolate_->factory();
// Create the compile event object.
Handle<Object> exec_state = MakeExecutionState(caught_exception);
Handle<Object> Debugger::MakeScriptCollectedEvent(int id,
bool* caught_exception) {
- ASSERT(Isolate::Current() == isolate_);
// Create the script collected event object.
Handle<Object> exec_state = MakeExecutionState(caught_exception);
Handle<Object> id_object = Handle<Smi>(Smi::FromInt(id));
void Debugger::OnException(Handle<Object> exception, bool uncaught) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
Debug* debug = isolate_->debug();
void Debugger::OnDebugBreak(Handle<Object> break_points_hit,
bool auto_continue) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
// Debugger has already been entered by caller.
if (!Debugger::EventActive(v8::Break)) return;
// Debugger must be entered in advance.
- ASSERT(Isolate::Current()->context() == *isolate_->debug()->debug_context());
+ ASSERT(isolate_->context() == *isolate_->debug()->debug_context());
// Create the event data object.
bool caught_exception = false;
void Debugger::OnBeforeCompile(Handle<Script> script) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
// Bail out based on state or if there is no listener for this event
// Handle debugger actions when a new script is compiled.
void Debugger::OnAfterCompile(Handle<Script> script,
AfterCompileFlags after_compile_flags) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
Debug* debug = isolate_->debug();
void Debugger::OnScriptCollected(int id) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
// No more to do if not debugging.
void Debugger::ProcessDebugEvent(v8::DebugEvent event,
Handle<JSObject> event_data,
bool auto_continue) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
// Clear any pending debug break if this is a real break.
Handle<Object> exec_state,
Handle<Object> event_data) {
ASSERT(event_listener_->IsJSFunction());
- ASSERT(Isolate::Current() == isolate_);
Handle<JSFunction> fun(Handle<JSFunction>::cast(event_listener_));
// Invoke the JavaScript debug event listener.
Handle<Context> Debugger::GetDebugContext() {
- ASSERT(Isolate::Current() == isolate_);
never_unload_debugger_ = true;
EnterDebugger debugger;
return isolate_->debug()->debug_context();
void Debugger::UnloadDebugger() {
- ASSERT(Isolate::Current() == isolate_);
Debug* debug = isolate_->debug();
// Make sure that there are no breakpoints left.
Handle<JSObject> exec_state,
Handle<JSObject> event_data,
bool auto_continue) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
if (!isolate_->debug()->Load()) return;
// Get the command from the queue.
CommandMessage command = command_queue_.Get();
- LOGGER->DebugTag("Got request from command queue, in interactive loop.");
+ isolate_->logger()->DebugTag(
+ "Got request from command queue, in interactive loop.");
if (!Debugger::IsDebuggerActive()) {
// Delete command text and user data.
command.Dispose();
void Debugger::SetEventListener(Handle<Object> callback,
Handle<Object> data) {
- ASSERT(Isolate::Current() == isolate_);
HandleScope scope(isolate_);
GlobalHandles* global_handles = isolate_->global_handles();
void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) {
- ASSERT(Isolate::Current() == isolate_);
ScopedLock with(debugger_access_);
message_handler_ = handler;
void Debugger::ListenersChanged() {
- ASSERT(Isolate::Current() == isolate_);
if (IsDebuggerActive()) {
// Disable the compilation cache when the debugger is active.
isolate_->compilation_cache()->Disable();
void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler,
int period) {
- ASSERT(Isolate::Current() == isolate_);
host_dispatch_handler_ = handler;
host_dispatch_micros_ = period * 1000;
}
void Debugger::SetDebugMessageDispatchHandler(
v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) {
- ASSERT(Isolate::Current() == isolate_);
ScopedLock with(dispatch_handler_access_);
debug_message_dispatch_handler_ = handler;
// Calls the registered debug message handler. This callback is part of the
// public API.
void Debugger::InvokeMessageHandler(MessageImpl message) {
- ASSERT(Isolate::Current() == isolate_);
ScopedLock with(debugger_access_);
if (message_handler_ != NULL) {
// by the API client thread.
void Debugger::ProcessCommand(Vector<const uint16_t> command,
v8::Debug::ClientData* client_data) {
- ASSERT(Isolate::Current() == isolate_);
// Need to cast away const.
CommandMessage message = CommandMessage::New(
Vector<uint16_t>(const_cast<uint16_t*>(command.start()),
command.length()),
client_data);
- LOGGER->DebugTag("Put command on command_queue.");
+ isolate_->logger()->DebugTag("Put command on command_queue.");
command_queue_.Put(message);
command_received_->Signal();
bool Debugger::HasCommands() {
- ASSERT(Isolate::Current() == isolate_);
return !command_queue_.IsEmpty();
}
void Debugger::EnqueueDebugCommand(v8::Debug::ClientData* client_data) {
- ASSERT(Isolate::Current() == isolate_);
CommandMessage message = CommandMessage::New(Vector<uint16_t>(), client_data);
event_command_queue_.Put(message);
bool Debugger::IsDebuggerActive() {
- ASSERT(Isolate::Current() == isolate_);
ScopedLock with(debugger_access_);
return message_handler_ != NULL || !event_listener_.is_null();
Handle<Object> Debugger::Call(Handle<JSFunction> fun,
Handle<Object> data,
bool* pending_exception) {
- ASSERT(Isolate::Current() == isolate_);
// When calling functions in the debugger prevent it from beeing unloaded.
Debugger::never_unload_debugger_ = true;
if (Socket::Setup()) {
if (agent_ == NULL) {
- agent_ = new DebuggerAgent(isolate_, name, port);
+ agent_ = new DebuggerAgent(name, port);
agent_->Start();
}
return true;
void Debugger::CallMessageDispatchHandler() {
- ASSERT(Isolate::Current() == isolate_);
v8::Debug::DebugMessageDispatchHandler handler;
{
ScopedLock with(dispatch_handler_access_);
}
-LockingCommandMessageQueue::LockingCommandMessageQueue(int size)
- : queue_(size) {
+LockingCommandMessageQueue::LockingCommandMessageQueue(Logger* logger, int size)
+ : logger_(logger), queue_(size) {
lock_ = OS::CreateMutex();
}
CommandMessage LockingCommandMessageQueue::Get() {
ScopedLock sl(lock_);
CommandMessage result = queue_.Get();
- LOGGER->DebugEvent("Get", result.text());
+ logger_->DebugEvent("Get", result.text());
return result;
}
void LockingCommandMessageQueue::Put(const CommandMessage& message) {
ScopedLock sl(lock_);
queue_.Put(message);
- LOGGER->DebugEvent("Put", message.text());
+ logger_->DebugEvent("Put", message.text());
}
MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate)
- : Thread(isolate, "v8:MsgDispHelpr"),
+ : Thread("v8:MsgDispHelpr"),
sem_(OS::CreateSemaphore(0)), mutex_(OS::CreateMutex()),
already_signalled_(false) {
}
// Mutex to CommandMessageQueue. Includes logging of all puts and gets.
class LockingCommandMessageQueue BASE_EMBEDDED {
public:
- explicit LockingCommandMessageQueue(int size);
+ LockingCommandMessageQueue(Logger* logger, int size);
~LockingCommandMessageQueue();
bool IsEmpty() const;
CommandMessage Get();
void Put(const CommandMessage& message);
void Clear();
private:
+ Logger* logger_;
CommandMessageQueue queue_;
Mutex* lock_;
DISALLOW_COPY_AND_ASSIGN(LockingCommandMessageQueue);
bool IsDebuggerActive();
private:
- Debugger();
+ explicit Debugger(Isolate* isolate);
void CallEventCallback(v8::DebugEvent event,
Handle<Object> exec_state,
private:
- explicit PreallocatedMemoryThread(Isolate* isolate)
- : Thread(isolate, "v8:PreallocMem"),
+ PreallocatedMemoryThread()
+ : Thread("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(this);
+ preallocated_memory_thread_ = new PreallocatedMemoryThread();
preallocated_memory_thread_->Start();
}
ASSERT(Isolate::Current() == this);
#ifdef ENABLE_DEBUGGER_SUPPORT
debug_ = new Debug(this);
- debugger_ = new Debugger();
- debugger_->isolate_ = this;
+ debugger_ = new Debugger(this);
#endif
memory_allocator_ = new MemoryAllocator();
return thread_local_top_.scheduled_exception_;
}
bool has_scheduled_exception() {
- return !thread_local_top_.scheduled_exception_->IsTheHole();
+ return thread_local_top_.scheduled_exception_ != heap_.the_hole_value();
}
void clear_scheduled_exception() {
thread_local_top_.scheduled_exception_ = heap_.the_hole_value();
// Returns the next index in the cyclic buffer.
int Succ(int index) { return (index + 1) % kBufferSize; }
+ Isolate* isolate_;
// Cyclic buffer for communicating profiling samples
// between the signal handler and the worker thread.
static const int kBufferSize = 128;
// Profiler implementation.
//
Profiler::Profiler(Isolate* isolate)
- : Thread(isolate, "v8:Profiler"),
+ : Thread("v8:Profiler"),
+ isolate_(isolate),
head_(0),
tail_(0),
overflow_(false),
void Profiler::Run() {
TickSample sample;
bool overflow = Remove(&sample);
- i::Isolate* isolate = ISOLATE;
while (running_) {
- LOG(isolate, TickEvent(&sample, overflow));
+ LOG(isolate_, TickEvent(&sample, overflow));
overflow = Remove(&sample);
}
}
if (FLAG_ll_prof) LogCodeInfo();
- ticker_ = new Ticker(Isolate::Current(), kSamplingIntervalMs);
-
Isolate* isolate = Isolate::Current();
+ ticker_ = new Ticker(isolate, kSamplingIntervalMs);
+
if (FLAG_sliding_state_window && sliding_state_window_ == NULL) {
sliding_state_window_ = new SlidingStateWindow(isolate);
}
-Thread::Thread(Isolate* isolate, const Options& options)
+Thread::Thread(const Options& options)
: data_(new PlatformData),
- isolate_(isolate),
stack_size_(options.stack_size) {
set_name(options.name);
}
-Thread::Thread(Isolate* isolate, const char* name)
+Thread::Thread(const char* name)
: data_(new PlatformData),
- isolate_(isolate),
stack_size_(0) {
set_name(name);
}
// one) so we initialize it here too.
thread->data()->thread_ = pthread_self();
ASSERT(thread->data()->thread_ != kNoThread);
- Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
thread->Run();
return NULL;
}
class SamplerThread : public Thread {
public:
explicit SamplerThread(int interval)
- : Thread(NULL, "SamplerThread"),
+ : Thread("SamplerThread"),
interval_(interval) {}
static void AddActiveSampler(Sampler* sampler) {
};
-Thread::Thread(Isolate* isolate, const Options& options)
+Thread::Thread(const Options& options)
: data_(new PlatformData),
- isolate_(isolate),
stack_size_(options.stack_size) {
set_name(options.name);
}
-Thread::Thread(Isolate* isolate, const char* name)
+Thread::Thread(const char* name)
: data_(new PlatformData),
- isolate_(isolate),
stack_size_(0) {
set_name(name);
}
// one) so we initialize it here too.
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(NULL, "SignalSender"),
+ : Thread("SignalSender"),
interval_(interval) {}
static void AddActiveSampler(Sampler* sampler) {
pthread_t thread_; // Thread handle for pthread.
};
-Thread::Thread(Isolate* isolate, const Options& options)
+Thread::Thread(const Options& options)
: data_(new PlatformData()),
- isolate_(isolate),
stack_size_(options.stack_size) {
set_name(options.name);
}
-Thread::Thread(Isolate* isolate, const char* name)
+Thread::Thread(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(NULL, "SignalSender"),
+ : Thread("SignalSender"),
vm_tgid_(getpid()),
interval_(interval) {}
pthread_t thread_; // Thread handle for pthread.
};
-Thread::Thread(Isolate* isolate, const Options& options)
+Thread::Thread(const Options& options)
: data_(new PlatformData),
- isolate_(isolate),
stack_size_(options.stack_size) {
set_name(options.name);
}
-Thread::Thread(Isolate* isolate, const char* name)
+Thread::Thread(const char* name)
: data_(new PlatformData),
- isolate_(isolate),
stack_size_(0) {
set_name(name);
}
thread->data()->thread_ = pthread_self();
SetThreadName(thread->name());
ASSERT(thread->data()->thread_ != kNoThread);
- Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
thread->Run();
return NULL;
}
class SamplerThread : public Thread {
public:
explicit SamplerThread(int interval)
- : Thread(NULL, "SamplerThread"),
+ : Thread("SamplerThread"),
interval_(interval) {}
static void AddActiveSampler(Sampler* sampler) {
};
-Thread::Thread(Isolate* isolate, const Options& options)
+Thread::Thread(const Options& options)
: data_(new PlatformData()),
- isolate_(isolate),
stack_size_(options.stack_size) {
set_name(options.name);
UNIMPLEMENTED();
}
-Thread::Thread(Isolate* isolate, const char* name)
+Thread::Thread(const char* name)
: data_(new PlatformData()),
- isolate_(isolate),
stack_size_(0) {
set_name(name);
UNIMPLEMENTED();
};
-Thread::Thread(Isolate* isolate, const Options& options)
+Thread::Thread(const Options& options)
: data_(new PlatformData),
- isolate_(isolate),
stack_size_(options.stack_size) {
set_name(options.name);
}
-Thread::Thread(Isolate* isolate, const char* name)
+Thread::Thread(const char* name)
: data_(new PlatformData),
- isolate_(isolate),
stack_size_(0) {
set_name(name);
}
// one) so we initialize it here too.
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(NULL, "SignalSender"),
+ : Thread("SignalSender"),
interval_(interval) {}
static void AddActiveSampler(Sampler* sampler) {
pthread_t thread_; // Thread handle for pthread.
};
-Thread::Thread(Isolate* isolate, const Options& options)
+Thread::Thread(const Options& options)
: data_(new PlatformData()),
- isolate_(isolate),
stack_size_(options.stack_size) {
set_name(options.name);
}
-Thread::Thread(Isolate* isolate, const char* name)
+Thread::Thread(const char* name)
: data_(new PlatformData()),
- isolate_(isolate),
stack_size_(0) {
set_name(name);
}
// convention.
static unsigned int __stdcall ThreadEntry(void* arg) {
Thread* thread = reinterpret_cast<Thread*>(arg);
- // This is also initialized by the last parameter to _beginthreadex() but we
- // don't know which thread will run first (the original thread or the new
- // one) so we initialize it here too.
- Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
thread->Run();
return 0;
}
// Initialize a Win32 thread object. The thread has an invalid thread
// handle until it is started.
-Thread::Thread(Isolate* isolate, const Options& options)
- : isolate_(isolate),
- stack_size_(options.stack_size) {
+Thread::Thread(const Options& options)
+ : stack_size_(options.stack_size) {
data_ = new PlatformData(kNoThread);
set_name(options.name);
}
-Thread::Thread(Isolate* isolate, const char* name)
- : isolate_(isolate),
- stack_size_(0) {
+Thread::Thread(const char* name)
+ : stack_size_(0) {
data_ = new PlatformData(kNoThread);
set_name(name);
}
class SamplerThread : public Thread {
public:
explicit SamplerThread(int interval)
- : Thread(NULL, "SamplerThread"),
+ : Thread("SamplerThread"),
interval_(interval) {}
static void AddActiveSampler(Sampler* sampler) {
int stack_size;
};
- // 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);
+ // Create new thread.
+ explicit Thread(const Options& options);
+ explicit Thread(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(isolate, "v8:CtxtSwitcher"),
+ : Thread("v8:CtxtSwitcher"),
keep_going_(true),
- sleep_ms_(every_n_ms) {
+ sleep_ms_(every_n_ms),
+ isolate_(isolate) {
}
static void PreemptionReceived();
private:
- explicit ContextSwitcher(Isolate* isolate, int every_n_ms);
+ ContextSwitcher(Isolate* isolate, int every_n_ms);
+
+ Isolate* isolate() const { return isolate_; }
void Run();
bool keep_going_;
int sleep_ms_;
+ Isolate* isolate_;
};
} } // namespace v8::internal
class ApiTestFuzzer: public v8::internal::Thread {
public:
void CallTest();
- explicit ApiTestFuzzer(v8::internal::Isolate* isolate, int num)
- : Thread(isolate, "ApiTestFuzzer"),
+ explicit ApiTestFuzzer(int num)
+ : Thread("ApiTestFuzzer"),
test_number_(num),
gate_(v8::internal::OS::CreateSemaphore(0)),
active_(true) {
test-api/Bug*: FAIL
##############################################################################
-# BUG(281): This test fails on some Linuxes.
-test-debug/DebuggerAgent: PASS, (PASS || FAIL) if $system == linux
-
# BUG(382): Weird test. Can't guarantee that it never times out.
test-api/ApplyInterruption: PASS || TIMEOUT
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::Isolate::Current(), i + start);
+ RegisterThreadedTest::nth(i)->fuzzer_ = new ApiTestFuzzer(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(i::Isolate::Current(), this);
+ GCThread gc_thread(this);
gc_thread.Start();
v8::Locker::StartPreemption(1);
class GCThread : public i::Thread {
public:
- explicit GCThread(i::Isolate* isolate, RegExpInterruptTest* test)
- : Thread(isolate, "GCThread"), test_(test) {}
+ explicit GCThread(RegExpInterruptTest* test)
+ : Thread("GCThread"), test_(test) {}
virtual void Run() {
test_->CollectGarbage();
}
gc_during_apply_ = 0;
apply_success_ = false;
gc_success_ = false;
- GCThread gc_thread(i::Isolate::Current(), this);
+ GCThread gc_thread(this);
gc_thread.Start();
v8::Locker::StartPreemption(1);
class GCThread : public i::Thread {
public:
- explicit GCThread(i::Isolate* isolate, ApplyInterruptTest* test)
- : Thread(isolate, "GCThread"), test_(test) {}
+ explicit GCThread(ApplyInterruptTest* test)
+ : Thread("GCThread"), test_(test) {}
virtual void Run() {
test_->CollectGarbage();
}
NONE,
i::kNonStrictMode)->ToObjectChecked();
- MorphThread morph_thread(i::Isolate::Current(), this);
+ MorphThread morph_thread(this);
morph_thread.Start();
v8::Locker::StartPreemption(1);
LongRunningRegExp();
class MorphThread : public i::Thread {
public:
- explicit MorphThread(i::Isolate* isolate,
- RegExpStringModificationTest* test)
- : Thread(isolate, "MorphThread"), test_(test) {}
+ explicit MorphThread(RegExpStringModificationTest* test)
+ : Thread("MorphThread"), test_(test) {}
virtual void Run() {
test_->MorphString();
}
class IsolateThread : public v8::internal::Thread {
public:
- explicit IsolateThread(v8::Isolate* isolate, int fib_limit)
- : Thread(NULL, "IsolateThread"),
+ IsolateThread(v8::Isolate* isolate, int fib_limit)
+ : Thread("IsolateThread"),
isolate_(isolate),
fib_limit_(fib_limit),
result_(0) { }
};
explicit InitDefaultIsolateThread(TestCase testCase)
- : Thread(NULL, "InitDefaultIsolateThread"),
+ : Thread("InitDefaultIsolateThread"),
testCase_(testCase),
result_(false) { }
public:
typedef SamplingCircularQueue::Cell Record;
- ProducerThread(i::Isolate* isolate,
- SamplingCircularQueue* scq,
+ ProducerThread(SamplingCircularQueue* scq,
int records_per_chunk,
Record value,
i::Semaphore* finished)
- : Thread(isolate, "producer"),
+ : Thread("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);
- 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);
+ ProducerThread producer1(&scq, kRecordsPerChunk, 1, semaphore);
+ ProducerThread producer2(&scq, kRecordsPerChunk, 10, semaphore);
+ ProducerThread producer3(&scq, kRecordsPerChunk, 20, semaphore);
CHECK_EQ(NULL, scq.StartDequeue());
producer1.Start();
TEST(StartStop) {
CpuProfilesCollection profiles;
ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
+ ProfilerEventsProcessor processor(&generator);
processor.Start();
processor.Stop();
processor.Join();
CpuProfilesCollection profiles;
profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
+ ProfilerEventsProcessor processor(&generator);
processor.Start();
// Enqueue code creation events.
CpuProfilesCollection profiles;
profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
+ ProfilerEventsProcessor processor(&generator);
processor.Start();
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
CpuProfilesCollection profiles;
profiles.StartProfiling("", 1);
ProfileGenerator generator(&profiles);
- ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
+ ProfilerEventsProcessor processor(&generator);
processor.Start();
processor.CodeCreateEvent(i::Logger::BUILTIN_TAG,
// placing JSON debugger commands in the queue.
class MessageQueueDebuggerThread : public v8::internal::Thread {
public:
- explicit MessageQueueDebuggerThread(v8::internal::Isolate* isolate)
- : Thread(isolate, "MessageQueueDebuggerThread") { }
+ MessageQueueDebuggerThread()
+ : Thread("MessageQueueDebuggerThread") { }
void Run();
};
// This thread runs the v8 engine.
TEST(MessageQueues) {
- MessageQueueDebuggerThread message_queue_debugger_thread(
- i::Isolate::Current());
+ MessageQueueDebuggerThread message_queue_debugger_thread;
// Create a V8 environment
v8::HandleScope scope;
class V8Thread : public v8::internal::Thread {
public:
- explicit V8Thread(v8::internal::Isolate* isolate)
- : Thread(isolate, "V8Thread") { }
+ V8Thread() : Thread("V8Thread") { }
void Run();
};
class DebuggerThread : public v8::internal::Thread {
public:
- explicit DebuggerThread(v8::internal::Isolate* isolate)
- : Thread(isolate, "DebuggerThread") { }
+ DebuggerThread() : Thread("DebuggerThread") { }
void Run();
};
"\n"
"foo();\n";
+ v8::V8::Initialize();
v8::HandleScope scope;
DebugLocalContext env;
v8::Debug::SetMessageHandler2(&ThreadedMessageHandler);
TEST(ThreadedDebugging) {
- DebuggerThread debugger_thread(i::Isolate::Current());
- V8Thread v8_thread(i::Isolate::Current());
+ DebuggerThread debugger_thread;
+ V8Thread v8_thread;
// Create a V8 environment
threaded_debugging_barriers.Initialize();
class BreakpointsV8Thread : public v8::internal::Thread {
public:
- explicit BreakpointsV8Thread(v8::internal::Isolate* isolate)
- : Thread(isolate, "BreakpointsV8Thread") { }
+ BreakpointsV8Thread() : Thread("BreakpointsV8Thread") { }
void Run();
};
class BreakpointsDebuggerThread : public v8::internal::Thread {
public:
- explicit BreakpointsDebuggerThread(v8::internal::Isolate* isolate,
- bool global_evaluate)
- : Thread(isolate, "BreakpointsDebuggerThread"),
+ explicit BreakpointsDebuggerThread(bool global_evaluate)
+ : Thread("BreakpointsDebuggerThread"),
global_evaluate_(global_evaluate) {}
void Run();
const char* source_2 = "cat(17);\n"
"cat(19);\n";
+ v8::V8::Initialize();
v8::HandleScope scope;
DebugLocalContext env;
v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler);
void TestRecursiveBreakpointsGeneric(bool global_evaluate) {
i::FLAG_debugger_auto_break = true;
- BreakpointsDebuggerThread breakpoints_debugger_thread(i::Isolate::Current(),
- global_evaluate);
- BreakpointsV8Thread breakpoints_v8_thread(i::Isolate::Current());
+ BreakpointsDebuggerThread breakpoints_debugger_thread(global_evaluate);
+ BreakpointsV8Thread breakpoints_v8_thread;
// Create a V8 environment
Barriers stack_allocated_breakpoints_barriers;
class HostDispatchV8Thread : public v8::internal::Thread {
public:
- explicit HostDispatchV8Thread(v8::internal::Isolate* isolate)
- : Thread(isolate, "HostDispatchV8Thread") { }
+ HostDispatchV8Thread() : Thread("HostDispatchV8Thread") { }
void Run();
};
class HostDispatchDebuggerThread : public v8::internal::Thread {
public:
- explicit HostDispatchDebuggerThread(v8::internal::Isolate* isolate)
- : Thread(isolate, "HostDispatchDebuggerThread") { }
+ HostDispatchDebuggerThread() : Thread("HostDispatchDebuggerThread") { }
void Run();
};
"\n";
const char* source_2 = "cat(17);\n";
+ v8::V8::Initialize();
v8::HandleScope scope;
DebugLocalContext env;
TEST(DebuggerHostDispatch) {
- HostDispatchDebuggerThread host_dispatch_debugger_thread(
- i::Isolate::Current());
- HostDispatchV8Thread host_dispatch_v8_thread(i::Isolate::Current());
+ HostDispatchDebuggerThread host_dispatch_debugger_thread;
+ HostDispatchV8Thread host_dispatch_v8_thread;
i::FLAG_debugger_auto_break = true;
// Create a V8 environment
class DebugMessageDispatchV8Thread : public v8::internal::Thread {
public:
- explicit DebugMessageDispatchV8Thread(v8::internal::Isolate* isolate)
- : Thread(isolate, "DebugMessageDispatchV8Thread") { }
+ DebugMessageDispatchV8Thread() : Thread("DebugMessageDispatchV8Thread") { }
void Run();
};
class DebugMessageDispatchDebuggerThread : public v8::internal::Thread {
public:
- explicit DebugMessageDispatchDebuggerThread(v8::internal::Isolate* isolate)
- : Thread(isolate, "DebugMessageDispatchDebuggerThread") { }
+ DebugMessageDispatchDebuggerThread()
+ : Thread("DebugMessageDispatchDebuggerThread") { }
void Run();
};
void DebugMessageDispatchV8Thread::Run() {
+ v8::V8::Initialize();
v8::HandleScope scope;
DebugLocalContext env;
TEST(DebuggerDebugMessageDispatch) {
- DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread(
- i::Isolate::Current());
- DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread(
- i::Isolate::Current());
+ DebugMessageDispatchDebuggerThread debug_message_dispatch_debugger_thread;
+ DebugMessageDispatchV8Thread debug_message_dispatch_v8_thread;
i::FLAG_debugger_auto_break = true;
// Test starting and stopping the agent without any client connection.
debugger->StartAgent("test", kPort1);
debugger->StopAgent();
-
// Test starting the agent, connecting a client and shutting down the agent
// with the client connected.
ok = debugger->StartAgent("test", kPort2);
i::Socket* client = i::OS::CreateSocket();
ok = client->Connect("localhost", port2_str);
CHECK(ok);
+ // It is important to wait for a message from the agent. Otherwise,
+ // we can close the server socket during "accept" syscall, making it failing
+ // (at least on Linux), and the test will work incorrectly.
+ char buf;
+ ok = client->Receive(&buf, 1) == 1;
+ CHECK(ok);
debugger->StopAgent();
delete client;
class DebuggerAgentProtocolServerThread : public i::Thread {
public:
- explicit DebuggerAgentProtocolServerThread(i::Isolate* isolate, int port)
- : Thread(isolate, "DebuggerAgentProtocolServerThread"),
+ explicit DebuggerAgentProtocolServerThread(int port)
+ : Thread("DebuggerAgentProtocolServerThread"),
port_(port),
server_(NULL),
client_(NULL),
// Create a socket server to receive a debugger agent message.
DebuggerAgentProtocolServerThread* server =
- new DebuggerAgentProtocolServerThread(i::Isolate::Current(), kPort);
+ new DebuggerAgentProtocolServerThread(kPort);
server->Start();
server->WaitForListening();
public:
KangarooThread(v8::Isolate* isolate,
v8::Handle<v8::Context> context, int value)
- : Thread(NULL, "KangarooThread"),
+ : Thread("KangarooThread"),
isolate_(isolate), context_(context), value_(value) {
}
class ThreadWithSemaphore : public i::Thread {
public:
explicit ThreadWithSemaphore(JoinableThread* joinable_thread)
- : Thread(NULL, joinable_thread->name_),
+ : Thread(joinable_thread->name_),
joinable_thread_(joinable_thread) {
}
class TestThread : public Thread {
public:
- TestThread() : Thread(NULL, "TestThread") {}
+ TestThread() : Thread("TestThread") {}
virtual void Run() {
DoTest();
class SocketListenerThread : public Thread {
public:
- explicit SocketListenerThread(Isolate* isolate, int port, int data_size)
- : Thread(isolate, "SocketListenerThread"),
+ SocketListenerThread(int port, int data_size)
+ : Thread("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(Isolate::Current(),
- port, len);
+ SocketListenerThread* listener = new SocketListenerThread(port, len);
listener->Start();
listener->WaitForListening();
class TerminatorThread : public v8::internal::Thread {
public:
explicit TerminatorThread(i::Isolate* isolate)
- : Thread(isolate, "TerminatorThread") { }
+ : Thread("TerminatorThread"),
+ isolate_(reinterpret_cast<v8::Isolate*>(isolate)) { }
void Run() {
semaphore->Wait();
- CHECK(!v8::V8::IsExecutionTerminating());
- v8::V8::TerminateExecution();
+ CHECK(!v8::V8::IsExecutionTerminating(isolate_));
+ v8::V8::TerminateExecution(isolate_);
}
+
+ private:
+ v8::Isolate* isolate_;
};
class LoopingThread : public v8::internal::Thread {
public:
- explicit LoopingThread(i::Isolate* isolate)
- : Thread(isolate, "LoopingThread") { }
+ LoopingThread() : Thread("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(i::Isolate::Current()));
+ threads.Add(new LoopingThread());
}
for (int i = 0; i < kThreads; i++) {
threads[i]->Start();
class ThreadA: public v8::internal::Thread {
public:
- explicit ThreadA(i::Isolate* isolate) : Thread(isolate, "ThreadA") { }
+ ThreadA() : Thread("ThreadA") { }
void Run() {
v8::Locker locker;
v8::HandleScope scope;
class ThreadB: public v8::internal::Thread {
public:
- explicit ThreadB(i::Isolate* isolate) : Thread(isolate, "ThreadB") { }
+ ThreadB() : Thread("ThreadB") { }
void Run() {
do {
{
TEST(JSFunctionResultCachesInTwoThreads) {
v8::V8::Initialize();
- ThreadA threadA(i::Isolate::Current());
- ThreadB threadB(i::Isolate::Current());
+ ThreadA threadA;
+ ThreadB threadB;
threadA.Start();
threadB.Start();
i::List<i::ThreadId>* refs,
unsigned int thread_no,
i::Semaphore* semaphore)
- : Thread(NULL, "ThreadRefValidationThread"),
+ : Thread("ThreadRefValidationThread"),
refs_(refs), thread_no_(thread_no), thread_to_start_(thread_to_start),
semaphore_(semaphore) {
}