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

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

Issue 2251713002: [Compiler] Add compile to CompilerDispatcherJob. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@offheap_compilerdispatcher
Patch Set: Fix comment Created 4 years, 3 months 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
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher-job.h ('k') | src/compiler/pipeline.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/compiler-dispatcher/compiler-dispatcher-job.h" 5 #include "src/compiler-dispatcher/compiler-dispatcher-job.h"
6 6
7 #include "src/assert-scope.h" 7 #include "src/assert-scope.h"
8 #include "src/compiler.h"
8 #include "src/global-handles.h" 9 #include "src/global-handles.h"
9 #include "src/isolate.h" 10 #include "src/isolate.h"
10 #include "src/objects-inl.h" 11 #include "src/objects-inl.h"
11 #include "src/parsing/parse-info.h" 12 #include "src/parsing/parse-info.h"
12 #include "src/parsing/parser.h" 13 #include "src/parsing/parser.h"
13 #include "src/parsing/scanner-character-streams.h" 14 #include "src/parsing/scanner-character-streams.h"
14 #include "src/unicode-cache.h" 15 #include "src/unicode-cache.h"
15 #include "src/zone.h" 16 #include "src/zone.h"
16 17
17 namespace v8 { 18 namespace v8 {
18 namespace internal { 19 namespace internal {
19 20
20 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, 21 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate,
21 Handle<JSFunction> function, 22 Handle<JSFunction> function,
22 size_t max_stack_size) 23 size_t max_stack_size)
23 : isolate_(isolate), 24 : isolate_(isolate),
24 function_(Handle<JSFunction>::cast( 25 function_(Handle<JSFunction>::cast(
25 isolate_->global_handles()->Create(*function))), 26 isolate_->global_handles()->Create(*function))),
26 max_stack_size_(max_stack_size) { 27 max_stack_size_(max_stack_size),
28 can_compile_on_background_thread_(false) {
27 HandleScope scope(isolate_); 29 HandleScope scope(isolate_);
28 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); 30 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_);
29 Handle<Script> script(Script::cast(shared->script()), isolate_); 31 Handle<Script> script(Script::cast(shared->script()), isolate_);
30 Handle<String> source(String::cast(script->source()), isolate_); 32 Handle<String> source(String::cast(script->source()), isolate_);
31 can_parse_on_background_thread_ = 33 can_parse_on_background_thread_ =
32 source->IsExternalTwoByteString() || source->IsExternalOneByteString(); 34 source->IsExternalTwoByteString() || source->IsExternalOneByteString();
33 } 35 }
34 36
35 CompilerDispatcherJob::~CompilerDispatcherJob() { 37 CompilerDispatcherJob::~CompilerDispatcherJob() {
36 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 38 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 DCHECK(status() == CompileJobStatus::kParsed); 126 DCHECK(status() == CompileJobStatus::kParsed);
125 127
126 if (!source_.is_null()) { 128 if (!source_.is_null()) {
127 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); 129 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location());
128 source_ = Handle<String>::null(); 130 source_ = Handle<String>::null();
129 } 131 }
130 132
131 if (parse_info_->literal() == nullptr) { 133 if (parse_info_->literal() == nullptr) {
132 status_ = CompileJobStatus::kFailed; 134 status_ = CompileJobStatus::kFailed;
133 } else { 135 } else {
134 status_ = CompileJobStatus::kReadyToCompile; 136 status_ = CompileJobStatus::kReadyToAnalyse;
135 } 137 }
136 138
137 DeferredHandleScope scope(isolate_); 139 DeferredHandleScope scope(isolate_);
138 { 140 {
139 // Create a canonical handle scope before internalizing parsed values if 141 // Create a canonical handle scope before internalizing parsed values if
140 // compiling bytecode. This is required for off-thread bytecode generation. 142 // compiling bytecode. This is required for off-thread bytecode generation.
141 std::unique_ptr<CanonicalHandleScope> canonical; 143 std::unique_ptr<CanonicalHandleScope> canonical;
142 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_)); 144 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_));
143 145
144 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_); 146 Handle<SharedFunctionInfo> shared(function_->shared(), isolate_);
145 Handle<Script> script(Script::cast(shared->script()), isolate_); 147 Handle<Script> script(Script::cast(shared->script()), isolate_);
146 148
147 parse_info_->set_script(script); 149 parse_info_->set_script(script);
148 parse_info_->set_context(handle(function_->context(), isolate_)); 150 parse_info_->set_context(handle(function_->context(), isolate_));
151 parse_info_->set_shared_info(handle(function_->shared(), isolate_));
149 152
150 // Do the parsing tasks which need to be done on the main thread. This will 153 // Do the parsing tasks which need to be done on the main thread. This will
151 // also handle parse errors. 154 // also handle parse errors.
152 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); 155 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr);
153 parser_->HandleSourceURLComments(isolate_, script); 156 parser_->HandleSourceURLComments(isolate_, script);
154 157
155 parse_info_->set_character_stream(nullptr); 158 parse_info_->set_character_stream(nullptr);
156 parse_info_->set_unicode_cache(nullptr); 159 parse_info_->set_unicode_cache(nullptr);
157 parser_.reset(); 160 parser_.reset();
158 unicode_cache_.reset(); 161 unicode_cache_.reset();
159 character_stream_.reset(); 162 character_stream_.reset();
160 } 163 }
161 handles_from_parsing_.reset(scope.Detach()); 164 handles_from_parsing_.reset(scope.Detach());
162 165
163 return status_ != CompileJobStatus::kFailed; 166 return status_ != CompileJobStatus::kFailed;
164 } 167 }
165 168
169 bool CompilerDispatcherJob::PrepareToCompileOnMainThread() {
170 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
171 DCHECK(status() == CompileJobStatus::kReadyToAnalyse);
172
173 compile_info_.reset(new CompilationInfo(parse_info_.get(), function_));
174
175 DeferredHandleScope scope(isolate_);
176 {
177 // Create a canonical handle scope before ast numbering if compiling
178 // bytecode. This is required for off-thread bytecode generation.
179 std::unique_ptr<CanonicalHandleScope> canonical;
180 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(isolate_));
181
182 if (Compiler::Analyze(parse_info_.get())) {
183 compile_job_.reset(
184 Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get()));
185 }
186 }
187 compile_info_->set_deferred_handles(scope.Detach());
188
189 if (!compile_job_.get()) {
190 if (!isolate_->has_pending_exception()) isolate_->StackOverflow();
191 status_ = CompileJobStatus::kFailed;
192 return false;
193 }
194
195 can_compile_on_background_thread_ =
196 compile_job_->can_execute_on_background_thread();
197 status_ = CompileJobStatus::kReadyToCompile;
198 return true;
199 }
200
201 void CompilerDispatcherJob::Compile() {
202 DCHECK(status() == CompileJobStatus::kReadyToCompile);
203 DCHECK(can_compile_on_background_thread_ ||
204 ThreadId::Current().Equals(isolate_->thread_id()));
205
206 // Disallowing of handle dereference and heap access dealt with in
207 // CompilationJob::ExecuteJob.
208
209 uintptr_t stack_limit =
210 reinterpret_cast<uintptr_t>(&stack_limit) - max_stack_size_ * KB;
211 compile_job_->set_stack_limit(stack_limit);
212
213 CompilationJob::Status status = compile_job_->ExecuteJob();
214 USE(status);
215
216 // Always transition to kCompiled - errors will be reported by
217 // FinalizeCompilingOnMainThread.
218 status_ = CompileJobStatus::kCompiled;
219 }
220
221 bool CompilerDispatcherJob::FinalizeCompilingOnMainThread() {
222 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
223 DCHECK(status() == CompileJobStatus::kCompiled);
224
225 if (compile_job_->state() == CompilationJob::State::kFailed ||
226 !Compiler::FinalizeCompilationJob(compile_job_.release())) {
227 if (!isolate_->has_pending_exception()) isolate_->StackOverflow();
228 status_ = CompileJobStatus::kFailed;
229 return false;
230 }
231
232 zone_.reset();
233 parse_info_.reset();
234 compile_info_.reset();
235 compile_job_.reset();
236 handles_from_parsing_.reset();
237
238 status_ = CompileJobStatus::kDone;
239 return true;
240 }
241
166 void CompilerDispatcherJob::ResetOnMainThread() { 242 void CompilerDispatcherJob::ResetOnMainThread() {
167 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); 243 DCHECK(ThreadId::Current().Equals(isolate_->thread_id()));
168 244
169 parser_.reset(); 245 parser_.reset();
170 unicode_cache_.reset(); 246 unicode_cache_.reset();
171 character_stream_.reset(); 247 character_stream_.reset();
172 parse_info_.reset(); 248 parse_info_.reset();
173 zone_.reset(); 249 zone_.reset();
174 handles_from_parsing_.reset(); 250 handles_from_parsing_.reset();
251 compile_info_.reset();
252 compile_job_.reset();
175 253
176 if (!source_.is_null()) { 254 if (!source_.is_null()) {
177 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); 255 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location());
178 source_ = Handle<String>::null(); 256 source_ = Handle<String>::null();
179 } 257 }
180 258
181 status_ = CompileJobStatus::kInitial; 259 status_ = CompileJobStatus::kInitial;
182 } 260 }
183 261
184 } // namespace internal 262 } // namespace internal
185 } // namespace v8 263 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler-dispatcher/compiler-dispatcher-job.h ('k') | src/compiler/pipeline.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698