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 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
78 private: | 78 private: |
79 DeferredHandleScope deferred_; | 79 DeferredHandleScope deferred_; |
80 CompilationInfo* info_; | 80 CompilationInfo* info_; |
81 }; | 81 }; |
82 | 82 |
83 // Exactly like a CompilationInfo, except being allocated via {new} and it also | 83 // Exactly like a CompilationInfo, except being allocated via {new} and it also |
84 // creates and enters a Zone on construction and deallocates it on destruction. | 84 // creates and enters a Zone on construction and deallocates it on destruction. |
85 class CompilationInfoWithZone : public CompilationInfo { | 85 class CompilationInfoWithZone : public CompilationInfo { |
86 public: | 86 public: |
87 explicit CompilationInfoWithZone(Handle<JSFunction> function) | 87 explicit CompilationInfoWithZone(Handle<JSFunction> function) |
88 : CompilationInfo(new ParseInfo(&zone_, function)) {} | 88 : CompilationInfo(new ParseInfo(&zone_, function)), |
| 89 zone_(function->GetIsolate()->allocator()) {} |
89 | 90 |
90 // Virtual destructor because a CompilationInfoWithZone has to exit the | 91 // Virtual destructor because a CompilationInfoWithZone has to exit the |
91 // zone scope and get rid of dependent maps even when the destructor is | 92 // zone scope and get rid of dependent maps even when the destructor is |
92 // called when cast as a CompilationInfo. | 93 // called when cast as a CompilationInfo. |
93 virtual ~CompilationInfoWithZone() { | 94 virtual ~CompilationInfoWithZone() { |
94 DisableFutureOptimization(); | 95 DisableFutureOptimization(); |
95 dependencies()->Rollback(); | 96 dependencies()->Rollback(); |
96 delete parse_info_; | 97 delete parse_info_; |
97 parse_info_ = nullptr; | 98 parse_info_ = nullptr; |
98 } | 99 } |
(...skipping 1069 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1168 | 1169 |
1169 return result; | 1170 return result; |
1170 } | 1171 } |
1171 | 1172 |
1172 | 1173 |
1173 bool CompileEvalForDebugging(Handle<JSFunction> function, | 1174 bool CompileEvalForDebugging(Handle<JSFunction> function, |
1174 Handle<SharedFunctionInfo> shared) { | 1175 Handle<SharedFunctionInfo> shared) { |
1175 Handle<Script> script(Script::cast(shared->script())); | 1176 Handle<Script> script(Script::cast(shared->script())); |
1176 Handle<Context> context(function->context()); | 1177 Handle<Context> context(function->context()); |
1177 | 1178 |
1178 Zone zone; | 1179 Zone zone(function->GetIsolate()->allocator()); |
1179 ParseInfo parse_info(&zone, script); | 1180 ParseInfo parse_info(&zone, script); |
1180 CompilationInfo info(&parse_info); | 1181 CompilationInfo info(&parse_info); |
1181 Isolate* isolate = info.isolate(); | 1182 Isolate* isolate = info.isolate(); |
1182 | 1183 |
1183 parse_info.set_eval(); | 1184 parse_info.set_eval(); |
1184 parse_info.set_context(context); | 1185 parse_info.set_context(context); |
1185 if (context->IsNativeContext()) parse_info.set_global(); | 1186 if (context->IsNativeContext()) parse_info.set_global(); |
1186 parse_info.set_toplevel(); | 1187 parse_info.set_toplevel(); |
1187 parse_info.set_allow_lazy_parsing(false); | 1188 parse_info.set_allow_lazy_parsing(false); |
1188 parse_info.set_language_mode(shared->language_mode()); | 1189 parse_info.set_language_mode(shared->language_mode()); |
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1423 return CompileEvalForDebugging(function, shared); | 1424 return CompileEvalForDebugging(function, shared); |
1424 } else { | 1425 } else { |
1425 CompilationInfoWithZone info(function); | 1426 CompilationInfoWithZone info(function); |
1426 return CompileForDebugging(&info); | 1427 return CompileForDebugging(&info); |
1427 } | 1428 } |
1428 } | 1429 } |
1429 | 1430 |
1430 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { | 1431 bool Compiler::CompileDebugCode(Handle<SharedFunctionInfo> shared) { |
1431 DCHECK(shared->allows_lazy_compilation_without_context()); | 1432 DCHECK(shared->allows_lazy_compilation_without_context()); |
1432 DCHECK(!IsEvalToplevel(shared)); | 1433 DCHECK(!IsEvalToplevel(shared)); |
1433 Zone zone; | 1434 Zone zone(shared->GetIsolate()->allocator()); |
1434 ParseInfo parse_info(&zone, shared); | 1435 ParseInfo parse_info(&zone, shared); |
1435 CompilationInfo info(&parse_info); | 1436 CompilationInfo info(&parse_info); |
1436 return CompileForDebugging(&info); | 1437 return CompileForDebugging(&info); |
1437 } | 1438 } |
1438 | 1439 |
1439 // TODO(turbofan): In the future, unoptimized code with deopt support could | 1440 // TODO(turbofan): In the future, unoptimized code with deopt support could |
1440 // be generated lazily once deopt is triggered. | 1441 // be generated lazily once deopt is triggered. |
1441 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { | 1442 bool Compiler::EnsureDeoptimizationSupport(CompilationInfo* info) { |
1442 DCHECK_NOT_NULL(info->literal()); | 1443 DCHECK_NOT_NULL(info->literal()); |
1443 DCHECK(info->has_scope()); | 1444 DCHECK(info->has_scope()); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1476 } | 1477 } |
1477 | 1478 |
1478 // The existing unoptimized code was replaced with the new one. | 1479 // The existing unoptimized code was replaced with the new one. |
1479 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, &unoptimized, shared); | 1480 RecordFunctionCompilation(Logger::LAZY_COMPILE_TAG, &unoptimized, shared); |
1480 } | 1481 } |
1481 return true; | 1482 return true; |
1482 } | 1483 } |
1483 | 1484 |
1484 void Compiler::CompileForLiveEdit(Handle<Script> script) { | 1485 void Compiler::CompileForLiveEdit(Handle<Script> script) { |
1485 // TODO(635): support extensions. | 1486 // TODO(635): support extensions. |
1486 Zone zone; | 1487 Zone zone(script->GetIsolate()->allocator()); |
1487 ParseInfo parse_info(&zone, script); | 1488 ParseInfo parse_info(&zone, script); |
1488 CompilationInfo info(&parse_info); | 1489 CompilationInfo info(&parse_info); |
1489 PostponeInterruptsScope postpone(info.isolate()); | 1490 PostponeInterruptsScope postpone(info.isolate()); |
1490 VMState<COMPILER> state(info.isolate()); | 1491 VMState<COMPILER> state(info.isolate()); |
1491 | 1492 |
1492 // Get rid of old list of shared function infos. | 1493 // Get rid of old list of shared function infos. |
1493 info.MarkAsFirstCompile(); | 1494 info.MarkAsFirstCompile(); |
1494 info.MarkAsDebug(); | 1495 info.MarkAsDebug(); |
1495 info.parse_info()->set_global(); | 1496 info.parse_info()->set_global(); |
1496 if (!Parser::ParseStatic(info.parse_info())) return; | 1497 if (!Parser::ParseStatic(info.parse_info())) return; |
(...skipping 26 matching lines...) Expand all Loading... |
1523 | 1524 |
1524 Handle<Script> script; | 1525 Handle<Script> script; |
1525 if (!maybe_shared_info.ToHandle(&shared_info)) { | 1526 if (!maybe_shared_info.ToHandle(&shared_info)) { |
1526 script = isolate->factory()->NewScript(source); | 1527 script = isolate->factory()->NewScript(source); |
1527 if (!script_name.is_null()) { | 1528 if (!script_name.is_null()) { |
1528 script->set_name(*script_name); | 1529 script->set_name(*script_name); |
1529 script->set_line_offset(line_offset); | 1530 script->set_line_offset(line_offset); |
1530 script->set_column_offset(column_offset); | 1531 script->set_column_offset(column_offset); |
1531 } | 1532 } |
1532 script->set_origin_options(options); | 1533 script->set_origin_options(options); |
1533 Zone zone; | 1534 Zone zone(isolate->allocator()); |
1534 ParseInfo parse_info(&zone, script); | 1535 ParseInfo parse_info(&zone, script); |
1535 CompilationInfo info(&parse_info); | 1536 CompilationInfo info(&parse_info); |
1536 parse_info.set_eval(); | 1537 parse_info.set_eval(); |
1537 if (context->IsNativeContext()) parse_info.set_global(); | 1538 if (context->IsNativeContext()) parse_info.set_global(); |
1538 parse_info.set_language_mode(language_mode); | 1539 parse_info.set_language_mode(language_mode); |
1539 parse_info.set_parse_restriction(restriction); | 1540 parse_info.set_parse_restriction(restriction); |
1540 parse_info.set_context(context); | 1541 parse_info.set_context(context); |
1541 | 1542 |
1542 Debug::RecordEvalCaller(script); | 1543 Debug::RecordEvalCaller(script); |
1543 | 1544 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1647 script->set_name(*script_name); | 1648 script->set_name(*script_name); |
1648 script->set_line_offset(line_offset); | 1649 script->set_line_offset(line_offset); |
1649 script->set_column_offset(column_offset); | 1650 script->set_column_offset(column_offset); |
1650 } | 1651 } |
1651 script->set_origin_options(resource_options); | 1652 script->set_origin_options(resource_options); |
1652 if (!source_map_url.is_null()) { | 1653 if (!source_map_url.is_null()) { |
1653 script->set_source_mapping_url(*source_map_url); | 1654 script->set_source_mapping_url(*source_map_url); |
1654 } | 1655 } |
1655 | 1656 |
1656 // Compile the function and add it to the cache. | 1657 // Compile the function and add it to the cache. |
1657 Zone zone; | 1658 Zone zone(isolate->allocator()); |
1658 ParseInfo parse_info(&zone, script); | 1659 ParseInfo parse_info(&zone, script); |
1659 CompilationInfo info(&parse_info); | 1660 CompilationInfo info(&parse_info); |
1660 if (is_module) { | 1661 if (is_module) { |
1661 parse_info.set_module(); | 1662 parse_info.set_module(); |
1662 } else { | 1663 } else { |
1663 parse_info.set_global(); | 1664 parse_info.set_global(); |
1664 } | 1665 } |
1665 if (compile_options != ScriptCompiler::kNoCompileOptions) { | 1666 if (compile_options != ScriptCompiler::kNoCompileOptions) { |
1666 parse_info.set_cached_data(cached_data); | 1667 parse_info.set_cached_data(cached_data); |
1667 } | 1668 } |
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1751 } | 1752 } |
1752 } | 1753 } |
1753 | 1754 |
1754 // Allocate a shared function info object. | 1755 // Allocate a shared function info object. |
1755 Handle<SharedFunctionInfo> result; | 1756 Handle<SharedFunctionInfo> result; |
1756 if (!maybe_existing.ToHandle(&result)) { | 1757 if (!maybe_existing.ToHandle(&result)) { |
1757 result = NewSharedFunctionInfoForLiteral(isolate, literal, script); | 1758 result = NewSharedFunctionInfoForLiteral(isolate, literal, script); |
1758 result->set_is_toplevel(false); | 1759 result->set_is_toplevel(false); |
1759 } | 1760 } |
1760 | 1761 |
1761 Zone zone; | 1762 Zone zone(isolate->allocator()); |
1762 ParseInfo parse_info(&zone, script); | 1763 ParseInfo parse_info(&zone, script); |
1763 CompilationInfo info(&parse_info); | 1764 CompilationInfo info(&parse_info); |
1764 parse_info.set_literal(literal); | 1765 parse_info.set_literal(literal); |
1765 parse_info.set_scope(literal->scope()); | 1766 parse_info.set_scope(literal->scope()); |
1766 parse_info.set_language_mode(literal->scope()->language_mode()); | 1767 parse_info.set_language_mode(literal->scope()->language_mode()); |
1767 if (outer_info->will_serialize()) info.PrepareForSerializing(); | 1768 if (outer_info->will_serialize()) info.PrepareForSerializing(); |
1768 if (outer_info->is_first_compile()) info.MarkAsFirstCompile(); | 1769 if (outer_info->is_first_compile()) info.MarkAsFirstCompile(); |
1769 if (outer_info->is_debug()) info.MarkAsDebug(); | 1770 if (outer_info->is_debug()) info.MarkAsDebug(); |
1770 | 1771 |
1771 LiveEditFunctionTracker live_edit_tracker(isolate, literal); | 1772 LiveEditFunctionTracker live_edit_tracker(isolate, literal); |
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1956 MaybeHandle<Code> code; | 1957 MaybeHandle<Code> code; |
1957 if (cached.code != nullptr) code = handle(cached.code); | 1958 if (cached.code != nullptr) code = handle(cached.code); |
1958 Handle<Context> native_context(function->context()->native_context()); | 1959 Handle<Context> native_context(function->context()->native_context()); |
1959 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, | 1960 SharedFunctionInfo::AddToOptimizedCodeMap(shared, native_context, code, |
1960 literals, BailoutId::None()); | 1961 literals, BailoutId::None()); |
1961 } | 1962 } |
1962 } | 1963 } |
1963 | 1964 |
1964 } // namespace internal | 1965 } // namespace internal |
1965 } // namespace v8 | 1966 } // namespace v8 |
OLD | NEW |