Revision: 8259
Author:   [email protected]
Date:     Fri Jun 10 02:54:04 2011
Log:      "Deiceolate" Thread classes.

Thread class was receiving an isolate parameter by default.
This approact violates the assumption that only VM threads
can have an associated isolate, and can lead to troubles,
because accessing the same isolate from different threads
leads to race conditions.

This was found by investigating mysterious failures of the
CPU profiler layout test on Linux Chromium. As almost all
threads were associated with some isolate, the sampler was
trying to sample them.

As a side effect, we have also fixed the DebuggerAgent test.

Thanks to Vitaly for help in fixing isolates handling!

[email protected]
BUG=none
TEST=none
http://code.google.com/p/v8/source/detail?r=8259

Modified:
 /branches/bleeding_edge/include/v8.h
 /branches/bleeding_edge/samples/shell.cc
 /branches/bleeding_edge/src/api.cc
 /branches/bleeding_edge/src/cpu-profiler.cc
 /branches/bleeding_edge/src/cpu-profiler.h
 /branches/bleeding_edge/src/debug-agent.cc
 /branches/bleeding_edge/src/debug-agent.h
 /branches/bleeding_edge/src/debug.cc
 /branches/bleeding_edge/src/debug.h
 /branches/bleeding_edge/src/isolate.cc
 /branches/bleeding_edge/src/isolate.h
 /branches/bleeding_edge/src/log.cc
 /branches/bleeding_edge/src/platform-cygwin.cc
 /branches/bleeding_edge/src/platform-freebsd.cc
 /branches/bleeding_edge/src/platform-linux.cc
 /branches/bleeding_edge/src/platform-macos.cc
 /branches/bleeding_edge/src/platform-nullos.cc
 /branches/bleeding_edge/src/platform-openbsd.cc
 /branches/bleeding_edge/src/platform-solaris.cc
 /branches/bleeding_edge/src/platform-win32.cc
 /branches/bleeding_edge/src/platform.h
 /branches/bleeding_edge/src/v8threads.cc
 /branches/bleeding_edge/src/v8threads.h
 /branches/bleeding_edge/test/cctest/cctest.h
 /branches/bleeding_edge/test/cctest/cctest.status
 /branches/bleeding_edge/test/cctest/test-api.cc
 /branches/bleeding_edge/test/cctest/test-circular-queue.cc
 /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc
 /branches/bleeding_edge/test/cctest/test-debug.cc
 /branches/bleeding_edge/test/cctest/test-lockers.cc
 /branches/bleeding_edge/test/cctest/test-platform-tls.cc
 /branches/bleeding_edge/test/cctest/test-sockets.cc
 /branches/bleeding_edge/test/cctest/test-thread-termination.cc
 /branches/bleeding_edge/test/cctest/test-threads.cc

=======================================
--- /branches/bleeding_edge/include/v8.h        Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/include/v8.h        Fri Jun 10 02:54:04 2011
@@ -3098,8 +3098,10 @@
    * 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
=======================================
--- /branches/bleeding_edge/samples/shell.cc    Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/samples/shell.cc    Fri Jun 10 02:54:04 2011
@@ -170,7 +170,7 @@
   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();
=======================================
--- /branches/bleeding_edge/src/api.cc  Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/api.cc  Fri Jun 10 02:54:04 2011
@@ -4902,9 +4902,10 @@
 }


-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);
 }


=======================================
--- /branches/bleeding_edge/src/cpu-profiler.cc Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/cpu-profiler.cc Fri Jun 10 02:54:04 2011
@@ -46,9 +46,8 @@
 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),
@@ -507,7 +506,7 @@
     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.
=======================================
--- /branches/bleeding_edge/src/cpu-profiler.h  Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/cpu-profiler.h  Fri Jun 10 02:54:04 2011
@@ -134,8 +134,7 @@
 // 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.
=======================================
--- /branches/bleeding_edge/src/debug-agent.cc  Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/debug-agent.cc  Fri Jun 10 02:54:04 2011
@@ -116,8 +116,8 @@
   }

   // 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();
 }

