| 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 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 // Record the function compilation event. | 475 // Record the function compilation event. |
| 476 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 476 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
| 477 | 477 |
| 478 return info->code(); | 478 return info->code(); |
| 479 } | 479 } |
| 480 | 480 |
| 481 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 481 MUST_USE_RESULT MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
| 482 Handle<JSFunction> function, BailoutId osr_ast_id) { | 482 Handle<JSFunction> function, BailoutId osr_ast_id) { |
| 483 Handle<SharedFunctionInfo> shared(function->shared()); | 483 Handle<SharedFunctionInfo> shared(function->shared()); |
| 484 DisallowHeapAllocation no_gc; | 484 DisallowHeapAllocation no_gc; |
| 485 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 485 Code* code = shared->SearchOptimizedCodeMap( |
| 486 function->context()->native_context(), osr_ast_id); | 486 function->context()->native_context(), osr_ast_id); |
| 487 if (cached.code != nullptr) { | 487 if (code != nullptr) { |
| 488 // Caching of optimized code enabled and optimized code found. | 488 // Caching of optimized code enabled and optimized code found. |
| 489 if (cached.literals != nullptr) function->set_literals(cached.literals); | 489 DCHECK(!code->marked_for_deoptimization()); |
| 490 DCHECK(!cached.code->marked_for_deoptimization()); | |
| 491 DCHECK(function->shared()->is_compiled()); | 490 DCHECK(function->shared()->is_compiled()); |
| 492 return Handle<Code>(cached.code); | 491 return Handle<Code>(code); |
| 493 } | 492 } |
| 494 return MaybeHandle<Code>(); | 493 return MaybeHandle<Code>(); |
| 495 } | 494 } |
| 496 | 495 |
| 497 void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { | 496 void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { |
| 498 Handle<Code> code = info->code(); | 497 Handle<Code> code = info->code(); |
| 499 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. | 498 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. |
| 500 | 499 |
| 501 // Function context specialization folds-in the function context, | 500 // Function context specialization folds-in the function context, |
| 502 // so no sharing can occur. | 501 // so no sharing can occur. |
| 503 if (info->is_function_context_specializing()) return; | 502 if (info->is_function_context_specializing()) return; |
| 504 // Frame specialization implies function context specialization. | 503 // Frame specialization implies function context specialization. |
| 505 DCHECK(!info->is_frame_specializing()); | 504 DCHECK(!info->is_frame_specializing()); |
| 506 | 505 |
| 507 // TODO(4764): When compiling for OSR from bytecode, BailoutId might derive | 506 // TODO(4764): When compiling for OSR from bytecode, BailoutId might derive |
| 508 // from bytecode offset and overlap with actual BailoutId. No caching! | 507 // from bytecode offset and overlap with actual BailoutId. No caching! |
| 509 if (info->is_osr() && info->is_optimizing_from_bytecode()) return; | 508 if (info->is_osr() && info->is_optimizing_from_bytecode()) return; |
| 510 | 509 |
| 511 // Cache optimized context-specific code. | 510 // Cache optimized context-specific code. |
| 512 Handle<JSFunction> function = info->closure(); | 511 Handle<JSFunction> function = info->closure(); |
| 513 Handle<SharedFunctionInfo> shared(function->shared()); | 512 Handle<SharedFunctionInfo> shared(function->shared()); |
| 514 Handle<LiteralsArray> literals(function->literals()); | |
| 515 Handle<Context> native_context(function->context()->native_context()); | 513 Handle<Context> native_context(function->context()->native_context()); |
| 516 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 514 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
| 517 literals, info->osr_ast_id()); | 515 info->osr_ast_id()); |
| 518 } | 516 } |
| 519 | 517 |
| 520 bool Renumber(ParseInfo* parse_info) { | 518 bool Renumber(ParseInfo* parse_info) { |
| 521 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), | 519 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), |
| 522 parse_info->literal())) { | 520 parse_info->literal())) { |
| 523 return false; | 521 return false; |
| 524 } | 522 } |
| 525 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); | 523 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); |
| 526 if (!shared_info.is_null()) { | 524 if (!shared_info.is_null()) { |
| 527 FunctionLiteral* lit = parse_info->literal(); | 525 FunctionLiteral* lit = parse_info->literal(); |
| (...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 762 // 3) The code may have already been invalidated due to dependency change. | 760 // 3) The code may have already been invalidated due to dependency change. |
| 763 // 4) Code generation may have failed. | 761 // 4) Code generation may have failed. |
| 764 if (job->state() == CompilationJob::State::kReadyToFinalize) { | 762 if (job->state() == CompilationJob::State::kReadyToFinalize) { |
| 765 if (shared->optimization_disabled()) { | 763 if (shared->optimization_disabled()) { |
| 766 job->RetryOptimization(kOptimizationDisabled); | 764 job->RetryOptimization(kOptimizationDisabled); |
| 767 } else if (info->dependencies()->HasAborted()) { | 765 } else if (info->dependencies()->HasAborted()) { |
| 768 job->RetryOptimization(kBailedOutDueToDependencyChange); | 766 job->RetryOptimization(kBailedOutDueToDependencyChange); |
| 769 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { | 767 } else if (job->FinalizeJob() == CompilationJob::SUCCEEDED) { |
| 770 job->RecordOptimizedCompilationStats(); | 768 job->RecordOptimizedCompilationStats(); |
| 771 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); | 769 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, info); |
| 772 if (shared | 770 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), |
| 773 ->SearchOptimizedCodeMap(info->context()->native_context(), | 771 info->osr_ast_id()) == nullptr) { |
| 774 info->osr_ast_id()) | |
| 775 .code == nullptr) { | |
| 776 InsertCodeIntoOptimizedCodeMap(info); | 772 InsertCodeIntoOptimizedCodeMap(info); |
| 777 } | 773 } |
| 778 if (FLAG_trace_opt) { | 774 if (FLAG_trace_opt) { |
| 779 PrintF("[completed optimizing "); | 775 PrintF("[completed optimizing "); |
| 780 info->closure()->ShortPrint(); | 776 info->closure()->ShortPrint(); |
| 781 PrintF("]\n"); | 777 PrintF("]\n"); |
| 782 } | 778 } |
| 783 info->closure()->ReplaceCode(*info->code()); | 779 info->closure()->ReplaceCode(*info->code()); |
| 784 return CompilationJob::SUCCEEDED; | 780 return CompilationJob::SUCCEEDED; |
| 785 } | 781 } |
| (...skipping 915 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1701 void Compiler::PostInstantiation(Handle<JSFunction> function, | 1697 void Compiler::PostInstantiation(Handle<JSFunction> function, |
| 1702 PretenureFlag pretenure) { | 1698 PretenureFlag pretenure) { |
| 1703 Handle<SharedFunctionInfo> shared(function->shared()); | 1699 Handle<SharedFunctionInfo> shared(function->shared()); |
| 1704 | 1700 |
| 1705 if (FLAG_always_opt && shared->allows_lazy_compilation() && | 1701 if (FLAG_always_opt && shared->allows_lazy_compilation() && |
| 1706 !function->shared()->HasAsmWasmData() && | 1702 !function->shared()->HasAsmWasmData() && |
| 1707 function->shared()->is_compiled()) { | 1703 function->shared()->is_compiled()) { |
| 1708 function->MarkForOptimization(); | 1704 function->MarkForOptimization(); |
| 1709 } | 1705 } |
| 1710 | 1706 |
| 1711 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( | 1707 Code* code = shared->SearchOptimizedCodeMap( |
| 1712 function->context()->native_context(), BailoutId::None()); | 1708 function->context()->native_context(), BailoutId::None()); |
| 1713 if (cached.code != nullptr) { | 1709 if (code != nullptr) { |
| 1714 // Caching of optimized code enabled and optimized code found. | 1710 // Caching of optimized code enabled and optimized code found. |
| 1715 DCHECK(!cached.code->marked_for_deoptimization()); | 1711 DCHECK(!code->marked_for_deoptimization()); |
| 1716 DCHECK(function->shared()->is_compiled()); | 1712 DCHECK(function->shared()->is_compiled()); |
| 1717 function->ReplaceCode(cached.code); | 1713 function->ReplaceCode(code); |
| 1718 } | 1714 } |
| 1719 | 1715 |
| 1720 if (cached.literals != nullptr) { | 1716 if (shared->is_compiled()) { |
| 1721 DCHECK(shared->is_compiled()); | |
| 1722 function->set_literals(cached.literals); | |
| 1723 } else if (shared->is_compiled()) { | |
| 1724 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1717 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
| 1725 JSFunction::EnsureLiterals(function); | 1718 JSFunction::EnsureLiterals(function); |
| 1726 } | 1719 } |
| 1727 } | 1720 } |
| 1728 | 1721 |
| 1729 } // namespace internal | 1722 } // namespace internal |
| 1730 } // namespace v8 | 1723 } // namespace v8 |
| OLD | NEW |