From ea5ab721e479a19257c14baa357be547825162af Mon Sep 17 00:00:00 2001 From: "yangguo@chromium.org" Date: Mon, 16 Sep 2013 15:34:46 +0000 Subject: [PATCH] Add mutex when accessing concurrent recompilation output queue. Also small refactorings. R=mstarzinger@chromium.org BUG=291236 Review URL: https://codereview.chromium.org/23902033 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@16740 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/execution.cc | 2 +- src/optimizing-compiler-thread.cc | 17 +++++++++++++---- src/optimizing-compiler-thread.h | 4 +++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/execution.cc b/src/execution.cc index 979641a..bb01dcf 100644 --- a/src/execution.cc +++ b/src/execution.cc @@ -952,7 +952,7 @@ MaybeObject* Execution::HandleStackGuardInterrupt(Isolate* isolate) { } if (stack_guard->IsInstallCodeRequest()) { ASSERT(FLAG_concurrent_recompilation); - stack_guard->Continue(INSTALL_CODE); + isolate_->stack_guard()->Continue(INSTALL_CODE); isolate->optimizing_compiler_thread()->InstallOptimizedFunctions(); } isolate->runtime_profiler()->OptimizeNow(); diff --git a/src/optimizing-compiler-thread.cc b/src/optimizing-compiler-thread.cc index 085143d..8d5e166 100644 --- a/src/optimizing-compiler-thread.cc +++ b/src/optimizing-compiler-thread.cc @@ -74,7 +74,6 @@ void OptimizingCompilerThread::Run() { { AllowHandleDereference allow_handle_dereference; FlushInputQueue(true); } - Release_Store(&queue_length_, static_cast(0)); Release_Store(&stop_thread_, static_cast(CONTINUE)); stop_semaphore_.Signal(); // Return to start of consumer loop. @@ -114,6 +113,7 @@ void OptimizingCompilerThread::CompileNext() { osr_candidates_.RemoveElement(optimizing_compiler); ready_for_osr_.Add(optimizing_compiler); } else { + LockGuard access_queue(&queue_mutex_); output_queue_.Enqueue(optimizing_compiler); isolate_->stack_guard()->RequestInstallCode(); } @@ -134,13 +134,20 @@ void OptimizingCompilerThread::FlushInputQueue(bool restore_function_code) { } delete info; } + Release_Store(&queue_length_, static_cast(0)); + + LockGuard access_osr_lists(&osr_list_mutex_); + osr_candidates_.Clear(); } void OptimizingCompilerThread::FlushOutputQueue(bool restore_function_code) { OptimizingCompiler* optimizing_compiler; // The optimizing compiler is allocated in the CompilationInfo's zone. - while (output_queue_.Dequeue(&optimizing_compiler)) { + while (true) { + { LockGuard access_queue(&queue_mutex_); + if (!output_queue_.Dequeue(&optimizing_compiler)) break; + } CompilationInfo* info = optimizing_compiler->info(); if (restore_function_code) { Handle function = info->closure(); @@ -149,7 +156,6 @@ void OptimizingCompilerThread::FlushOutputQueue(bool restore_function_code) { delete info; } - osr_candidates_.Clear(); RemoveStaleOSRCandidates(0); } @@ -196,9 +202,12 @@ void OptimizingCompilerThread::Stop() { void OptimizingCompilerThread::InstallOptimizedFunctions() { ASSERT(!IsOptimizerThread()); HandleScope handle_scope(isolate_); + OptimizingCompiler* compiler; while (true) { - if (!output_queue_.Dequeue(&compiler)) return; + { LockGuard access_queue(&queue_mutex_); + if (!output_queue_.Dequeue(&optimizing_compiler)) break; + } Compiler::InstallOptimizedCode(compiler); } diff --git a/src/optimizing-compiler-thread.h b/src/optimizing-compiler-thread.h index d1ed6a2..4231765 100644 --- a/src/optimizing-compiler-thread.h +++ b/src/optimizing-compiler-thread.h @@ -115,7 +115,7 @@ class OptimizingCompilerThread : public Thread { UnboundQueue input_queue_; // Queue of recompilation tasks ready to be installed (excluding OSR). UnboundQueue output_queue_; - // List of all OSR related recompilation tasks (both incoming and ready ones). + // List of recompilation tasks for OSR in the input queue. List osr_candidates_; // List of recompilation tasks ready for OSR. List ready_for_osr_; @@ -125,6 +125,8 @@ class OptimizingCompilerThread : public Thread { TimeDelta time_spent_compiling_; TimeDelta time_spent_total_; + // TODO(yangguo): remove this once the memory leak has been figured out. + Mutex queue_mutex_; Mutex osr_list_mutex_; int osr_hits_; int osr_attempts_; -- 2.7.4