Reviewers: Jakob,

Description:
Use mutex instead of busy wait when installing optimized function.

[email protected]
BUG=

Please review this at https://codereview.chromium.org/17099012/

SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge

Affected files:
  M src/optimizing-compiler-thread.h
  M src/optimizing-compiler-thread.cc
  M src/runtime.cc


Index: src/optimizing-compiler-thread.cc
diff --git a/src/optimizing-compiler-thread.cc b/src/optimizing-compiler-thread.cc index e092248b6f56613ee3b196bf08a0fd701bfade32..387575bf86ef323b9d88c9589e56a50b4e46e18a 100644
--- a/src/optimizing-compiler-thread.cc
+++ b/src/optimizing-compiler-thread.cc
@@ -89,8 +89,8 @@ void OptimizingCompilerThread::CompileNext() {
   ASSERT(status != OptimizingCompiler::FAILED);

   // The function may have already been optimized by OSR.  Simply continue.
- // Mark it for installing before queuing so that we can be sure of the write
-  // order: marking first and (after being queued) installing code second.
+  // Use a mutex to make sure that functions marked for install
+  // are always also queued.
   { Heap::RelocationLock relocation_lock(isolate_->heap());
     AllowHandleDereference ahd;
optimizing_compiler->info()->closure()->MarkForInstallingRecompiledCode();
@@ -127,11 +127,13 @@ void OptimizingCompilerThread::Stop() {
 void OptimizingCompilerThread::InstallOptimizedFunctions() {
   ASSERT(!IsOptimizerThread());
   HandleScope handle_scope(isolate_);
-  int functions_installed = 0;
   OptimizingCompiler* compiler;
-  while (output_queue_.Dequeue(&compiler)) {
+  while (true) {
+    { // Memory barrier to ensure marked functions are queued.
+      ScopedLock marked_and_queued(install_mutex_);
+      if (!output_queue_.Dequeue(&compiler)) return;
+    }
     Compiler::InstallOptimizedCode(compiler);
-    functions_installed++;
   }
 }

Index: src/optimizing-compiler-thread.h
diff --git a/src/optimizing-compiler-thread.h b/src/optimizing-compiler-thread.h index 8cb5e2dd59dec0e26d81984e8d929d3e613ae8c0..004fce7adac9253c5088dab83e13d46b0d3e2b60 100644
--- a/src/optimizing-compiler-thread.h
+++ b/src/optimizing-compiler-thread.h
@@ -50,6 +50,7 @@ class OptimizingCompilerThread : public Thread {
       isolate_(isolate),
       stop_semaphore_(OS::CreateSemaphore(0)),
       input_queue_semaphore_(OS::CreateSemaphore(0)),
+      install_mutex_(OS::CreateMutex()),
       time_spent_compiling_(0),
       time_spent_total_(0) {
     NoBarrier_Store(&stop_thread_, static_cast<AtomicWord>(false));
@@ -95,6 +96,7 @@ class OptimizingCompilerThread : public Thread {
   Semaphore* input_queue_semaphore_;
   UnboundQueue<OptimizingCompiler*> input_queue_;
   UnboundQueue<OptimizingCompiler*> output_queue_;
+  Mutex* install_mutex_;
   volatile AtomicWord stop_thread_;
   volatile Atomic32 queue_length_;
   int64_t time_spent_compiling_;
Index: src/runtime.cc
diff --git a/src/runtime.cc b/src/runtime.cc
index 0046ff667ead130fd9bb19c70caf972d90e17cd4..fc6ebb8bb5a02564e0a6b0224e432494e038fc33 100644
--- a/src/runtime.cc
+++ b/src/runtime.cc
@@ -7912,12 +7912,7 @@ RUNTIME_FUNCTION(MaybeObject*, Runtime_InstallRecompiledCode) {
   ASSERT(args.length() == 1);
   CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
   ASSERT(V8::UseCrankshaft() && FLAG_parallel_recompilation);
- OptimizingCompilerThread* opt_thread = isolate->optimizing_compiler_thread();
-  do {
- // The function could have been marked for installing, but not queued just
-    // yet.  In this case, retry until installed.
-    opt_thread->InstallOptimizedFunctions();
-  } while (function->IsMarkedForInstallingRecompiledCode());
+  isolate->optimizing_compiler_thread()->InstallOptimizedFunctions();
   return function->code();
 }



--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to