@@ -203,7 +203,9 @@

     // 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.
=======================================
--- /branches/bleeding_edge/src/debug-agent.h   Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/debug-agent.h   Fri Jun 10 02:54:04 2011
@@ -43,23 +43,26 @@
 // 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();
@@ -68,6 +71,7 @@
   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.
@@ -88,8 +92,8 @@
 // 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);
=======================================
--- /branches/bleeding_edge/src/debug.cc        Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/debug.cc        Fri Jun 10 02:54:04 2011
@@ -796,7 +796,6 @@
   // 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
@@ -1048,7 +1047,6 @@

 // 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_);

@@ -1234,7 +1232,6 @@


 void Debug::PrepareStep(StepAction step_action, int step_count) {
-  ASSERT(Isolate::Current() == isolate_);
   HandleScope scope(isolate_);
   ASSERT(Debug::InDebugger());

@@ -1739,7 +1736,6 @@


 void Debug::SetAfterBreakTarget(JavaScriptFrame* frame) {
-  ASSERT(Isolate::Current() == isolate_);
   HandleScope scope(isolate_);

   // Get the executing function in which the debug break occurred.
@@ -1872,7 +1868,6 @@


 void Debug::ClearMirrorCache() {
-  ASSERT(Isolate::Current() == isolate_);
   PostponeInterruptsScope postpone(isolate_);
   HandleScope scope(isolate_);
   ASSERT(isolate_->context() == *Debug::debug_context());
@@ -1892,7 +1887,6 @@


 void Debug::CreateScriptCache() {
-  ASSERT(Isolate::Current() == isolate_);
   Heap* heap = isolate_->heap();
   HandleScope scope(isolate_);

@@ -1934,7 +1928,6 @@


 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) {
@@ -1964,7 +1957,7 @@
 }


-Debugger::Debugger()
+Debugger::Debugger(Isolate* isolate)
     : debugger_access_(OS::CreateMutex()),
       event_listener_(Handle<Object>()),
       event_listener_data_(Handle<Object>()),
@@ -1979,9 +1972,10 @@
       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) {
 }


@@ -1998,7 +1992,6 @@
 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.
@@ -2020,7 +2013,6 @@


 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());
@@ -2034,7 +2026,6 @@
 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(),
@@ -2050,7 +2041,6 @@
                                             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;
@@ -2065,7 +2055,6 @@

 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() };
@@ -2077,7 +2066,6 @@
 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);
@@ -2097,7 +2085,6 @@

 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));
