From bcb255d5a8e20c3e7544c5f963596ecb48802e0c Mon Sep 17 00:00:00 2001 From: Keyhan Vakil Date: Thu, 6 Jul 2023 07:28:15 +0000 Subject: [PATCH] deps: V8: cherry-pick cb00db4dba6c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Original commit message: [compiler] fix CompileFunction ignoring kEagerCompile v8::ScriptCompiler::CompileFunction was ignoring kEagerCompile. Unlike the other functions in v8::ScriptCompiler, it was not actually propagating kEagerCompile to the parser. The newly updated test fails without this change. I did some archeology and found that this was commented out since the original CL in https://crrev.com/c/980944. As far as I know Node.js is the main consumer of this particular API. This CL speeds up Node.js's overall startup time by ~13%. Change-Id: Ifc3cd6653555194d46ca48db14f7ba7a4afe0053 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4571822 Commit-Queue: Marja Hölttä Reviewed-by: Marja Hölttä Cr-Commit-Position: refs/heads/main@{#87944} Refs: https://github.com/v8/v8/commit/cb00db4dba6c4a1900700d134e2293c59155db28 PR-URL: https://github.com/nodejs/node/pull/48671 Refs: https://github.com/nodejs/node/pull/48576 Reviewed-By: Darshan Sen Reviewed-By: Michaël Zasso --- deps/v8/src/codegen/compiler.cc | 2 +- deps/v8/test/cctest/test-serialize.cc | 31 +++++++++++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/deps/v8/src/codegen/compiler.cc b/deps/v8/src/codegen/compiler.cc index a0d2e45ffc9729..d821913f650bd8 100644 --- a/deps/v8/src/codegen/compiler.cc +++ b/deps/v8/src/codegen/compiler.cc @@ -3199,7 +3199,7 @@ MaybeHandle Compiler::GetWrappedFunction( // functions fully non-lazy instead thus preventing source positions from // being omitted. flags.set_collect_source_positions(true); - // flags.set_eager(compile_options == ScriptCompiler::kEagerCompile); + flags.set_is_eager(compile_options == ScriptCompiler::kEagerCompile); UnoptimizedCompileState compile_state; ReusableUnoptimizedCompileState reusable_state(isolate); diff --git a/deps/v8/test/cctest/test-serialize.cc b/deps/v8/test/cctest/test-serialize.cc index 7d3e57af49d92c..4252d4bd652034 100644 --- a/deps/v8/test/cctest/test-serialize.cc +++ b/deps/v8/test/cctest/test-serialize.cc @@ -4937,6 +4937,37 @@ TEST(CachedCompileFunction) { } } +TEST(CachedCompileFunctionRespectsEager) { + DisableAlwaysOpt(); + LocalContext env; + Isolate* isolate = CcTest::i_isolate(); + isolate->compilation_cache() + ->DisableScriptAndEval(); // Disable same-isolate code cache. + + v8::HandleScope scope(CcTest::isolate()); + + v8::Local source = v8_str("return function() { return 42; }"); + v8::ScriptCompiler::Source script_source(source); + + for (bool eager_compile : {false, true}) { + v8::ScriptCompiler::CompileOptions options = + eager_compile ? v8::ScriptCompiler::kEagerCompile + : v8::ScriptCompiler::kNoCompileOptions; + v8::Local fun = + v8::ScriptCompiler::CompileFunction(env.local(), &script_source, 0, + nullptr, 0, nullptr, options) + .ToLocalChecked() + .As() + ->Call(env.local(), v8::Undefined(CcTest::isolate()), 0, nullptr) + .ToLocalChecked(); + + auto i_fun = i::Handle::cast(Utils::OpenHandle(*fun)); + + // Function should be compiled iff kEagerCompile was used. + CHECK_EQ(i_fun->shared().is_compiled(), eager_compile); + } +} + UNINITIALIZED_TEST(SnapshotCreatorAnonClassWithKeep) { DisableAlwaysOpt(); v8::SnapshotCreator creator;