| Index: src/optimizing-compiler-thread.cc
|
| diff --git a/src/optimizing-compiler-thread.cc b/src/optimizing-compiler-thread.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..12420644411c711f097dc35c42892956bd89a1e6
|
| --- /dev/null
|
| +++ b/src/optimizing-compiler-thread.cc
|
| @@ -0,0 +1,115 @@
|
| +// Copyright 2010 the V8 project authors. All rights reserved.
|
| +// Redistribution and use in source and binary forms, with or without
|
| +// modification, are permitted provided that the following conditions are
|
| +// met:
|
| +//
|
| +// * Redistributions of source code must retain the above copyright
|
| +// notice, this list of conditions and the following disclaimer.
|
| +// * Redistributions in binary form must reproduce the above
|
| +// copyright notice, this list of conditions and the following
|
| +// disclaimer in the documentation and/or other materials provided
|
| +// with the distribution.
|
| +// * Neither the name of Google Inc. nor the names of its
|
| +// contributors may be used to endorse or promote products derived
|
| +// from this software without specific prior written permission.
|
| +//
|
| +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
| +// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
| +// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
| +// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
| +// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
| +// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
| +// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
| +// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
| +// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
| +// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| +// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
| +
|
| +#include "optimizing-compiler-thread.h"
|
| +
|
| +#include "isolate.h"
|
| +#include "v8threads.h"
|
| +
|
| +namespace v8 {
|
| +namespace internal {
|
| +
|
| +
|
| +void OptimizingCompilerThread::Run() {
|
| + while (true) {
|
| + queue_semaphore_->Wait();
|
| + if (Acquire_Load(&stop_thread_)) {
|
| + return;
|
| + }
|
| + Handle<JSFunction> function;
|
| + {
|
| + ScopedLock mutex_lock(queue_mutex_);
|
| + queue_.Dequeue(&function);
|
| + }
|
| +
|
| + Locker lock(reinterpret_cast<v8::Isolate*>(isolate_));
|
| + if (Acquire_Load(&stop_thread_)) {
|
| + return;
|
| + }
|
| +
|
| + if (isolate_->context() == NULL || !isolate_->context()->IsContext()) {
|
| + continue;
|
| + }
|
| +
|
| + isolate_->Enter();
|
| + {
|
| + HandleScope scope(isolate_);
|
| + if (!function->IsOptimized()) {
|
| + isolate_->factory()->CompileJSFunction(function);
|
| + isolate_->counters()->functions_compiled_parallely()->Increment();
|
| + }
|
| +
|
| + isolate_->global_handles()->Destroy(
|
| + reinterpret_cast<Object **>(function.location()));
|
| + }
|
| + isolate_->Exit();
|
| + }
|
| +}
|
| +
|
| +
|
| +void OptimizingCompilerThread::StopThread() {
|
| + Release_Store(&stop_thread_, static_cast<AtomicWord>(true));
|
| + queue_semaphore_->Signal();
|
| + {
|
| + // We don't need to use the Unlocker class here because we don't
|
| + // need to present a consistent view of the isolate to the
|
| + // optimizing compiler thread at this point. Either the compiler
|
| + // is waiting for the ThreadManager lock and will return
|
| + // immediately after the getting it or is currently optimizing a
|
| + // function and hence already has the lock.
|
| +
|
| + bool to_unlock = isolate_->thread_manager()->IsLockedByCurrentThread();
|
| + if (to_unlock)
|
| + isolate_->thread_manager()->Unlock();
|
| +
|
| + Join();
|
| +
|
| + if (to_unlock)
|
| + isolate_->thread_manager()->Lock();
|
| + }
|
| +
|
| + Handle<JSFunction> not_used;
|
| + while (!queue_.IsEmpty()) {
|
| + queue_.Dequeue(¬_used);
|
| + }
|
| +}
|
| +
|
| +
|
| +void OptimizingCompilerThread::QueueForOptimization(
|
| + Handle<JSFunction> function) {
|
| + {
|
| + ScopedLock lock(queue_mutex_);
|
| + queue_.Enqueue(function);
|
| + }
|
| + queue_semaphore_->Signal();
|
| + Unlocker unlock(reinterpret_cast<v8::Isolate*>(isolate_));
|
| + Thread::YieldCPU();
|
| +}
|
| +
|
| +
|
| +} } // namespace v8::internal
|
| +
|
|
|