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 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 return false; | 1228 return false; |
1232 } | 1229 } |
1233 | 1230 |
1234 // Check postconditions on success. | 1231 // Check postconditions on success. |
1235 DCHECK(!isolate->has_pending_exception()); | 1232 DCHECK(!isolate->has_pending_exception()); |
1236 DCHECK(shared->is_compiled()); | 1233 DCHECK(shared->is_compiled()); |
1237 DCHECK(shared->HasDebugCode()); | 1234 DCHECK(shared->HasDebugCode()); |
1238 return true; | 1235 return true; |
1239 } | 1236 } |
1240 | 1237 |
1241 bool Compiler::CompileForLiveEdit(Handle<Script> script) { | 1238 MaybeHandle<JSArray> Compiler::CompileForLiveEdit(Handle<Script> script) { |
1242 Isolate* isolate = script->GetIsolate(); | 1239 Isolate* isolate = script->GetIsolate(); |
1243 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1240 DCHECK(AllowCompilation::IsAllowed(isolate)); |
1244 | 1241 |
1245 // In order to ensure that live edit function info collection finds the newly | 1242 // In order to ensure that live edit function info collection finds the newly |
1246 // generated shared function infos, clear the script's list temporarily | 1243 // generated shared function infos, clear the script's list temporarily |
1247 // and restore it at the end of this method. | 1244 // and restore it at the end of this method. |
1248 Handle<Object> old_function_infos(script->shared_function_infos(), isolate); | 1245 Handle<Object> old_function_infos(script->shared_function_infos(), isolate); |
1249 script->set_shared_function_infos(Smi::FromInt(0)); | 1246 script->set_shared_function_infos(Smi::FromInt(0)); |
1250 | 1247 |
1251 // Start a compilation. | 1248 // Start a compilation. |
1252 Zone zone(isolate->allocator()); | 1249 Zone zone(isolate->allocator()); |
1253 ParseInfo parse_info(&zone, script); | 1250 ParseInfo parse_info(&zone, script); |
1254 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1251 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1255 parse_info.set_global(); | 1252 parse_info.set_global(); |
1256 info.MarkAsDebug(); | 1253 info.MarkAsDebug(); |
| 1254 |
1257 // TODO(635): support extensions. | 1255 // TODO(635): support extensions. |
1258 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); | 1256 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); |
| 1257 Handle<JSArray> infos; |
| 1258 if (compilation_succeeded) { |
| 1259 // Check postconditions on success. |
| 1260 DCHECK(!isolate->has_pending_exception()); |
| 1261 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script, |
| 1262 &zone, isolate); |
| 1263 } |
1259 | 1264 |
1260 // Restore the original function info list in order to remain side-effect | 1265 // Restore the original function info list in order to remain side-effect |
1261 // free as much as possible, since some code expects the old shared function | 1266 // free as much as possible, since some code expects the old shared function |
1262 // infos to stick around. | 1267 // infos to stick around. |
1263 script->set_shared_function_infos(*old_function_infos); | 1268 script->set_shared_function_infos(*old_function_infos); |
1264 | 1269 |
1265 if (!compilation_succeeded) { | 1270 return infos; |
1266 return false; | |
1267 } | |
1268 | |
1269 // Check postconditions on success. | |
1270 DCHECK(!isolate->has_pending_exception()); | |
1271 | |
1272 return compilation_succeeded; | |
1273 } | 1271 } |
1274 | 1272 |
1275 // TODO(turbofan): In the future, unoptimized code with deopt support could | 1273 // TODO(turbofan): In the future, unoptimized code with deopt support could |
1276 // be generated lazily once deopt is triggered. | 1274 // be generated lazily once deopt is triggered. |
1277 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { | 1275 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { |
1278 DCHECK_NOT_NULL(info->literal()); | 1276 DCHECK_NOT_NULL(info->literal()); |
1279 DCHECK_NOT_NULL(info->scope()); | 1277 DCHECK_NOT_NULL(info->scope()); |
1280 Handle<SharedFunctionInfo> shared = info->shared_info(); | 1278 Handle<SharedFunctionInfo> shared = info->shared_info(); |
1281 if (!shared->has_deoptimization_support()) { | 1279 if (!shared->has_deoptimization_support()) { |
1282 Zone zone(info->isolate()->allocator()); | 1280 Zone zone(info->isolate()->allocator()); |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1591 Zone zone(isolate->allocator()); | 1589 Zone zone(isolate->allocator()); |
1592 ParseInfo parse_info(&zone, script); | 1590 ParseInfo parse_info(&zone, script); |
1593 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1591 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1594 parse_info.set_literal(literal); | 1592 parse_info.set_literal(literal); |
1595 parse_info.set_shared_info(result); | 1593 parse_info.set_shared_info(result); |
1596 parse_info.set_scope(literal->scope()); | 1594 parse_info.set_scope(literal->scope()); |
1597 parse_info.set_language_mode(literal->scope()->language_mode()); | 1595 parse_info.set_language_mode(literal->scope()->language_mode()); |
1598 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1596 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
1599 if (outer_info->is_debug()) info.MarkAsDebug(); | 1597 if (outer_info->is_debug()) info.MarkAsDebug(); |
1600 | 1598 |
1601 LiveEditFunctionTracker live_edit_tracker(isolate, literal); | |
1602 // Determine if the function can be lazily compiled. This is necessary to | 1599 // Determine if the function can be lazily compiled. This is necessary to |
1603 // allow some of our builtin JS files to be lazily compiled. These | 1600 // allow some of our builtin JS files to be lazily compiled. These |
1604 // builtins cannot be handled lazily by the parser, since we have to know | 1601 // builtins cannot be handled lazily by the parser, since we have to know |
1605 // if a function uses the special natives syntax, which is something the | 1602 // if a function uses the special natives syntax, which is something the |
1606 // parser records. | 1603 // parser records. |
1607 // If the debugger requests compilation for break points, we cannot be | 1604 // If the debugger requests compilation for break points, we cannot be |
1608 // aggressive about lazy compilation, because it might trigger compilation | 1605 // aggressive about lazy compilation, because it might trigger compilation |
1609 // of functions without an outer context when setting a breakpoint through | 1606 // of functions without an outer context when setting a breakpoint through |
1610 // Debug::FindSharedFunctionInfoInScript. | 1607 // Debug::FindSharedFunctionInfoInScript. |
1611 bool allow_lazy = literal->AllowsLazyCompilation() && !info.is_debug(); | 1608 bool allow_lazy = literal->AllowsLazyCompilation() && !info.is_debug(); |
(...skipping 22 matching lines...) Expand all Loading... |
1634 // Update the shared function info with the scope info. | 1631 // Update the shared function info with the scope info. |
1635 InstallSharedScopeInfo(&info, result); | 1632 InstallSharedScopeInfo(&info, result); |
1636 // Install compilation result on the shared function info. | 1633 // Install compilation result on the shared function info. |
1637 InstallSharedCompilationResult(&info, result); | 1634 InstallSharedCompilationResult(&info, result); |
1638 } else { | 1635 } else { |
1639 return Handle<SharedFunctionInfo>::null(); | 1636 return Handle<SharedFunctionInfo>::null(); |
1640 } | 1637 } |
1641 | 1638 |
1642 if (maybe_existing.is_null()) { | 1639 if (maybe_existing.is_null()) { |
1643 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info); | 1640 RecordFunctionCompilation(Logger::FUNCTION_TAG, &info); |
1644 live_edit_tracker.RecordFunctionInfo(result, literal, info.zone()); | |
1645 } | 1641 } |
1646 | 1642 |
1647 return result; | 1643 return result; |
1648 } | 1644 } |
1649 | 1645 |
1650 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( | 1646 Handle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForNative( |
1651 v8::Extension* extension, Handle<String> name) { | 1647 v8::Extension* extension, Handle<String> name) { |
1652 Isolate* isolate = name->GetIsolate(); | 1648 Isolate* isolate = name->GetIsolate(); |
1653 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); | 1649 v8::Isolate* v8_isolate = reinterpret_cast<v8::Isolate*>(isolate); |
1654 | 1650 |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1769 MaybeHandle<Code> code; | 1765 MaybeHandle<Code> code; |
1770 if (cached.code != nullptr) code = handle(cached.code); | 1766 if (cached.code != nullptr) code = handle(cached.code); |
1771 Handle<Context> native_context(function->context()->native_context()); | 1767 Handle<Context> native_context(function->context()->native_context()); |
1772 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1768 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
1773 literals, BailoutId::None()); | 1769 literals, BailoutId::None()); |
1774 } | 1770 } |
1775 } | 1771 } |
1776 | 1772 |
1777 } // namespace internal | 1773 } // namespace internal |
1778 } // namespace v8 | 1774 } // namespace v8 |
OLD | NEW |