diff options
Diffstat (limited to 'deps/v8/src/optimizing-compiler-thread.cc')
-rw-r--r-- | deps/v8/src/optimizing-compiler-thread.cc | 37 |
1 files changed, 25 insertions, 12 deletions
diff --git a/deps/v8/src/optimizing-compiler-thread.cc b/deps/v8/src/optimizing-compiler-thread.cc index b2abc813ab..21ef237107 100644 --- a/deps/v8/src/optimizing-compiler-thread.cc +++ b/deps/v8/src/optimizing-compiler-thread.cc @@ -39,7 +39,9 @@ namespace internal { void OptimizingCompilerThread::Run() { #ifdef DEBUG - thread_id_ = ThreadId::Current().ToInteger(); + { ScopedLock lock(thread_id_mutex_); + thread_id_ = ThreadId::Current().ToInteger(); + } #endif Isolate::SetIsolateThreadLocals(isolate_, NULL); DisallowHeapAllocation no_allocation; @@ -89,8 +91,9 @@ 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. + ScopedLock mark_and_queue(install_mutex_); { Heap::RelocationLock relocation_lock(isolate_->heap()); AllowHandleDereference ahd; optimizing_compiler->info()->closure()->MarkForInstallingRecompiledCode(); @@ -106,12 +109,18 @@ void OptimizingCompilerThread::Stop() { stop_semaphore_->Wait(); if (FLAG_parallel_recompilation_delay != 0) { - InstallOptimizedFunctions(); // Barrier when loading queue length is not necessary since the write // happens in CompileNext on the same thread. - while (NoBarrier_Load(&queue_length_) > 0) { - CompileNext(); - InstallOptimizedFunctions(); + while (NoBarrier_Load(&queue_length_) > 0) CompileNext(); + InstallOptimizedFunctions(); + } else { + OptimizingCompiler* optimizing_compiler; + // The optimizing compiler is allocated in the CompilationInfo's zone. + while (input_queue_.Dequeue(&optimizing_compiler)) { + delete optimizing_compiler->info(); + } + while (output_queue_.Dequeue(&optimizing_compiler)) { + delete optimizing_compiler->info(); } } @@ -121,18 +130,21 @@ void OptimizingCompilerThread::Stop() { double percentage = (compile_time * 100) / total_time; PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage); } + + Join(); } void OptimizingCompilerThread::InstallOptimizedFunctions() { ASSERT(!IsOptimizerThread()); HandleScope handle_scope(isolate_); - int functions_installed = 0; - while (!output_queue_.IsEmpty()) { - OptimizingCompiler* compiler; - output_queue_.Dequeue(&compiler); + OptimizingCompiler* 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++; } } @@ -151,6 +163,7 @@ void OptimizingCompilerThread::QueueForOptimization( #ifdef DEBUG bool OptimizingCompilerThread::IsOptimizerThread() { if (!FLAG_parallel_recompilation) return false; + ScopedLock lock(thread_id_mutex_); return ThreadId::Current().ToInteger() == thread_id_; } #endif |