| 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 1001 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1012 parse_info->set_compile_options(ScriptCompiler::kNoCompileOptions); | 1012 parse_info->set_compile_options(ScriptCompiler::kNoCompileOptions); |
| 1013 } | 1013 } |
| 1014 if (!Parser::ParseStatic(parse_info)) { | 1014 if (!Parser::ParseStatic(parse_info)) { |
| 1015 return Handle<SharedFunctionInfo>::null(); | 1015 return Handle<SharedFunctionInfo>::null(); |
| 1016 } | 1016 } |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 DCHECK(!info->is_debug() || !parse_info->allow_lazy_parsing()); | 1019 DCHECK(!info->is_debug() || !parse_info->allow_lazy_parsing()); |
| 1020 | 1020 |
| 1021 FunctionLiteral* lit = parse_info->literal(); | 1021 FunctionLiteral* lit = parse_info->literal(); |
| 1022 LiveEditFunctionTracker live_edit_tracker(isolate, lit); | |
| 1023 | 1022 |
| 1024 // Measure how long it takes to do the compilation; only take the | 1023 // Measure how long it takes to do the compilation; only take the |
| 1025 // rest of the function into account to avoid overlap with the | 1024 // rest of the function into account to avoid overlap with the |
| 1026 // parsing statistics. | 1025 // parsing statistics. |
| 1027 RuntimeCallTimerScope runtimeTimer( | 1026 RuntimeCallTimerScope runtimeTimer( |
| 1028 isolate, parse_info->is_eval() ? &RuntimeCallStats::CompileEval | 1027 isolate, parse_info->is_eval() ? &RuntimeCallStats::CompileEval |
| 1029 : &RuntimeCallStats::Compile); | 1028 : &RuntimeCallStats::Compile); |
| 1030 HistogramTimer* rate = parse_info->is_eval() | 1029 HistogramTimer* rate = parse_info->is_eval() |
| 1031 ? info->isolate()->counters()->compile_eval() | 1030 ? info->isolate()->counters()->compile_eval() |
| 1032 : info->isolate()->counters()->compile(); | 1031 : info->isolate()->counters()->compile(); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1061 Logger::LogEventsAndTags log_tag = | 1060 Logger::LogEventsAndTags log_tag = |
| 1062 parse_info->is_eval() | 1061 parse_info->is_eval() |
| 1063 ? Logger::EVAL_TAG | 1062 ? Logger::EVAL_TAG |
| 1064 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); | 1063 : Logger::ToNativeByScript(Logger::SCRIPT_TAG, *script); |
| 1065 | 1064 |
| 1066 PROFILE(isolate, CodeCreateEvent(log_tag, result->abstract_code(), *result, | 1065 PROFILE(isolate, CodeCreateEvent(log_tag, result->abstract_code(), *result, |
| 1067 *script_name)); | 1066 *script_name)); |
| 1068 | 1067 |
| 1069 if (!script.is_null()) | 1068 if (!script.is_null()) |
| 1070 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); | 1069 script->set_compilation_state(Script::COMPILATION_STATE_COMPILED); |
| 1071 | |
| 1072 live_edit_tracker.RecordFunctionInfo(result, lit, info->zone()); | |
| 1073 } | 1070 } |
| 1074 | 1071 |
| 1075 return result; | 1072 return result; |
| 1076 } | 1073 } |
| 1077 | 1074 |
| 1078 } // namespace | 1075 } // namespace |
| 1079 | 1076 |
| 1080 // ---------------------------------------------------------------------------- | 1077 // ---------------------------------------------------------------------------- |
| 1081 // Implementation of Compiler | 1078 // Implementation of Compiler |
| 1082 | 1079 |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1221 return false; | 1218 return false; |
| 1222 } | 1219 } |
| 1223 | 1220 |
| 1224 // Check postconditions on success. | 1221 // Check postconditions on success. |
| 1225 DCHECK(!isolate->has_pending_exception()); | 1222 DCHECK(!isolate->has_pending_exception()); |
| 1226 DCHECK(shared->is_compiled()); | 1223 DCHECK(shared->is_compiled()); |
| 1227 DCHECK(shared->HasDebugCode()); | 1224 DCHECK(shared->HasDebugCode()); |
| 1228 return true; | 1225 return true; |
| 1229 } | 1226 } |
| 1230 | 1227 |
| 1231 bool Compiler::CompileForLiveEdit(Handle<Script> script) { | 1228 MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) { |
| 1232 Isolate* isolate = script->GetIsolate(); | 1229 Isolate* isolate = script->GetIsolate(); |
| 1233 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1230 DCHECK(AllowCompilation::IsAllowed(isolate)); |
| 1234 | 1231 |
| 1235 // In order to ensure that live edit function info collection finds the newly | 1232 // In order to ensure that live edit function info collection finds the newly |
| 1236 // generated shared function infos, clear the script's list temporarily | 1233 // generated shared function infos, clear the script's list temporarily |
| 1237 // and restore it at the end of this method. | 1234 // and restore it at the end of this method. |
| 1238 Handle<Object> old_function_infos(script->shared_function_infos(), isolate); | 1235 Handle<Object> old_function_infos(script->shared_function_infos(), isolate); |
| 1239 script->set_shared_function_infos(Smi::FromInt(0)); | 1236 script->set_shared_function_infos(Smi::FromInt(0)); |
| 1240 | 1237 |
| 1241 // Start a compilation. | 1238 // Start a compilation. |
| 1242 Zone zone(isolate->allocator()); | 1239 Zone zone(isolate->allocator()); |
| 1243 ParseInfo parse_info(&zone, script); | 1240 ParseInfo parse_info(&zone, script); |
| 1244 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1241 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 1245 parse_info.set_global(); | 1242 parse_info.set_global(); |
| 1246 info.MarkAsDebug(); | 1243 info.MarkAsDebug(); |
| 1244 |
| 1247 // TODO(635): support extensions. | 1245 // TODO(635): support extensions. |
| 1248 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); | 1246 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); |
| 1247 Handle<JSArray> infos; |
| 1248 if (compilation_succeeded) { |
| 1249 // Check postconditions on success. |
| 1250 DCHECK(!isolate->has_pending_exception()); |
| 1251 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script, |
| 1252 &zone, isolate); |
| 1253 } |
| 1249 | 1254 |
| 1250 // Restore the original function info list in order to remain side-effect | 1255 // Restore the original function info list in order to remain side-effect |
| 1251 // free as much as possible, since some code expects the old shared function | 1256 // free as much as possible, since some code expects the old shared function |
| 1252 // infos to stick around. | 1257 // infos to stick around. |
| 1253 script->set_shared_function_infos(*old_function_infos); | 1258 script->set_shared_function_infos(*old_function_infos); |
| 1254 | 1259 |
| 1255 if (!compilation_succeeded) { | 1260 return infos; |
| 1256 return false; | |
| 1257 } | |
| 1258 | |
| 1259 // Check postconditions on success. | |
| 1260 DCHECK(!isolate->has_pending_exception()); | |
| 1261 | |
| 1262 return compilation_succeeded; | |
| 1263 } | 1261 } |
| 1264 | 1262 |
| 1265 // TODO(turbofan): In the future, unoptimized code with deopt support could | 1263 // TODO(turbofan): In the future, unoptimized code with deopt support could |
| 1266 // be generated lazily once deopt is triggered. | 1264 // be generated lazily once deopt is triggered. |
| 1267 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { | 1265 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { |
| 1268 DCHECK_NOT_NULL(info->literal()); | 1266 DCHECK_NOT_NULL(info->literal()); |
| 1269 DCHECK_NOT_NULL(info->scope()); | 1267 DCHECK_NOT_NULL(info->scope()); |
| 1270 Handle<SharedFunctionInfo> shared = info->shared_info(); | 1268 Handle<SharedFunctionInfo> shared = info->shared_info(); |
| 1271 if (!shared->has_deoptimization_support()) { | 1269 if (!shared->has_deoptimization_support()) { |
| 1272 Zone zone(info->isolate()->allocator()); | 1270 Zone zone(info->isolate()->allocator()); |
| (...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1582 Zone zone(isolate->allocator()); | 1580 Zone zone(isolate->allocator()); |
| 1583 ParseInfo parse_info(&zone, script); | 1581 ParseInfo parse_info(&zone, script); |
| 1584 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1582 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 1585 parse_info.set_literal(literal); | 1583 parse_info.set_literal(literal); |
| 1586 parse_info.set_shared_info(result); | 1584 parse_info.set_shared_info(result); |
| 1587 parse_info.set_scope(literal->scope()); | 1585 parse_info.set_scope(literal->scope()); |
| 1588 parse_info.set_language_mode(literal->scope()->language_mode()); | 1586 parse_info.set_language_mode(literal->scope()->language_mode()); |
| 1589 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1587 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
| 1590 if (outer_info->is_debug()) info.MarkAsDebug(); | 1588 if (outer_info->is_debug()) info.MarkAsDebug(); |
| 1591 | 1589 |
| 1592 LiveEditFunctionTracker live_edit_tracker(isolate, literal); | |
| 1593 // Determine if the function can be lazily compiled. This is necessary to | 1590 // Determine if the function can be lazily compiled. This is necessary to |
| 1594 // allow some of our builtin JS files to be lazily compiled. These | 1591 // allow some of our builtin JS files to be lazily compiled. These |
| 1595 // builtins cannot be handled lazily by the parser, since we have to know | 1592 // builtins cannot be handled lazily by the parser, since we have to know |
| 1596 // if a function uses the special natives syntax, which is something the | 1593 // if a function uses the special natives syntax, which is something the |
| 1597 // parser records. | 1594 // parser records. |
| 1598 // If the debugger requests compilation for break points, we cannot be | 1595 // If the debugger requests compilation for break points, we cannot be |
| 1599 // aggressive about lazy compilation, because it might trigger compilation | 1596 // aggressive about lazy compilation, because it might trigger compilation |
| 1600 // of functions without an outer context when setting a breakpoint through | 1597 // of functions without an outer context when setting a breakpoint through |
| 1601 // Debug::FindSharedFunctionInfoInScript. | 1598 // Debug::FindSharedFunctionInfoInScript. |
| 1602 bool allow_lazy = literal->AllowsLazyCompilation() && !info.is_debug(); | 1599 bool allow_lazy = literal->AllowsLazyCompilation() && !info.is_debug(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1625 // Update the shared function info with the scope info. | 1622 // Update the shared function info with the scope info. |
| 1626 InstallSharedScopeInfo(&info, result); | 1623 InstallSharedScopeInfo(&info, result); |
| 1627 // Install compilation result on the shared function info. | 1624 // Install compilation result on the shared function info. |
| 1628 InstallSharedCompilationResult(&info, result); | 1625 InstallSharedCompilationResult(&info, result); |
| 1629 } else { | 1626 } else { |
| 1630 return Handle<SharedFunctionInfo>::null(); | 1627 return Handle<SharedFunctionInfo>::null(); |
| 1631 } | 1628 } |
| 1632 | 1629 |
| 1633 if (maybe_existing.is_null()) { | 1630 if (maybe_existing.is_null()) { |
| 1634 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info); | 1631 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info); |
| 1635 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); | |
| 1636 } | 1632 } |
| 1637 | 1633 |
| 1638 return result; | 1634 return result; |
| 1639 } | 1635 } |
| 1640 | 1636 |
| 1641 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( | 1637 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( |
| 1642 v8::Extension* extension, Handle<String> name) { | 1638 v8::Extension* extension, Handle<String> name) { |
| 1643 Isolate* isolate = name->GetIsolate(); | 1639 Isolate* isolate = name->GetIsolate(); |
| 1644 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 1640 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
| 1645 | 1641 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1760 MaybeHandle<Code> code; | 1756 MaybeHandle<Code> code; |
| 1761 if (cached.code != nullptr) code = handle(cached.code); | 1757 if (cached.code != nullptr) code = handle(cached.code); |
| 1762 Handle<Context> native_context(function->context()->native_context()); | 1758 Handle<Context> native_context(function->context()->native_context()); |
| 1763 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1759 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
| 1764 literals, BailoutId::None()); | 1760 literals, BailoutId::None()); |
| 1765 } | 1761 } |
| 1766 } | 1762 } |
| 1767 | 1763 |
| 1768 } // namespace internal | 1764 } // namespace internal |
| 1769 } // namespace v8 | 1765 } // namespace v8 |
| OLD | NEW |