Reviewers: Vitaly Repeshko,
Description:
[Isolates] Fix debugger and termination APIs callable from other threads.
A couple of debugger methods and one of the execution termination methods
can be
called from any thread. If they do not supply an isolate, use the default
isolate. This ensures backwards compatibility and gives the possibility of
specifying an isolate.
[email protected]
Please review this at http://codereview.chromium.org/6672044/
SVN Base: https://v8.googlecode.com/svn/branches/experimental/isolates
Affected files:
M include/v8-debug.h
M include/v8.h
M src/api.cc
M src/isolate.h
M src/isolate.cc
Index: include/v8-debug.h
diff --git a/include/v8-debug.h b/include/v8-debug.h
index
f17b848550d0f0736ebda3b7dfa3cd506227f4c4..607263145fa2bd2cf4620c13b33ce924dbe5ef09
100755
--- a/include/v8-debug.h
+++ b/include/v8-debug.h
@@ -254,16 +254,17 @@ class EXPORT Debug {
Handle<Value> data = Handle<Value>());
// Schedule a debugger break to happen when JavaScript code is run.
- static void DebugBreak();
+ static void DebugBreak(Isolate* isolate = NULL);
// Remove scheduled debugger break if it has not happened yet.
- static void CancelDebugBreak();
+ static void CancelDebugBreak(Isolate* isolate = NULL);
// Break execution of JavaScript (this method can be invoked from a
// non-VM thread) for further client command execution on a VM
// thread. Client data is then passed in EventDetails to
// EventCallback at the moment when the VM actually stops.
- static void DebugBreakForCommand(ClientData* data = NULL);
+ static void DebugBreakForCommand(ClientData* data = NULL,
+ Isolate* isolate = NULL);
// Message based interface. The message protocol is JSON. NOTE the
message
// handler thread is not supported any more parameter must be false.
Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index
9a8c59c1e674bc01664da26c90ca5aa8b70b524d..7dd27bf9828c9768caf0e3c581da6e4cdccd2120
100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -2948,7 +2948,7 @@ class V8EXPORT V8 {
* This method can be used by any thread even if that thread has not
* acquired the V8 lock with a Locker object.
*/
- static void TerminateExecution();
+ static void TerminateExecution(Isolate* isolate = NULL);
/**
* Is V8 terminating JavaScript execution.
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index
3f7a345b0ab0fc7b0ac1cb5d7d3b8c44798fa6f7..5dc78befa4e841fbd5db7b017d3292d2a8f8df5d
100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -4291,9 +4291,13 @@ void V8::TerminateExecution(int thread_id) {
}
-void V8::TerminateExecution() {
- if (!i::Isolate::Current()->IsInitialized()) return;
- i::Isolate::Current()->stack_guard()->TerminateExecution();
+void V8::TerminateExecution(Isolate* isolate) {
+ // If no isolate is supplied, use the default isolate.
+ if (isolate != NULL) {
+
reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->TerminateExecution();
+ } else {
+ i::Isolate::GetDefaultIsolateStackGuard()->TerminateExecution();
+ }
}
@@ -4558,20 +4562,35 @@ bool
Debug::SetDebugEventListener(v8::Handle<v8::Object> that,
}
-void Debug::DebugBreak() {
- if (!i::Isolate::Current()->IsInitialized()) return;
- i::Isolate::Current()->stack_guard()->DebugBreak();
+void Debug::DebugBreak(Isolate* isolate) {
+ // If no isolate is supplied, use the default isolate.
+ if (isolate != NULL) {
+ reinterpret_cast<i::Isolate*>(isolate)->stack_guard()->DebugBreak();
+ } else {
+ i::Isolate::GetDefaultIsolateStackGuard()->DebugBreak();
+ }
}
-void Debug::CancelDebugBreak() {
- i::Isolate::Current()->stack_guard()->Continue(i::DEBUGBREAK);
+void Debug::CancelDebugBreak(Isolate* isolate) {
+ // If no isolate is supplied, use the default isolate.
+ if (isolate != NULL) {
+ i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ internal_isolate->stack_guard()->Continue(i::DEBUGBREAK);
+ } else {
+ i::Isolate::GetDefaultIsolateStackGuard()->Continue(i::DEBUGBREAK);
+ }
}
-void Debug::DebugBreakForCommand(ClientData* data) {
- if (!i::Isolate::Current()->IsInitialized()) return;
- i::Isolate::Current()->debugger()->EnqueueDebugCommand(data);
+void Debug::DebugBreakForCommand(ClientData* data, Isolate* isolate) {
+ // If no isolate is supplied, use the default isolate.
+ if (isolate != NULL) {
+ i::Isolate* internal_isolate = reinterpret_cast<i::Isolate*>(isolate);
+ internal_isolate->debugger()->EnqueueDebugCommand(data);
+ } else {
+ i::Isolate::GetDefaultIsolateDebugger()->EnqueueDebugCommand(data);
+ }
}
Index: src/isolate.cc
diff --git a/src/isolate.cc b/src/isolate.cc
index
60077e495277f4b05552bf16963bffc59dc17601..171e9f38351a5bb0439ebc8e084db9fbabc30c0b
100644
--- a/src/isolate.cc
+++ b/src/isolate.cc
@@ -254,6 +254,18 @@ void Isolate::EnsureDefaultIsolate() {
}
+Debugger* Isolate::GetDefaultIsolateDebugger() {
+ EnsureDefaultIsolate();
+ return default_isolate_->debugger();
+}
+
+
+StackGuard* Isolate::GetDefaultIsolateStackGuard() {
+ EnsureDefaultIsolate();
+ return default_isolate_->stack_guard();
+}
+
+
void Isolate::EnterDefaultIsolate() {
EnsureDefaultIsolate();
ASSERT(default_isolate_ != NULL);
Index: src/isolate.h
diff --git a/src/isolate.h b/src/isolate.h
index
91bdb8102d5da6a769404d3b0ccd9eda091e5d71..b2d8d3982f5463720b310011ae20f54f9257a4e0
100644
--- a/src/isolate.h
+++ b/src/isolate.h
@@ -431,6 +431,14 @@ class Isolate {
// Safe to call multiple times.
static void EnsureDefaultIsolate();
+ // Get the debugger from the default isolate. Preinitializes the
+ // default isolate if needed.
+ static Debugger* GetDefaultIsolateDebugger();
+
+ // Get the stack guard from the default isolate. Preinitializes the
+ // default isolate if needed.
+ static StackGuard* GetDefaultIsolateStackGuard();
+
// Returns the key used to store the pointer to the current isolate.
// Used internally for V8 threads that do not execute JavaScript but
still
// are part of the domain of an isolate (like the context switcher).
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev