Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(878)

Side by Side Diff: src/compiler.cc

Issue 2065453002: [module] Track script "module code" status Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Extend compilation cache to recognize module code Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 1465 matching lines...) Expand 10 before | Expand all | Expand 10 after
1476 LanguageMode language_mode = construct_language_mode(FLAG_use_strict); 1476 LanguageMode language_mode = construct_language_mode(FLAG_use_strict);
1477 CompilationCache* compilation_cache = isolate->compilation_cache(); 1477 CompilationCache* compilation_cache = isolate->compilation_cache();
1478 1478
1479 // Do a lookup in the compilation cache but not for extensions. 1479 // Do a lookup in the compilation cache but not for extensions.
1480 MaybeHandle<SharedFunctionInfo> maybe_result; 1480 MaybeHandle<SharedFunctionInfo> maybe_result;
1481 Handle<SharedFunctionInfo> result; 1481 Handle<SharedFunctionInfo> result;
1482 if (extension == NULL) { 1482 if (extension == NULL) {
1483 // First check per-isolate compilation cache. 1483 // First check per-isolate compilation cache.
1484 maybe_result = compilation_cache->LookupScript( 1484 maybe_result = compilation_cache->LookupScript(
1485 source, script_name, line_offset, column_offset, resource_options, 1485 source, script_name, line_offset, column_offset, resource_options,
1486 context, language_mode); 1486 context, language_mode, is_module);
1487 if (maybe_result.is_null() && FLAG_serialize_toplevel && 1487 if (maybe_result.is_null() && FLAG_serialize_toplevel &&
1488 compile_options == ScriptCompiler::kConsumeCodeCache && 1488 compile_options == ScriptCompiler::kConsumeCodeCache &&
1489 !isolate->debug()->is_loaded()) { 1489 !isolate->debug()->is_loaded()) {
1490 // Then check cached code provided by embedder. 1490 // Then check cached code provided by embedder.
1491 HistogramTimerScope timer(isolate->counters()->compile_deserialize()); 1491 HistogramTimerScope timer(isolate->counters()->compile_deserialize());
1492 RuntimeCallTimerScope runtimeTimer(isolate, 1492 RuntimeCallTimerScope runtimeTimer(isolate,
1493 &RuntimeCallStats::CompileDeserialize); 1493 &RuntimeCallStats::CompileDeserialize);
1494 TRACE_EVENT0("v8", "V8.CompileDeserialize"); 1494 TRACE_EVENT0("v8", "V8.CompileDeserialize");
1495 Handle<SharedFunctionInfo> result; 1495 Handle<SharedFunctionInfo> result;
1496 if (CodeSerializer::Deserialize(isolate, *cached_data, source) 1496 if (CodeSerializer::Deserialize(isolate, *cached_data, source)
1497 .ToHandle(&result)) { 1497 .ToHandle(&result)) {
1498 // Promote to per-isolate compilation cache. 1498 // Promote to per-isolate compilation cache.
1499 compilation_cache->PutScript(source, context, language_mode, result); 1499 compilation_cache->PutScript(source, context, language_mode, is_module,
1500 result);
1500 return result; 1501 return result;
1501 } 1502 }
1502 // Deserializer failed. Fall through to compile. 1503 // Deserializer failed. Fall through to compile.
1503 } 1504 }
1504 } 1505 }
1505 1506
1506 base::ElapsedTimer timer; 1507 base::ElapsedTimer timer;
1507 if (FLAG_profile_deserialization && FLAG_serialize_toplevel && 1508 if (FLAG_profile_deserialization && FLAG_serialize_toplevel &&
1508 compile_options == ScriptCompiler::kProduceCodeCache) { 1509 compile_options == ScriptCompiler::kProduceCodeCache) {
1509 timer.Start(); 1510 timer.Start();
(...skipping 15 matching lines...) Expand all
1525 } 1526 }
1526 if (!script_name.is_null()) { 1527 if (!script_name.is_null()) {
1527 script->set_name(*script_name); 1528 script->set_name(*script_name);
1528 script->set_line_offset(line_offset); 1529 script->set_line_offset(line_offset);
1529 script->set_column_offset(column_offset); 1530 script->set_column_offset(column_offset);
1530 } 1531 }
1531 script->set_origin_options(resource_options); 1532 script->set_origin_options(resource_options);
1532 if (!source_map_url.is_null()) { 1533 if (!source_map_url.is_null()) {
1533 script->set_source_mapping_url(*source_map_url); 1534 script->set_source_mapping_url(*source_map_url);
1534 } 1535 }
1536 script->set_is_module(is_module);
1535 1537
1536 // Compile the function and add it to the cache. 1538 // Compile the function and add it to the cache.
1537 Zone zone(isolate->allocator()); 1539 Zone zone(isolate->allocator());
1538 ParseInfo parse_info(&zone, script); 1540 ParseInfo parse_info(&zone, script);
1539 CompilationInfo info(&parse_info, Handle<JSFunction>::null()); 1541 CompilationInfo info(&parse_info, Handle<JSFunction>::null());
1540 if (is_module) { 1542 if (is_module) {
1541 parse_info.set_module(); 1543 // The ParseInfo constructor unconditionally sets the `is_module` bit
1544 // when its script is module code.
1545 DCHECK(parse_info.is_module());
1542 } else { 1546 } else {
1547 // In the current context of script compilation, the input cannot be eval
1548 // code, so the input must be global code.
1543 parse_info.set_global(); 1549 parse_info.set_global();
1544 } 1550 }
1545 if (compile_options != ScriptCompiler::kNoCompileOptions) { 1551 if (compile_options != ScriptCompiler::kNoCompileOptions) {
1546 parse_info.set_cached_data(cached_data); 1552 parse_info.set_cached_data(cached_data);
1547 } 1553 }
1548 parse_info.set_compile_options(compile_options); 1554 parse_info.set_compile_options(compile_options);
1549 parse_info.set_extension(extension); 1555 parse_info.set_extension(extension);
1550 parse_info.set_context(context); 1556 parse_info.set_context(context);
1551 if (FLAG_serialize_toplevel && 1557 if (FLAG_serialize_toplevel &&
1552 compile_options == ScriptCompiler::kProduceCodeCache) { 1558 compile_options == ScriptCompiler::kProduceCodeCache) {
1553 info.PrepareForSerializing(); 1559 info.PrepareForSerializing();
1554 } 1560 }
1555 1561
1556 parse_info.set_language_mode( 1562 parse_info.set_language_mode(
1557 static_cast<LanguageMode>(parse_info.language_mode() | language_mode)); 1563 static_cast<LanguageMode>(parse_info.language_mode() | language_mode));
1558 result = CompileToplevel(&info); 1564 result = CompileToplevel(&info);
1559 if (extension == NULL && !result.is_null()) { 1565 if (extension == NULL && !result.is_null()) {
1560 compilation_cache->PutScript(source, context, language_mode, result); 1566 compilation_cache->PutScript(source, context, language_mode, is_module,
1567 result);
1561 if (FLAG_serialize_toplevel && 1568 if (FLAG_serialize_toplevel &&
1562 compile_options == ScriptCompiler::kProduceCodeCache) { 1569 compile_options == ScriptCompiler::kProduceCodeCache) {
1563 HistogramTimerScope histogram_timer( 1570 HistogramTimerScope histogram_timer(
1564 isolate->counters()->compile_serialize()); 1571 isolate->counters()->compile_serialize());
1565 RuntimeCallTimerScope runtimeTimer(isolate, 1572 RuntimeCallTimerScope runtimeTimer(isolate,
1566 &RuntimeCallStats::CompileSerialize); 1573 &RuntimeCallStats::CompileSerialize);
1567 TRACE_EVENT0("v8", "V8.CompileSerialize"); 1574 TRACE_EVENT0("v8", "V8.CompileSerialize");
1568 *cached_data = CodeSerializer::Serialize(isolate, result, source); 1575 *cached_data = CodeSerializer::Serialize(isolate, result, source);
1569 if (FLAG_profile_deserialization) { 1576 if (FLAG_profile_deserialization) {
1570 PrintF("[Compiling and serializing took %0.3f ms]\n", 1577 PrintF("[Compiling and serializing took %0.3f ms]\n",
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
1820 DCHECK(shared->is_compiled()); 1827 DCHECK(shared->is_compiled());
1821 function->set_literals(cached.literals); 1828 function->set_literals(cached.literals);
1822 } else if (shared->is_compiled()) { 1829 } else if (shared->is_compiled()) {
1823 // TODO(mvstanton): pass pretenure flag to EnsureLiterals. 1830 // TODO(mvstanton): pass pretenure flag to EnsureLiterals.
1824 JSFunction::EnsureLiterals(function); 1831 JSFunction::EnsureLiterals(function);
1825 } 1832 }
1826 } 1833 }
1827 1834
1828 } // namespace internal 1835 } // namespace internal
1829 } // namespace v8 1836 } // namespace v8
OLDNEW
« no previous file with comments | « src/compilation-cache.cc ('k') | src/objects.h » ('j') | src/objects.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698