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 1014 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1025 parse_info->set_compile_options(ScriptCompiler::kNoCompileOptions); | 1025 parse_info->set_compile_options(ScriptCompiler::kNoCompileOptions); |
1026 } | 1026 } |
1027 if (!Parser::ParseStatic(parse_info)) { | 1027 if (!Parser::ParseStatic(parse_info)) { |
1028 return Handle<SharedFunctionInfo>::null(); | 1028 return Handle<SharedFunctionInfo>::null(); |
1029 } | 1029 } |
1030 } | 1030 } |
1031 | 1031 |
1032 DCHECK(!info->is_debug() || !parse_info->allow_lazy_parsing()); | 1032 DCHECK(!info->is_debug() || !parse_info->allow_lazy_parsing()); |
1033 | 1033 |
1034 FunctionLiteral* lit = parse_info->literal(); | 1034 FunctionLiteral* lit = parse_info->literal(); |
1035 LiveEditFunctionTracker live_edit_tracker(isolate, lit); | |
1036 | 1035 |
1037 // Measure how long it takes to do the compilation; only take the | 1036 // Measure how long it takes to do the compilation; only take the |
1038 // rest of the function into account to avoid overlap with the | 1037 // rest of the function into account to avoid overlap with the |
1039 // parsing statistics. | 1038 // parsing statistics. |
1040 HistogramTimer* rate = parse_info->is_eval() | 1039 HistogramTimer* rate = parse_info->is_eval() |
1041 ? info->isolate()->counters()->compile_eval() | 1040 ? info->isolate()->counters()->compile_eval() |
1042 : info->isolate()->counters()->compile(); | 1041 : info->isolate()->counters()->compile(); |
1043 HistogramTimerScope timer(rate); | 1042 HistogramTimerScope timer(rate); |
1044 TRACE_EVENT0("v8", parse_info->is_eval() ? "V8.CompileEval" : "V8.Compile"); | 1043 TRACE_EVENT0("v8", parse_info->is_eval() ? "V8.CompileEval" : "V8.Compile"); |
1045 | 1044 |
(...skipping 25 matching lines...) Expand all Loading... | |
1071 Logger::LogEventsAndTags log_tag = | 1070 Logger::LogEventsAndTags log_tag = |
1072 parse_info->is_eval() | 1071 parse_info->is_eval() |
1073 ? Logger::EVAL_TAG | 1072 ? Logger::EVAL_TAG |
1074 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); | 1073 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); |
1075 | 1074 |
1076 PROFILE(isolate, CodeCreateEvent(log_tag, result->abstract_code(), *result, | 1075 PROFILE(isolate, CodeCreateEvent(log_tag, result->abstract_code(), *result, |
1077 *script_name)); | 1076 *script_name)); |
1078 | 1077 |
1079 if (!script.is_null()) | 1078 if (!script.is_null()) |
1080 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); | 1079 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); |
1081 | |
1082 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); | |
1083 } | 1080 } |
1084 | 1081 |
1085 return result; | 1082 return result; |
1086 } | 1083 } |
1087 | 1084 |
1088 } // namespace | 1085 } // namespace |
1089 | 1086 |
1090 // ---------------------------------------------------------------------------- | 1087 // ---------------------------------------------------------------------------- |
1091 // Implementation of Compiler | 1088 // Implementation of Compiler |
1092 | 1089 |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1249 Zone zone(isolate->allocator()); | 1246 Zone zone(isolate->allocator()); |
1250 ParseInfo parse_info(&zone, script); | 1247 ParseInfo parse_info(&zone, script); |
1251 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1248 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1252 parse_info.set_global(); | 1249 parse_info.set_global(); |
1253 info.MarkAsDebug(); | 1250 info.MarkAsDebug(); |
1254 // TODO(635): support extensions. | 1251 // TODO(635): support extensions. |
1255 if (CompileToplevel(&info).is_null()) { | 1252 if (CompileToplevel(&info).is_null()) { |
1256 return false; | 1253 return false; |
1257 } | 1254 } |
1258 | 1255 |
1256 LiveEditFunctionTracker::Collect(script, &parse_info, isolate); | |
Yang
2016/05/11 07:29:09
The caller of CompileForLiveEdit (LiveEdit::Gather
jgruber1
2016/05/12 12:30:25
Done.
| |
1257 | |
1259 // Check postconditions on success. | 1258 // Check postconditions on success. |
1260 DCHECK(!isolate->has_pending_exception()); | 1259 DCHECK(!isolate->has_pending_exception()); |
1261 return true; | 1260 return true; |
1262 } | 1261 } |
1263 | 1262 |
1264 // TODO(turbofan): In the future, unoptimized code with deopt support could | 1263 // TODO(turbofan): In the future, unoptimized code with deopt support could |
1265 // be generated lazily once deopt is triggered. | 1264 // be generated lazily once deopt is triggered. |
1266 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { | 1265 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { |
1267 DCHECK_NOT_NULL(info->literal()); | 1266 DCHECK_NOT_NULL(info->literal()); |
1268 DCHECK_NOT_NULL(info->scope()); | 1267 DCHECK_NOT_NULL(info->scope()); |
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1579 Zone zone(isolate->allocator()); | 1578 Zone zone(isolate->allocator()); |
1580 ParseInfo parse_info(&zone, script); | 1579 ParseInfo parse_info(&zone, script); |
1581 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1580 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1582 parse_info.set_literal(literal); | 1581 parse_info.set_literal(literal); |
1583 parse_info.set_shared_info(result); | 1582 parse_info.set_shared_info(result); |
1584 parse_info.set_scope(literal->scope()); | 1583 parse_info.set_scope(literal->scope()); |
1585 parse_info.set_language_mode(literal->scope()->language_mode()); | 1584 parse_info.set_language_mode(literal->scope()->language_mode()); |
1586 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1585 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
1587 if (outer_info->is_debug()) info.MarkAsDebug(); | 1586 if (outer_info->is_debug()) info.MarkAsDebug(); |
1588 | 1587 |
1589 LiveEditFunctionTracker live_edit_tracker(isolate, literal); | |
1590 // Determine if the function can be lazily compiled. This is necessary to | 1588 // Determine if the function can be lazily compiled. This is necessary to |
1591 // allow some of our builtin JS files to be lazily compiled. These | 1589 // allow some of our builtin JS files to be lazily compiled. These |
1592 // builtins cannot be handled lazily by the parser, since we have to know | 1590 // builtins cannot be handled lazily by the parser, since we have to know |
1593 // if a function uses the special natives syntax, which is something the | 1591 // if a function uses the special natives syntax, which is something the |
1594 // parser records. | 1592 // parser records. |
1595 // If the debugger requests compilation for break points, we cannot be | 1593 // If the debugger requests compilation for break points, we cannot be |
1596 // aggressive about lazy compilation, because it might trigger compilation | 1594 // aggressive about lazy compilation, because it might trigger compilation |
1597 // of functions without an outer context when setting a breakpoint through | 1595 // of functions without an outer context when setting a breakpoint through |
1598 // Debug::FindSharedFunctionInfoInScript. | 1596 // Debug::FindSharedFunctionInfoInScript. |
1599 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); | 1597 bool allow_lazy_without_ctx = literal->AllowsLazyCompilationWithoutContext(); |
(...skipping 28 matching lines...) Expand all Loading... | |
1628 // Update the shared function info with the scope info. | 1626 // Update the shared function info with the scope info. |
1629 InstallSharedScopeInfo(&info, result); | 1627 InstallSharedScopeInfo(&info, result); |
1630 // Install compilation result on the shared function info. | 1628 // Install compilation result on the shared function info. |
1631 InstallSharedCompilationResult(&info, result); | 1629 InstallSharedCompilationResult(&info, result); |
1632 } else { | 1630 } else { |
1633 return Handle<SharedFunctionInfo>::null(); | 1631 return Handle<SharedFunctionInfo>::null(); |
1634 } | 1632 } |
1635 | 1633 |
1636 if (maybe_existing.is_null()) { | 1634 if (maybe_existing.is_null()) { |
1637 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info); | 1635 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info); |
1638 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); | |
1639 } | 1636 } |
1640 | 1637 |
1641 return result; | 1638 return result; |
1642 } | 1639 } |
1643 | 1640 |
1644 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( | 1641 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( |
1645 v8::Extension* extension, Handle<String> name) { | 1642 v8::Extension* extension, Handle<String> name) { |
1646 Isolate* isolate = name->GetIsolate(); | 1643 Isolate* isolate = name->GetIsolate(); |
1647 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 1644 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
1648 | 1645 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1763 MaybeHandle<Code> code; | 1760 MaybeHandle<Code> code; |
1764 if (cached.code != nullptr) code = handle(cached.code); | 1761 if (cached.code != nullptr) code = handle(cached.code); |
1765 Handle<Context> native_context(function->context()->native_context()); | 1762 Handle<Context> native_context(function->context()->native_context()); |
1766 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1763 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
1767 literals, BailoutId::None()); | 1764 literals, BailoutId::None()); |
1768 } | 1765 } |
1769 } | 1766 } |
1770 | 1767 |
1771 } // namespace internal | 1768 } // namespace internal |
1772 } // namespace v8 | 1769 } // namespace v8 |
OLD | NEW |