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