@@ -2112,7 +2099,6 @@


 void Debugger::OnException(Handle<Object> exception, bool uncaught) {
-  ASSERT(Isolate::Current() == isolate_);
   HandleScope scope(isolate_);
   Debug* debug = isolate_->debug();

@@ -2157,7 +2143,6 @@

 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.
@@ -2167,7 +2152,7 @@
   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;
@@ -2190,7 +2175,6 @@


 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
@@ -2220,7 +2204,6 @@
 // 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();

@@ -2289,7 +2272,6 @@


 void Debugger::OnScriptCollected(int id) {
-  ASSERT(Isolate::Current() == isolate_);
   HandleScope scope(isolate_);

   // No more to do if not debugging.
@@ -2319,7 +2301,6 @@
 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.
@@ -2395,7 +2376,6 @@
                                    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.
@@ -2411,7 +2391,6 @@


 Handle<Context> Debugger::GetDebugContext() {
-  ASSERT(Isolate::Current() == isolate_);
   never_unload_debugger_ = true;
   EnterDebugger debugger;
   return isolate_->debug()->debug_context();
@@ -2419,7 +2398,6 @@


 void Debugger::UnloadDebugger() {
-  ASSERT(Isolate::Current() == isolate_);
   Debug* debug = isolate_->debug();

   // Make sure that there are no breakpoints left.
@@ -2439,7 +2417,6 @@
                                     Handle<JSObject> exec_state,
                                     Handle<JSObject> event_data,
                                     bool auto_continue) {
-  ASSERT(Isolate::Current() == isolate_);
   HandleScope scope(isolate_);

   if (!isolate_->debug()->Load()) return;
@@ -2535,7 +2512,8 @@

     // 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();
@@ -2609,7 +2587,6 @@

 void Debugger::SetEventListener(Handle<Object> callback,
                                 Handle<Object> data) {
-  ASSERT(Isolate::Current() == isolate_);
   HandleScope scope(isolate_);
   GlobalHandles* global_handles = isolate_->global_handles();

@@ -2643,7 +2620,6 @@


 void Debugger::SetMessageHandler(v8::Debug::MessageHandler2 handler) {
-  ASSERT(Isolate::Current() == isolate_);
   ScopedLock with(debugger_access_);

   message_handler_ = handler;
@@ -2659,7 +2635,6 @@


 void Debugger::ListenersChanged() {
-  ASSERT(Isolate::Current() == isolate_);
   if (IsDebuggerActive()) {
     // Disable the compilation cache when the debugger is active.
     isolate_->compilation_cache()->Disable();
@@ -2675,7 +2650,6 @@

void Debugger::SetHostDispatchHandler(v8::Debug::HostDispatchHandler handler,
                                       int period) {
-  ASSERT(Isolate::Current() == isolate_);
   host_dispatch_handler_ = handler;
   host_dispatch_micros_ = period * 1000;
 }
@@ -2683,7 +2657,6 @@

 void Debugger::SetDebugMessageDispatchHandler(
     v8::Debug::DebugMessageDispatchHandler handler, bool provide_locker) {
-  ASSERT(Isolate::Current() == isolate_);
   ScopedLock with(dispatch_handler_access_);
   debug_message_dispatch_handler_ = handler;

@@ -2697,7 +2670,6 @@
 // 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) {
@@ -2712,13 +2684,12 @@
 // 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();

@@ -2742,13 +2713,11 @@


 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);

@@ -2760,7 +2729,6 @@


 bool Debugger::IsDebuggerActive() {
-  ASSERT(Isolate::Current() == isolate_);
   ScopedLock with(debugger_access_);

   return message_handler_ != NULL || !event_listener_.is_null();
@@ -2770,7 +2738,6 @@
 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;

@@ -2820,7 +2787,7 @@

   if (Socket::Setup()) {
     if (agent_ == NULL) {
-      agent_ = new DebuggerAgent(isolate_, name, port);
+      agent_ = new DebuggerAgent(name, port);
       agent_->Start();
     }
     return true;
@@ -2849,7 +2816,6 @@


 void Debugger::CallMessageDispatchHandler() {
-  ASSERT(Isolate::Current() == isolate_);
   v8::Debug::DebugMessageDispatchHandler handler;
   {
     ScopedLock with(dispatch_handler_access_);
@@ -3083,8 +3049,8 @@
 }


-LockingCommandMessageQueue::LockingCommandMessageQueue(int size)
-    : queue_(size) {
+LockingCommandMessageQueue::LockingCommandMessageQueue(Logger* logger, int size)
+    : logger_(logger), queue_(size) {
   lock_ = OS::CreateMutex();
 }

@@ -3103,7 +3069,7 @@
 CommandMessage LockingCommandMessageQueue::Get() {
   ScopedLock sl(lock_);
   CommandMessage result = queue_.Get();
-  LOGGER->DebugEvent("Get", result.text());
+  logger_->DebugEvent("Get", result.text());
   return result;
 }

@@ -3111,7 +3077,7 @@
 void LockingCommandMessageQueue::Put(const CommandMessage& message) {
   ScopedLock sl(lock_);
   queue_.Put(message);
-  LOGGER->DebugEvent("Put", message.text());
+  logger_->DebugEvent("Put", message.text());
 }


@@ -3122,7 +3088,7 @@


 MessageDispatchHelperThread::MessageDispatchHelperThread(Isolate* isolate)
-    : Thread(isolate, "v8:MsgDispHelpr"),
+    : Thread("v8:MsgDispHelpr"),
       sem_(OS::CreateSemaphore(0)), mutex_(OS::CreateMutex()),
       already_signalled_(false) {
 }
=======================================
--- /branches/bleeding_edge/src/debug.h Thu May  5 23:50:20 2011
+++ /branches/bleeding_edge/src/debug.h Fri Jun 10 02:54:04 2011
@@ -678,13 +678,14 @@
 // 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);
@@ -811,7 +812,7 @@
   bool IsDebuggerActive();

  private:
-  Debugger();
+  explicit Debugger(Isolate* isolate);

   void CallEventCallback(v8::DebugEvent event,
                          Handle<Object> exec_state,
=======================================
--- /branches/bleeding_edge/src/isolate.cc      Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/isolate.cc      Fri Jun 10 02:54:04 2011
@@ -190,8 +190,8 @@


  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)),
@@ -219,7 +219,7 @@

 void Isolate::PreallocatedMemoryThreadStart() {
   if (preallocated_memory_thread_ != NULL) return;
-  preallocated_memory_thread_ = new PreallocatedMemoryThread(this);
+  preallocated_memory_thread_ = new PreallocatedMemoryThread();
   preallocated_memory_thread_->Start();
 }

@@ -1617,8 +1617,7 @@
   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();
=======================================
--- /branches/bleeding_edge/src/isolate.h       Tue Jun  7 11:33:03 2011
+++ /branches/bleeding_edge/src/isolate.h       Fri Jun 10 02:54:04 2011
@@ -595,7 +595,7 @@
     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();
=======================================
--- /branches/bleeding_edge/src/log.cc  Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/log.cc  Fri Jun 10 02:54:04 2011
@@ -122,6 +122,7 @@
   // 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;
@@ -271,7 +272,8 @@
 // Profiler implementation.
 //
 Profiler::Profiler(Isolate* isolate)
-    : Thread(isolate, "v8:Profiler"),
+    : Thread("v8:Profiler"),
+      isolate_(isolate),
       head_(0),
       tail_(0),
       overflow_(false),
@@ -326,9 +328,8 @@
 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);
   }
 }
@@ -1842,9 +1843,9 @@

   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);
   }
=======================================
--- /branches/bleeding_edge/src/platform-cygwin.cc      Mon Apr 11 16:46:22 2011
+++ /branches/bleeding_edge/src/platform-cygwin.cc      Fri Jun 10 02:54:04 2011
@@ -371,17 +371,15 @@



-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);
 }
@@ -399,7 +397,6 @@
   // 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;
 }
@@ -631,7 +628,7 @@
 class SamplerThread : public Thread {
  public:
   explicit SamplerThread(int interval)
-      : Thread(NULL, "SamplerThread"),
+      : Thread("SamplerThread"),
         interval_(interval) {}

   static void AddActiveSampler(Sampler* sampler) {
=======================================
--- /branches/bleeding_edge/src/platform-freebsd.cc     Sun May  8 07:50:09 2011
+++ /branches/bleeding_edge/src/platform-freebsd.cc     Fri Jun 10 02:54:04 2011
@@ -398,17 +398,15 @@
 };


-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);
 }
@@ -426,7 +424,6 @@
   // 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;
 }
@@ -660,7 +657,7 @@
   };

   explicit SignalSender(int interval)
