| 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/asmjs/asm-js.h" | 9 #include "src/asmjs/asm-js.h" |
| 10 #include "src/asmjs/typing-asm.h" | 10 #include "src/asmjs/typing-asm.h" |
| (...skipping 1470 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1481 LanguageMode language_mode = construct_language_mode(FLAG_use_strict); | 1481 LanguageMode language_mode = construct_language_mode(FLAG_use_strict); |
| 1482 CompilationCache* compilation_cache = isolate->compilation_cache(); | 1482 CompilationCache* compilation_cache = isolate->compilation_cache(); |
| 1483 | 1483 |
| 1484 // Do a lookup in the compilation cache but not for extensions. | 1484 // Do a lookup in the compilation cache but not for extensions. |
| 1485 MaybeHandle<SharedFunctionInfo> maybe_result; | 1485 MaybeHandle<SharedFunctionInfo> maybe_result; |
| 1486 Handle<SharedFunctionInfo> result; | 1486 Handle<SharedFunctionInfo> result; |
| 1487 if (extension == NULL) { | 1487 if (extension == NULL) { |
| 1488 // First check per-isolate compilation cache. | 1488 // First check per-isolate compilation cache. |
| 1489 maybe_result = compilation_cache->LookupScript( | 1489 maybe_result = compilation_cache->LookupScript( |
| 1490 source, script_name, line_offset, column_offset, resource_options, | 1490 source, script_name, line_offset, column_offset, resource_options, |
| 1491 context, language_mode); | 1491 context, language_mode, is_module); |
| 1492 if (maybe_result.is_null() && FLAG_serialize_toplevel && | 1492 if (maybe_result.is_null() && FLAG_serialize_toplevel && |
| 1493 compile_options == ScriptCompiler::kConsumeCodeCache && | 1493 compile_options == ScriptCompiler::kConsumeCodeCache && |
| 1494 !isolate->debug()->is_loaded()) { | 1494 !isolate->debug()->is_loaded()) { |
| 1495 // Then check cached code provided by embedder. | 1495 // Then check cached code provided by embedder. |
| 1496 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); | 1496 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); |
| 1497 RuntimeCallTimerScope runtimeTimer(isolate, | 1497 RuntimeCallTimerScope runtimeTimer(isolate, |
| 1498 &RuntimeCallStats::CompileDeserialize); | 1498 &RuntimeCallStats::CompileDeserialize); |
| 1499 TRACE_EVENT0("v8", "V8.CompileDeserialize"); | 1499 TRACE_EVENT0("v8", "V8.CompileDeserialize"); |
| 1500 Handle<SharedFunctionInfo> result; | 1500 Handle<SharedFunctionInfo> result; |
| 1501 if (CodeSerializer::Deserialize(isolate, *cached_data, source) | 1501 if (CodeSerializer::Deserialize(isolate, *cached_data, source) |
| 1502 .ToHandle(&result)) { | 1502 .ToHandle(&result)) { |
| 1503 // Promote to per-isolate compilation cache. | 1503 // Promote to per-isolate compilation cache. |
| 1504 compilation_cache->PutScript(source, context, language_mode, result); | 1504 compilation_cache->PutScript(source, context, language_mode, is_module, |
| 1505 result); |
| 1505 return result; | 1506 return result; |
| 1506 } | 1507 } |
| 1507 // Deserializer failed. Fall through to compile. | 1508 // Deserializer failed. Fall through to compile. |
| 1508 } | 1509 } |
| 1509 } | 1510 } |
| 1510 | 1511 |
| 1511 base::ElapsedTimer timer; | 1512 base::ElapsedTimer timer; |
| 1512 if (FLAG_profile_deserialization && FLAG_serialize_toplevel && | 1513 if (FLAG_profile_deserialization && FLAG_serialize_toplevel && |
| 1513 compile_options == ScriptCompiler::kProduceCodeCache) { | 1514 compile_options == ScriptCompiler::kProduceCodeCache) { |
| 1514 timer.Start(); | 1515 timer.Start(); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1530 } | 1531 } |
| 1531 if (!script_name.is_null()) { | 1532 if (!script_name.is_null()) { |
| 1532 script->set_name(*script_name); | 1533 script->set_name(*script_name); |
| 1533 script->set_line_offset(line_offset); | 1534 script->set_line_offset(line_offset); |
| 1534 script->set_column_offset(column_offset); | 1535 script->set_column_offset(column_offset); |
| 1535 } | 1536 } |
| 1536 script->set_origin_options(resource_options); | 1537 script->set_origin_options(resource_options); |
| 1537 if (!source_map_url.is_null()) { | 1538 if (!source_map_url.is_null()) { |
| 1538 script->set_source_mapping_url(*source_map_url); | 1539 script->set_source_mapping_url(*source_map_url); |
| 1539 } | 1540 } |
| 1541 script->set_is_module(is_module); |
| 1540 | 1542 |
| 1541 // Compile the function and add it to the cache. | 1543 // Compile the function and add it to the cache. |
| 1542 Zone zone(isolate->allocator()); | 1544 Zone zone(isolate->allocator()); |
| 1543 ParseInfo parse_info(&zone, script); | 1545 ParseInfo parse_info(&zone, script); |
| 1544 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); | 1546 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); |
| 1545 if (is_module) { | 1547 if (is_module) { |
| 1546 parse_info.set_module(); | 1548 // The ParseInfo constructor unconditionally sets the `is_module` bit |
| 1549 // when its script is module code. |
| 1550 DCHECK(parse_info.is_module()); |
| 1547 } else { | 1551 } else { |
| 1552 // In the current context of script compilation, the input cannot be eval |
| 1553 // code, so the input must be global code. |
| 1548 parse_info.set_global(); | 1554 parse_info.set_global(); |
| 1549 } | 1555 } |
| 1550 if (compile_options != ScriptCompiler::kNoCompileOptions) { | 1556 if (compile_options != ScriptCompiler::kNoCompileOptions) { |
| 1551 parse_info.set_cached_data(cached_data); | 1557 parse_info.set_cached_data(cached_data); |
| 1552 } | 1558 } |
| 1553 parse_info.set_compile_options(compile_options); | 1559 parse_info.set_compile_options(compile_options); |
| 1554 parse_info.set_extension(extension); | 1560 parse_info.set_extension(extension); |
| 1555 parse_info.set_context(context); | 1561 parse_info.set_context(context); |
| 1556 if (FLAG_serialize_toplevel && | 1562 if (FLAG_serialize_toplevel && |
| 1557 compile_options == ScriptCompiler::kProduceCodeCache) { | 1563 compile_options == ScriptCompiler::kProduceCodeCache) { |
| 1558 info.PrepareForSerializing(); | 1564 info.PrepareForSerializing(); |
| 1559 } | 1565 } |
| 1560 | 1566 |
| 1561 parse_info.set_language_mode( | 1567 parse_info.set_language_mode( |
| 1562 static_cast<LanguageMode>(parse_info.language_mode() | language_mode)); | 1568 static_cast<LanguageMode>(parse_info.language_mode() | language_mode)); |
| 1563 result = CompileToplevel(&info); | 1569 result = CompileToplevel(&info); |
| 1564 if (extension == NULL && !result.is_null()) { | 1570 if (extension == NULL && !result.is_null()) { |
| 1565 compilation_cache->PutScript(source, context, language_mode, result); | 1571 compilation_cache->PutScript(source, context, language_mode, is_module, |
| 1572 result); |
| 1566 if (FLAG_serialize_toplevel && | 1573 if (FLAG_serialize_toplevel && |
| 1567 compile_options == ScriptCompiler::kProduceCodeCache) { | 1574 compile_options == ScriptCompiler::kProduceCodeCache) { |
| 1568 HistogramTimerScope histogram_timer( | 1575 HistogramTimerScope histogram_timer( |
| 1569 isolate->counters()->compile_serialize()); | 1576 isolate->counters()->compile_serialize()); |
| 1570 RuntimeCallTimerScope runtimeTimer(isolate, | 1577 RuntimeCallTimerScope runtimeTimer(isolate, |
| 1571 &RuntimeCallStats::CompileSerialize); | 1578 &RuntimeCallStats::CompileSerialize); |
| 1572 TRACE_EVENT0("v8", "V8.CompileSerialize"); | 1579 TRACE_EVENT0("v8", "V8.CompileSerialize"); |
| 1573 *cached_data = CodeSerializer::Serialize(isolate, result, source); | 1580 *cached_data = CodeSerializer::Serialize(isolate, result, source); |
| 1574 if (FLAG_profile_deserialization) { | 1581 if (FLAG_profile_deserialization) { |
| 1575 PrintF("[Compiling and serializing took %0.3f ms]\n", | 1582 PrintF("[Compiling and serializing took %0.3f ms]\n", |
| (...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1825 DCHECK(shared->is_compiled()); | 1832 DCHECK(shared->is_compiled()); |
| 1826 function->set_literals(cached.literals); | 1833 function->set_literals(cached.literals); |
| 1827 } else if (shared->is_compiled()) { | 1834 } else if (shared->is_compiled()) { |
| 1828 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. | 1835 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. |
| 1829 JSFunction::EnsureLiterals(function); | 1836 JSFunction::EnsureLiterals(function); |
| 1830 } | 1837 } |
| 1831 } | 1838 } |
| 1832 | 1839 |
| 1833 } // namespace internal | 1840 } // namespace internal |
| 1834 } // namespace v8 | 1841 } // namespace v8 |
| OLD | NEW |