Chromium Code Reviews| Index: src/compiler-dispatcher/compiler-dispatcher.cc |
| diff --git a/src/compiler-dispatcher/compiler-dispatcher.cc b/src/compiler-dispatcher/compiler-dispatcher.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..af6196e9e2ab3228de96cea04a996cf4388045fd |
| --- /dev/null |
| +++ b/src/compiler-dispatcher/compiler-dispatcher.cc |
| @@ -0,0 +1,124 @@ |
| +// Copyright 2016 the V8 project authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "src/compiler-dispatcher/compiler-dispatcher.h" |
| + |
| +#include "src/compiler-dispatcher/compiler-dispatcher-job.h" |
| +#include "src/compiler-dispatcher/compiler-dispatcher-tracer.h" |
| +#include "src/objects-inl.h" |
| + |
| +namespace v8 { |
| +namespace internal { |
| + |
| +namespace { |
| + |
| +bool DoNextStepOnMainThread(CompilerDispatcherJob* job) { |
| + switch (job->status()) { |
| + case CompileJobStatus::kInitial: |
| + job->PrepareToParseOnMainThread(); |
| + break; |
| + |
| + case CompileJobStatus::kReadyToParse: |
| + job->Parse(); |
| + break; |
| + |
| + case CompileJobStatus::kParsed: |
| + job->FinalizeParsingOnMainThread(); |
| + break; |
| + |
| + case CompileJobStatus::kReadyToAnalyse: |
| + job->PrepareToCompileOnMainThread(); |
| + break; |
| + |
| + case CompileJobStatus::kReadyToCompile: |
| + job->Compile(); |
| + break; |
| + |
| + case CompileJobStatus::kCompiled: |
| + job->FinalizeCompilingOnMainThread(); |
| + break; |
| + |
| + case CompileJobStatus::kFailed: |
| + case CompileJobStatus::kDone: |
| + break; |
| + } |
| + |
| + return job->status() != CompileJobStatus::kFailed; |
| +} |
| + |
| +bool IsDone(CompilerDispatcherJob* job) { |
| + return job->status() == CompileJobStatus::kDone || |
| + job->status() == CompileJobStatus::kFailed; |
| +} |
| + |
| +} // namespace |
| + |
| +CompilerDispatcher::CompilerDispatcher(Isolate* isolate, size_t max_stack_size) |
| + : isolate_(isolate), |
| + max_stack_size_(max_stack_size), |
| + tracer_(new CompilerDispatcherTracer(isolate_)) {} |
| + |
| +CompilerDispatcher::~CompilerDispatcher() {} |
| + |
| +bool CompilerDispatcher::Enqueue(Handle<SharedFunctionInfo> function) { |
|
marja
2016/12/12 12:25:01
Now the return value is not meaningful any more.
jochen (gone - plz use gerrit)
2016/12/12 12:34:37
I added a meaningful "return false" code path
|
| + DCHECK(function->script()->IsScript()); |
| + if (IsEnqueued(function)) return true; |
| + std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( |
| + isolate_, tracer_.get(), function, max_stack_size_)); |
| + std::pair<int, int> key(Script::cast(function->script())->id(), |
| + function->function_literal_id()); |
| + jobs_.insert(std::make_pair(key, std::move(job))); |
| + return true; |
| +} |
| + |
| +bool CompilerDispatcher::IsEnqueued(Handle<SharedFunctionInfo> function) const { |
| + return GetJobFor(function) != jobs_.end(); |
| +} |
| + |
| +bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) { |
|
marja
2016/12/12 12:25:01
How would we use the return value? false can mean
jochen (gone - plz use gerrit)
2016/12/12 12:34:37
I added "UNREACHABLE()" to the "not in queue" case
|
| + JobMap::const_iterator job = GetJobFor(function); |
| + if (job == jobs_.end()) return false; |
| + |
| + // TODO(jochen): Check if there's an in-flight background task working on this |
| + // job. |
| + while (!IsDone(job->second.get())) { |
| + DoNextStepOnMainThread(job->second.get()); |
| + } |
| + bool result = job->second->status() != CompileJobStatus::kFailed; |
| + jobs_.erase(job); |
| + return result; |
| +} |
| + |
| +void CompilerDispatcher::Abort(Handle<SharedFunctionInfo> function, |
| + BlockingBehavior blocking) { |
| + USE(blocking); |
| + JobMap::const_iterator job = GetJobFor(function); |
| + if (job == jobs_.end()) return; |
| + |
| + // TODO(jochen): Check if there's an in-flight background task working on this |
| + // job. |
| + jobs_.erase(job); |
| +} |
| + |
| +void CompilerDispatcher::AbortAll(BlockingBehavior blocking) { |
| + USE(blocking); |
| + // TODO(jochen): Check if there's an in-flight background task working on this |
| + // job. |
| + jobs_.clear(); |
| +} |
| + |
| +CompilerDispatcher::JobMap::const_iterator CompilerDispatcher::GetJobFor( |
| + Handle<SharedFunctionInfo> shared) const { |
| + if (!shared->script()->IsScript()) return jobs_.end(); |
| + std::pair<int, int> key(Script::cast(shared->script())->id(), |
| + shared->function_literal_id()); |
| + auto range = jobs_.equal_range(key); |
| + for (auto job = range.first; job != range.second; ++job) { |
| + if (job->second->IsAssociatedWith(shared)) return job; |
| + } |
| + return jobs_.end(); |
| +} |
| + |
| +} // namespace internal |
| +} // namespace v8 |