OLD | NEW |
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/compilation-info.h" | 8 #include "src/compilation-info.h" |
9 #include "src/compiler.h" | 9 #include "src/compiler.h" |
10 #include "src/global-handles.h" | 10 #include "src/global-handles.h" |
(...skipping 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
169 | 169 |
170 bool CompilerDispatcherJob::PrepareToCompileOnMainThread() { | 170 bool CompilerDispatcherJob::PrepareToCompileOnMainThread() { |
171 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 171 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
172 DCHECK(status() == CompileJobStatus::kReadyToAnalyse); | 172 DCHECK(status() == CompileJobStatus::kReadyToAnalyse); |
173 | 173 |
174 compile_info_.reset( | 174 compile_info_.reset( |
175 new CompilationInfo(parse_info_.get(), Handle<JSFunction>::null())); | 175 new CompilationInfo(parse_info_.get(), Handle<JSFunction>::null())); |
176 | 176 |
177 DeferredHandleScope scope(isolate_); | 177 DeferredHandleScope scope(isolate_); |
178 if (Compiler::Analyze(parse_info_.get())) { | 178 if (Compiler::Analyze(parse_info_.get())) { |
179 compile_job_.reset( | 179 compile_jobs_ = |
180 Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get())); | 180 Compiler::PrepareUnoptimizedCompilationJobs(compile_info_.get()); |
181 } | 181 } |
182 compile_info_->set_deferred_handles(scope.Detach()); | 182 compile_info_->set_deferred_handles(scope.Detach()); |
183 | 183 |
184 if (!compile_job_.get()) { | 184 if (compile_jobs_.empty()) { |
185 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); | 185 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); |
186 status_ = CompileJobStatus::kFailed; | 186 status_ = CompileJobStatus::kFailed; |
187 return false; | 187 return false; |
188 } | 188 } |
189 | 189 |
190 can_compile_on_background_thread_ = | 190 can_compile_on_background_thread_ = |
191 compile_job_->can_execute_on_background_thread(); | 191 compile_jobs_.at(0)->can_execute_on_background_thread(); |
192 status_ = CompileJobStatus::kReadyToCompile; | 192 status_ = CompileJobStatus::kReadyToCompile; |
193 return true; | 193 return true; |
194 } | 194 } |
195 | 195 |
196 void CompilerDispatcherJob::Compile() { | 196 void CompilerDispatcherJob::Compile() { |
197 DCHECK(status() == CompileJobStatus::kReadyToCompile); | 197 DCHECK(status() == CompileJobStatus::kReadyToCompile); |
198 DCHECK(can_compile_on_background_thread_ || | 198 DCHECK(can_compile_on_background_thread_ || |
199 ThreadId::Current().Equals(isolate_->thread_id())); | 199 ThreadId::Current().Equals(isolate_->thread_id())); |
200 | 200 |
201 // Disallowing of handle dereference and heap access dealt with in | 201 // Disallowing of handle dereference and heap access dealt with in |
202 // CompilationJob::ExecuteJob. | 202 // CompilationJob::ExecuteJob. |
203 | 203 |
204 uintptr_t stack_limit = GetCurrentStackPosition() - max_stack_size_ * KB; | 204 uintptr_t stack_limit = GetCurrentStackPosition() - max_stack_size_ * KB; |
205 compile_job_->set_stack_limit(stack_limit); | |
206 | 205 |
207 CompilationJob::Status status = compile_job_->ExecuteJob(); | 206 for (auto& job : compile_jobs_) { |
208 USE(status); | 207 job->set_stack_limit(stack_limit); |
| 208 if (job->ExecuteJob() == CompilationJob::FAILED) break; |
| 209 } |
209 | 210 |
210 // Always transition to kCompiled - errors will be reported by | 211 // Always transition to kCompiled - errors will be reported by |
211 // FinalizeCompilingOnMainThread. | 212 // FinalizeCompilingOnMainThread. |
212 status_ = CompileJobStatus::kCompiled; | 213 status_ = CompileJobStatus::kCompiled; |
213 } | 214 } |
214 | 215 |
215 bool CompilerDispatcherJob::FinalizeCompilingOnMainThread() { | 216 bool CompilerDispatcherJob::FinalizeCompilingOnMainThread() { |
216 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 217 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
217 DCHECK(status() == CompileJobStatus::kCompiled); | 218 DCHECK(status() == CompileJobStatus::kCompiled); |
218 | 219 |
219 if (compile_job_->state() == CompilationJob::State::kFailed || | 220 for (auto& job : compile_jobs_) { |
220 !Compiler::FinalizeCompilationJob(compile_job_.release())) { | 221 if (job->state() == CompilationJob::State::kFailed || |
221 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); | 222 !Compiler::FinalizeCompilationJob(job.release())) { |
222 status_ = CompileJobStatus::kFailed; | 223 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); |
223 return false; | 224 status_ = CompileJobStatus::kFailed; |
| 225 return false; |
| 226 } |
224 } | 227 } |
225 | 228 |
226 zone_.reset(); | 229 zone_.reset(); |
227 parse_info_.reset(); | 230 parse_info_.reset(); |
228 compile_info_.reset(); | 231 compile_info_.reset(); |
229 compile_job_.reset(); | 232 compile_jobs_.clear(); |
230 handles_from_parsing_.reset(); | 233 handles_from_parsing_.reset(); |
231 | 234 |
232 status_ = CompileJobStatus::kDone; | 235 status_ = CompileJobStatus::kDone; |
233 return true; | 236 return true; |
234 } | 237 } |
235 | 238 |
236 void CompilerDispatcherJob::ResetOnMainThread() { | 239 void CompilerDispatcherJob::ResetOnMainThread() { |
237 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 240 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
238 | 241 |
239 parser_.reset(); | 242 parser_.reset(); |
240 unicode_cache_.reset(); | 243 unicode_cache_.reset(); |
241 character_stream_.reset(); | 244 character_stream_.reset(); |
242 parse_info_.reset(); | 245 parse_info_.reset(); |
243 zone_.reset(); | 246 zone_.reset(); |
244 handles_from_parsing_.reset(); | 247 handles_from_parsing_.reset(); |
245 compile_info_.reset(); | 248 compile_info_.reset(); |
246 compile_job_.reset(); | 249 compile_jobs_.clear(); |
247 | 250 |
248 if (!source_.is_null()) { | 251 if (!source_.is_null()) { |
249 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 252 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); |
250 source_ = Handle<String>::null(); | 253 source_ = Handle<String>::null(); |
251 } | 254 } |
252 | 255 |
253 status_ = CompileJobStatus::kInitial; | 256 status_ = CompileJobStatus::kInitial; |
254 } | 257 } |
255 | 258 |
256 } // namespace internal | 259 } // namespace internal |
257 } // namespace v8 | 260 } // namespace v8 |
OLD | NEW |