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

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

Issue 2558293004: Add a basic compiler dispatcher (Closed)
Patch Set: back out runtime-compiler.cc change 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) {
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) {
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
65 DCHECK(function->script()->IsScript());
66 if (IsEnqueued(function)) return true;
67 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob(
68 isolate_, tracer_.get(), function, max_stack_size_));
69 std::pair<int, int> key(Script::cast(function->script())->id(),
70 function->function_literal_id());
71 jobs_.insert(std::make_pair(key, std::move(job)));
72 return true;
73 }
74
75 bool CompilerDispatcher::IsEnqueued(Handle<SharedFunctionInfo> function) const {
76 return GetJobFor(function) != jobs_.end();
77 }
78
79 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
80 JobMap::const_iterator job = GetJobFor(function);
81 if (job == jobs_.end()) return false;
82
83 // TODO(jochen): Check if there's an in-flight background task working on this
84 // job.
85 while (!IsDone(job->second.get())) {
86 DoNextStepOnMainThread(job->second.get());
87 }
88 bool result = job->second->status() != CompileJobStatus::kFailed;
89 jobs_.erase(job);
90 return result;
91 }
92
93 void CompilerDispatcher::Abort(Handle<SharedFunctionInfo> function,
94 BlockingBehavior blocking) {
95 USE(blocking);
96 JobMap::const_iterator job = GetJobFor(function);
97 if (job == jobs_.end()) return;
98
99 // TODO(jochen): Check if there's an in-flight background task working on this
100 // job.
101 jobs_.erase(job);
102 }
103
104 void CompilerDispatcher::AbortAll(BlockingBehavior blocking) {
105 USE(blocking);
106 // TODO(jochen): Check if there's an in-flight background task working on this
107 // job.
108 jobs_.clear();
109 }
110
111 CompilerDispatcher::JobMap::const_iterator CompilerDispatcher::GetJobFor(
112 Handle<SharedFunctionInfo> shared) const {
113 if (!shared->script()->IsScript()) return jobs_.end();
114 std::pair<int, int> key(Script::cast(shared->script())->id(),
115 shared->function_literal_id());
116 auto range = jobs_.equal_range(key);
117 for (auto job = range.first; job != range.second; ++job) {
118 if (job->second->IsAssociatedWith(shared)) return job;
119 }
120 return jobs_.end();
121 }
122
123 } // namespace internal
124 } // 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