From 658d2f471057c0b5b2bd5f70faa1a47b4f3b80d2 Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Tue, 24 Jan 2023 21:35:27 +0100 Subject: [PATCH] src: make build_snapshot a per-Isolate option, rather than a global one PR-URL: https://github.com/nodejs/node/pull/45888 Reviewed-By: James M Snell Reviewed-By: Joyee Cheung --- src/node.cc | 4 ++-- src/node_options.cc | 10 +++++----- src/node_options.h | 2 +- src/node_snapshotable.cc | 2 +- tools/snapshot/node_mksnapshot.cc | 2 +- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/node.cc b/src/node.cc index c5b6c2b8444499..af680ed5b658d9 100644 --- a/src/node.cc +++ b/src/node.cc @@ -307,7 +307,7 @@ MaybeLocal StartExecution(Environment* env, StartExecutionCallback cb) { return StartExecution(env, "internal/main/inspect"); } - if (per_process::cli_options->build_snapshot) { + if (env->isolate_data()->options()->build_snapshot) { return StartExecution(env, "internal/main/mksnapshot"); } @@ -1221,7 +1221,7 @@ static ExitCode StartInternal(int argc, char** argv) { uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME); // --build-snapshot indicates that we are in snapshot building mode. - if (per_process::cli_options->build_snapshot) { + if (per_process::cli_options->per_isolate->build_snapshot) { if (result->args().size() < 2) { fprintf(stderr, "--build-snapshot must be used with an entry point script.\n" diff --git a/src/node_options.cc b/src/node_options.cc index af2b79ad0b86fd..e9c5ac2b190728 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -777,6 +777,11 @@ PerIsolateOptionsParser::PerIsolateOptionsParser( Implies("--experimental-shadow-realm", "--harmony-shadow-realm"); Implies("--harmony-shadow-realm", "--experimental-shadow-realm"); ImpliesNot("--no-harmony-shadow-realm", "--experimental-shadow-realm"); + AddOption("--build-snapshot", + "Generate a snapshot blob when the process exits." + " Currently only supported in the node_mksnapshot binary.", + &PerIsolateOptions::build_snapshot, + kDisallowedInEnvvar); Insert(eop, &PerIsolateOptions::get_per_env_options); } @@ -815,11 +820,6 @@ PerProcessOptionsParser::PerProcessOptionsParser( "disable Object.prototype.__proto__", &PerProcessOptions::disable_proto, kAllowedInEnvvar); - AddOption("--build-snapshot", - "Generate a snapshot blob when the process exits." - " Currently only supported in the node_mksnapshot binary.", - &PerProcessOptions::build_snapshot, - kDisallowedInEnvvar); AddOption("--node-snapshot", "", // It's a debug-only option. &PerProcessOptions::node_snapshot, diff --git a/src/node_options.h b/src/node_options.h index 7d2c1f98560709..07ec47d861c77f 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -224,6 +224,7 @@ class PerIsolateOptions : public Options { bool report_on_signal = false; bool experimental_shadow_realm = false; std::string report_signal = "SIGUSR2"; + bool build_snapshot = false; inline EnvironmentOptions* get_per_env_options(); void CheckOptions(std::vector* errors, std::vector* argv) override; @@ -248,7 +249,6 @@ class PerProcessOptions : public Options { bool zero_fill_all_buffers = false; bool debug_arraybuffer_allocations = false; std::string disable_proto; - bool build_snapshot = false; // We enable the shared read-only heap which currently requires that the // snapshot used in different isolates in the same process to be the same. // Therefore --node-snapshot is a per-process option. diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index eba39064a24fea..aec96199130c6b 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -1136,7 +1136,7 @@ ExitCode SnapshotBuilder::Generate(SnapshotData* out, // It's only possible to be kDefault in node_mksnapshot. SnapshotMetadata::Type snapshot_type = - per_process::cli_options->build_snapshot + per_process::cli_options->per_isolate->build_snapshot ? SnapshotMetadata::Type::kFullyCustomized : SnapshotMetadata::Type::kDefault; diff --git a/tools/snapshot/node_mksnapshot.cc b/tools/snapshot/node_mksnapshot.cc index 7e69b5053d15c2..d6d92ab156da62 100644 --- a/tools/snapshot/node_mksnapshot.cc +++ b/tools/snapshot/node_mksnapshot.cc @@ -72,7 +72,7 @@ int BuildSnapshot(int argc, char* argv[]) { CHECK_EQ(result->exit_code(), 0); std::string out_path; - if (node::per_process::cli_options->build_snapshot) { + if (node::per_process::cli_options->per_isolate->build_snapshot) { out_path = result->args()[2]; } else { out_path = result->args()[1];