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 579 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
590 return info->code(); | 590 return info->code(); |
591 } | 591 } |
592 | 592 |
593 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 593 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
594 Handle<JSFunction> function, BailoutId osr_ast_id) { | 594 Handle<JSFunction> function, BailoutId osr_ast_id) { |
595 RuntimeCallTimerScope runtimeTimer( | 595 RuntimeCallTimerScope runtimeTimer( |
596 function->GetIsolate(), | 596 function->GetIsolate(), |
597 &RuntimeCallStats::CompileGetFromOptimizedCodeMap); | 597 &RuntimeCallStats::CompileGetFromOptimizedCodeMap); |
598 Handle<SharedFunctionInfo> shared(function->shared()); | 598 Handle<SharedFunctionInfo> shared(function->shared()); |
599 DisallowHeapAllocation no_gc; | 599 DisallowHeapAllocation no_gc; |
600 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 600 Code* code = shared->SearchOptimizedCodeMap( |
601 function->context()->native_context(), osr_ast_id); | 601 function->context()->native_context(), osr_ast_id); |
602 if (cached.code != nullptr) { | 602 if (code != nullptr) { |
603 // Caching of optimized code enabled and optimized code found. | 603 // Caching of optimized code enabled and optimized code found. |
604 if (cached.literals != nullptr) function->set_literals(cached.literals); | 604 DCHECK(!code->marked_for_deoptimization()); |
605 DCHECK(!cached.code->marked_for_deoptimization()); | |
606 DCHECK(function->shared()->is_compiled()); | 605 DCHECK(function->shared()->is_compiled()); |
607 return Handle<Code>(cached.code); | 606 return Handle<Code>(code); |
608 } | 607 } |
609 return MaybeHandle<Code>(); | 608 return MaybeHandle<Code>(); |
610 } | 609 } |
611 | 610 |
612 void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { | 611 void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { |
613 Handle<Code> code = info->code(); | 612 Handle<Code> code = info->code(); |
614 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. | 613 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. |
615 | 614 |
616 // Function context specialization folds-in the function context, | 615 // Function context specialization folds-in the function context, |
617 // so no sharing can occur. | 616 // so no sharing can occur. |
618 if (info->is_function_context_specializing()) return; | 617 if (info->is_function_context_specializing()) return; |
619 // Frame specialization implies function context specialization. | 618 // Frame specialization implies function context specialization. |
620 DCHECK(!info->is_frame_specializing()); | 619 DCHECK(!info->is_frame_specializing()); |
621 | 620 |
622 // TODO(4764): When compiling for OSR from bytecode, BailoutId might derive | 621 // TODO(4764): When compiling for OSR from bytecode, BailoutId might derive |
623 // from bytecode offset and overlap with actual BailoutId. No caching! | 622 // from bytecode offset and overlap with actual BailoutId. No caching! |
624 if (info->is_osr() && info->is_optimizing_from_bytecode()) return; | 623 if (info->is_osr() && info->is_optimizing_from_bytecode()) return; |
625 | 624 |
626 // Cache optimized context-specific code. | 625 // Cache optimized context-specific code. |
627 Handle<JSFunction> function = info->closure(); | 626 Handle<JSFunction> function = info->closure(); |
628 Handle<SharedFunctionInfo> shared(function->shared()); | 627 Handle<SharedFunctionInfo> shared(function->shared()); |
629 Handle<LiteralsArray> literals(function->literals()); | |
630 Handle<Context> native_context(function->context()->native_context()); | 628 Handle<Context> native_context(function->context()->native_context()); |
631 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 629 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
632 literals, info->osr_ast_id()); | 630 info->osr_ast_id()); |
633 } | 631 } |
634 | 632 |
635 bool GetOptimizedCodeNow(CompilationJob* job) { | 633 bool GetOptimizedCodeNow(CompilationJob* job) { |
636 CompilationInfo* info = job->info(); | 634 CompilationInfo* info = job->info(); |
637 Isolate* isolate = info->isolate(); | 635 Isolate* isolate = info->isolate(); |
638 | 636 |
639 // Parsing is not required when optimizing from existing bytecode. | 637 // Parsing is not required when optimizing from existing bytecode. |
640 if (!info->is_optimizing_from_bytecode()) { | 638 if (!info->is_optimizing_from_bytecode()) { |
641 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; | 639 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; |
642 EnsureFeedbackMetadata(info); | 640 EnsureFeedbackMetadata(info); |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 // 3) The code may have already been invalidated due to dependency change. | 856 // 3) The code may have already been invalidated due to dependency change. |
859 // 4) Code generation may have failed. | 857 // 4) Code generation may have failed. |
860 if (job->state() == CompilationJob::State::kReadyToFinalize) { | 858 if (job->state() == CompilationJob::State::kReadyToFinalize) { |
861 if (shared->optimization_disabled()) { | 859 if (shared->optimization_disabled()) { |
862 job->RetryOptimization(kOptimizationDisabled); | 860 job->RetryOptimization(kOptimizationDisabled); |
863 } else if (info->dependencies()->HasAborted()) { | 861 } else if (info->dependencies()->HasAborted()) { |
864 job->RetryOptimization(kBailedOutDueToDependencyChange); | 862 job->RetryOptimization(kBailedOutDueToDependencyChange); |
865 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { | 863 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { |
866 job->RecordOptimizedCompilationStats(); | 864 job->RecordOptimizedCompilationStats(); |
867 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 865 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
868 if (shared | 866 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), |
869 ->SearchOptimizedCodeMap(info->context()->native_context(), | 867 info->osr_ast_id()) == nullptr) { |
870 info->osr_ast_id()) | |
871 .code == nullptr) { | |
872 InsertCodeIntoOptimizedCodeMap(info); | 868 InsertCodeIntoOptimizedCodeMap(info); |
873 } | 869 } |
874 if (FLAG_trace_opt) { | 870 if (FLAG_trace_opt) { |
875 PrintF("[completed optimizing "); | 871 PrintF("[completed optimizing "); |
876 info->closure()->ShortPrint(); | 872 info->closure()->ShortPrint(); |
877 PrintF("]\n"); | 873 PrintF("]\n"); |
878 } | 874 } |
879 info->closure()->ReplaceCode(*info->code()); | 875 info->closure()->ReplaceCode(*info->code()); |
880 return CompilationJob::SUCCEEDED; | 876 return CompilationJob::SUCCEEDED; |
881 } | 877 } |
(...skipping 867 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 |