-      : Thread(NULL, "SignalSender"),
+      : Thread("SignalSender"),
         interval_(interval) {}

   static void AddActiveSampler(Sampler* sampler) {
=======================================
--- /branches/bleeding_edge/src/platform-linux.cc       Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/platform-linux.cc       Fri Jun 10 02:54:04 2011
@@ -653,17 +653,15 @@
   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);
 }
@@ -684,7 +682,6 @@
         0, 0, 0);
   thread->data()->thread_ = pthread_self();
   ASSERT(thread->data()->thread_ != kNoThread);
-  Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
   thread->Run();
   return NULL;
 }
@@ -974,7 +971,7 @@
   };

   explicit SignalSender(int interval)
-      : Thread(NULL, "SignalSender"),
+      : Thread("SignalSender"),
         vm_tgid_(getpid()),
         interval_(interval) {}

=======================================
--- /branches/bleeding_edge/src/platform-macos.cc       Mon Apr 11 16:46:22 2011
+++ /branches/bleeding_edge/src/platform-macos.cc       Fri Jun 10 02:54:04 2011
@@ -398,17 +398,15 @@
   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);
 }
@@ -444,7 +442,6 @@
   thread->data()->thread_ = pthread_self();
   SetThreadName(thread->name());
   ASSERT(thread->data()->thread_ != kNoThread);
