Skip to content

Commit 37ca110

Browse files
joyeecheungtargos
authored andcommitted
src: make --no-node-snapshot a per-process option
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 --no-node-snapshot is a per-process option. PR-URL: #42864 Refs: #42809 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
1 parent 1102922 commit 37ca110

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

src/node.cc

+1-2
Original file line numberDiff line numberDiff line change
@@ -1169,8 +1169,7 @@ int Start(int argc, char** argv) {
11691169
}
11701170

11711171
{
1172-
bool use_node_snapshot =
1173-
per_process::cli_options->per_isolate->node_snapshot;
1172+
bool use_node_snapshot = per_process::cli_options->node_snapshot;
11741173
const SnapshotData* snapshot_data =
11751174
use_node_snapshot ? SnapshotBuilder::GetEmbeddedSnapshotData()
11761175
: nullptr;

src/node_options.cc

+4-5
Original file line numberDiff line numberDiff line change
@@ -650,10 +650,6 @@ PerIsolateOptionsParser::PerIsolateOptionsParser(
650650
"track heap object allocations for heap snapshots",
651651
&PerIsolateOptions::track_heap_objects,
652652
kAllowedInEnvironment);
653-
AddOption("--node-snapshot",
654-
"", // It's a debug-only option.
655-
&PerIsolateOptions::node_snapshot,
656-
kAllowedInEnvironment);
657653

658654
// Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS.
659655
AddOption("--abort-on-uncaught-exception",
@@ -755,7 +751,10 @@ PerProcessOptionsParser::PerProcessOptionsParser(
755751
"Currently only supported in the node_mksnapshot binary.",
756752
&PerProcessOptions::build_snapshot,
757753
kDisallowedInEnvironment);
758-
754+
AddOption("--node-snapshot",
755+
"", // It's a debug-only option.
756+
&PerProcessOptions::node_snapshot,
757+
kAllowedInEnvironment);
759758
// 12.x renamed this inadvertently, so alias it for consistency within the
760759
// release line, while using the original name for consistency with older
761760
// release lines.

src/node_options.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,6 @@ class PerIsolateOptions : public Options {
203203
public:
204204
std::shared_ptr<EnvironmentOptions> per_env { new EnvironmentOptions() };
205205
bool track_heap_objects = false;
206-
bool node_snapshot = true;
207206
bool report_uncaught_exception = false;
208207
bool report_on_signal = false;
209208
bool experimental_top_level_await = true;
@@ -231,7 +230,11 @@ class PerProcessOptions : public Options {
231230
bool zero_fill_all_buffers = false;
232231
bool debug_arraybuffer_allocations = false;
233232
std::string disable_proto;
234-
bool build_snapshot;
233+
bool build_snapshot = false;
234+
// We enable the shared read-only heap which currently requires that the
235+
// snapshot used in different isolates in the same process to be the same.
236+
// Therefore --node-snapshot is a per-process option.
237+
bool node_snapshot = true;
235238

236239
std::vector<std::string> security_reverts;
237240
bool print_bash_completion = false;

src/node_worker.cc

+1-8
Original file line numberDiff line numberDiff line change
@@ -147,14 +147,7 @@ class WorkerThreadData {
147147
SetIsolateCreateParamsForNode(&params);
148148
params.array_buffer_allocator_shared = allocator;
149149

150-
bool use_node_snapshot = true;
151-
if (w_->per_isolate_opts_) {
152-
use_node_snapshot = w_->per_isolate_opts_->node_snapshot;
153-
} else {
154-
// IsolateData is created after the Isolate is created so we'll
155-
// inherit the option from the parent here.
156-
use_node_snapshot = per_process::cli_options->per_isolate->node_snapshot;
157-
}
150+
bool use_node_snapshot = per_process::cli_options->node_snapshot;
158151
const SnapshotData* snapshot_data =
159152
use_node_snapshot ? SnapshotBuilder::GetEmbeddedSnapshotData()
160153
: nullptr;

0 commit comments

Comments
 (0)