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