-  Thread::SetThreadLocal(Isolate::isolate_key(), thread->isolate());
   thread->Run();
   return NULL;
 }
@@ -670,7 +667,7 @@
 class SamplerThread : public Thread {
  public:
   explicit SamplerThread(int interval)
-      : Thread(NULL, "SamplerThread"),
+      : Thread("SamplerThread"),
         interval_(interval) {}

   static void AddActiveSampler(Sampler* sampler) {
=======================================
--- /branches/bleeding_edge/src/platform-nullos.cc      Fri Apr 29 01:50:38 2011
+++ /branches/bleeding_edge/src/platform-nullos.cc      Fri Jun 10 02:54:04 2011
@@ -314,18 +314,16 @@
 };


-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();
=======================================
--- /branches/bleeding_edge/src/platform-openbsd.cc     Tue Jun  7 00:17:46 2011
+++ /branches/bleeding_edge/src/platform-openbsd.cc     Fri Jun 10 02:54:04 2011
@@ -396,17 +396,15 @@
 };


-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);
 }
@@ -424,7 +422,6 @@
   // 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;
 }
@@ -661,7 +658,7 @@
   };

   explicit SignalSender(int interval)
-      : Thread(NULL, "SignalSender"),
+      : Thread("SignalSender"),
         interval_(interval) {}

   static void AddActiveSampler(Sampler* sampler) {
=======================================
--- /branches/bleeding_edge/src/platform-solaris.cc     Mon Apr 11 16:46:22 2011
+++ /branches/bleeding_edge/src/platform-solaris.cc     Fri Jun 10 02:54:04 2011
@@ -380,17 +380,15 @@
   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);
 }
=======================================
--- /branches/bleeding_edge/src/platform-win32.cc       Wed Jun  8 00:28:31 2011
+++ /branches/bleeding_edge/src/platform-win32.cc       Fri Jun 10 02:54:04 2011
@@ -1473,10 +1473,6 @@
 // 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;
 }
@@ -1492,17 +1488,15 @@
 // 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);
 }
@@ -1871,7 +1865,7 @@
 class SamplerThread : public Thread {
  public:
   explicit SamplerThread(int interval)
-      : Thread(NULL, "SamplerThread"),
+      : Thread("SamplerThread"),
         interval_(interval) {}

   static void AddActiveSampler(Sampler* sampler) {
=======================================
--- /branches/bleeding_edge/src/platform.h      Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/platform.h      Fri Jun 10 02:54:04 2011
@@ -384,9 +384,9 @@
     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.
@@ -433,7 +433,6 @@
   // 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().
@@ -447,7 +446,6 @@

   PlatformData* data_;

-  Isolate* isolate_;
   char name_[kMaxThreadNameLength];
   int stack_size_;

=======================================
--- /branches/bleeding_edge/src/v8threads.cc    Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/v8threads.cc    Fri Jun 10 02:54:04 2011
@@ -401,9 +401,10 @@


 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) {
 }


=======================================
--- /branches/bleeding_edge/src/v8threads.h     Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/src/v8threads.h     Fri Jun 10 02:54:04 2011
@@ -152,12 +152,15 @@
   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
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.h        Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/test/cctest/cctest.h        Fri Jun 10 02:54:04 2011
@@ -87,8 +87,8 @@
 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) {
=======================================
--- /branches/bleeding_edge/test/cctest/cctest.status Tue May 31 04:54:46 2011 +++ /branches/bleeding_edge/test/cctest/cctest.status Fri Jun 10 02:54:04 2011
@@ -30,9 +30,6 @@
 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

=======================================
--- /branches/bleeding_edge/test/cctest/test-api.cc     Fri Jun 10 02:42:08 2011
+++ /branches/bleeding_edge/test/cctest/test-api.cc     Fri Jun 10 02:54:04 2011
@@ -9342,8 +9342,7 @@
   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();
@@ -10459,7 +10458,7 @@
     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);

