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-dispatcher/compiler-dispatcher-tracer.h" | 9 #include "src/compiler-dispatcher/compiler-dispatcher-tracer.h" |
10 #include "src/compiler.h" | 10 #include "src/compiler.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
77 DCHECK(!shared_->outer_scope_info()->IsTheHole(isolate_)); | 77 DCHECK(!shared_->outer_scope_info()->IsTheHole(isolate_)); |
78 Handle<Script> script(Script::cast(shared_->script()), isolate_); | 78 Handle<Script> script(Script::cast(shared_->script()), isolate_); |
79 Handle<String> source(String::cast(script->source()), isolate_); | 79 Handle<String> source(String::cast(script->source()), isolate_); |
80 if (trace_compiler_dispatcher_jobs_) { | 80 if (trace_compiler_dispatcher_jobs_) { |
81 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); | 81 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); |
82 shared_->ShortPrint(); | 82 shared_->ShortPrint(); |
83 PrintF(" in initial state.\n"); | 83 PrintF(" in initial state.\n"); |
84 } | 84 } |
85 } | 85 } |
86 | 86 |
87 CompilerDispatcherJob::CompilerDispatcherJob( | 87 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, |
88 Isolate* isolate, CompilerDispatcherTracer* tracer, | 88 CompilerDispatcherTracer* tracer, |
89 Handle<SharedFunctionInfo> shared, FunctionLiteral* literal, | 89 Handle<SharedFunctionInfo> shared, |
90 std::shared_ptr<Zone> parse_zone, | 90 FunctionLiteral* literal, |
91 std::shared_ptr<DeferredHandles> parse_handles, | 91 size_t max_stack_size) |
92 std::shared_ptr<DeferredHandles> compile_handles, size_t max_stack_size) | |
93 : status_(CompileJobStatus::kAnalyzed), | 92 : status_(CompileJobStatus::kAnalyzed), |
94 isolate_(isolate), | 93 isolate_(isolate), |
95 tracer_(tracer), | 94 tracer_(tracer), |
96 shared_(Handle<SharedFunctionInfo>::cast( | 95 shared_(Handle<SharedFunctionInfo>::cast( |
97 isolate_->global_handles()->Create(*shared))), | 96 isolate_->global_handles()->Create(*shared))), |
98 max_stack_size_(max_stack_size), | 97 max_stack_size_(max_stack_size), |
99 parse_info_(new ParseInfo(shared_)), | 98 parse_info_( |
100 parse_zone_(parse_zone), | 99 new ParseInfo(Handle<Script>(Script::cast(shared->script())))), |
101 compile_info_(new CompilationInfo(parse_info_->zone(), parse_info_.get(), | 100 compile_info_(new CompilationInfo(parse_info_->zone(), parse_info_.get(), |
102 Handle<JSFunction>::null())), | 101 Handle<JSFunction>::null())), |
103 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { | 102 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { |
104 parse_info_->set_literal(literal); | 103 parse_info_->set_literal(literal); |
105 parse_info_->set_deferred_handles(parse_handles); | 104 parse_info_->set_shared_info(shared); |
106 compile_info_->set_deferred_handles(compile_handles); | 105 parse_info_->set_function_literal_id(shared->function_literal_id()); |
107 | 106 parse_info_->set_language_mode(literal->scope()->language_mode()); |
108 if (trace_compiler_dispatcher_jobs_) { | 107 if (trace_compiler_dispatcher_jobs_) { |
109 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); | 108 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); |
110 shared_->ShortPrint(); | 109 shared_->ShortPrint(); |
111 PrintF(" in Analyzed state.\n"); | 110 PrintF(" in Analyzed state.\n"); |
112 } | 111 } |
113 } | 112 } |
114 | 113 |
115 CompilerDispatcherJob::~CompilerDispatcherJob() { | 114 CompilerDispatcherJob::~CompilerDispatcherJob() { |
116 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 115 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
117 DCHECK(status_ == CompileJobStatus::kInitial || | 116 DCHECK(status_ == CompileJobStatus::kInitial || |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
270 | 269 |
271 if (!source_.is_null()) { | 270 if (!source_.is_null()) { |
272 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 271 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); |
273 source_ = Handle<String>::null(); | 272 source_ = Handle<String>::null(); |
274 } | 273 } |
275 if (!wrapper_.is_null()) { | 274 if (!wrapper_.is_null()) { |
276 i::GlobalHandles::Destroy(Handle<Object>::cast(wrapper_).location()); | 275 i::GlobalHandles::Destroy(Handle<Object>::cast(wrapper_).location()); |
277 wrapper_ = Handle<String>::null(); | 276 wrapper_ = Handle<String>::null(); |
278 } | 277 } |
279 | 278 |
280 Handle<Script> script(Script::cast(shared_->script()), isolate_); | |
281 parse_info_->set_script(script); | |
282 if (parse_info_->literal() == nullptr) { | 279 if (parse_info_->literal() == nullptr) { |
283 parser_->ReportErrors(isolate_, script); | |
284 status_ = CompileJobStatus::kFailed; | 280 status_ = CompileJobStatus::kFailed; |
285 } else { | 281 } else { |
286 status_ = CompileJobStatus::kReadyToAnalyze; | 282 status_ = CompileJobStatus::kReadyToAnalyze; |
287 } | 283 } |
288 parser_->UpdateStatistics(isolate_, script); | |
289 | 284 |
290 DeferredHandleScope scope(isolate_); | 285 DeferredHandleScope scope(isolate_); |
291 { | 286 { |
292 parse_info_->ReopenHandlesInNewHandleScope(); | 287 Handle<Script> script(Script::cast(shared_->script()), isolate_); |
| 288 |
| 289 parse_info_->set_script(script); |
293 Handle<ScopeInfo> outer_scope_info( | 290 Handle<ScopeInfo> outer_scope_info( |
294 handle(ScopeInfo::cast(shared_->outer_scope_info()))); | 291 handle(ScopeInfo::cast(shared_->outer_scope_info()))); |
295 if (outer_scope_info->length() > 0) { | 292 if (outer_scope_info->length() > 0) { |
296 parse_info_->set_outer_scope_info(outer_scope_info); | 293 parse_info_->set_outer_scope_info(outer_scope_info); |
297 } | 294 } |
298 parse_info_->set_shared_info(shared_); | 295 parse_info_->set_shared_info(shared_); |
299 | 296 |
300 // Internalize ast values on the main thread. | 297 // Do the parsing tasks which need to be done on the main thread. This |
301 parse_info_->ast_value_factory()->Internalize(isolate_); | 298 // will also handle parse errors. |
| 299 parser_->Internalize(isolate_, script, parse_info_->literal() == nullptr); |
302 parser_->HandleSourceURLComments(isolate_, script); | 300 parser_->HandleSourceURLComments(isolate_, script); |
303 | 301 |
304 parse_info_->set_character_stream(nullptr); | 302 parse_info_->set_character_stream(nullptr); |
305 parse_info_->set_unicode_cache(nullptr); | 303 parse_info_->set_unicode_cache(nullptr); |
306 parser_.reset(); | 304 parser_.reset(); |
307 unicode_cache_.reset(); | 305 unicode_cache_.reset(); |
308 character_stream_.reset(); | 306 character_stream_.reset(); |
309 } | 307 } |
310 parse_info_->set_deferred_handles(scope.Detach()); | 308 handles_from_parsing_.reset(scope.Detach()); |
311 | 309 |
312 return status_ != CompileJobStatus::kFailed; | 310 return status_ != CompileJobStatus::kFailed; |
313 } | 311 } |
314 | 312 |
315 bool CompilerDispatcherJob::AnalyzeOnMainThread() { | 313 bool CompilerDispatcherJob::AnalyzeOnMainThread() { |
316 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 314 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
317 DCHECK(status() == CompileJobStatus::kReadyToAnalyze); | 315 DCHECK(status() == CompileJobStatus::kReadyToAnalyze); |
318 COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kAnalyze); | 316 COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kAnalyze); |
319 if (trace_compiler_dispatcher_jobs_) { | 317 if (trace_compiler_dispatcher_jobs_) { |
320 PrintF("CompilerDispatcherJob[%p]: Analyzing\n", static_cast<void*>(this)); | 318 PrintF("CompilerDispatcherJob[%p]: Analyzing\n", static_cast<void*>(this)); |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
388 | 386 |
389 if (compile_job_->state() == CompilationJob::State::kFailed || | 387 if (compile_job_->state() == CompilationJob::State::kFailed || |
390 !Compiler::FinalizeCompilationJob(compile_job_.release())) { | 388 !Compiler::FinalizeCompilationJob(compile_job_.release())) { |
391 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); | 389 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); |
392 status_ = CompileJobStatus::kFailed; | 390 status_ = CompileJobStatus::kFailed; |
393 return false; | 391 return false; |
394 } | 392 } |
395 | 393 |
396 compile_job_.reset(); | 394 compile_job_.reset(); |
397 compile_info_.reset(); | 395 compile_info_.reset(); |
398 parse_zone_.reset(); | 396 handles_from_parsing_.reset(); |
399 parse_info_.reset(); | 397 parse_info_.reset(); |
400 | 398 |
401 status_ = CompileJobStatus::kDone; | 399 status_ = CompileJobStatus::kDone; |
402 return true; | 400 return true; |
403 } | 401 } |
404 | 402 |
405 void CompilerDispatcherJob::ResetOnMainThread() { | 403 void CompilerDispatcherJob::ResetOnMainThread() { |
406 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 404 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
407 | 405 |
408 if (trace_compiler_dispatcher_jobs_) { | 406 if (trace_compiler_dispatcher_jobs_) { |
409 PrintF("CompilerDispatcherJob[%p]: Resetting\n", static_cast<void*>(this)); | 407 PrintF("CompilerDispatcherJob[%p]: Resetting\n", static_cast<void*>(this)); |
410 } | 408 } |
411 | 409 |
412 compile_job_.reset(); | 410 compile_job_.reset(); |
413 compile_info_.reset(); | 411 compile_info_.reset(); |
414 parse_zone_.reset(); | |
415 parser_.reset(); | 412 parser_.reset(); |
416 unicode_cache_.reset(); | 413 unicode_cache_.reset(); |
417 character_stream_.reset(); | 414 character_stream_.reset(); |
| 415 handles_from_parsing_.reset(); |
418 parse_info_.reset(); | 416 parse_info_.reset(); |
419 | 417 |
420 if (!source_.is_null()) { | 418 if (!source_.is_null()) { |
421 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 419 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); |
422 source_ = Handle<String>::null(); | 420 source_ = Handle<String>::null(); |
423 } | 421 } |
424 if (!wrapper_.is_null()) { | 422 if (!wrapper_.is_null()) { |
425 i::GlobalHandles::Destroy(Handle<Object>::cast(wrapper_).location()); | 423 i::GlobalHandles::Destroy(Handle<Object>::cast(wrapper_).location()); |
426 wrapper_ = Handle<String>::null(); | 424 wrapper_ = Handle<String>::null(); |
427 } | 425 } |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 return 0.0; | 461 return 0.0; |
464 } | 462 } |
465 | 463 |
466 void CompilerDispatcherJob::ShortPrint() { | 464 void CompilerDispatcherJob::ShortPrint() { |
467 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 465 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
468 shared_->ShortPrint(); | 466 shared_->ShortPrint(); |
469 } | 467 } |
470 | 468 |
471 } // namespace internal | 469 } // namespace internal |
472 } // namespace v8 | 470 } // namespace v8 |
OLD | NEW |