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 | 8 |
9 #include "src/ast-numbering.h" | 9 #include "src/ast-numbering.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 | 684 |
685 return info->code(); | 685 return info->code(); |
686 } | 686 } |
687 | 687 |
688 | 688 |
689 MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap( | 689 MUST_USE_RESULT static MaybeHandle<Code> GetCodeFromOptimizedCodeMap( |
690 Handle<JSFunction> function, BailoutId osr_ast_id) { | 690 Handle<JSFunction> function, BailoutId osr_ast_id) { |
691 if (FLAG_cache_optimized_code) { | 691 if (FLAG_cache_optimized_code) { |
692 Handle<SharedFunctionInfo> shared(function->shared()); | 692 Handle<SharedFunctionInfo> shared(function->shared()); |
693 DisallowHeapAllocation no_gc; | 693 DisallowHeapAllocation no_gc; |
694 int index = shared->SearchOptimizedCodeMap( | 694 CodeAndLiterals cached = shared->SearchOptimizedCodeMap( |
695 function->context()->native_context(), osr_ast_id); | 695 function->context()->native_context(), osr_ast_id); |
696 if (index > 0) { | 696 if (cached.code != nullptr) { |
697 if (FLAG_trace_opt) { | 697 // Caching of optimized code enabled and optimized code found. |
698 PrintF("[found optimized code for "); | 698 if (cached.literals != nullptr) function->set_literals(cached.literals); |
699 function->ShortPrint(); | 699 DCHECK(!cached.code->marked_for_deoptimization()); |
700 if (!osr_ast_id.IsNone()) { | |
701 PrintF(" at OSR AST id %d", osr_ast_id.ToInt()); | |
702 } | |
703 PrintF("]\n"); | |
704 } | |
705 FixedArray* literals = shared->GetLiteralsFromOptimizedCodeMap(index); | |
706 if (literals != NULL) function->set_literals(literals); | |
707 Code* code = shared->GetCodeFromOptimizedCodeMap(index); | |
708 DCHECK(!code->marked_for_deoptimization()); | |
709 DCHECK(function->shared()->is_compiled()); | 700 DCHECK(function->shared()->is_compiled()); |
710 return Handle<Code>(code); | 701 return Handle<Code>(cached.code); |
711 } | 702 } |
712 } | 703 } |
713 return MaybeHandle<Code>(); | 704 return MaybeHandle<Code>(); |
714 } | 705 } |
715 | 706 |
716 | 707 |
717 static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { | 708 static void InsertCodeIntoOptimizedCodeMap(CompilationInfo* info) { |
718 Handle<Code> code = info->code(); | 709 Handle<Code> code = info->code(); |
719 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. | 710 if (code->kind() != Code::OPTIMIZED_FUNCTION) return; // Nothing to do. |
720 | 711 |
(...skipping 696 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1417 } | 1408 } |
1418 | 1409 |
1419 | 1410 |
1420 MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function, | 1411 MaybeHandle<Code> Compiler::GetOptimizedCode(Handle<JSFunction> function, |
1421 Handle<Code> current_code, | 1412 Handle<Code> current_code, |
1422 ConcurrencyMode mode, | 1413 ConcurrencyMode mode, |
1423 BailoutId osr_ast_id) { | 1414 BailoutId osr_ast_id) { |
1424 Handle<Code> cached_code; | 1415 Handle<Code> cached_code; |
1425 if (GetCodeFromOptimizedCodeMap( | 1416 if (GetCodeFromOptimizedCodeMap( |
1426 function, osr_ast_id).ToHandle(&cached_code)) { | 1417 function, osr_ast_id).ToHandle(&cached_code)) { |
| 1418 if (FLAG_trace_opt) { |
| 1419 PrintF("[found optimized code for "); |
| 1420 function->ShortPrint(); |
| 1421 if (!osr_ast_id.IsNone()) { |
| 1422 PrintF(" at OSR AST id %d", osr_ast_id.ToInt()); |
| 1423 } |
| 1424 PrintF("]\n"); |
| 1425 } |
1427 return cached_code; | 1426 return cached_code; |
1428 } | 1427 } |
1429 | 1428 |
1430 SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(function)); | 1429 SmartPointer<CompilationInfo> info(new CompilationInfoWithZone(function)); |
1431 Isolate* isolate = info->isolate(); | 1430 Isolate* isolate = info->isolate(); |
1432 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1431 DCHECK(AllowCompilation::IsAllowed(isolate)); |
1433 VMState<COMPILER> state(isolate); | 1432 VMState<COMPILER> state(isolate); |
1434 DCHECK(!isolate->has_pending_exception()); | 1433 DCHECK(!isolate->has_pending_exception()); |
1435 PostponeInterruptsScope postpone(isolate); | 1434 PostponeInterruptsScope postpone(isolate); |
1436 | 1435 |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1496 // 5) Code generation may have failed. | 1495 // 5) Code generation may have failed. |
1497 if (job->last_status() == OptimizedCompileJob::SUCCEEDED) { | 1496 if (job->last_status() == OptimizedCompileJob::SUCCEEDED) { |
1498 if (shared->optimization_disabled()) { | 1497 if (shared->optimization_disabled()) { |
1499 job->RetryOptimization(kOptimizationDisabled); | 1498 job->RetryOptimization(kOptimizationDisabled); |
1500 } else if (info->dependencies()->HasAborted()) { | 1499 } else if (info->dependencies()->HasAborted()) { |
1501 job->RetryOptimization(kBailedOutDueToDependencyChange); | 1500 job->RetryOptimization(kBailedOutDueToDependencyChange); |
1502 } else if (isolate->debug()->has_break_points()) { | 1501 } else if (isolate->debug()->has_break_points()) { |
1503 job->RetryOptimization(kDebuggerHasBreakPoints); | 1502 job->RetryOptimization(kDebuggerHasBreakPoints); |
1504 } else if (job->GenerateCode() == OptimizedCompileJob::SUCCEEDED) { | 1503 } else if (job->GenerateCode() == OptimizedCompileJob::SUCCEEDED) { |
1505 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info.get(), shared); | 1504 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info.get(), shared); |
1506 if (info->shared_info()->SearchOptimizedCodeMap( | 1505 if (shared->SearchOptimizedCodeMap(info->context()->native_context(), |
1507 info->context()->native_context(), info->osr_ast_id()) == -1) { | 1506 info->osr_ast_id()).code == nullptr) { |
1508 InsertCodeIntoOptimizedCodeMap(info.get()); | 1507 InsertCodeIntoOptimizedCodeMap(info.get()); |
1509 } | 1508 } |
1510 if (FLAG_trace_opt) { | 1509 if (FLAG_trace_opt) { |
1511 PrintF("[completed optimizing "); | 1510 PrintF("[completed optimizing "); |
1512 info->closure()->ShortPrint(); | 1511 info->closure()->ShortPrint(); |
1513 PrintF("]\n"); | 1512 PrintF("]\n"); |
1514 } | 1513 } |
1515 return Handle<Code>(*info->code()); | 1514 return Handle<Code>(*info->code()); |
1516 } | 1515 } |
1517 } | 1516 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1567 | 1566 |
1568 | 1567 |
1569 #if DEBUG | 1568 #if DEBUG |
1570 void CompilationInfo::PrintAstForTesting() { | 1569 void CompilationInfo::PrintAstForTesting() { |
1571 PrintF("--- Source from AST ---\n%s\n", | 1570 PrintF("--- Source from AST ---\n%s\n", |
1572 PrettyPrinter(isolate(), zone()).PrintProgram(function())); | 1571 PrettyPrinter(isolate(), zone()).PrintProgram(function())); |
1573 } | 1572 } |
1574 #endif | 1573 #endif |
1575 } // namespace internal | 1574 } // namespace internal |
1576 } // namespace v8 | 1575 } // namespace v8 |
OLD | NEW |