@@ -10479,8 +10478,8 @@

   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();
     }
@@ -10582,7 +10581,7 @@
     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);

@@ -10602,8 +10601,8 @@

   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();
     }
@@ -10877,7 +10876,7 @@
         NONE,
         i::kNonStrictMode)->ToObjectChecked();

-    MorphThread morph_thread(i::Isolate::Current(), this);
+    MorphThread morph_thread(this);
     morph_thread.Start();
     v8::Locker::StartPreemption(1);
     LongRunningRegExp();
@@ -10897,9 +10896,8 @@

   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();
     }
@@ -13716,8 +13714,8 @@

 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) { }
@@ -13797,7 +13795,7 @@
   };

   explicit InitDefaultIsolateThread(TestCase testCase)
-      : Thread(NULL, "InitDefaultIsolateThread"),
+      : Thread("InitDefaultIsolateThread"),
         testCase_(testCase),
         result_(false) { }

=======================================
--- /branches/bleeding_edge/test/cctest/test-circular-queue.cc Fri Jun 10 02:42:08 2011 +++ /branches/bleeding_edge/test/cctest/test-circular-queue.cc Fri Jun 10 02:54:04 2011
@@ -84,12 +84,11 @@
  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),
@@ -133,10 +132,9 @@
   // 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();
=======================================
--- /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Fri Jun 10 02:42:08 2011 +++ /branches/bleeding_edge/test/cctest/test-cpu-profiler.cc Fri Jun 10 02:54:04 2011
@@ -24,7 +24,7 @@
 TEST(StartStop) {
   CpuProfilesCollection profiles;
   ProfileGenerator generator(&profiles);
-  ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
+  ProfilerEventsProcessor processor(&generator);
   processor.Start();
   processor.Stop();
   processor.Join();
@@ -85,7 +85,7 @@
   CpuProfilesCollection profiles;
   profiles.StartProfiling("", 1);
   ProfileGenerator generator(&profiles);
-  ProfilerEventsProcessor processor(i::Isolate::Current(), &generator);
+  ProfilerEventsProcessor processor(&generator);
   processor.Start();

   // Enqueue code creation events.
@@ -146,7 +146,7 @@
   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,
@@ -236,7 +236,7 @@
   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,
=======================================
--- /branches/bleeding_edge/test/cctest/test-debug.cc Fri Jun 10 02:42:08 2011 +++ /branches/bleeding_edge/test/cctest/test-debug.cc Fri Jun 10 02:54:04 2011
@@ -4728,8 +4728,8 @@
 // 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();
 };

@@ -4832,8 +4832,7 @@

 // 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;
@@ -4980,15 +4979,13 @@

 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();
 };

@@ -5032,6 +5029,7 @@
       "\n"
       "foo();\n";

+  v8::V8::Initialize();
   v8::HandleScope scope;
   DebugLocalContext env;
   v8::Debug::SetMessageHandler2(&ThreadedMessageHandler);
@@ -5065,8 +5063,8 @@


 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();
@@ -5087,16 +5085,14 @@

 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();

@@ -5146,6 +5142,7 @@
   const char* source_2 = "cat(17);\n"
     "cat(19);\n";

+  v8::V8::Initialize();
   v8::HandleScope scope;
   DebugLocalContext env;
   v8::Debug::SetMessageHandler2(&BreakpointsMessageHandler);
@@ -5273,9 +5270,8 @@
 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;
@@ -5657,15 +5653,13 @@

 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();
 };

