Use mutex instead of busy wait when installing optimized function.

R=jkummerow@chromium.org
BUG=

Review URL: https://codereview.chromium.org/17099012

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15262 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
yangguo@chromium.org 2013-06-21 08:38:12 +00:00
parent 2e10e3e336
commit cbf6244029
3 changed files with 11 additions and 11 deletions

View File

@ -89,8 +89,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();
@ -130,11 +131,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++;
}
}

View File

@ -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_;

View File

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