Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(66)

Side by Side Diff: src/compiler-dispatcher/compiler-dispatcher.cc

Issue 2558293004: Add a basic compiler dispatcher (Closed)
Patch Set: updates Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "src/compiler-dispatcher/compiler-dispatcher.h"
6
7 #include "src/compiler-dispatcher/compiler-dispatcher-job.h"
8 #include "src/compiler-dispatcher/compiler-dispatcher-tracer.h"
9 #include "src/objects-inl.h"
10
11 namespace v8 {
12 namespace internal {
13
14 namespace {
15
16 bool DoNextStepOnMainThread(CompilerDispatcherJob* job) {
17 switch (job->status()) {
18 case CompileJobStatus::kInitial:
19 job->PrepareToParseOnMainThread();
20 break;
21
22 case CompileJobStatus::kReadyToParse:
23 job->Parse();
24 break;
25
26 case CompileJobStatus::kParsed:
27 job->FinalizeParsingOnMainThread();
28 break;
29
30 case CompileJobStatus::kReadyToAnalyse:
31 job->PrepareToCompileOnMainThread();
32 break;
33
34 case CompileJobStatus::kReadyToCompile:
35 job->Compile();
36 break;
37
38 case CompileJobStatus::kCompiled:
39 job->FinalizeCompilingOnMainThread();
40 break;
41
42 case CompileJobStatus::kFailed:
43 case CompileJobStatus::kDone:
44 break;
45 }
46
47 return job->status() != CompileJobStatus::kFailed;
48 }
49
50 bool IsDone(CompilerDispatcherJob* job) {
rmcilroy 2016/12/12 14:00:19 nit - IsFinished or something to avoid confusion w
51 return job->status() == CompileJobStatus::kDone ||
52 job->status() == CompileJobStatus::kFailed;
53 }
54
55 } // namespace
56
57 CompilerDispatcher::CompilerDispatcher(Isolate* isolate, size_t max_stack_size)
58 : isolate_(isolate),
59 max_stack_size_(max_stack_size),
60 tracer_(new CompilerDispatcherTracer(isolate_)) {}
61
62 CompilerDispatcher::~CompilerDispatcher() {}
63
64 bool CompilerDispatcher::Enqueue(Handle<SharedFunctionInfo> function) {
65 // We only handle functions (no eval / top-level code / wasm) that are
66 // attached to a script.
67 if (!function->script()->IsScript() || !function->is_function() ||
68 function->asm_function() || function->native()) {
69 return false;
70 }
71
72 if (IsEnqueued(function)) return true;
73 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
74 isolate_, tracer_.get(), function, max_stack_size_));
75 std::pair<int, int> key(Script::cast(function->script())->id(),
76 function->function_literal_id());
77 jobs_.insert(std::make_pair(key, std::move(job)));
78 return true;
79 }
80
81 bool CompilerDispatcher::IsEnqueued(Handle<SharedFunctionInfo> function) const {
82 return GetJobFor(function) != jobs_.end();
83 }
84
85 bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) {
86 JobMap::const_iterator job = GetJobFor(function);
87 if (job == jobs_.end()) {
88 UNREACHABLE();
89 return false;
90 }
91
92 // TODO(jochen): Check if there's an in-flight background task working on this
93 // job.
94 while (!IsDone(job->second.get())) {
95 DoNextStepOnMainThread(job->second.get());
96 }
97 bool result = job->second->status() != CompileJobStatus::kFailed;
98 jobs_.erase(job);
99 return result;
100 }
101
102 void CompilerDispatcher::Abort(Handle<SharedFunctionInfo> function,
103 BlockingBehavior blocking) {
104 USE(blocking);
105 JobMap::const_iterator job = GetJobFor(function);
106 if (job == jobs_.end()) {
107 UNREACHABLE();
108 return;
rmcilroy 2016/12/12 14:00:19 nit - how about just do CHECK(job != Jobs_.end())?
109 }
110
111 // TODO(jochen): Check if there's an in-flight background task working on this
112 // job.
113 jobs_.erase(job);
114 }
115
116 void CompilerDispatcher::AbortAll(BlockingBehavior blocking) {
117 USE(blocking);
118 // TODO(jochen): Check if there's an in-flight background task working on this
119 // job.
120 jobs_.clear();
121 }
122
123 CompilerDispatcher::JobMap::const_iterator CompilerDispatcher::GetJobFor(
124 Handle<SharedFunctionInfo> shared) const {
125 if (!shared->script()->IsScript()) return jobs_.end();
126 std::pair<int, int> key(Script::cast(shared->script())->id(),
127 shared->function_literal_id());
128 auto range = jobs_.equal_range(key);
129 for (auto job = range.first; job != range.second; ++job) {
130 if (job->second->IsAssociatedWith(shared)) return job;
131 }
132 return jobs_.end();
133 }
134
135 } // namespace internal
136 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher.h ('k') | src/compiler-dispatcher/compiler-dispatcher-job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698