Chromium Code Reviews| Index: src/optimizing-compiler-thread.cc |
| diff --git a/src/optimizing-compiler-thread.cc b/src/optimizing-compiler-thread.cc |
| index 029c115fcab978f1beef82e7fcfdeca2c83efde3..7907b736cea26b5d81df4290148224ace7a0ca6c 100644 |
| --- a/src/optimizing-compiler-thread.cc |
| +++ b/src/optimizing-compiler-thread.cc |
| @@ -29,6 +29,7 @@ |
| #include "v8.h" |
| +#include "full-codegen.h" |
| #include "hydrogen.h" |
| #include "isolate.h" |
| #include "v8threads.h" |
| @@ -107,16 +108,20 @@ void OptimizingCompilerThread::CompileNext() { |
| // The function may have already been optimized by OSR. Simply continue. |
| // Use a mutex to make sure that functions marked for install |
| // are always also queued. |
| - if (!optimizing_compiler->info()->osr_ast_id().IsNone()) { |
| - ASSERT(FLAG_concurrent_osr); |
| - LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
| - 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(); |
| + LockGuard<Mutex> access_queue(&queue_mutex_); |
| + output_queue_.Enqueue(optimizing_compiler); |
| + isolate_->stack_guard()->RequestInstallCode(); |
| +} |
| + |
| + |
| +static void DisposeOptimizingCompiler(OptimizingCompiler* compiler, |
| + bool restore_function_code) { |
| + CompilationInfo* info = compiler->info(); |
| + if (restore_function_code) { |
| + Handle<JSFunction> function = info->closure(); |
| + function->ReplaceCode(function->shared()->code()); |
| } |
| + delete info; |
| } |
| @@ -127,16 +132,10 @@ void OptimizingCompilerThread::FlushInputQueue(bool restore_function_code) { |
| // This should not block, since we have one signal on the input queue |
| // semaphore corresponding to each element in the input queue. |
| input_queue_semaphore_.Wait(); |
| - CompilationInfo* info = optimizing_compiler->info(); |
| - if (restore_function_code) { |
| - Handle<JSFunction> function = info->closure(); |
| - function->ReplaceCode(function->shared()->code()); |
| - } |
| - delete info; |
| + DisposeOptimizingCompiler(optimizing_compiler, restore_function_code); |
| } |
| Release_Store(&queue_length_, static_cast<AtomicWord>(0)); |
| - LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
| osr_candidates_.Clear(); |
| } |
| @@ -148,15 +147,16 @@ void OptimizingCompilerThread::FlushOutputQueue(bool restore_function_code) { |
| { 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(); |
| - function->ReplaceCode(function->shared()->code()); |
| - } |
| - delete info; |
| + DisposeOptimizingCompiler(optimizing_compiler, restore_function_code); |
| } |
| - RemoveStaleOSRCandidates(0); |
| + for (int i = 0; i < kOsrBufferSize; i++) { |
| + optimizing_compiler = osr_buffer_[i]; |
| + if (optimizing_compiler != NULL) { |
| + DisposeOptimizingCompiler(optimizing_compiler, restore_function_code); |
| + } |
| + } |
| + osr_cursor_ = 0; |
| } |
| @@ -191,7 +191,8 @@ void OptimizingCompilerThread::Stop() { |
| PrintF(" ** Compiler thread did %.2f%% useful work\n", percentage); |
| } |
| - if (FLAG_trace_osr && FLAG_concurrent_osr) { |
| + if ((FLAG_trace_osr || FLAG_trace_concurrent_recompilation) && |
| + FLAG_concurrent_osr) { |
| PrintF("[COSR hit rate %d / %d]\n", osr_hits_, osr_attempts_); |
| } |
| @@ -208,12 +209,21 @@ void OptimizingCompilerThread::InstallOptimizedFunctions() { |
| { LockGuard<Mutex> access_queue(&queue_mutex_); |
| if (!output_queue_.Dequeue(&compiler)) break; |
| } |
| - Compiler::InstallOptimizedCode(compiler); |
| + CompilationInfo* info = compiler->info(); |
| + if (info->osr_ast_id().IsNone()) { |
| + Compiler::InstallOptimizedCode(compiler); |
| + } else { |
| + if (FLAG_trace_osr) { |
| + PrintF("[COSR - "); |
| + info->closure()->PrintName(); |
| + PrintF(" is ready for install and entry at AST id %d]\n", |
| + info->osr_ast_id().ToInt()); |
| + } |
| + osr_candidates_.RemoveElement(compiler); |
| + AddToOsrBuffer(compiler); |
| + BackEdgeTable::RemoveStackCheck(info); |
| + } |
| } |
| - |
| - // Remove the oldest OSR candidates that are ready so that we |
| - // only have limited number of them waiting. |
| - if (FLAG_concurrent_osr) RemoveStaleOSRCandidates(); |
| } |
| @@ -222,12 +232,18 @@ void OptimizingCompilerThread::QueueForOptimization( |
| ASSERT(IsQueueAvailable()); |
| ASSERT(!IsOptimizerThread()); |
| Barrier_AtomicIncrement(&queue_length_, static_cast<Atomic32>(1)); |
| - if (optimizing_compiler->info()->osr_ast_id().IsNone()) { |
| - optimizing_compiler->info()->closure()->MarkInRecompileQueue(); |
| + CompilationInfo* info = optimizing_compiler->info(); |
| + if (info->osr_ast_id().IsNone()) { |
| + info->closure()->MarkInRecompileQueue(); |
| } else { |
| - LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
| + if (FLAG_trace_concurrent_recompilation) { |
| + PrintF(" ** Queueing "); |
| + info->closure()->PrintName(); |
| + PrintF(" for concurrent on-stack replacement.\n"); |
| + } |
| osr_candidates_.Add(optimizing_compiler); |
| osr_attempts_++; |
| + BackEdgeTable::AddStackCheck(info); |
| } |
| input_queue_.Enqueue(optimizing_compiler); |
| input_queue_semaphore_.Signal(); |
| @@ -238,24 +254,22 @@ OptimizingCompiler* OptimizingCompilerThread::FindReadyOSRCandidate( |
| Handle<JSFunction> function, uint32_t osr_pc_offset) { |
| ASSERT(!IsOptimizerThread()); |
| OptimizingCompiler* result = NULL; |
| - { LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
| - for (int i = 0; i < ready_for_osr_.length(); i++) { |
| - if (ready_for_osr_[i]->info()->HasSameOsrEntry(function, osr_pc_offset)) { |
| - osr_hits_++; |
| - result = ready_for_osr_.Remove(i); |
| - break; |
| - } |
| + for (int i = 0; i < kOsrBufferSize; i++) { |
| + result = osr_buffer_[i]; |
| + if (result == NULL) continue; |
| + if (result->info()->HasSameOsrEntry(function, osr_pc_offset)) { |
| + osr_hits_++; |
| + osr_buffer_[i] = NULL; |
| + return result; |
| } |
| } |
| - RemoveStaleOSRCandidates(); |
| - return result; |
| + return NULL; |
| } |
| bool OptimizingCompilerThread::IsQueuedForOSR(Handle<JSFunction> function, |
| uint32_t osr_pc_offset) { |
| ASSERT(!IsOptimizerThread()); |
| - LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
| for (int i = 0; i < osr_candidates_.length(); i++) { |
| if (osr_candidates_[i]->info()->HasSameOsrEntry(function, osr_pc_offset)) { |
| return true; |
| @@ -267,7 +281,6 @@ bool OptimizingCompilerThread::IsQueuedForOSR(Handle<JSFunction> function, |
| bool OptimizingCompilerThread::IsQueuedForOSR(JSFunction* function) { |
| ASSERT(!IsOptimizerThread()); |
| - LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
| for (int i = 0; i < osr_candidates_.length(); i++) { |
| if (*osr_candidates_[i]->info()->closure() == function) { |
| return true; |
| @@ -277,20 +290,22 @@ bool OptimizingCompilerThread::IsQueuedForOSR(JSFunction* function) { |
| } |
| -void OptimizingCompilerThread::RemoveStaleOSRCandidates(int limit) { |
| +void OptimizingCompilerThread::AddToOsrBuffer(OptimizingCompiler* compiler) { |
| ASSERT(!IsOptimizerThread()); |
| - LockGuard<Mutex> access_osr_lists(&osr_list_mutex_); |
| - while (ready_for_osr_.length() > limit) { |
| - OptimizingCompiler* compiler = ready_for_osr_.Remove(0); |
| - CompilationInfo* throw_away = compiler->info(); |
| + OptimizingCompiler* stale = osr_buffer_[osr_cursor_]; |
| + if (stale != NULL) { |
| + CompilationInfo* info = stale->info(); |
| if (FLAG_trace_osr) { |
| PrintF("[COSR - Discarded "); |
| - throw_away->closure()->PrintName(); |
| - PrintF(", AST id %d]\n", |
| - throw_away->osr_ast_id().ToInt()); |
| + info->closure()->PrintName(); |
| + PrintF(", AST id %d]\n", info->osr_ast_id().ToInt()); |
| } |
| - delete throw_away; |
| + BackEdgeTable::RemoveStackCheck(info); |
| + delete info; |
|
titzer
2013/09/24 09:42:01
Maybe you want DisposeOptimizingCompiler(stale, fa
Yang
2013/09/24 10:07:11
Done.
|
| } |
| + |
| + osr_buffer_[osr_cursor_] = compiler; |
| + osr_cursor_ = (osr_cursor_ + 1) % kOsrBufferSize; |
| } |