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 483 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
494 // Record the function compilation event. | 494 // Record the function compilation event. |
495 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 495 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
496 | 496 |
497 return info->code(); | 497 return info->code(); |
498 } | 498 } |
499 | 499 |
500 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 500 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
501 Handle<JSFunction> function, BailoutId osr_ast_id) { | 501 Handle<JSFunction> function, BailoutId osr_ast_id) { |
502 Handle<SharedFunctionInfo> shared(function->shared()); | 502 Handle<SharedFunctionInfo> shared(function->shared()); |
503 DisallowHeapAllocation no_gc; | 503 DisallowHeapAllocation no_gc; |
504 Code* code = shared->SearchOptimizedCodeMap( | 504 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( |
505 function->context()->native_context(), osr_ast_id); | 505 function->context()->native_context(), osr_ast_id); |
506 if (code != nullptr) { | 506 if (cached.code != nullptr) { |
507 // Caching of optimized code enabled and optimized code found. | 507 // Caching of optimized code enabled and optimized code found. |
508 DCHECK(!code->marked_for_deoptimization()); | 508 if (cached.literals != nullptr) function->set_literals(cached.literals); |
| 509 DCHECK(!cached.code->marked_for_deoptimization()); |
509 DCHECK(function->shared()->is_compiled()); | 510 DCHECK(function->shared()->is_compiled()); |
510 return Handle<Code>(code); | 511 return Handle<Code>(cached.code); |
511 } | 512 } |
512 return MaybeHandle<Code>(); | 513 return MaybeHandle<Code>(); |
513 } | 514 } |
514 | 515 |
515 void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { | 516 void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { |
516 Handle<Code> code = info->code(); | 517 Handle<Code> code = info->code(); |
517 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. | 518 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. |
518 | 519 |
519 // Function context specialization folds-in the function context, | 520 // Function context specialization folds-in the function context, |
520 // so no sharing can occur. | 521 // so no sharing can occur. |
521 if (info->is_function_context_specializing()) return; | 522 if (info->is_function_context_specializing()) return; |
522 // Frame specialization implies function context specialization. | 523 // Frame specialization implies function context specialization. |
523 DCHECK(!info->is_frame_specializing()); | 524 DCHECK(!info->is_frame_specializing()); |
524 | 525 |
525 // TODO(4764): When compiling for OSR from bytecode, BailoutId might derive | 526 // TODO(4764): When compiling for OSR from bytecode, BailoutId might derive |
526 // from bytecode offset and overlap with actual BailoutId. No caching! | 527 // from bytecode offset and overlap with actual BailoutId. No caching! |
527 if (info->is_osr() && info->is_optimizing_from_bytecode()) return; | 528 if (info->is_osr() && info->is_optimizing_from_bytecode()) return; |
528 | 529 |
529 // Cache optimized context-specific code. | 530 // Cache optimized context-specific code. |
530 Handle<JSFunction> function = info->closure(); | 531 Handle<JSFunction> function = info->closure(); |
531 Handle<SharedFunctionInfo> shared(function->shared()); | 532 Handle<SharedFunctionInfo> shared(function->shared()); |
| 533 Handle<LiteralsArray> literals(function->literals()); |
532 Handle<Context> native_context(function->context()->native_context()); | 534 Handle<Context> native_context(function->context()->native_context()); |
533 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 535 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
534 info->osr_ast_id()); | 536 literals, info->osr_ast_id()); |
535 } | 537 } |
536 | 538 |
537 bool Renumber(ParseInfo* parse_info) { | 539 bool Renumber(ParseInfo* parse_info) { |
538 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), | 540 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), |
539 parse_info->literal())) { | 541 parse_info->literal())) { |
540 return false; | 542 return false; |
541 } | 543 } |
542 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); | 544 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); |
543 if (!shared_info.is_null()) { | 545 if (!shared_info.is_null()) { |
544 FunctionLiteral* lit = parse_info->literal(); | 546 FunctionLiteral* lit = parse_info->literal(); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
779 // 3) The code may have already been invalidated due to dependency change. | 781 // 3) The code may have already been invalidated due to dependency change. |
780 // 4) Code generation may have failed. | 782 // 4) Code generation may have failed. |
781 if (job->state() == CompilationJob::State::kReadyToFinalize) { | 783 if (job->state() == CompilationJob::State::kReadyToFinalize) { |
782 if (shared->optimization_disabled()) { | 784 if (shared->optimization_disabled()) { |
783 job->RetryOptimization(kOptimizationDisabled); | 785 job->RetryOptimization(kOptimizationDisabled); |
784 } else if (info->dependencies()->HasAborted()) { | 786 } else if (info->dependencies()->HasAborted()) { |
785 job->RetryOptimization(kBailedOutDueToDependencyChange); | 787 job->RetryOptimization(kBailedOutDueToDependencyChange); |
786 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { | 788 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { |
787 job->RecordOptimizedCompilationStats(); | 789 job->RecordOptimizedCompilationStats(); |
788 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 790 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
789 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), | 791 if (shared |
790 info->osr_ast_id()) == nullptr) { | 792 ->SearchOptimizedCodeMap(info->context()->native_context(), |
| 793 info->osr_ast_id()) |
| 794 .code == nullptr) { |
791 InsertCodeIntoOptimizedCodeMap(info); | 795 InsertCodeIntoOptimizedCodeMap(info); |
792 } | 796 } |
793 if (FLAG_trace_opt) { | 797 if (FLAG_trace_opt) { |
794 PrintF("[completed optimizing "); | 798 PrintF("[completed optimizing "); |
795 info->closure()->ShortPrint(); | 799 info->closure()->ShortPrint(); |
796 PrintF("]\n"); | 800 PrintF("]\n"); |
797 } | 801 } |
798 info->closure()->ReplaceCode(*info->code()); | 802 info->closure()->ReplaceCode(*info->code()); |
799 return CompilationJob::SUCCEEDED; | 803 return CompilationJob::SUCCEEDED; |
800 } | 804 } |
(...skipping 921 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1722 void Compiler::PostInstantiation(Handle<JSFunction> function, | 1726 void Compiler::PostInstantiation(Handle<JSFunction> function, |
1723 PretenureFlag pretenure) { | 1727 PretenureFlag pretenure) { |
1724 Handle<SharedFunctionInfo> shared(function->shared()); | 1728 Handle<SharedFunctionInfo> shared(function->shared()); |
1725 | 1729 |
1726 if (FLAG_always_opt && shared->allows_lazy_compilation() && | 1730 if (FLAG_always_opt && shared->allows_lazy_compilation() && |
1727 !function->shared()->HasAsmWasmData() && | 1731 !function->shared()->HasAsmWasmData() && |
1728 function->shared()->is_compiled()) { | 1732 function->shared()->is_compiled()) { |
1729 function->MarkForOptimization(); | 1733 function->MarkForOptimization(); |
1730 } | 1734 } |
1731 | 1735 |
1732 Code* code = shared->SearchOptimizedCodeMap( | 1736 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( |
1733 function->context()->native_context(), BailoutId::None()); | 1737 function->context()->native_context(), BailoutId::None()); |
1734 if (code != nullptr) { | 1738 if (cached.code != nullptr) { |
1735 // Caching of optimized code enabled and optimized code found. | 1739 // Caching of optimized code enabled and optimized code found. |
1736 DCHECK(!code->marked_for_deoptimization()); | 1740 DCHECK(!cached.code->marked_for_deoptimization()); |
1737 DCHECK(function->shared()->is_compiled()); | 1741 DCHECK(function->shared()->is_compiled()); |
1738 function->ReplaceCode(code); | 1742 function->ReplaceCode(cached.code); |
1739 } | 1743 } |
1740 | 1744 |
1741 if (shared->is_compiled()) { | 1745 if (cached.literals != nullptr) { |
| 1746 DCHECK(shared->is_compiled()); |
| 1747 function->set_literals(cached.literals); |
| 1748 } else if (shared->is_compiled()) { |
1742 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1749 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
1743 JSFunction::EnsureLiterals(function); | 1750 JSFunction::EnsureLiterals(function); |
1744 } | 1751 } |
1745 } | 1752 } |
1746 | 1753 |
1747 } // namespace internal | 1754 } // namespace internal |
1748 } // namespace v8 | 1755 } // namespace v8 |
OLD | NEW |