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 701 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 if (info->is_osr() && !ignition_osr) return MaybeHandle<Code>(); | 712 if (info->is_osr() && !ignition_osr) return MaybeHandle<Code>(); |
713 if (!Compiler::EnsureBytecode(info)) { | 713 if (!Compiler::EnsureBytecode(info)) { |
714 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); | 714 if (isolate->has_pending_exception()) isolate->clear_pending_exception(); |
715 return MaybeHandle<Code>(); | 715 return MaybeHandle<Code>(); |
716 } | 716 } |
717 info->MarkAsOptimizeFromBytecode(); | 717 info->MarkAsOptimizeFromBytecode(); |
718 } | 718 } |
719 | 719 |
720 if (IsEvalToplevel(shared)) { | 720 if (IsEvalToplevel(shared)) { |
721 parse_info->set_eval(); | 721 parse_info->set_eval(); |
722 if (function->context()->IsNativeContext()) parse_info->set_global(); | |
723 parse_info->set_toplevel(); | 722 parse_info->set_toplevel(); |
724 parse_info->set_allow_lazy_parsing(false); | 723 parse_info->set_allow_lazy_parsing(false); |
725 parse_info->set_lazy(false); | 724 parse_info->set_lazy(false); |
726 } | 725 } |
727 | 726 |
728 // Verify that OSR compilations are delegated to the correct graph builder. | 727 // Verify that OSR compilations are delegated to the correct graph builder. |
729 // Depending on the underlying frame the semantics of the {BailoutId} differ | 728 // Depending on the underlying frame the semantics of the {BailoutId} differ |
730 // and the various graph builders hard-code a certain semantic: | 729 // and the various graph builders hard-code a certain semantic: |
731 // - Interpreter : The BailoutId represents a bytecode offset. | 730 // - Interpreter : The BailoutId represents a bytecode offset. |
732 // - FullCodegen : The BailoutId represents the id of an AST node. | 731 // - FullCodegen : The BailoutId represents the id of an AST node. |
(...skipping 319 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1052 DCHECK(!isolate->native_context().is_null()); | 1051 DCHECK(!isolate->native_context().is_null()); |
1053 ParseInfo* parse_info = info->parse_info(); | 1052 ParseInfo* parse_info = info->parse_info(); |
1054 Handle<Script> script = parse_info->script(); | 1053 Handle<Script> script = parse_info->script(); |
1055 | 1054 |
1056 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? | 1055 // TODO(svenpanne) Obscure place for this, perhaps move to OnBeforeCompile? |
1057 FixedArray* array = isolate->native_context()->embedder_data(); | 1056 FixedArray* array = isolate->native_context()->embedder_data(); |
1058 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); | 1057 script->set_context_data(array->get(v8::Context::kDebugIdIndex)); |
1059 | 1058 |
1060 isolate->debug()->OnBeforeCompile(script); | 1059 isolate->debug()->OnBeforeCompile(script); |
1061 | 1060 |
1062 DCHECK(parse_info->is_eval() || parse_info->is_global() || | |
1063 parse_info->is_module()); | |
1064 | |
1065 parse_info->set_toplevel(); | 1061 parse_info->set_toplevel(); |
1066 | 1062 |
1067 Handle<SharedFunctionInfo> result; | 1063 Handle<SharedFunctionInfo> result; |
1068 | 1064 |
1069 { VMState<COMPILER> state(info->isolate()); | 1065 { VMState<COMPILER> state(info->isolate()); |
1070 if (parse_info->literal() == NULL) { | 1066 if (parse_info->literal() == NULL) { |
1071 // Parse the script if needed (if it's already parsed, literal() is | 1067 // Parse the script if needed (if it's already parsed, literal() is |
1072 // non-NULL). If compiling for debugging, we may eagerly compile inner | 1068 // non-NULL). If compiling for debugging, we may eagerly compile inner |
1073 // functions, so do not parse lazily in that case. | 1069 // functions, so do not parse lazily in that case. |
1074 ScriptCompiler::CompileOptions options = parse_info->compile_options(); | 1070 ScriptCompiler::CompileOptions options = parse_info->compile_options(); |
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1269 bool Compiler::CompileDebugCode(Handle<JSFunction> function) { | 1265 bool Compiler::CompileDebugCode(Handle<JSFunction> function) { |
1270 Isolate* isolate = function->GetIsolate(); | 1266 Isolate* isolate = function->GetIsolate(); |
1271 DCHECK(AllowCompilation::IsAllowed(isolate)); | 1267 DCHECK(AllowCompilation::IsAllowed(isolate)); |
1272 | 1268 |
1273 // Start a compilation. | 1269 // Start a compilation. |
1274 Zone zone(isolate->allocator()); | 1270 Zone zone(isolate->allocator()); |
1275 ParseInfo parse_info(&zone, function); | 1271 ParseInfo parse_info(&zone, function); |
1276 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1272 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1277 if (IsEvalToplevel(handle(function->shared()))) { | 1273 if (IsEvalToplevel(handle(function->shared()))) { |
1278 parse_info.set_eval(); | 1274 parse_info.set_eval(); |
1279 if (function->context()->IsNativeContext()) parse_info.set_global(); | |
1280 parse_info.set_toplevel(); | 1275 parse_info.set_toplevel(); |
1281 parse_info.set_allow_lazy_parsing(false); | 1276 parse_info.set_allow_lazy_parsing(false); |
1282 parse_info.set_lazy(false); | 1277 parse_info.set_lazy(false); |
1283 } | 1278 } |
1284 info.MarkAsDebug(); | 1279 info.MarkAsDebug(); |
1285 if (GetUnoptimizedCode(&info).is_null()) { | 1280 if (GetUnoptimizedCode(&info).is_null()) { |
1286 isolate->clear_pending_exception(); | 1281 isolate->clear_pending_exception(); |
1287 return false; | 1282 return false; |
1288 } | 1283 } |
1289 | 1284 |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1324 // In order to ensure that live edit function info collection finds the newly | 1319 // In order to ensure that live edit function info collection finds the newly |
1325 // generated shared function infos, clear the script's list temporarily | 1320 // generated shared function infos, clear the script's list temporarily |
1326 // and restore it at the end of this method. | 1321 // and restore it at the end of this method. |
1327 Handle<Object> old_function_infos(script->shared_function_infos(), isolate); | 1322 Handle<Object> old_function_infos(script->shared_function_infos(), isolate); |
1328 script->set_shared_function_infos(Smi::FromInt(0)); | 1323 script->set_shared_function_infos(Smi::FromInt(0)); |
1329 | 1324 |
1330 // Start a compilation. | 1325 // Start a compilation. |
1331 Zone zone(isolate->allocator()); | 1326 Zone zone(isolate->allocator()); |
1332 ParseInfo parse_info(&zone, script); | 1327 ParseInfo parse_info(&zone, script); |
1333 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1328 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1334 parse_info.set_global(); | |
1335 info.MarkAsDebug(); | 1329 info.MarkAsDebug(); |
1336 | 1330 |
1337 // TODO(635): support extensions. | 1331 // TODO(635): support extensions. |
1338 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); | 1332 const bool compilation_succeeded = !CompileToplevel(&info).is_null(); |
1339 Handle<JSArray> infos; | 1333 Handle<JSArray> infos; |
1340 if (compilation_succeeded) { | 1334 if (compilation_succeeded) { |
1341 // Check postconditions on success. | 1335 // Check postconditions on success. |
1342 DCHECK(!isolate->has_pending_exception()); | 1336 DCHECK(!isolate->has_pending_exception()); |
1343 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script, | 1337 infos = LiveEditFunctionTracker::Collect(parse_info.literal(), script, |
1344 &zone, isolate); | 1338 &zone, isolate); |
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1474 script->set_column_offset(column_offset); | 1468 script->set_column_offset(column_offset); |
1475 } | 1469 } |
1476 script->set_origin_options(options); | 1470 script->set_origin_options(options); |
1477 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); | 1471 script->set_compilation_type(Script::COMPILATION_TYPE_EVAL); |
1478 Script::SetEvalOrigin(script, outer_info, eval_position); | 1472 Script::SetEvalOrigin(script, outer_info, eval_position); |
1479 | 1473 |
1480 Zone zone(isolate->allocator()); | 1474 Zone zone(isolate->allocator()); |
1481 ParseInfo parse_info(&zone, script); | 1475 ParseInfo parse_info(&zone, script); |
1482 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1476 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1483 parse_info.set_eval(); | 1477 parse_info.set_eval(); |
1484 if (context->IsNativeContext()) parse_info.set_global(); | |
1485 parse_info.set_language_mode(language_mode); | 1478 parse_info.set_language_mode(language_mode); |
1486 parse_info.set_parse_restriction(restriction); | 1479 parse_info.set_parse_restriction(restriction); |
1487 if (!context->IsNativeContext()) { | 1480 if (!context->IsNativeContext()) { |
1488 parse_info.set_outer_scope_info(handle(context->scope_info())); | 1481 parse_info.set_outer_scope_info(handle(context->scope_info())); |
1489 } | 1482 } |
1490 | 1483 |
1491 shared_info = CompileToplevel(&info); | 1484 shared_info = CompileToplevel(&info); |
1492 | 1485 |
1493 if (shared_info.is_null()) { | 1486 if (shared_info.is_null()) { |
1494 return MaybeHandle<JSFunction>(); | 1487 return MaybeHandle<JSFunction>(); |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1642 } | 1635 } |
1643 script->set_origin_options(resource_options); | 1636 script->set_origin_options(resource_options); |
1644 if (!source_map_url.is_null()) { | 1637 if (!source_map_url.is_null()) { |
1645 script->set_source_mapping_url(*source_map_url); | 1638 script->set_source_mapping_url(*source_map_url); |
1646 } | 1639 } |
1647 | 1640 |
1648 // Compile the function and add it to the cache. | 1641 // Compile the function and add it to the cache. |
1649 Zone zone(isolate->allocator()); | 1642 Zone zone(isolate->allocator()); |
1650 ParseInfo parse_info(&zone, script); | 1643 ParseInfo parse_info(&zone, script); |
1651 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1644 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
1652 if (is_module) { | 1645 if (is_module) parse_info.set_module(); |
1653 parse_info.set_module(); | |
1654 } else { | |
1655 parse_info.set_global(); | |
1656 } | |
1657 if (compile_options != ScriptCompiler::kNoCompileOptions) { | 1646 if (compile_options != ScriptCompiler::kNoCompileOptions) { |
1658 parse_info.set_cached_data(cached_data); | 1647 parse_info.set_cached_data(cached_data); |
1659 } | 1648 } |
1660 parse_info.set_compile_options(compile_options); | 1649 parse_info.set_compile_options(compile_options); |
1661 parse_info.set_extension(extension); | 1650 parse_info.set_extension(extension); |
1662 if (!context->IsNativeContext()) { | 1651 if (!context->IsNativeContext()) { |
1663 parse_info.set_outer_scope_info(handle(context->scope_info())); | 1652 parse_info.set_outer_scope_info(handle(context->scope_info())); |
1664 } | 1653 } |
1665 if (FLAG_serialize_toplevel && | 1654 if (FLAG_serialize_toplevel && |
1666 compile_options == ScriptCompiler::kProduceCodeCache) { | 1655 compile_options == ScriptCompiler::kProduceCodeCache) { |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1913 DCHECK(shared->is_compiled()); | 1902 DCHECK(shared->is_compiled()); |
1914 function->set_literals(cached.literals); | 1903 function->set_literals(cached.literals); |
1915 } else if (shared->is_compiled()) { | 1904 } else if (shared->is_compiled()) { |
1916 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1905 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
1917 JSFunction::EnsureLiterals(function); | 1906 JSFunction::EnsureLiterals(function); |
1918 } | 1907 } |
1919 } | 1908 } |
1920 | 1909 |
1921 } // namespace internal | 1910 } // namespace internal |
1922 } // namespace v8 | 1911 } // namespace v8 |
OLD | NEW |