Skip to content

Commit 4d0f930

Browse files
committed
bootstrap: only use the isolate snapshot when compiling code cache
We do not actually need to deserialize the context and the whole environment to compile the code cache, since code cache are not context-dependent anyway, deserializing just the isolate snapshot is enough. PR-URL: #49288 Reviewed-By: Chengzhong Wu <[email protected]>
1 parent 1235426 commit 4d0f930

File tree

1 file changed

+7
-18
lines changed

1 file changed

+7
-18
lines changed

src/node_snapshotable.cc

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -975,21 +975,8 @@ ExitCode BuildSnapshotWithoutCodeCache(
975975
ExitCode BuildCodeCacheFromSnapshot(SnapshotData* out,
976976
const std::vector<std::string>& args,
977977
const std::vector<std::string>& exec_args) {
978-
std::vector<std::string> errors;
979-
auto data_wrapper = out->AsEmbedderWrapper();
980-
auto setup = CommonEnvironmentSetup::CreateFromSnapshot(
981-
per_process::v8_platform.Platform(),
982-
&errors,
983-
data_wrapper.get(),
984-
args,
985-
exec_args);
986-
if (!setup) {
987-
for (const auto& err : errors)
988-
fprintf(stderr, "%s: %s\n", args[0].c_str(), err.c_str());
989-
return ExitCode::kBootstrapFailure;
990-
}
991-
992-
Isolate* isolate = setup->isolate();
978+
RAIIIsolate raii_isolate(out);
979+
Isolate* isolate = raii_isolate.get();
993980
v8::Locker locker(isolate);
994981
Isolate::Scope isolate_scope(isolate);
995982
HandleScope handle_scope(isolate);
@@ -1002,12 +989,14 @@ ExitCode BuildCodeCacheFromSnapshot(SnapshotData* out,
1002989
}
1003990
});
1004991

1005-
Environment* env = setup->env();
992+
Local<Context> context = Context::New(isolate);
993+
Context::Scope context_scope(context);
994+
builtins::BuiltinLoader builtin_loader;
1006995
// Regenerate all the code cache.
1007-
if (!env->builtin_loader()->CompileAllBuiltins(setup->context())) {
996+
if (!builtin_loader.CompileAllBuiltins(context)) {
1008997
return ExitCode::kGenericUserError;
1009998
}
1010-
env->builtin_loader()->CopyCodeCache(&(out->code_cache));
999+
builtin_loader.CopyCodeCache(&(out->code_cache));
10111000
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
10121001
for (const auto& item : out->code_cache) {
10131002
std::string size_str = FormatSize(item.data.length);

0 commit comments

Comments
 (0)