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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 } // namespace | 63 } // namespace |
64 | 64 |
65 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, | 65 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, |
66 CompilerDispatcherTracer* tracer, | 66 CompilerDispatcherTracer* tracer, |
67 Handle<SharedFunctionInfo> shared, | 67 Handle<SharedFunctionInfo> shared, |
68 size_t max_stack_size) | 68 size_t max_stack_size) |
69 : status_(CompileJobStatus::kInitial), | 69 : status_(CompileJobStatus::kInitial), |
70 isolate_(isolate), | 70 isolate_(isolate), |
71 tracer_(tracer), | 71 tracer_(tracer), |
| 72 context_(Handle<Context>::cast( |
| 73 isolate_->global_handles()->Create(isolate->context()))), |
72 shared_(Handle<SharedFunctionInfo>::cast( | 74 shared_(Handle<SharedFunctionInfo>::cast( |
73 isolate_->global_handles()->Create(*shared))), | 75 isolate_->global_handles()->Create(*shared))), |
74 max_stack_size_(max_stack_size), | 76 max_stack_size_(max_stack_size), |
75 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { | 77 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { |
76 HandleScope scope(isolate_); | 78 HandleScope scope(isolate_); |
77 DCHECK(!shared_->outer_scope_info()->IsTheHole(isolate_)); | 79 DCHECK(!shared_->outer_scope_info()->IsTheHole(isolate_)); |
78 Handle<Script> script(Script::cast(shared_->script()), isolate_); | 80 Handle<Script> script(Script::cast(shared_->script()), isolate_); |
79 Handle<String> source(String::cast(script->source()), isolate_); | 81 Handle<String> source(String::cast(script->source()), isolate_); |
80 if (trace_compiler_dispatcher_jobs_) { | 82 if (trace_compiler_dispatcher_jobs_) { |
81 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); | 83 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); |
82 shared_->ShortPrint(); | 84 shared_->ShortPrint(); |
83 PrintF(" in initial state.\n"); | 85 PrintF(" in initial state.\n"); |
84 } | 86 } |
85 } | 87 } |
86 | 88 |
87 CompilerDispatcherJob::CompilerDispatcherJob( | 89 CompilerDispatcherJob::CompilerDispatcherJob( |
88 Isolate* isolate, CompilerDispatcherTracer* tracer, | 90 Isolate* isolate, CompilerDispatcherTracer* tracer, |
89 Handle<SharedFunctionInfo> shared, FunctionLiteral* literal, | 91 Handle<SharedFunctionInfo> shared, FunctionLiteral* literal, |
90 std::shared_ptr<Zone> parse_zone, | 92 std::shared_ptr<Zone> parse_zone, |
91 std::shared_ptr<DeferredHandles> parse_handles, | 93 std::shared_ptr<DeferredHandles> parse_handles, |
92 std::shared_ptr<DeferredHandles> compile_handles, size_t max_stack_size) | 94 std::shared_ptr<DeferredHandles> compile_handles, size_t max_stack_size) |
93 : status_(CompileJobStatus::kAnalyzed), | 95 : status_(CompileJobStatus::kAnalyzed), |
94 isolate_(isolate), | 96 isolate_(isolate), |
95 tracer_(tracer), | 97 tracer_(tracer), |
| 98 context_(Handle<Context>::cast( |
| 99 isolate_->global_handles()->Create(isolate->context()))), |
96 shared_(Handle<SharedFunctionInfo>::cast( | 100 shared_(Handle<SharedFunctionInfo>::cast( |
97 isolate_->global_handles()->Create(*shared))), | 101 isolate_->global_handles()->Create(*shared))), |
98 max_stack_size_(max_stack_size), | 102 max_stack_size_(max_stack_size), |
99 parse_info_(new ParseInfo(shared_)), | 103 parse_info_(new ParseInfo(shared_)), |
100 parse_zone_(parse_zone), | 104 parse_zone_(parse_zone), |
101 compile_info_(new CompilationInfo(parse_info_->zone(), parse_info_.get(), | 105 compile_info_(new CompilationInfo(parse_info_->zone(), parse_info_.get(), |
102 Handle<JSFunction>::null())), | 106 Handle<JSFunction>::null())), |
103 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { | 107 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { |
104 parse_info_->set_literal(literal); | 108 parse_info_->set_literal(literal); |
105 parse_info_->set_deferred_handles(parse_handles); | 109 parse_info_->set_deferred_handles(parse_handles); |
106 compile_info_->set_deferred_handles(compile_handles); | 110 compile_info_->set_deferred_handles(compile_handles); |
107 | 111 |
108 if (trace_compiler_dispatcher_jobs_) { | 112 if (trace_compiler_dispatcher_jobs_) { |
109 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); | 113 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); |
110 shared_->ShortPrint(); | 114 shared_->ShortPrint(); |
111 PrintF(" in Analyzed state.\n"); | 115 PrintF(" in Analyzed state.\n"); |
112 } | 116 } |
113 } | 117 } |
114 | 118 |
115 CompilerDispatcherJob::~CompilerDispatcherJob() { | 119 CompilerDispatcherJob::~CompilerDispatcherJob() { |
116 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 120 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
117 DCHECK(status_ == CompileJobStatus::kInitial || | 121 DCHECK(status_ == CompileJobStatus::kInitial || |
118 status_ == CompileJobStatus::kDone); | 122 status_ == CompileJobStatus::kDone); |
119 i::GlobalHandles::Destroy(Handle<Object>::cast(shared_).location()); | 123 i::GlobalHandles::Destroy(Handle<Object>::cast(shared_).location()); |
| 124 i::GlobalHandles::Destroy(Handle<Object>::cast(context_).location()); |
120 } | 125 } |
121 | 126 |
122 bool CompilerDispatcherJob::IsAssociatedWith( | 127 bool CompilerDispatcherJob::IsAssociatedWith( |
123 Handle<SharedFunctionInfo> shared) const { | 128 Handle<SharedFunctionInfo> shared) const { |
124 return *shared_ == *shared; | 129 return *shared_ == *shared; |
125 } | 130 } |
126 | 131 |
127 void CompilerDispatcherJob::PrepareToParseOnMainThread() { | 132 void CompilerDispatcherJob::PrepareToParseOnMainThread() { |
128 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 133 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
129 DCHECK(status() == CompileJobStatus::kInitial); | 134 DCHECK(status() == CompileJobStatus::kInitial); |
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
379 | 384 |
380 bool CompilerDispatcherJob::FinalizeCompilingOnMainThread() { | 385 bool CompilerDispatcherJob::FinalizeCompilingOnMainThread() { |
381 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 386 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
382 DCHECK(status() == CompileJobStatus::kCompiled); | 387 DCHECK(status() == CompileJobStatus::kCompiled); |
383 COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kFinalizeCompiling); | 388 COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kFinalizeCompiling); |
384 if (trace_compiler_dispatcher_jobs_) { | 389 if (trace_compiler_dispatcher_jobs_) { |
385 PrintF("CompilerDispatcherJob[%p]: Finalizing compiling\n", | 390 PrintF("CompilerDispatcherJob[%p]: Finalizing compiling\n", |
386 static_cast<void*>(this)); | 391 static_cast<void*>(this)); |
387 } | 392 } |
388 | 393 |
389 if (compile_job_->state() == CompilationJob::State::kFailed || | 394 { |
390 !Compiler::FinalizeCompilationJob(compile_job_.release())) { | 395 HandleScope scope(isolate_); |
391 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); | 396 if (compile_job_->state() == CompilationJob::State::kFailed || |
392 status_ = CompileJobStatus::kFailed; | 397 !Compiler::FinalizeCompilationJob(compile_job_.release())) { |
393 return false; | 398 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); |
| 399 status_ = CompileJobStatus::kFailed; |
| 400 return false; |
| 401 } |
394 } | 402 } |
395 | 403 |
396 compile_job_.reset(); | 404 compile_job_.reset(); |
397 compile_info_.reset(); | 405 compile_info_.reset(); |
398 parse_zone_.reset(); | 406 parse_zone_.reset(); |
399 parse_info_.reset(); | 407 parse_info_.reset(); |
400 | 408 |
401 status_ = CompileJobStatus::kDone; | 409 status_ = CompileJobStatus::kDone; |
402 return true; | 410 return true; |
403 } | 411 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
463 return 0.0; | 471 return 0.0; |
464 } | 472 } |
465 | 473 |
466 void CompilerDispatcherJob::ShortPrint() { | 474 void CompilerDispatcherJob::ShortPrint() { |
467 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 475 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
468 shared_->ShortPrint(); | 476 shared_->ShortPrint(); |
469 } | 477 } |
470 | 478 |
471 } // namespace internal | 479 } // namespace internal |
472 } // namespace v8 | 480 } // namespace v8 |
OLD | NEW |