@@ -5695,6 +5689,7 @@
     "\n";
   const char* source_2 = "cat(17);\n";

+  v8::V8::Initialize();
   v8::HandleScope scope;
   DebugLocalContext env;

@@ -5737,9 +5732,8 @@


 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
@@ -5763,15 +5757,14 @@

 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();
 };

@@ -5784,6 +5777,7 @@


 void DebugMessageDispatchV8Thread::Run() {
+  v8::V8::Initialize();
   v8::HandleScope scope;
   DebugLocalContext env;

@@ -5805,10 +5799,8 @@


 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;

@@ -5847,7 +5839,6 @@
   // 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);
@@ -5856,6 +5847,12 @@
   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;

@@ -5873,8 +5870,8 @@

 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),
@@ -5939,7 +5936,7 @@

   // 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();

=======================================
--- /branches/bleeding_edge/test/cctest/test-lockers.cc Fri Jun 10 02:42:08 2011 +++ /branches/bleeding_edge/test/cctest/test-lockers.cc Fri Jun 10 02:54:04 2011
@@ -64,7 +64,7 @@
  public:
   KangarooThread(v8::Isolate* isolate,
                  v8::Handle<v8::Context> context, int value)
-      : Thread(NULL, "KangarooThread"),
+      : Thread("KangarooThread"),
         isolate_(isolate), context_(context), value_(value) {
   }

@@ -150,7 +150,7 @@
   class ThreadWithSemaphore : public i::Thread {
    public:
     explicit ThreadWithSemaphore(JoinableThread* joinable_thread)
-      : Thread(NULL, joinable_thread->name_),
+      : Thread(joinable_thread->name_),
         joinable_thread_(joinable_thread) {
     }

=======================================
--- /branches/bleeding_edge/test/cctest/test-platform-tls.cc Fri Jun 10 02:42:08 2011 +++ /branches/bleeding_edge/test/cctest/test-platform-tls.cc Fri Jun 10 02:54:04 2011
@@ -48,7 +48,7 @@

 class TestThread : public Thread {
  public:
-  TestThread() : Thread(NULL, "TestThread") {}
+  TestThread() : Thread("TestThread") {}

   virtual void Run() {
     DoTest();
=======================================
--- /branches/bleeding_edge/test/cctest/test-sockets.cc Fri Jun 10 02:42:08 2011 +++ /branches/bleeding_edge/test/cctest/test-sockets.cc Fri Jun 10 02:54:04 2011
@@ -10,8 +10,8 @@

 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),
@@ -92,8 +92,7 @@
   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();

=======================================
--- /branches/bleeding_edge/test/cctest/test-thread-termination.cc Fri Jun 10 02:42:08 2011 +++ /branches/bleeding_edge/test/cctest/test-thread-termination.cc Fri Jun 10 02:54:04 2011
@@ -161,12 +161,16 @@
 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_;
 };


@@ -196,8 +200,7 @@

 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;
@@ -233,7 +236,7 @@
   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();
=======================================
--- /branches/bleeding_edge/test/cctest/test-threads.cc Fri Jun 10 02:42:08 2011 +++ /branches/bleeding_edge/test/cctest/test-threads.cc Fri Jun 10 02:54:04 2011
@@ -65,7 +65,7 @@

 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;
@@ -101,7 +101,7 @@

 class ThreadB: public v8::internal::Thread {
  public:
-  explicit ThreadB(i::Isolate* isolate) : Thread(isolate, "ThreadB") { }
+  ThreadB() : Thread("ThreadB") { }
   void Run() {
     do {
       {
@@ -126,8 +126,8 @@
 TEST(JSFunctionResultCachesInTwoThreads) {
   v8::V8::Initialize();

-  ThreadA threadA(i::Isolate::Current());
-  ThreadB threadB(i::Isolate::Current());
+  ThreadA threadA;
+  ThreadB threadB;

   threadA.Start();
   threadB.Start();
@@ -144,7 +144,7 @@
                            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) {
   }

--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to