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
This commit is contained in:
yangguo@chromium.org 2013-09-16 15:34:46 +00:00
parent 42879d1038
commit ea5ab721e4
3 changed files with 17 additions and 6 deletions

View File

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

View File

@ -74,7 +74,6 @@ void OptimizingCompilerThread::Run() {
{ AllowHandleDereference allow_handle_dereference;
FlushInputQueue(true);
}
Release_Store(&queue_length_, static_cast<AtomicWord>(0));
Release_Store(&stop_thread_, static_cast<AtomicWord>(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<Mutex> 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<AtomicWord>(0));
LockGuard<Mutex> 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<Mutex> access_queue(&queue_mutex_);
if (!output_queue_.Dequeue(&optimizing_compiler)) break;
}
CompilationInfo* info = optimizing_compiler->info();
if (restore_function_code) {
Handle<JSFunction> 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<Mutex> access_queue(&queue_mutex_);
if (!output_queue_.Dequeue(&optimizing_compiler)) break;
}
Compiler::InstallOptimizedCode(compiler);
}

View File

@ -115,7 +115,7 @@ class OptimizingCompilerThread : public Thread {
UnboundQueue<OptimizingCompiler*> input_queue_;
// Queue of recompilation tasks ready to be installed (excluding OSR).
UnboundQueue<OptimizingCompiler*> 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<OptimizingCompiler*> osr_candidates_;
// List of recompilation tasks ready for OSR.
List<OptimizingCompiler*> 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_;