Commit 5217e050 authored by Toon Verwaest's avatar Toon Verwaest Committed by V8 LUCI CQ

[parsing] Split FLAG_lazy into three subflags

Splits FLAG_lazy into
  - FLAG_lazy for main-thread compiled scripts/modules
  - FLAG_lazy_streaming for streamed scripts
  - FLAG_lazy_eval for eval

This allows us to evaluate the impact of non-lazy compilation for streamed
scripts.

Change-Id: I8a362ea184e0afd3aa7cdb11a7eab5b7497a4691
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2999090Reviewed-by: 's avatarSantiago Aboy Solanes <solanes@chromium.org>
Reviewed-by: 's avatarMarja Hölttä <marja@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#75518}
parent ef2318ee
......@@ -1483,7 +1483,7 @@ BackgroundCompileTask::BackgroundCompileTask(ScriptStreamingData* streamed_data,
Isolate* isolate, ScriptType type)
: flags_(UnoptimizedCompileFlags::ForToplevelCompile(
isolate, true, construct_language_mode(FLAG_use_strict),
REPLMode::kNo, type)),
REPLMode::kNo, type, FLAG_lazy_streaming)),
compile_state_(isolate),
info_(std::make_unique<ParseInfo>(isolate, flags_, &compile_state_)),
isolate_for_local_isolate_(isolate),
......@@ -1723,9 +1723,7 @@ bool Compiler::CollectSourcePositions(Isolate* isolate,
// Set up parse info.
UnoptimizedCompileFlags flags =
UnoptimizedCompileFlags::ForFunctionCompile(isolate, *shared_info);
flags.set_is_lazy_compile(true);
flags.set_collect_source_positions(true);
flags.set_allow_natives_syntax(FLAG_allow_natives_syntax);
UnoptimizedCompileState compile_state(isolate);
ParseInfo parse_info(isolate, flags, &compile_state);
......@@ -1800,7 +1798,6 @@ bool Compiler::Compile(Isolate* isolate, Handle<SharedFunctionInfo> shared_info,
// Set up parse info.
UnoptimizedCompileFlags flags =
UnoptimizedCompileFlags::ForFunctionCompile(isolate, *shared_info);
flags.set_is_lazy_compile(true);
UnoptimizedCompileState compile_state(isolate);
ParseInfo parse_info(isolate, flags, &compile_state);
......@@ -2149,7 +2146,8 @@ MaybeHandle<JSFunction> Compiler::GetFunctionFromEval(
allow_eval_cache = true;
} else {
UnoptimizedCompileFlags flags = UnoptimizedCompileFlags::ForToplevelCompile(
isolate, true, language_mode, REPLMode::kNo);
isolate, true, language_mode, REPLMode::kNo, ScriptType::kClassic,
FLAG_lazy_eval);
flags.set_is_eval(true);
DCHECK(!flags.is_module());
flags.set_parse_restriction(restriction);
......@@ -2880,7 +2878,8 @@ MaybeHandle<SharedFunctionInfo> Compiler::GetSharedFunctionInfoForScript(
isolate, natives == NOT_NATIVES_CODE, language_mode,
script_details.repl_mode,
origin_options.IsModule() ? ScriptType::kModule
: ScriptType::kClassic);
: ScriptType::kClassic,
FLAG_lazy);
flags.set_is_eager(compile_options == ScriptCompiler::kEagerCompile);
......@@ -2948,7 +2947,8 @@ MaybeHandle<JSFunction> Compiler::GetWrappedFunction(
IsCompiledScope is_compiled_scope;
if (!maybe_result.ToHandle(&wrapped)) {
UnoptimizedCompileFlags flags = UnoptimizedCompileFlags::ForToplevelCompile(
isolate, true, language_mode, script_details.repl_mode);
isolate, true, language_mode, script_details.repl_mode,
ScriptType::kClassic, FLAG_lazy);
flags.set_is_eval(true); // Use an eval scope as declaration scope.
flags.set_function_syntax_kind(FunctionSyntaxKind::kWrapped);
// TODO(delphick): Remove this and instead make the wrapped and wrapper
......
......@@ -655,7 +655,7 @@ bool Shell::ExecuteString(Isolate* isolate, Local<String> source,
i::UnoptimizedCompileFlags flags =
i::UnoptimizedCompileFlags::ForToplevelCompile(
i_isolate, true, i::construct_language_mode(i::FLAG_use_strict),
i::REPLMode::kNo);
i::REPLMode::kNo, ScriptType::kClassic, i::FLAG_lazy);
if (options.compile_options == v8::ScriptCompiler::kEagerCompile) {
flags.set_is_eager(true);
......
......@@ -1445,6 +1445,9 @@ DEFINE_BOOL(trace, false, "trace javascript function calls")
// codegen.cc
DEFINE_BOOL(lazy, true, "use lazy compilation")
DEFINE_BOOL(lazy_eval, true, "use lazy compilation during eval")
DEFINE_BOOL(lazy_streaming, true,
"use lazy compilation during streaming compilation")
DEFINE_BOOL(max_lazy, false, "ignore eager compilation hints")
DEFINE_IMPLICATION(max_lazy, lazy)
DEFINE_BOOL(trace_opt, false, "trace optimized compilation")
......
......@@ -32,7 +32,7 @@ UnoptimizedCompileFlags::UnoptimizedCompileFlags(Isolate* isolate,
set_block_coverage_enabled(isolate->is_block_code_coverage());
set_might_always_opt(FLAG_always_opt || FLAG_prepare_always_opt);
set_allow_natives_syntax(FLAG_allow_natives_syntax);
set_allow_lazy_compile(FLAG_lazy);
set_allow_lazy_compile(true);
set_collect_source_positions(!FLAG_enable_lazy_source_positions ||
isolate->NeedsDetailedOptimizedCodeLineInfo());
set_allow_harmony_top_level_await(FLAG_harmony_top_level_await);
......@@ -47,8 +47,9 @@ UnoptimizedCompileFlags UnoptimizedCompileFlags::ForFunctionCompile(
flags.SetFlagsFromFunction(&shared);
flags.SetFlagsForFunctionFromScript(script);
flags.set_allow_lazy_parsing(true);
flags.set_is_lazy_compile(true);
#if V8_ENABLE_WEBASSEMBLY
flags.set_is_asm_wasm_broken(shared.is_asm_wasm_broken());
#endif // V8_ENABLE_WEBASSEMBLY
......@@ -79,7 +80,8 @@ UnoptimizedCompileFlags UnoptimizedCompileFlags::ForScriptCompile(
isolate->is_collecting_type_profile(), script.IsUserJavaScript(),
flags.outer_language_mode(), construct_repl_mode(script.is_repl_mode()),
script.origin_options().IsModule() ? ScriptType::kModule
: ScriptType::kClassic);
: ScriptType::kClassic,
FLAG_lazy);
if (script.is_wrapped()) {
flags.set_function_syntax_kind(FunctionSyntaxKind::kWrapped);
}
......@@ -90,11 +92,11 @@ UnoptimizedCompileFlags UnoptimizedCompileFlags::ForScriptCompile(
// static
UnoptimizedCompileFlags UnoptimizedCompileFlags::ForToplevelCompile(
Isolate* isolate, bool is_user_javascript, LanguageMode language_mode,
REPLMode repl_mode, ScriptType type) {
REPLMode repl_mode, ScriptType type, bool lazy) {
UnoptimizedCompileFlags flags(isolate, isolate->GetNextScriptId());
flags.SetFlagsForToplevelCompile(isolate->is_collecting_type_profile(),
is_user_javascript, language_mode, repl_mode,
type);
type, lazy);
LOG(isolate,
ScriptEvent(Logger::ScriptEventType::kReserveId, flags.script_id()));
......@@ -135,9 +137,11 @@ void UnoptimizedCompileFlags::SetFlagsFromFunction(T function) {
void UnoptimizedCompileFlags::SetFlagsForToplevelCompile(
bool is_collecting_type_profile, bool is_user_javascript,
LanguageMode language_mode, REPLMode repl_mode, ScriptType type) {
set_allow_lazy_parsing(true);
LanguageMode language_mode, REPLMode repl_mode, ScriptType type,
bool lazy) {
set_is_toplevel(true);
set_allow_lazy_parsing(lazy);
set_allow_lazy_compile(lazy);
set_collect_type_profile(is_user_javascript && is_collecting_type_profile);
set_outer_language_mode(
stricter_language_mode(outer_language_mode(), language_mode));
......@@ -304,7 +308,6 @@ void ParseInfo::set_character_stream(
void ParseInfo::CheckFlagsForToplevelCompileFromScript(
Script script, bool is_collecting_type_profile) {
CheckFlagsForFunctionFromScript(script);
DCHECK(flags().allow_lazy_parsing());
DCHECK(flags().is_toplevel());
DCHECK_EQ(flags().collect_type_profile(),
is_collecting_type_profile && script.IsUserJavaScript());
......
......@@ -67,9 +67,11 @@ class Zone;
class V8_EXPORT_PRIVATE UnoptimizedCompileFlags {
public:
// Set-up flags for a toplevel compilation.
static UnoptimizedCompileFlags ForToplevelCompile(
Isolate* isolate, bool is_user_javascript, LanguageMode language_mode,
REPLMode repl_mode, ScriptType type = ScriptType::kClassic);
static UnoptimizedCompileFlags ForToplevelCompile(Isolate* isolate,
bool is_user_javascript,
LanguageMode language_mode,
REPLMode repl_mode,
ScriptType type, bool lazy);
// Set-up flags for a compiling a particular function (either a lazy compile
// or a recompile).
......@@ -132,7 +134,8 @@ class V8_EXPORT_PRIVATE UnoptimizedCompileFlags {
void SetFlagsForToplevelCompile(bool is_collecting_type_profile,
bool is_user_javascript,
LanguageMode language_mode,
REPLMode repl_mode, ScriptType type);
REPLMode repl_mode, ScriptType type,
bool lazy);
void SetFlagsForFunctionFromScript(Script script);
uint32_t flags_;
......
......@@ -1643,7 +1643,8 @@ void TestParserSyncWithFlags(i::Handle<i::String> source,
i::UnoptimizedCompileState compile_state(isolate);
i::UnoptimizedCompileFlags compile_flags =
i::UnoptimizedCompileFlags::ForToplevelCompile(
isolate, true, LanguageMode::kSloppy, REPLMode::kNo);
isolate, true, LanguageMode::kSloppy, REPLMode::kNo,
ScriptType::kClassic, FLAG_lazy);
SetParserFlags(&compile_flags, flags);
compile_flags.set_is_module(is_module);
......@@ -4394,6 +4395,7 @@ TEST(SloppyModeUseCount) {
global_use_counts = use_counts;
// Force eager parsing (preparser doesn't update use counts).
i::FLAG_lazy = false;
i::FLAG_lazy_streaming = false;
CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
CompileRun("function bar() { var baz = 1; }");
CHECK_LT(0, use_counts[v8::Isolate::kSloppyMode]);
......@@ -4407,8 +4409,8 @@ TEST(BothModesUseCount) {
LocalContext env;
int use_counts[v8::Isolate::kUseCounterFeatureCount] = {};
global_use_counts = use_counts;
// Force eager parsing (preparser doesn't update use counts).
i::FLAG_lazy = false;
i::FLAG_lazy_streaming = false;
CcTest::isolate()->SetUseCounterCallback(MockUseCounterCallback);
CompileRun("function bar() { 'use strict'; var baz = 1; }");
CHECK_LT(0, use_counts[v8::Isolate::kSloppyMode]);
......
......@@ -60,10 +60,9 @@ class LocalFactoryTest : public TestWithIsolateAndZone {
isolate(),
UnoptimizedCompileFlags::ForToplevelCompile(
isolate(), true, construct_language_mode(FLAG_use_strict),
REPLMode::kNo),
REPLMode::kNo, ScriptType::kClassic, FLAG_lazy),
&state_),
local_isolate_(isolate()->main_thread_local_isolate()) {
}
local_isolate_(isolate()->main_thread_local_isolate()) {}
FunctionLiteral* ParseProgram(const char* source) {
auto utf16_source = DecodeUtf8(source);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment