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/ast-numbering.h" | 9 #include "src/ast/ast-numbering.h" |
10 #include "src/ast/prettyprinter.h" | 10 #include "src/ast/prettyprinter.h" |
(...skipping 875 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
886 return MaybeHandle<Code>(); | 886 return MaybeHandle<Code>(); |
887 } | 887 } |
888 | 888 |
889 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { | 889 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { |
890 Isolate* isolate = function->GetIsolate(); | 890 Isolate* isolate = function->GetIsolate(); |
891 DCHECK(!isolate->has_pending_exception()); | 891 DCHECK(!isolate->has_pending_exception()); |
892 DCHECK(!function->is_compiled()); | 892 DCHECK(!function->is_compiled()); |
893 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); | 893 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); |
894 TRACE_EVENT0("v8", "V8.CompileCode"); | 894 TRACE_EVENT0("v8", "V8.CompileCode"); |
895 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 895 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| 896 |
| 897 if (FLAG_turbo_cache_shared_code) { |
| 898 CodeAndLiterals result; |
| 899 result = function->shared()->SearchOptimizedCodeMap( |
| 900 *isolate->native_context(), BailoutId::None()); |
| 901 if (result.code != nullptr) { |
| 902 return Handle<Code>(result.code); |
| 903 } |
| 904 } |
| 905 |
896 // If the debugger is active, do not compile with turbofan unless we can | 906 // If the debugger is active, do not compile with turbofan unless we can |
897 // deopt from turbofan code. | 907 // deopt from turbofan code. |
898 if (FLAG_turbo_asm && function->shared()->asm_function() && | 908 if (FLAG_turbo_asm && function->shared()->asm_function() && |
899 (FLAG_turbo_asm_deoptimization || !isolate->debug()->is_active()) && | 909 (FLAG_turbo_asm_deoptimization || !isolate->debug()->is_active()) && |
900 !FLAG_turbo_osr) { | 910 !FLAG_turbo_osr) { |
901 Handle<Code> code; | 911 Handle<Code> code; |
902 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT).ToHandle(&code)) { | 912 if (GetOptimizedCode(function, Compiler::NOT_CONCURRENT).ToHandle(&code)) { |
903 DCHECK(function->shared()->is_compiled()); | 913 DCHECK(function->shared()->is_compiled()); |
904 return code; | 914 return code; |
905 } | 915 } |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1116 return true; | 1126 return true; |
1117 } | 1127 } |
1118 | 1128 |
1119 bool Compiler::ParseAndAnalyze(ParseInfo* info) { | 1129 bool Compiler::ParseAndAnalyze(ParseInfo* info) { |
1120 if (!Parser::ParseStatic(info)) return false; | 1130 if (!Parser::ParseStatic(info)) return false; |
1121 return Compiler::Analyze(info); | 1131 return Compiler::Analyze(info); |
1122 } | 1132 } |
1123 | 1133 |
1124 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { | 1134 bool Compiler::Compile(Handle<JSFunction> function, ClearExceptionFlag flag) { |
1125 if (function->is_compiled()) return true; | 1135 if (function->is_compiled()) return true; |
| 1136 |
1126 MaybeHandle<Code> maybe_code = GetLazyCode(function); | 1137 MaybeHandle<Code> maybe_code = GetLazyCode(function); |
1127 Handle<Code> code; | 1138 Handle<Code> code; |
1128 if (!maybe_code.ToHandle(&code)) { | 1139 if (!maybe_code.ToHandle(&code)) { |
1129 if (flag == CLEAR_EXCEPTION) { | 1140 if (flag == CLEAR_EXCEPTION) { |
1130 function->GetIsolate()->clear_pending_exception(); | 1141 function->GetIsolate()->clear_pending_exception(); |
1131 } | 1142 } |
1132 return false; | 1143 return false; |
1133 } | 1144 } |
1134 DCHECK(code->IsJavaScriptCode()); | 1145 |
1135 function->ReplaceCode(*code); | 1146 function->ReplaceCode(*code); |
1136 DCHECK(function->is_compiled()); | 1147 DCHECK(function->is_compiled()); |
1137 return true; | 1148 return true; |
1138 } | 1149 } |
1139 | 1150 |
1140 bool Compiler::CompileOptimized(Handle<JSFunction> function, | 1151 bool Compiler::CompileOptimized(Handle<JSFunction> function, |
1141 ConcurrencyMode mode) { | 1152 ConcurrencyMode mode) { |
1142 Handle<Code> code; | 1153 Handle<Code> code; |
1143 if (GetOptimizedCode(function, mode).ToHandle(&code)) { | 1154 if (GetOptimizedCode(function, mode).ToHandle(&code)) { |
1144 // Optimization succeeded, return optimized code. | 1155 // Optimization succeeded, return optimized code. |
(...skipping 558 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1703 MaybeHandle<Code> code; | 1714 MaybeHandle<Code> code; |
1704 if (cached.code != nullptr) code = handle(cached.code); | 1715 if (cached.code != nullptr) code = handle(cached.code); |
1705 Handle<Context> native_context(function->context()->native_context()); | 1716 Handle<Context> native_context(function->context()->native_context()); |
1706 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1717 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
1707 literals, BailoutId::None()); | 1718 literals, BailoutId::None()); |
1708 } | 1719 } |
1709 } | 1720 } |
1710 | 1721 |
1711 } // namespace internal | 1722 } // namespace internal |
1712 } // namespace v8 | 1723 } // namespace v8 |
OLD | NEW |