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 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
510 return info->code(); | 510 return info->code(); |
511 } | 511 } |
512 | 512 |
513 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 513 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
514 Handle<JSFunction> function, BailoutId osr_ast_id) { | 514 Handle<JSFunction> function, BailoutId osr_ast_id) { |
515 RuntimeCallTimerScope runtimeTimer( | 515 RuntimeCallTimerScope runtimeTimer( |
516 function->GetIsolate(), | 516 function->GetIsolate(), |
517 &RuntimeCallStats::CompileGetFromOptimizedCodeMap); | 517 &RuntimeCallStats::CompileGetFromOptimizedCodeMap); |
518 Handle<SharedFunctionInfo> shared(function->shared()); | 518 Handle<SharedFunctionInfo> shared(function->shared()); |
519 DisallowHeapAllocation no_gc; | 519 DisallowHeapAllocation no_gc; |
520 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 520 Code* code = shared->SearchOptimizedCodeMap( |
521 function->context()->native_context(), osr_ast_id); | 521 function->context()->native_context(), osr_ast_id); |
522 if (cached.code != nullptr) { | 522 if (code != nullptr) { |
523 // Caching of optimized code enabled and optimized code found. | 523 // Caching of optimized code enabled and optimized code found. |
524 if (cached.literals != nullptr) function->set_literals(cached.literals); | 524 DCHECK(!code->marked_for_deoptimization()); |
525 DCHECK(!cached.code->marked_for_deoptimization()); | |
526 DCHECK(function->shared()->is_compiled()); | 525 DCHECK(function->shared()->is_compiled()); |
527 return Handle<Code>(cached.code); | 526 return Handle<Code>(code); |
528 } | 527 } |
529 return MaybeHandle<Code>(); | 528 return MaybeHandle<Code>(); |
530 } | 529 } |
531 | 530 |
532 void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { | 531 void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { |
533 Handle<Code> code = info->code(); | 532 Handle<Code> code = info->code(); |
534 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. | 533 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. |
535 | 534 |
536 // Function context specialization folds-in the function context, | 535 // Function context specialization folds-in the function context, |
537 // so no sharing can occur. | 536 // so no sharing can occur. |
538 if (info->is_function_context_specializing()) return; | 537 if (info->is_function_context_specializing()) return; |
539 // Frame specialization implies function context specialization. | 538 // Frame specialization implies function context specialization. |
540 DCHECK(!info->is_frame_specializing()); | 539 DCHECK(!info->is_frame_specializing()); |
541 | 540 |
542 // TODO(4764): When compiling for OSR from bytecode, BailoutId might derive | 541 // TODO(4764): When compiling for OSR from bytecode, BailoutId might derive |
543 // from bytecode offset and overlap with actual BailoutId. No caching! | 542 // from bytecode offset and overlap with actual BailoutId. No caching! |
544 if (info->is_osr() && info->is_optimizing_from_bytecode()) return; | 543 if (info->is_osr() && info->is_optimizing_from_bytecode()) return; |
545 | 544 |
546 // Cache optimized context-specific code. | 545 // Cache optimized context-specific code. |
547 Handle<JSFunction> function = info->closure(); | 546 Handle<JSFunction> function = info->closure(); |
548 Handle<SharedFunctionInfo> shared(function->shared()); | 547 Handle<SharedFunctionInfo> shared(function->shared()); |
549 Handle<LiteralsArray> literals(function->literals()); | |
550 Handle<Context> native_context(function->context()->native_context()); | 548 Handle<Context> native_context(function->context()->native_context()); |
551 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 549 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
552 literals, info->osr_ast_id()); | 550 info->osr_ast_id()); |
553 } | 551 } |
554 | 552 |
555 bool Renumber(ParseInfo* parse_info) { | 553 bool Renumber(ParseInfo* parse_info) { |
556 RuntimeCallTimerScope runtimeTimer(parse_info->isolate(), | 554 RuntimeCallTimerScope runtimeTimer(parse_info->isolate(), |
557 &RuntimeCallStats::CompileRenumber); | 555 &RuntimeCallStats::CompileRenumber); |
558 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), | 556 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), |
559 parse_info->literal())) { | 557 parse_info->literal())) { |
560 return false; | 558 return false; |
561 } | 559 } |
562 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); | 560 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
799 // 3) The code may have already been invalidated due to dependency change. | 797 // 3) The code may have already been invalidated due to dependency change. |
800 // 4) Code generation may have failed. | 798 // 4) Code generation may have failed. |
801 if (job->state() == CompilationJob::State::kReadyToFinalize) { | 799 if (job->state() == CompilationJob::State::kReadyToFinalize) { |
802 if (shared->optimization_disabled()) { | 800 if (shared->optimization_disabled()) { |
803 job->RetryOptimization(kOptimizationDisabled); | 801 job->RetryOptimization(kOptimizationDisabled); |
804 } else if (info->dependencies()->HasAborted()) { | 802 } else if (info->dependencies()->HasAborted()) { |
805 job->RetryOptimization(kBailedOutDueToDependencyChange); | 803 job->RetryOptimization(kBailedOutDueToDependencyChange); |
806 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { | 804 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { |
807 job->RecordOptimizedCompilationStats(); | 805 job->RecordOptimizedCompilationStats(); |
808 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 806 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
809 if (shared | 807 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), |
810 ->SearchOptimizedCodeMap(info->context()->native_context(), | 808 info->osr_ast_id()) == nullptr) { |
811 info->osr_ast_id()) | |
812 .code == nullptr) { | |
813 InsertCodeIntoOptimizedCodeMap(info); | 809 InsertCodeIntoOptimizedCodeMap(info); |
814 } | 810 } |
815 if (FLAG_trace_opt) { | 811 if (FLAG_trace_opt) { |
816 PrintF("[completed optimizing "); | 812 PrintF("[completed optimizing "); |
817 info->closure()->ShortPrint(); | 813 info->closure()->ShortPrint(); |
818 PrintF("]\n"); | 814 PrintF("]\n"); |
819 } | 815 } |
820 info->closure()->ReplaceCode(*info->code()); | 816 info->closure()->ReplaceCode(*info->code()); |
821 return CompilationJob::SUCCEEDED; | 817 return CompilationJob::SUCCEEDED; |
822 } | 818 } |
(...skipping 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1749 void Compiler::PostInstantiation(Handle<JSFunction> function, | 1745 void Compiler::PostInstantiation(Handle<JSFunction> function, |
1750 PretenureFlag pretenure) { | 1746 PretenureFlag pretenure) { |
1751 Handle<SharedFunctionInfo> shared(function->shared()); | 1747 Handle<SharedFunctionInfo> shared(function->shared()); |
1752 | 1748 |
1753 if (FLAG_always_opt && shared->allows_lazy_compilation() && | 1749 if (FLAG_always_opt && shared->allows_lazy_compilation() && |
1754 !function->shared()->HasAsmWasmData() && | 1750 !function->shared()->HasAsmWasmData() && |
1755 function->shared()->is_compiled()) { | 1751 function->shared()->is_compiled()) { |
1756 function->MarkForOptimization(); | 1752 function->MarkForOptimization(); |
1757 } | 1753 } |
1758 | 1754 |
1759 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 1755 Code* code = shared->SearchOptimizedCodeMap( |
1760 function->context()->native_context(), BailoutId::None()); | 1756 function->context()->native_context(), BailoutId::None()); |
1761 if (cached.code != nullptr) { | 1757 if (code != nullptr) { |
1762 // Caching of optimized code enabled and optimized code found. | 1758 // Caching of optimized code enabled and optimized code found. |
1763 DCHECK(!cached.code->marked_for_deoptimization()); | 1759 DCHECK(!code->marked_for_deoptimization()); |
1764 DCHECK(function->shared()->is_compiled()); | 1760 DCHECK(function->shared()->is_compiled()); |
1765 function->ReplaceCode(cached.code); | 1761 function->ReplaceCode(code); |
1766 } | 1762 } |
1767 | 1763 |
1768 if (cached.literals != nullptr) { | 1764 if (shared->is_compiled()) { |
1769 DCHECK(shared->is_compiled()); | |
1770 function->set_literals(cached.literals); | |
1771 } else if (shared->is_compiled()) { | |
1772 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1765 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
1773 JSFunction::EnsureLiterals(function); | 1766 JSFunction::EnsureLiterals(function); |
1774 } | 1767 } |
1775 } | 1768 } |
1776 | 1769 |
1777 } // namespace internal | 1770 } // namespace internal |
1778 } // namespace v8 | 1771 } // namespace v8 |
OLD | NEW |