| 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 535 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 546 // Cache optimized context-specific code. | 546 // Cache optimized context-specific code. |
| 547 Handle<JSFunction> function = info->closure(); | 547 Handle<JSFunction> function = info->closure(); |
| 548 Handle<SharedFunctionInfo> shared(function->shared()); | 548 Handle<SharedFunctionInfo> shared(function->shared()); |
| 549 Handle<LiteralsArray> literals(function->literals()); | 549 Handle<LiteralsArray> literals(function->literals()); |
| 550 Handle<Context> native_context(function->context()->native_context()); | 550 Handle<Context> native_context(function->context()->native_context()); |
| 551 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 551 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
| 552 literals, info->osr_ast_id()); | 552 literals, info->osr_ast_id()); |
| 553 } | 553 } |
| 554 | 554 |
| 555 bool Renumber(ParseInfo* parse_info) { | 555 bool Renumber(ParseInfo* parse_info) { |
| 556 RuntimeCallTimerScope runtimeTimer(parse_info->isolate(), |
| 557 &RuntimeCallStats::CompileRenumber); |
| 556 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), | 558 if (!AstNumbering::Renumber(parse_info->isolate(), parse_info->zone(), |
| 557 parse_info->literal())) { | 559 parse_info->literal())) { |
| 558 return false; | 560 return false; |
| 559 } | 561 } |
| 560 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); | 562 Handle<SharedFunctionInfo> shared_info = parse_info->shared_info(); |
| 561 if (!shared_info.is_null()) { | 563 if (!shared_info.is_null()) { |
| 562 FunctionLiteral* lit = parse_info->literal(); | 564 FunctionLiteral* lit = parse_info->literal(); |
| 563 shared_info->set_ast_node_count(lit->ast_node_count()); | 565 shared_info->set_ast_node_count(lit->ast_node_count()); |
| 564 if (lit->dont_optimize_reason() != kNoReason) { | 566 if (lit->dont_optimize_reason() != kNoReason) { |
| 565 shared_info->DisableOptimization(lit->dont_optimize_reason()); | 567 shared_info->DisableOptimization(lit->dont_optimize_reason()); |
| (...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 893 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, &info); | 895 RecordFunctionCompilation(CodeEventListener::LAZY_COMPILE_TAG, &info); |
| 894 | 896 |
| 895 return info.code(); | 897 return info.code(); |
| 896 } | 898 } |
| 897 | 899 |
| 898 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { | 900 MaybeHandle<Code> GetLazyCode(Handle<JSFunction> function) { |
| 899 Isolate* isolate = function->GetIsolate(); | 901 Isolate* isolate = function->GetIsolate(); |
| 900 DCHECK(!isolate->has_pending_exception()); | 902 DCHECK(!isolate->has_pending_exception()); |
| 901 DCHECK(!function->is_compiled()); | 903 DCHECK(!function->is_compiled()); |
| 902 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); | 904 TimerEventScope<TimerEventCompileCode> compile_timer(isolate); |
| 905 RuntimeCallTimerScope runtimeTimer(isolate, |
| 906 &RuntimeCallStats::CompileFunction); |
| 903 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); | 907 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); |
| 904 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); | 908 AggregatedHistogramTimerScope timer(isolate->counters()->compile_lazy()); |
| 905 | 909 |
| 906 Handle<Code> cached_code; | 910 Handle<Code> cached_code; |
| 907 if (GetCodeFromOptimizedCodeMap(function, BailoutId::None()) | 911 if (GetCodeFromOptimizedCodeMap(function, BailoutId::None()) |
| 908 .ToHandle(&cached_code)) { | 912 .ToHandle(&cached_code)) { |
| 909 if (FLAG_trace_opt) { | 913 if (FLAG_trace_opt) { |
| 910 PrintF("[found optimized code for "); | 914 PrintF("[found optimized code for "); |
| 911 function->ShortPrint(); | 915 function->ShortPrint(); |
| 912 PrintF(" during unoptimized compile]\n"); | 916 PrintF(" during unoptimized compile]\n"); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 980 } | 984 } |
| 981 } | 985 } |
| 982 | 986 |
| 983 return result; | 987 return result; |
| 984 } | 988 } |
| 985 | 989 |
| 986 | 990 |
| 987 Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { | 991 Handle<SharedFunctionInfo> CompileToplevel(CompilationInfo* info) { |
| 988 Isolate* isolate = info->isolate(); | 992 Isolate* isolate = info->isolate(); |
| 989 TimerEventScope<TimerEventCompileCode> timer(isolate); | 993 TimerEventScope<TimerEventCompileCode> timer(isolate); |
| 990 RuntimeCallTimerScope runtimeTimer(isolate, &RuntimeCallStats::CompileCode); | |
| 991 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); | 994 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); |
| 992 PostponeInterruptsScope postpone(isolate); | 995 PostponeInterruptsScope postpone(isolate); |
| 993 DCHECK(!isolate->native_context().is_null()); | 996 DCHECK(!isolate->native_context().is_null()); |
| 994 ParseInfo* parse_info = info->parse_info(); | 997 ParseInfo* parse_info = info->parse_info(); |
| 998 |
| 999 RuntimeCallTimerScope runtimeTimer( |
| 1000 isolate, parse_info->is_eval() ? &RuntimeCallStats::CompileEval |
| 1001 : &RuntimeCallStats::CompileScript); |
| 1002 |
| 995 Handle<Script> script = parse_info->script(); | 1003 Handle<Script> script = parse_info->script(); |
| 996 | 1004 |
| 997 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 1005 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
| 998 FixedArray* array = isolate->native_context()->embedder_data(); | 1006 FixedArray* array = isolate->native_context()->embedder_data(); |
| 999 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); | 1007 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); |
| 1000 | 1008 |
| 1001 Handle<SharedFunctionInfo> result; | 1009 Handle<SharedFunctionInfo> result; |
| 1002 | 1010 |
| 1003 { VMState<COMPILER> state(info->isolate()); | 1011 { VMState<COMPILER> state(info->isolate()); |
| 1004 if (parse_info->literal() == nullptr && | 1012 if (parse_info->literal() == nullptr && |
| 1005 !parsing::ParseProgram(parse_info)) { | 1013 !parsing::ParseProgram(parse_info)) { |
| 1006 return Handle<SharedFunctionInfo>::null(); | 1014 return Handle<SharedFunctionInfo>::null(); |
| 1007 } | 1015 } |
| 1008 | 1016 |
| 1009 EnsureSharedFunctionInfosArrayOnScript(parse_info); | 1017 EnsureSharedFunctionInfosArrayOnScript(parse_info); |
| 1010 | 1018 |
| 1011 FunctionLiteral* lit = parse_info->literal(); | 1019 FunctionLiteral* lit = parse_info->literal(); |
| 1012 | 1020 |
| 1013 // Measure how long it takes to do the compilation; only take the | 1021 // Measure how long it takes to do the compilation; only take the |
| 1014 // rest of the function into account to avoid overlap with the | 1022 // rest of the function into account to avoid overlap with the |
| 1015 // parsing statistics. | 1023 // parsing statistics. |
| 1016 RuntimeCallTimerScope runtimeTimer( | |
| 1017 isolate, parse_info->is_eval() ? &RuntimeCallStats::CompileEval | |
| 1018 : &RuntimeCallStats::Compile); | |
| 1019 HistogramTimer* rate = parse_info->is_eval() | 1024 HistogramTimer* rate = parse_info->is_eval() |
| 1020 ? info->isolate()->counters()->compile_eval() | 1025 ? info->isolate()->counters()->compile_eval() |
| 1021 : info->isolate()->counters()->compile(); | 1026 : info->isolate()->counters()->compile(); |
| 1022 HistogramTimerScope timer(rate); | 1027 HistogramTimerScope timer(rate); |
| 1023 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), | 1028 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), |
| 1024 parse_info->is_eval() ? "V8.CompileEval" : "V8.Compile"); | 1029 parse_info->is_eval() ? "V8.CompileEval" : "V8.Compile"); |
| 1025 | 1030 |
| 1026 // Allocate a shared function info object. | 1031 // Allocate a shared function info object. |
| 1027 DCHECK_EQ(kNoSourcePosition, lit->function_token_position()); | 1032 DCHECK_EQ(kNoSourcePosition, lit->function_token_position()); |
| 1028 result = isolate->factory()->NewSharedFunctionInfoForLiteral(lit, script); | 1033 result = isolate->factory()->NewSharedFunctionInfoForLiteral(lit, script); |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1642 if (mode == LazyCompilationMode::kAlways || | 1647 if (mode == LazyCompilationMode::kAlways || |
| 1643 !literal->ShouldEagerCompile()) { | 1648 !literal->ShouldEagerCompile()) { |
| 1644 info.SetCode(isolate->builtins()->CompileLazy()); | 1649 info.SetCode(isolate->builtins()->CompileLazy()); |
| 1645 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext(); | 1650 Scope* outer_scope = literal->scope()->GetOuterScopeWithContext(); |
| 1646 if (outer_scope) { | 1651 if (outer_scope) { |
| 1647 result->set_outer_scope_info(*outer_scope->scope_info()); | 1652 result->set_outer_scope_info(*outer_scope->scope_info()); |
| 1648 } | 1653 } |
| 1649 } else { | 1654 } else { |
| 1650 // Generate code | 1655 // Generate code |
| 1651 TimerEventScope<TimerEventCompileCode> timer(isolate); | 1656 TimerEventScope<TimerEventCompileCode> timer(isolate); |
| 1652 RuntimeCallTimerScope runtimeTimer(isolate, | 1657 RuntimeCallTimerScope runtimeTimer( |
| 1653 &RuntimeCallStats::CompileCode); | 1658 isolate, &RuntimeCallStats::CompileInnerFunction); |
| 1654 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); | 1659 TRACE_EVENT0(TRACE_DISABLED_BY_DEFAULT("v8.compile"), "V8.CompileCode"); |
| 1655 if (Renumber(info.parse_info()) && GenerateUnoptimizedCode(&info)) { | 1660 if (Renumber(info.parse_info()) && GenerateUnoptimizedCode(&info)) { |
| 1656 // Code generation will ensure that the feedback vector is present and | 1661 // Code generation will ensure that the feedback vector is present and |
| 1657 // appropriately sized. | 1662 // appropriately sized. |
| 1658 DCHECK(!info.code().is_null()); | 1663 DCHECK(!info.code().is_null()); |
| 1659 if (literal->should_be_used_once_hint()) { | 1664 if (literal->should_be_used_once_hint()) { |
| 1660 info.code()->MarkToBeExecutedOnce(isolate); | 1665 info.code()->MarkToBeExecutedOnce(isolate); |
| 1661 } | 1666 } |
| 1662 } else { | 1667 } else { |
| 1663 return Handle<SharedFunctionInfo>::null(); | 1668 return Handle<SharedFunctionInfo>::null(); |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1764 DCHECK(shared->is_compiled()); | 1769 DCHECK(shared->is_compiled()); |
| 1765 function->set_literals(cached.literals); | 1770 function->set_literals(cached.literals); |
| 1766 } else if (shared->is_compiled()) { | 1771 } else if (shared->is_compiled()) { |
| 1767 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1772 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
| 1768 JSFunction::EnsureLiterals(function); | 1773 JSFunction::EnsureLiterals(function); |
| 1769 } | 1774 } |
| 1770 } | 1775 } |
| 1771 | 1776 |
| 1772 } // namespace internal | 1777 } // namespace internal |
| 1773 } // namespace v8 | 1778 } // namespace v8 |
| OLD | NEW |