OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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.h" | 5 #include "src/compiler.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "src/asmjs/asm-js.h" | 10 #include "src/asmjs/asm-js.h" |
(...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 } | 271 } |
272 | 272 |
273 CompilationJob::Status CompilationJob::FinalizeJob() { | 273 CompilationJob::Status CompilationJob::FinalizeJob() { |
274 DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id())); | 274 DCHECK(ThreadId::Current().Equals(info()->isolate()->thread_id())); |
275 DisallowCodeDependencyChange no_dependency_change; | 275 DisallowCodeDependencyChange no_dependency_change; |
276 DisallowJavascriptExecution no_js(isolate()); | 276 DisallowJavascriptExecution no_js(isolate()); |
277 DCHECK(!info()->dependencies()->HasAborted()); | 277 DCHECK(!info()->dependencies()->HasAborted()); |
278 | 278 |
279 // Delegate to the underlying implementation. | 279 // Delegate to the underlying implementation. |
280 DCHECK(state() == State::kReadyToFinalize); | 280 DCHECK(state() == State::kReadyToFinalize); |
281 ScopedTimer t(&time_taken_to_finalize_); | 281 Status status; |
282 return UpdateState(FinalizeJobImpl(), State::kSucceeded); | 282 { |
| 283 ScopedTimer t(&time_taken_to_finalize_); |
| 284 status = FinalizeJobImpl(); |
| 285 if (status == SUCCEEDED) { |
| 286 RecordCompilationStats(); |
| 287 } |
| 288 } |
| 289 return UpdateState(status, State::kSucceeded); |
283 } | 290 } |
284 | 291 |
285 void CompilationJob::RecordOptimizationStats() { | 292 void CompilationJob::RecordUnoptimizedCompilationStats() const { |
| 293 DCHECK(!info()->IsOptimizing()); |
| 294 |
| 295 int code_size; |
| 296 if (info()->has_bytecode_array()) { |
| 297 code_size = info()->bytecode_array()->SizeIncludingMetadata(); |
| 298 } else { |
| 299 code_size = info()->code()->SizeIncludingMetadata(); |
| 300 } |
| 301 |
| 302 Counters* counters = isolate()->counters(); |
| 303 // TODO(4280): Rename counters from "baseline" to "unoptimized" eventually. |
| 304 counters->total_baseline_code_size()->Increment(code_size); |
| 305 counters->total_baseline_compile_count()->Increment(1); |
| 306 |
| 307 // TODO(5203): Add timers for each phase of compilation. |
| 308 } |
| 309 |
| 310 void CompilationJob::RecordOptimizedCompilationStats() const { |
286 DCHECK(info()->IsOptimizing()); | 311 DCHECK(info()->IsOptimizing()); |
287 Handle<JSFunction> function = info()->closure(); | 312 Handle<JSFunction> function = info()->closure(); |
288 if (!function->IsOptimized()) { | 313 if (!function->IsOptimized()) { |
289 // Concurrent recompilation and OSR may race. Increment only once. | 314 // Concurrent recompilation and OSR may race. Increment only once. |
290 int opt_count = function->shared()->opt_count(); | 315 int opt_count = function->shared()->opt_count(); |
291 function->shared()->set_opt_count(opt_count + 1); | 316 function->shared()->set_opt_count(opt_count + 1); |
292 } | 317 } |
293 double ms_creategraph = time_taken_to_prepare_.InMillisecondsF(); | 318 double ms_creategraph = time_taken_to_prepare_.InMillisecondsF(); |
294 double ms_optimize = time_taken_to_execute_.InMillisecondsF(); | 319 double ms_optimize = time_taken_to_execute_.InMillisecondsF(); |
295 double ms_codegen = time_taken_to_finalize_.InMillisecondsF(); | 320 double ms_codegen = time_taken_to_finalize_.InMillisecondsF(); |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
402 // Checks whether top level functions should be passed by the filter. | 427 // Checks whether top level functions should be passed by the filter. |
403 if (info->shared_info()->is_toplevel()) { | 428 if (info->shared_info()->is_toplevel()) { |
404 Vector<const char> filter = CStrVector(FLAG_ignition_filter); | 429 Vector<const char> filter = CStrVector(FLAG_ignition_filter); |
405 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*'); | 430 return (filter.length() == 0) || (filter.length() == 1 && filter[0] == '*'); |
406 } | 431 } |
407 | 432 |
408 // Finally respect the filter. | 433 // Finally respect the filter. |
409 return info->shared_info()->PassesFilter(FLAG_ignition_filter); | 434 return info->shared_info()->PassesFilter(FLAG_ignition_filter); |
410 } | 435 } |
411 | 436 |
412 int CodeAndMetadataSize(CompilationInfo* info) { | 437 CompilationJob* GetUnoptimizedCompilationJob(CompilationInfo* info) { |
413 if (info->has_bytecode_array()) { | 438 // Function should have been parsed and analyzed before creating a compilation |
414 return info->bytecode_array()->SizeIncludingMetadata(); | 439 // job. |
| 440 DCHECK_NOT_NULL(info->literal()); |
| 441 DCHECK_NOT_NULL(info->scope()); |
| 442 DCHECK(!(FLAG_validate_asm && info->scope()->asm_module())); |
| 443 |
| 444 EnsureFeedbackMetadata(info); |
| 445 |
| 446 if (ShouldUseIgnition(info)) { |
| 447 return interpreter::Interpreter::NewCompilationJob(info); |
| 448 } else { |
| 449 return FullCodeGenerator::NewCompilationJob(info); |
415 } | 450 } |
416 return info->code()->SizeIncludingMetadata(); | |
417 } | 451 } |
418 | 452 |
419 bool GenerateUnoptimizedCode(CompilationInfo* info) { | 453 bool GenerateUnoptimizedCode(CompilationInfo* info) { |
420 bool success; | |
421 EnsureFeedbackMetadata(info); | |
422 if (FLAG_validate_asm && info->scope()->asm_module()) { | 454 if (FLAG_validate_asm && info->scope()->asm_module()) { |
423 MaybeHandle<FixedArray> wasm_data; | 455 MaybeHandle<FixedArray> wasm_data; |
424 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info()); | 456 wasm_data = AsmJs::ConvertAsmToWasm(info->parse_info()); |
425 if (!wasm_data.is_null()) { | 457 if (!wasm_data.is_null()) { |
426 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); | 458 info->shared_info()->set_asm_wasm_data(*wasm_data.ToHandleChecked()); |
427 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); | 459 info->SetCode(info->isolate()->builtins()->InstantiateAsmJs()); |
428 return true; | 460 return true; |
429 } | 461 } |
430 } | 462 } |
431 if (ShouldUseIgnition(info)) { | 463 |
432 success = interpreter::Interpreter::MakeBytecode(info); | 464 std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info)); |
433 } else { | 465 if (job->PrepareJob() != CompilationJob::SUCCEEDED) return false; |
434 success = FullCodeGenerator::MakeCode(info); | 466 if (job->ExecuteJob() != CompilationJob::SUCCEEDED) return false; |
435 } | 467 if (job->FinalizeJob() != CompilationJob::SUCCEEDED) return false; |
436 if (success) { | 468 return true; |
437 Isolate* isolate = info->isolate(); | |
438 Counters* counters = isolate->counters(); | |
439 // TODO(4280): Rename counters from "baseline" to "unoptimized" eventually. | |
440 counters->total_baseline_code_size()->Increment(CodeAndMetadataSize(info)); | |
441 counters->total_baseline_compile_count()->Increment(1); | |
442 } | |
443 return success; | |
444 } | 469 } |
445 | 470 |
446 bool CompileUnoptimizedCode(CompilationInfo* info) { | 471 bool CompileUnoptimizedCode(CompilationInfo* info) { |
447 DCHECK(AllowCompilation::IsAllowed(info->isolate())); | 472 DCHECK(AllowCompilation::IsAllowed(info->isolate())); |
448 if (!Compiler::Analyze(info->parse_info()) || | 473 if (!Compiler::Analyze(info->parse_info()) || |
449 !GenerateUnoptimizedCode(info)) { | 474 !GenerateUnoptimizedCode(info)) { |
450 Isolate* isolate = info->isolate(); | 475 Isolate* isolate = info->isolate(); |
451 if (!isolate->has_pending_exception()) isolate->StackOverflow(); | 476 if (!isolate->has_pending_exception()) isolate->StackOverflow(); |
452 return false; | 477 return false; |
453 } | 478 } |
(...skipping 16 matching lines...) Expand all Loading... |
470 shared->ClearBytecodeArray(); | 495 shared->ClearBytecodeArray(); |
471 } | 496 } |
472 DCHECK(!info->code().is_null()); | 497 DCHECK(!info->code().is_null()); |
473 shared->ReplaceCode(*info->code()); | 498 shared->ReplaceCode(*info->code()); |
474 if (info->has_bytecode_array()) { | 499 if (info->has_bytecode_array()) { |
475 DCHECK(!shared->HasBytecodeArray()); // Only compiled once. | 500 DCHECK(!shared->HasBytecodeArray()); // Only compiled once. |
476 shared->set_bytecode_array(*info->bytecode_array()); | 501 shared->set_bytecode_array(*info->bytecode_array()); |
477 } | 502 } |
478 } | 503 } |
479 | 504 |
| 505 void InstallUnoptimizedCode(CompilationInfo* info) { |
| 506 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 507 |
| 508 // Update the shared function info with the scope info. |
| 509 InstallSharedScopeInfo(info, shared); |
| 510 |
| 511 // Install compilation result on the shared function info |
| 512 InstallSharedCompilationResult(info, shared); |
| 513 |
| 514 // Record the function compilation event. |
| 515 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
| 516 } |
| 517 |
480 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { | 518 MUST_USE_RESULT MaybeHandle<Code> GetUnoptimizedCode(CompilationInfo* info) { |
481 VMState<COMPILER> state(info->isolate()); | 519 VMState<COMPILER> state(info->isolate()); |
482 PostponeInterruptsScope postpone(info->isolate()); | 520 PostponeInterruptsScope postpone(info->isolate()); |
483 | 521 |
484 // Create a canonical handle scope before internalizing parsed values if | 522 // Create a canonical handle scope before internalizing parsed values if |
485 // compiling bytecode. This is required for off-thread bytecode generation. | 523 // compiling bytecode. This is required for off-thread bytecode generation. |
486 std::unique_ptr<CanonicalHandleScope> canonical; | 524 std::unique_ptr<CanonicalHandleScope> canonical; |
487 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(info->isolate())); | 525 if (FLAG_ignition) canonical.reset(new CanonicalHandleScope(info->isolate())); |
488 | 526 |
489 // Parse and update CompilationInfo with the results. | 527 // Parse and update CompilationInfo with the results. |
490 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); | 528 if (!Parser::ParseStatic(info->parse_info())) return MaybeHandle<Code>(); |
491 Handle<SharedFunctionInfo> shared = info->shared_info(); | 529 DCHECK_EQ(info->shared_info()->language_mode(), |
492 DCHECK_EQ(shared->language_mode(), info->literal()->language_mode()); | 530 info->literal()->language_mode()); |
493 | 531 |
494 // Compile either unoptimized code or bytecode for the interpreter. | 532 // Compile either unoptimized code or bytecode for the interpreter. |
495 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); | 533 if (!CompileUnoptimizedCode(info)) return MaybeHandle<Code>(); |
496 | 534 |
497 // Update the shared function info with the scope info. | 535 InstallUnoptimizedCode(info); |
498 InstallSharedScopeInfo(info, shared); | |
499 | |
500 // Install compilation result on the shared function info | |
501 InstallSharedCompilationResult(info, shared); | |
502 | |
503 // Record the function compilation event. | |
504 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | |
505 | 536 |
506 return info->code(); | 537 return info->code(); |
507 } | 538 } |
508 | 539 |
| 540 CompilationJob::Status FinalizeUnoptimizedCompilationJob(CompilationJob* job) { |
| 541 CompilationJob::Status status = job->FinalizeJob(); |
| 542 if (status == CompilationJob::SUCCEEDED) { |
| 543 InstallUnoptimizedCode(job->info()); |
| 544 } |
| 545 return status; |
| 546 } |
| 547 |
509 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 548 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
510 Handle<JSFunction> function, BailoutId osr_ast_id) { | 549 Handle<JSFunction> function, BailoutId osr_ast_id) { |
511 Handle<SharedFunctionInfo> shared(function->shared()); | 550 Handle<SharedFunctionInfo> shared(function->shared()); |
512 DisallowHeapAllocation no_gc; | 551 DisallowHeapAllocation no_gc; |
513 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 552 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( |
514 function->context()->native_context(), osr_ast_id); | 553 function->context()->native_context(), osr_ast_id); |
515 if (cached.code != nullptr) { | 554 if (cached.code != nullptr) { |
516 // Caching of optimized code enabled and optimized code found. | 555 // Caching of optimized code enabled and optimized code found. |
517 if (cached.literals != nullptr) function->set_literals(cached.literals); | 556 if (cached.literals != nullptr) function->set_literals(cached.literals); |
518 DCHECK(!cached.code->marked_for_deoptimization()); | 557 DCHECK(!cached.code->marked_for_deoptimization()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 job->FinalizeJob() != CompilationJob::SUCCEEDED) { | 659 job->FinalizeJob() != CompilationJob::SUCCEEDED) { |
621 if (FLAG_trace_opt) { | 660 if (FLAG_trace_opt) { |
622 PrintF("[aborted optimizing "); | 661 PrintF("[aborted optimizing "); |
623 info->closure()->ShortPrint(); | 662 info->closure()->ShortPrint(); |
624 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); | 663 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); |
625 } | 664 } |
626 return false; | 665 return false; |
627 } | 666 } |
628 | 667 |
629 // Success! | 668 // Success! |
630 job->RecordOptimizationStats(); | |
631 DCHECK(!isolate->has_pending_exception()); | 669 DCHECK(!isolate->has_pending_exception()); |
632 InsertCodeIntoOptimizedCodeMap(info); | 670 InsertCodeIntoOptimizedCodeMap(info); |
633 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 671 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
634 return true; | 672 return true; |
635 } | 673 } |
636 | 674 |
637 bool GetOptimizedCodeLater(CompilationJob* job) { | 675 bool GetOptimizedCodeLater(CompilationJob* job) { |
638 CompilationInfo* info = job->info(); | 676 CompilationInfo* info = job->info(); |
639 Isolate* isolate = info->isolate(); | 677 Isolate* isolate = info->isolate(); |
640 | 678 |
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
780 return isolate->builtins()->InOptimizationQueue(); | 818 return isolate->builtins()->InOptimizationQueue(); |
781 } | 819 } |
782 } else { | 820 } else { |
783 if (GetOptimizedCodeNow(job.get())) return info->code(); | 821 if (GetOptimizedCodeNow(job.get())) return info->code(); |
784 } | 822 } |
785 | 823 |
786 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); | 824 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); |
787 return MaybeHandle<Code>(); | 825 return MaybeHandle<Code>(); |
788 } | 826 } |
789 | 827 |
| 828 CompilationJob::Status FinalizeOptimizedCompilationJob(CompilationJob* job) { |
| 829 CompilationInfo* info = job->info(); |
| 830 Isolate* isolate = info->isolate(); |
| 831 |
| 832 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); |
| 833 RuntimeCallTimerScope runtimeTimer(isolate, |
| 834 &RuntimeCallStats::RecompileSynchronous); |
| 835 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( |
| 836 isolate, &tracing::TraceEventStatsTable::RecompileSynchronous); |
| 837 |
| 838 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 839 shared->code()->set_profiler_ticks(0); |
| 840 |
| 841 DCHECK(!shared->HasDebugInfo()); |
| 842 |
| 843 // 1) Optimization on the concurrent thread may have failed. |
| 844 // 2) The function may have already been optimized by OSR. Simply continue. |
| 845 // Except when OSR already disabled optimization for some reason. |
| 846 // 3) The code may have already been invalidated due to dependency change. |
| 847 // 4) Code generation may have failed. |
| 848 if (job->state() == CompilationJob::State::kReadyToFinalize) { |
| 849 if (shared->optimization_disabled()) { |
| 850 job->RetryOptimization(kOptimizationDisabled); |
| 851 } else if (info->dependencies()->HasAborted()) { |
| 852 job->RetryOptimization(kBailedOutDueToDependencyChange); |
| 853 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { |
| 854 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
| 855 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), |
| 856 info->osr_ast_id()).code == nullptr) { |
| 857 InsertCodeIntoOptimizedCodeMap(info); |
| 858 } |
| 859 if (FLAG_trace_opt) { |
| 860 PrintF("[completed optimizing "); |
| 861 info->closure()->ShortPrint(); |
| 862 PrintF("]\n"); |
| 863 } |
| 864 info->closure()->ReplaceCode(*info->code()); |
| 865 return CompilationJob::SUCCEEDED; |
| 866 } |
| 867 } |
| 868 |
| 869 DCHECK(job->state() == CompilationJob::State::kFailed); |
| 870 if (FLAG_trace_opt) { |
| 871 PrintF("[aborted optimizing "); |
| 872 info->closure()->ShortPrint(); |
| 873 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); |
| 874 } |
| 875 info->closure()->ReplaceCode(shared->code()); |
| 876 return CompilationJob::FAILED; |
| 877 } |
| 878 |
790 class InterpreterActivationsFinder : public ThreadVisitor, | 879 class InterpreterActivationsFinder : public ThreadVisitor, |
791 public OptimizedFunctionVisitor { | 880 public OptimizedFunctionVisitor { |
792 public: | 881 public: |
793 explicit InterpreterActivationsFinder(SharedFunctionInfo* shared) | 882 explicit InterpreterActivationsFinder(SharedFunctionInfo* shared) |
794 : shared_(shared), has_activations_(false) {} | 883 : shared_(shared), has_activations_(false) {} |
795 | 884 |
796 void VisitThread(Isolate* isolate, ThreadLocalTop* top) { | 885 void VisitThread(Isolate* isolate, ThreadLocalTop* top) { |
797 Address* activation_pc_address = nullptr; | 886 Address* activation_pc_address = nullptr; |
798 JavaScriptFrameIterator it(isolate, top); | 887 JavaScriptFrameIterator it(isolate, top); |
799 for (; !it.done(); it.Advance()) { | 888 for (; !it.done(); it.Advance()) { |
(...skipping 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1814 } | 1903 } |
1815 | 1904 |
1816 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, | 1905 MaybeHandle<Code> Compiler::GetOptimizedCodeForOSR(Handle<JSFunction> function, |
1817 BailoutId osr_ast_id, | 1906 BailoutId osr_ast_id, |
1818 JavaScriptFrame* osr_frame) { | 1907 JavaScriptFrame* osr_frame) { |
1819 DCHECK(!osr_ast_id.IsNone()); | 1908 DCHECK(!osr_ast_id.IsNone()); |
1820 DCHECK_NOT_NULL(osr_frame); | 1909 DCHECK_NOT_NULL(osr_frame); |
1821 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame); | 1910 return GetOptimizedCode(function, NOT_CONCURRENT, osr_ast_id, osr_frame); |
1822 } | 1911 } |
1823 | 1912 |
1824 void Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { | 1913 CompilationJob* Compiler::PrepareUnoptimizedCompilationJob( |
| 1914 CompilationInfo* info) { |
| 1915 VMState<COMPILER> state(info->isolate()); |
| 1916 std::unique_ptr<CompilationJob> job(GetUnoptimizedCompilationJob(info)); |
| 1917 if (job->PrepareJob() != CompilationJob::SUCCEEDED) { |
| 1918 return nullptr; |
| 1919 } |
| 1920 return job.release(); |
| 1921 } |
| 1922 |
| 1923 bool Compiler::FinalizeCompilationJob(CompilationJob* raw_job) { |
1825 // Take ownership of compilation job. Deleting job also tears down the zone. | 1924 // Take ownership of compilation job. Deleting job also tears down the zone. |
1826 std::unique_ptr<CompilationJob> job(raw_job); | 1925 std::unique_ptr<CompilationJob> job(raw_job); |
1827 CompilationInfo* info = job->info(); | |
1828 Isolate* isolate = info->isolate(); | |
1829 | 1926 |
1830 VMState<COMPILER> state(isolate); | 1927 VMState<COMPILER> state(job->info()->isolate()); |
1831 TimerEventScope<TimerEventRecompileSynchronous> timer(info->isolate()); | 1928 if (job->info()->IsOptimizing()) { |
1832 RuntimeCallTimerScope runtimeTimer(isolate, | 1929 return FinalizeOptimizedCompilationJob(job.get()) == |
1833 &RuntimeCallStats::RecompileSynchronous); | 1930 CompilationJob::SUCCEEDED; |
1834 TRACE_EVENT_RUNTIME_CALL_STATS_TRACING_SCOPED( | 1931 } else { |
1835 isolate, &tracing::TraceEventStatsTable::RecompileSynchronous); | 1932 return FinalizeUnoptimizedCompilationJob(job.get()) == |
1836 | 1933 CompilationJob::SUCCEEDED; |
1837 Handle<SharedFunctionInfo> shared = info->shared_info(); | |
1838 shared->code()->set_profiler_ticks(0); | |
1839 | |
1840 DCHECK(!shared->HasDebugInfo()); | |
1841 | |
1842 // 1) Optimization on the concurrent thread may have failed. | |
1843 // 2) The function may have already been optimized by OSR. Simply continue. | |
1844 // Except when OSR already disabled optimization for some reason. | |
1845 // 3) The code may have already been invalidated due to dependency change. | |
1846 // 4) Code generation may have failed. | |
1847 if (job->state() == CompilationJob::State::kReadyToFinalize) { | |
1848 if (shared->optimization_disabled()) { | |
1849 job->RetryOptimization(kOptimizationDisabled); | |
1850 } else if (info->dependencies()->HasAborted()) { | |
1851 job->RetryOptimization(kBailedOutDueToDependencyChange); | |
1852 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { | |
1853 job->RecordOptimizationStats(); | |
1854 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | |
1855 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), | |
1856 info->osr_ast_id()).code == nullptr) { | |
1857 InsertCodeIntoOptimizedCodeMap(info); | |
1858 } | |
1859 if (FLAG_trace_opt) { | |
1860 PrintF("[completed optimizing "); | |
1861 info->closure()->ShortPrint(); | |
1862 PrintF("]\n"); | |
1863 } | |
1864 info->closure()->ReplaceCode(*info->code()); | |
1865 return; | |
1866 } | |
1867 } | 1934 } |
1868 | |
1869 DCHECK(job->state() == CompilationJob::State::kFailed); | |
1870 if (FLAG_trace_opt) { | |
1871 PrintF("[aborted optimizing "); | |
1872 info->closure()->ShortPrint(); | |
1873 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); | |
1874 } | |
1875 info->closure()->ReplaceCode(shared->code()); | |
1876 } | 1935 } |
1877 | 1936 |
1878 void Compiler::PostInstantiation(Handle<JSFunction> function, | 1937 void Compiler::PostInstantiation(Handle<JSFunction> function, |
1879 PretenureFlag pretenure) { | 1938 PretenureFlag pretenure) { |
1880 Handle<SharedFunctionInfo> shared(function->shared()); | 1939 Handle<SharedFunctionInfo> shared(function->shared()); |
1881 | 1940 |
1882 if (FLAG_always_opt && shared->allows_lazy_compilation()) { | 1941 if (FLAG_always_opt && shared->allows_lazy_compilation()) { |
1883 function->MarkForOptimization(); | 1942 function->MarkForOptimization(); |
1884 } | 1943 } |
1885 | 1944 |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1955 Map::AddDependentCode(map, DependentCode::kWeakCodeGroup, code); | 2014 Map::AddDependentCode(map, DependentCode::kWeakCodeGroup, code); |
1956 } | 2015 } |
1957 for (Handle<HeapObject> object : objects) { | 2016 for (Handle<HeapObject> object : objects) { |
1958 AddWeakObjectToCodeDependency(isolate, object, code); | 2017 AddWeakObjectToCodeDependency(isolate, object, code); |
1959 } | 2018 } |
1960 code->set_can_have_weak_objects(true); | 2019 code->set_can_have_weak_objects(true); |
1961 } | 2020 } |
1962 | 2021 |
1963 } // namespace internal | 2022 } // namespace internal |
1964 } // namespace v8 | 2023 } // namespace v8 |
OLD | NEW |