OLD | NEW |
---|---|
(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 CompilerDispatcher::CompilerDispatcher(Isolate* isolate, size_t max_stack_size) | |
15 : isolate_(isolate), | |
16 max_stack_size_(max_stack_size), | |
17 tracer_(new CompilerDispatcherTracer(isolate_)) {} | |
18 | |
19 CompilerDispatcher::~CompilerDispatcher() {} | |
20 | |
21 bool CompilerDispatcher::Enqueue(Handle<SharedFunctionInfo> function) { | |
22 DCHECK(function->script()->IsScript()); | |
23 if (IsEnqueued(function)) return true; | |
24 std::unique_ptr<CompilerDispatcherJob> job(new CompilerDispatcherJob( | |
marja
2016/12/12 09:00:02
Nit: no need to construct job if we do the early r
| |
25 isolate_, tracer_.get(), function, max_stack_size_)); | |
26 std::pair<int, int> key(Script::cast(function->script())->id(), | |
27 function->function_literal_id()); | |
28 // Script::id() is not guaranteed to be unique, so even if the function isn't | |
29 // enqueued, we might not be able to enqueue it. | |
marja
2016/12/12 09:00:02
Hmm, this is weird. So we cannot enqueue things be
rmcilroy
2016/12/12 09:50:39
Also, does this mean we are only able to enqueue o
marja
2016/12/12 09:54:59
I don't think it means that, since the key is the
rmcilroy
2016/12/12 10:08:30
Ahh right enough, I was thinking the pair was for
jochen (gone - plz use gerrit)
2016/12/12 10:51:17
done
| |
30 if (jobs_.find(key) != jobs_.end()) return false; | |
31 jobs_.insert(std::make_pair(key, std::move(job))); | |
32 return true; | |
33 } | |
34 | |
35 bool CompilerDispatcher::IsEnqueued(Handle<SharedFunctionInfo> function) const { | |
36 if (!function->script()->IsScript()) return false; | |
37 std::pair<int, int> key(Script::cast(function->script())->id(), | |
38 function->function_literal_id()); | |
39 auto job = jobs_.find(key); | |
40 if (job == jobs_.end()) return false; | |
41 return job->second->IsProcessing(function); | |
42 } | |
43 | |
44 bool CompilerDispatcher::FinishNow(Handle<SharedFunctionInfo> function) { | |
45 if (!IsEnqueued(function)) return false; | |
46 std::pair<int, int> key(Script::cast(function->script())->id(), | |
marja
2016/12/12 09:00:02
How about having a job-finding helper function - i
jochen (gone - plz use gerrit)
2016/12/12 10:51:17
done
| |
47 function->function_literal_id()); | |
48 auto job = jobs_.find(key); | |
49 | |
50 // TODO(jochen): Check if there's an in-flight background task working on this | |
rmcilroy
2016/12/12 09:50:39
Could you DCHECK there is no background thread pro
jochen (gone - plz use gerrit)
2016/12/12 10:51:17
there's currently no way to check whether a job is
| |
51 // job. | |
52 while (!IsDone(job->second.get())) { | |
53 DoNextStepOnMainThread(job->second.get()); | |
54 } | |
55 bool result = job->second->status() != CompileJobStatus::kFailed; | |
56 jobs_.erase(job); | |
57 return result; | |
58 } | |
59 | |
60 void CompilerDispatcher::Abort(Handle<SharedFunctionInfo> function, | |
61 BlockingBehavior blocking) { | |
62 USE(blocking); | |
63 if (!IsEnqueued(function)) return; | |
marja
2016/12/12 09:00:02
Ditto
| |
64 std::pair<int, int> key(Script::cast(function->script())->id(), | |
65 function->function_literal_id()); | |
66 auto job = jobs_.find(key); | |
67 | |
68 // TODO(jochen): Check if there's an in-flight background task working on this | |
rmcilroy
2016/12/12 09:50:39
Ditto (and below).
| |
69 // job. | |
70 jobs_.erase(job); | |
71 } | |
72 | |
73 void CompilerDispatcher::AbortAll(BlockingBehavior blocking) { | |
74 USE(blocking); | |
75 // TODO(jochen): Check if there's an in-flight background task working on this | |
76 // job. | |
77 jobs_.clear(); | |
78 } | |
79 | |
80 // static | |
81 bool CompilerDispatcher::DoNextStepOnMainThread(CompilerDispatcherJob* job) { | |
82 switch (job->status()) { | |
83 case CompileJobStatus::kInitial: | |
84 job->PrepareToParseOnMainThread(); | |
85 break; | |
86 | |
87 case CompileJobStatus::kReadyToParse: | |
88 job->Parse(); | |
89 break; | |
90 | |
91 case CompileJobStatus::kParsed: | |
92 job->FinalizeParsingOnMainThread(); | |
93 break; | |
94 | |
95 case CompileJobStatus::kReadyToAnalyse: | |
96 job->PrepareToCompileOnMainThread(); | |
97 break; | |
98 | |
99 case CompileJobStatus::kReadyToCompile: | |
100 job->Compile(); | |
101 break; | |
102 | |
103 case CompileJobStatus::kCompiled: | |
104 job->FinalizeCompilingOnMainThread(); | |
105 break; | |
106 | |
107 case CompileJobStatus::kFailed: | |
108 case CompileJobStatus::kDone: | |
109 break; | |
110 } | |
111 | |
112 return job->status() != CompileJobStatus::kFailed; | |
113 } | |
114 | |
115 // static | |
116 bool CompilerDispatcher::IsDone(CompilerDispatcherJob* job) { | |
117 return job->status() == CompileJobStatus::kDone || | |
118 job->status() == CompileJobStatus::kFailed; | |
119 } | |
120 | |
121 } // namespace internal | |
122 } // namespace v8 | |
OLD | NEW |