| 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 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 | 892 |
| 893 bool Compiler::ParseAndAnalyze(ParseInfo* info) { | 893 bool Compiler::ParseAndAnalyze(ParseInfo* info) { |
| 894 if (!Parser::ParseStatic(info)) return false; | 894 if (!Parser::ParseStatic(info)) return false; |
| 895 return Compiler::Analyze(info); | 895 return Compiler::Analyze(info); |
| 896 } | 896 } |
| 897 | 897 |
| 898 | 898 |
| 899 static bool GetOptimizedCodeNow(CompilationInfo* info) { | 899 static bool GetOptimizedCodeNow(CompilationInfo* info) { |
| 900 Isolate* isolate = info->isolate(); | 900 Isolate* isolate = info->isolate(); |
| 901 CanonicalHandleScope canonical(isolate); | 901 CanonicalHandleScope canonical(isolate); |
| 902 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); |
| 902 | 903 |
| 903 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; | 904 if (!Compiler::ParseAndAnalyze(info->parse_info())) return false; |
| 904 | 905 |
| 905 TimerEventScope<TimerEventRecompileSynchronous> timer(isolate); | 906 TimerEventScope<TimerEventRecompileSynchronous> timer(isolate); |
| 906 | 907 |
| 907 OptimizedCompileJob job(info); | 908 OptimizedCompileJob job(info); |
| 908 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED || | 909 if (job.CreateGraph() != OptimizedCompileJob::SUCCEEDED || |
| 909 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED || | 910 job.OptimizeGraph() != OptimizedCompileJob::SUCCEEDED || |
| 910 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) { | 911 job.GenerateCode() != OptimizedCompileJob::SUCCEEDED) { |
| 911 if (FLAG_trace_opt) { | 912 if (FLAG_trace_opt) { |
| 912 PrintF("[aborted optimizing "); | 913 PrintF("[aborted optimizing "); |
| 913 info->closure()->ShortPrint(); | 914 info->closure()->ShortPrint(); |
| 914 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); | 915 PrintF(" because: %s]\n", GetBailoutReason(info->bailout_reason())); |
| 915 } | 916 } |
| 916 return false; | 917 return false; |
| 917 } | 918 } |
| 918 | 919 |
| 919 // Success! | 920 // Success! |
| 920 DCHECK(!isolate->has_pending_exception()); | 921 DCHECK(!isolate->has_pending_exception()); |
| 921 InsertCodeIntoOptimizedCodeMap(info); | 922 InsertCodeIntoOptimizedCodeMap(info); |
| 922 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, | 923 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, info, |
| 923 info->shared_info()); | 924 info->shared_info()); |
| 924 return true; | 925 return true; |
| 925 } | 926 } |
| 926 | 927 |
| 927 | 928 |
| 928 static bool GetOptimizedCodeLater(CompilationInfo* info) { | 929 static bool GetOptimizedCodeLater(CompilationInfo* info) { |
| 929 Isolate* isolate = info->isolate(); | 930 Isolate* isolate = info->isolate(); |
| 930 CanonicalHandleScope canonical(isolate); | 931 CanonicalHandleScope canonical(isolate); |
| 932 TimerEventScope<TimerEventOptimizeCode> optimize_code_timer(isolate); |
| 931 | 933 |
| 932 if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) { | 934 if (!isolate->optimizing_compile_dispatcher()->IsQueueAvailable()) { |
| 933 if (FLAG_trace_concurrent_recompilation) { | 935 if (FLAG_trace_concurrent_recompilation) { |
| 934 PrintF(" ** Compilation queue full, will retry optimizing "); | 936 PrintF(" ** Compilation queue full, will retry optimizing "); |
| 935 info->closure()->ShortPrint(); | 937 info->closure()->ShortPrint(); |
| 936 PrintF(" later.\n"); | 938 PrintF(" later.\n"); |
| 937 } | 939 } |
| 938 return false; | 940 return false; |
| 939 } | 941 } |
| 940 | 942 |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 978 GetUnoptimizedCodeCommon(&info), | 980 GetUnoptimizedCodeCommon(&info), |
| 979 Code); | 981 Code); |
| 980 return result; | 982 return result; |
| 981 } | 983 } |
| 982 | 984 |
| 983 | 985 |
| 984 MaybeHandle<Code> Compiler::GetLazyCode(Handle<JSFunction> function) { | 986 MaybeHandle<Code> Compiler::GetLazyCode(Handle<JSFunction> function) { |
| 985 Isolate* isolate = function->GetIsolate(); | 987 Isolate* isolate = function->GetIsolate(); |
| 986 DCHECK(!isolate->has_pending_exception()); | 988 DCHECK(!isolate->has_pending_exception()); |
| 987 DCHECK(!function->is_compiled()); | 989 DCHECK(!function->is_compiled()); |
| 990 TimerEventScope<TimerEventCompileCode> timer(isolate); |
| 988 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 991 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| 989 // If the debugger is active, do not compile with turbofan unless we can | 992 // If the debugger is active, do not compile with turbofan unless we can |
| 990 // deopt from turbofan code. | 993 // deopt from turbofan code. |
| 991 if (FLAG_turbo_asm && function->shared()->asm_function() && | 994 if (FLAG_turbo_asm && function->shared()->asm_function() && |
| 992 (FLAG_turbo_asm_deoptimization || !isolate->debug()->is_active()) && | 995 (FLAG_turbo_asm_deoptimization || !isolate->debug()->is_active()) && |
| 993 !FLAG_turbo_osr) { | 996 !FLAG_turbo_osr) { |
| 994 CompilationInfoWithZone info(function); | 997 CompilationInfoWithZone info(function); |
| 995 | 998 |
| 996 VMState<COMPILER> state(isolate); | 999 VMState<COMPILER> state(isolate); |
| 997 PostponeInterruptsScope postpone(isolate); | 1000 PostponeInterruptsScope postpone(isolate); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1185 Handle<ScopeInfo> scope_info = | 1188 Handle<ScopeInfo> scope_info = |
| 1186 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); | 1189 ScopeInfo::Create(info.isolate(), info.zone(), info.scope()); |
| 1187 info.shared_info()->set_scope_info(*scope_info); | 1190 info.shared_info()->set_scope_info(*scope_info); |
| 1188 } | 1191 } |
| 1189 tracker.RecordRootFunctionInfo(info.code()); | 1192 tracker.RecordRootFunctionInfo(info.code()); |
| 1190 } | 1193 } |
| 1191 | 1194 |
| 1192 | 1195 |
| 1193 static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { | 1196 static Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { |
| 1194 Isolate* isolate = info->isolate(); | 1197 Isolate* isolate = info->isolate(); |
| 1198 TimerEventScope<TimerEventCompileCode> timer(isolate); |
| 1195 PostponeInterruptsScope postpone(isolate); | 1199 PostponeInterruptsScope postpone(isolate); |
| 1196 DCHECK(!isolate->native_context().is_null()); | 1200 DCHECK(!isolate->native_context().is_null()); |
| 1197 ParseInfo* parse_info = info->parse_info(); | 1201 ParseInfo* parse_info = info->parse_info(); |
| 1198 Handle<Script> script = parse_info->script(); | 1202 Handle<Script> script = parse_info->script(); |
| 1199 | 1203 |
| 1200 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 1204 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
| 1201 FixedArray* array = isolate->native_context()->embedder_data(); | 1205 FixedArray* array = isolate->native_context()->embedder_data(); |
| 1202 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); | 1206 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); |
| 1203 | 1207 |
| 1204 isolate->debug()->OnBeforeCompile(script); | 1208 isolate->debug()->OnBeforeCompile(script); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1579 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); | 1583 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); |
| 1580 // Compile eagerly for live edit. When compiling debug code, eagerly compile | 1584 // Compile eagerly for live edit. When compiling debug code, eagerly compile |
| 1581 // unless we can lazily compile without the context. | 1585 // unless we can lazily compile without the context. |
| 1582 bool allow_lazy = literal->AllowsLazyCompilation() && | 1586 bool allow_lazy = literal->AllowsLazyCompilation() && |
| 1583 !LiveEditFunctionTracker::IsActive(isolate) && | 1587 !LiveEditFunctionTracker::IsActive(isolate) && |
| 1584 (!info.is_debug() || allow_lazy_without_ctx); | 1588 (!info.is_debug() || allow_lazy_without_ctx); |
| 1585 | 1589 |
| 1586 bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile(); | 1590 bool lazy = FLAG_lazy && allow_lazy && !literal->should_eager_compile(); |
| 1587 | 1591 |
| 1588 // Generate code | 1592 // Generate code |
| 1593 TimerEventScope<TimerEventCompileCode> timer(info->isolate()); |
| 1589 Handle<ScopeInfo> scope_info; | 1594 Handle<ScopeInfo> scope_info; |
| 1590 if (lazy) { | 1595 if (lazy) { |
| 1591 Handle<Code> code = isolate->builtins()->CompileLazy(); | 1596 Handle<Code> code = isolate->builtins()->CompileLazy(); |
| 1592 info.SetCode(code); | 1597 info.SetCode(code); |
| 1593 // There's no need in theory for a lazy-compiled function to have a type | 1598 // There's no need in theory for a lazy-compiled function to have a type |
| 1594 // feedback vector, but some parts of the system expect all | 1599 // feedback vector, but some parts of the system expect all |
| 1595 // SharedFunctionInfo instances to have one. The size of the vector depends | 1600 // SharedFunctionInfo instances to have one. The size of the vector depends |
| 1596 // on how many feedback-needing nodes are in the tree, and when lazily | 1601 // on how many feedback-needing nodes are in the tree, and when lazily |
| 1597 // parsing we might not know that, if this function was never parsed before. | 1602 // parsing we might not know that, if this function was never parsed before. |
| 1598 // In that case the vector will be replaced the next time MakeCode is | 1603 // In that case the vector will be replaced the next time MakeCode is |
| (...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 } | 1842 } |
| 1838 | 1843 |
| 1839 #if DEBUG | 1844 #if DEBUG |
| 1840 void CompilationInfo::PrintAstForTesting() { | 1845 void CompilationInfo::PrintAstForTesting() { |
| 1841 PrintF("--- Source from AST ---\n%s\n", | 1846 PrintF("--- Source from AST ---\n%s\n", |
| 1842 PrettyPrinter(isolate()).PrintProgram(literal())); | 1847 PrettyPrinter(isolate()).PrintProgram(literal())); |
| 1843 } | 1848 } |
| 1844 #endif | 1849 #endif |
| 1845 } // namespace internal | 1850 } // namespace internal |
| 1846 } // namespace v8 | 1851 } // namespace v8 |
| OLD | NEW |