| 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" |
| 11 #include "src/flags.h" | 11 #include "src/flags.h" |
| 12 #include "src/global-handles.h" | 12 #include "src/global-handles.h" |
| 13 #include "src/isolate.h" | 13 #include "src/isolate.h" |
| 14 #include "src/objects-inl.h" | 14 #include "src/objects-inl.h" |
| 15 #include "src/parsing/parse-info.h" | 15 #include "src/parsing/parse-info.h" |
| 16 #include "src/parsing/parser.h" | 16 #include "src/parsing/parser.h" |
| 17 #include "src/parsing/scanner-character-streams.h" | 17 #include "src/parsing/scanner-character-streams.h" |
| 18 #include "src/unicode-cache.h" | 18 #include "src/unicode-cache.h" |
| 19 #include "src/utils.h" | 19 #include "src/utils.h" |
| 20 #include "src/zone/zone.h" | 20 #include "src/zone/zone.h" |
| 21 | 21 |
| 22 namespace v8 { | 22 namespace v8 { |
| 23 namespace internal { | 23 namespace internal { |
| 24 | 24 |
| 25 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, | 25 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, |
| 26 CompilerDispatcherTracer* tracer, | 26 CompilerDispatcherTracer* tracer, |
| 27 Handle<SharedFunctionInfo> shared, | 27 Handle<SharedFunctionInfo> shared, |
| 28 size_t max_stack_size) | 28 size_t max_stack_size) |
| 29 : isolate_(isolate), | 29 : status_(CompileJobStatus::kInitial), |
| 30 isolate_(isolate), |
| 30 tracer_(tracer), | 31 tracer_(tracer), |
| 31 shared_(Handle<SharedFunctionInfo>::cast( | 32 shared_(Handle<SharedFunctionInfo>::cast( |
| 32 isolate_->global_handles()->Create(*shared))), | 33 isolate_->global_handles()->Create(*shared))), |
| 33 max_stack_size_(max_stack_size), | 34 max_stack_size_(max_stack_size), |
| 34 can_compile_on_background_thread_(false), | 35 can_compile_on_background_thread_(false), |
| 35 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { | 36 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { |
| 36 HandleScope scope(isolate_); | 37 HandleScope scope(isolate_); |
| 37 DCHECK(!shared_->outer_scope_info()->IsTheHole(isolate_)); | 38 DCHECK(!shared_->outer_scope_info()->IsTheHole(isolate_)); |
| 38 Handle<Script> script(Script::cast(shared_->script()), isolate_); | 39 Handle<Script> script(Script::cast(shared_->script()), isolate_); |
| 39 Handle<String> source(String::cast(script->source()), isolate_); | 40 Handle<String> source(String::cast(script->source()), isolate_); |
| 40 can_parse_on_background_thread_ = | 41 can_parse_on_background_thread_ = |
| 41 source->IsExternalTwoByteString() || source->IsExternalOneByteString(); | 42 source->IsExternalTwoByteString() || source->IsExternalOneByteString(); |
| 42 if (trace_compiler_dispatcher_jobs_) { | 43 if (trace_compiler_dispatcher_jobs_) { |
| 43 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); | 44 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); |
| 44 shared_->ShortPrint(); | 45 shared_->ShortPrint(); |
| 45 PrintF("\n"); | 46 PrintF(" in initial state.\n"); |
| 46 } | 47 } |
| 47 } | 48 } |
| 48 | 49 |
| 50 CompilerDispatcherJob::CompilerDispatcherJob(Isolate* isolate, |
| 51 CompilerDispatcherTracer* tracer, |
| 52 Handle<SharedFunctionInfo> shared, |
| 53 FunctionLiteral* literal, |
| 54 AstValueFactory* ast_value_factory, |
| 55 size_t max_stack_size) |
| 56 : status_(CompileJobStatus::kAnalyzed), |
| 57 isolate_(isolate), |
| 58 tracer_(tracer), |
| 59 shared_(Handle<SharedFunctionInfo>::cast( |
| 60 isolate_->global_handles()->Create(*shared))), |
| 61 max_stack_size_(max_stack_size), |
| 62 zone_(new Zone(isolate->allocator(), ZONE_NAME)), |
| 63 parse_info_(new ParseInfo( |
| 64 zone_.get(), Handle<Script>(Script::cast(shared->script())))), |
| 65 compile_info_( |
| 66 new CompilationInfo(parse_info_.get(), Handle<JSFunction>::null())), |
| 67 can_parse_on_background_thread_(false), |
| 68 can_compile_on_background_thread_(false), |
| 69 trace_compiler_dispatcher_jobs_(FLAG_trace_compiler_dispatcher_jobs) { |
| 70 parse_info_->set_literal(literal); |
| 71 parse_info_->set_shared_info(shared); |
| 72 parse_info_->set_function_literal_id(shared->function_literal_id()); |
| 73 parse_info_->set_language_mode(literal->scope()->language_mode()); |
| 74 parse_info_->set_ast_value_factory(ast_value_factory); |
| 75 parse_info_->set_ast_value_factory_owned(false); |
| 76 if (trace_compiler_dispatcher_jobs_) { |
| 77 PrintF("CompilerDispatcherJob[%p] created for ", static_cast<void*>(this)); |
| 78 shared_->ShortPrint(); |
| 79 PrintF(" in Analyzed state.\n"); |
| 80 } |
| 81 } |
| 82 |
| 49 CompilerDispatcherJob::~CompilerDispatcherJob() { | 83 CompilerDispatcherJob::~CompilerDispatcherJob() { |
| 50 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 84 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
| 51 DCHECK(status_ == CompileJobStatus::kInitial || | 85 DCHECK(status_ == CompileJobStatus::kInitial || |
| 52 status_ == CompileJobStatus::kDone); | 86 status_ == CompileJobStatus::kDone); |
| 53 i::GlobalHandles::Destroy(Handle<Object>::cast(shared_).location()); | 87 i::GlobalHandles::Destroy(Handle<Object>::cast(shared_).location()); |
| 54 } | 88 } |
| 55 | 89 |
| 56 bool CompilerDispatcherJob::IsAssociatedWith( | 90 bool CompilerDispatcherJob::IsAssociatedWith( |
| 57 Handle<SharedFunctionInfo> shared) const { | 91 Handle<SharedFunctionInfo> shared) const { |
| 58 return *shared_ == *shared; | 92 return *shared_ == *shared; |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 } | 188 } |
| 155 | 189 |
| 156 if (!source_.is_null()) { | 190 if (!source_.is_null()) { |
| 157 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); | 191 i::GlobalHandles::Destroy(Handle<Object>::cast(source_).location()); |
| 158 source_ = Handle<String>::null(); | 192 source_ = Handle<String>::null(); |
| 159 } | 193 } |
| 160 | 194 |
| 161 if (parse_info_->literal() == nullptr) { | 195 if (parse_info_->literal() == nullptr) { |
| 162 status_ = CompileJobStatus::kFailed; | 196 status_ = CompileJobStatus::kFailed; |
| 163 } else { | 197 } else { |
| 164 status_ = CompileJobStatus::kReadyToAnalyse; | 198 status_ = CompileJobStatus::kReadyToAnalyze; |
| 165 } | 199 } |
| 166 | 200 |
| 167 DeferredHandleScope scope(isolate_); | 201 DeferredHandleScope scope(isolate_); |
| 168 { | 202 { |
| 169 Handle<Script> script(Script::cast(shared_->script()), isolate_); | 203 Handle<Script> script(Script::cast(shared_->script()), isolate_); |
| 170 | 204 |
| 171 parse_info_->set_script(script); | 205 parse_info_->set_script(script); |
| 172 Handle<ScopeInfo> outer_scope_info( | 206 Handle<ScopeInfo> outer_scope_info( |
| 173 handle(ScopeInfo::cast(shared_->outer_scope_info()))); | 207 handle(ScopeInfo::cast(shared_->outer_scope_info()))); |
| 174 if (outer_scope_info->length() > 0) { | 208 if (outer_scope_info->length() > 0) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 185 parse_info_->set_unicode_cache(nullptr); | 219 parse_info_->set_unicode_cache(nullptr); |
| 186 parser_.reset(); | 220 parser_.reset(); |
| 187 unicode_cache_.reset(); | 221 unicode_cache_.reset(); |
| 188 character_stream_.reset(); | 222 character_stream_.reset(); |
| 189 } | 223 } |
| 190 handles_from_parsing_.reset(scope.Detach()); | 224 handles_from_parsing_.reset(scope.Detach()); |
| 191 | 225 |
| 192 return status_ != CompileJobStatus::kFailed; | 226 return status_ != CompileJobStatus::kFailed; |
| 193 } | 227 } |
| 194 | 228 |
| 195 bool CompilerDispatcherJob::PrepareToCompileOnMainThread() { | 229 bool CompilerDispatcherJob::AnalyzeOnMainThread() { |
| 196 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 230 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
| 197 DCHECK(status() == CompileJobStatus::kReadyToAnalyse); | 231 DCHECK(status() == CompileJobStatus::kReadyToAnalyze); |
| 198 COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kPrepareToCompile); | 232 COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kAnalyze); |
| 199 if (trace_compiler_dispatcher_jobs_) { | 233 if (trace_compiler_dispatcher_jobs_) { |
| 200 PrintF("CompilerDispatcherJob[%p]: Preparing to compile\n", | 234 PrintF("CompilerDispatcherJob[%p]: Analyzing\n", static_cast<void*>(this)); |
| 201 static_cast<void*>(this)); | |
| 202 } | 235 } |
| 203 | 236 |
| 204 compile_info_.reset( | 237 compile_info_.reset( |
| 205 new CompilationInfo(parse_info_.get(), Handle<JSFunction>::null())); | 238 new CompilationInfo(parse_info_.get(), Handle<JSFunction>::null())); |
| 206 | 239 |
| 207 DeferredHandleScope scope(isolate_); | 240 DeferredHandleScope scope(isolate_); |
| 208 if (Compiler::Analyze(parse_info_.get())) { | 241 { |
| 209 compile_job_.reset( | 242 if (Compiler::Analyze(parse_info_.get())) { |
| 210 Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get())); | 243 status_ = CompileJobStatus::kAnalyzed; |
| 244 } else { |
| 245 status_ = CompileJobStatus::kFailed; |
| 246 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); |
| 247 } |
| 211 } | 248 } |
| 212 compile_info_->set_deferred_handles(scope.Detach()); | 249 compile_info_->set_deferred_handles(scope.Detach()); |
| 213 | 250 |
| 251 return status_ != CompileJobStatus::kFailed; |
| 252 } |
| 253 |
| 254 bool CompilerDispatcherJob::PrepareToCompileOnMainThread() { |
| 255 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
| 256 DCHECK(status() == CompileJobStatus::kAnalyzed); |
| 257 COMPILER_DISPATCHER_TRACE_SCOPE(tracer_, kPrepareToCompile); |
| 258 |
| 259 compile_job_.reset( |
| 260 Compiler::PrepareUnoptimizedCompilationJob(compile_info_.get())); |
| 214 if (!compile_job_.get()) { | 261 if (!compile_job_.get()) { |
| 215 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); | 262 if (!isolate_->has_pending_exception()) isolate_->StackOverflow(); |
| 216 status_ = CompileJobStatus::kFailed; | 263 status_ = CompileJobStatus::kFailed; |
| 217 return false; | 264 return false; |
| 218 } | 265 } |
| 219 | 266 |
| 220 can_compile_on_background_thread_ = | 267 can_compile_on_background_thread_ = |
| 221 compile_job_->can_execute_on_background_thread(); | 268 compile_job_->can_execute_on_background_thread(); |
| 222 status_ = CompileJobStatus::kReadyToCompile; | 269 status_ = CompileJobStatus::kReadyToCompile; |
| 223 return true; | 270 return true; |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 302 case CompileJobStatus::kInitial: | 349 case CompileJobStatus::kInitial: |
| 303 return tracer_->EstimatePrepareToParseInMs(); | 350 return tracer_->EstimatePrepareToParseInMs(); |
| 304 | 351 |
| 305 case CompileJobStatus::kReadyToParse: | 352 case CompileJobStatus::kReadyToParse: |
| 306 return tracer_->EstimateParseInMs(parse_info_->end_position() - | 353 return tracer_->EstimateParseInMs(parse_info_->end_position() - |
| 307 parse_info_->start_position()); | 354 parse_info_->start_position()); |
| 308 | 355 |
| 309 case CompileJobStatus::kParsed: | 356 case CompileJobStatus::kParsed: |
| 310 return tracer_->EstimateFinalizeParsingInMs(); | 357 return tracer_->EstimateFinalizeParsingInMs(); |
| 311 | 358 |
| 312 case CompileJobStatus::kReadyToAnalyse: | 359 case CompileJobStatus::kReadyToAnalyze: |
| 360 return tracer_->EstimateAnalyzeInMs(); |
| 361 |
| 362 case CompileJobStatus::kAnalyzed: |
| 313 return tracer_->EstimatePrepareToCompileInMs(); | 363 return tracer_->EstimatePrepareToCompileInMs(); |
| 314 | 364 |
| 315 case CompileJobStatus::kReadyToCompile: | 365 case CompileJobStatus::kReadyToCompile: |
| 316 return tracer_->EstimateCompileInMs( | 366 return tracer_->EstimateCompileInMs( |
| 317 parse_info_->literal()->ast_node_count()); | 367 parse_info_->literal()->ast_node_count()); |
| 318 | 368 |
| 319 case CompileJobStatus::kCompiled: | 369 case CompileJobStatus::kCompiled: |
| 320 return tracer_->EstimateFinalizeCompilingInMs(); | 370 return tracer_->EstimateFinalizeCompilingInMs(); |
| 321 | 371 |
| 322 case CompileJobStatus::kFailed: | 372 case CompileJobStatus::kFailed: |
| 323 case CompileJobStatus::kDone: | 373 case CompileJobStatus::kDone: |
| 324 return 0.0; | 374 return 0.0; |
| 325 } | 375 } |
| 326 | 376 |
| 327 UNREACHABLE(); | 377 UNREACHABLE(); |
| 328 return 0.0; | 378 return 0.0; |
| 329 } | 379 } |
| 330 | 380 |
| 331 void CompilerDispatcherJob::ShortPrint() { | 381 void CompilerDispatcherJob::ShortPrint() { |
| 332 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); | 382 DCHECK(ThreadId::Current().Equals(isolate_->thread_id())); |
| 333 shared_->ShortPrint(); | 383 shared_->ShortPrint(); |
| 334 } | 384 } |
| 335 | 385 |
| 336 } // namespace internal | 386 } // namespace internal |
| 337 } // namespace v8 | 387 } // namespace v8 |
| OLD | NEW |