From 581bddc656ff822978bc0a23c61c2f0c40328ddb Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Sat, 6 Jul 2019 02:43:27 +0800 Subject: [PATCH] src: implement runtime option --no-node-snapshot for debugging PR-URL: https://github.com/nodejs/node/pull/28567 Refs: https://github.com/nodejs/node/issues/28558 Reviewed-By: Gus Caplan Reviewed-By: Anna Henningsen Reviewed-By: Rich Trott --- src/node.cc | 25 +++++++++++-------- src/node_options.cc | 4 +++ src/node_options.h | 1 + test/parallel/test-no-node-snapshot.js | 5 ++++ ...rocess-env-allowed-flags-are-documented.js | 2 ++ 5 files changed, 27 insertions(+), 10 deletions(-) create mode 100644 test/parallel/test-no-node-snapshot.js diff --git a/src/node.cc b/src/node.cc index 371e7c9f029e38..ea3bc5688e566d 100644 --- a/src/node.cc +++ b/src/node.cc @@ -1052,16 +1052,21 @@ int Start(int argc, char** argv) { { Isolate::CreateParams params; - // TODO(joyeecheung): collect external references and set it in - // params.external_references. - std::vector external_references = { - reinterpret_cast(nullptr)}; - v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob(); - const std::vector* indexes = - NodeMainInstance::GetIsolateDataIndexes(); - if (blob != nullptr) { - params.external_references = external_references.data(); - params.snapshot_blob = blob; + const std::vector* indexes = nullptr; + std::vector external_references; + + bool force_no_snapshot = + per_process::cli_options->per_isolate->no_node_snapshot; + if (!force_no_snapshot) { + v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob(); + if (blob != nullptr) { + // TODO(joyeecheung): collect external references and set it in + // params.external_references. + external_references.push_back(reinterpret_cast(nullptr)); + params.external_references = external_references.data(); + params.snapshot_blob = blob; + indexes = NodeMainInstance::GetIsolateDataIndexes(); + } } NodeMainInstance main_instance(¶ms, diff --git a/src/node_options.cc b/src/node_options.cc index 2b177806683a63..beb272d146336b 100644 --- a/src/node_options.cc +++ b/src/node_options.cc @@ -522,6 +522,10 @@ PerIsolateOptionsParser::PerIsolateOptionsParser( "track heap object allocations for heap snapshots", &PerIsolateOptions::track_heap_objects, kAllowedInEnvironment); + AddOption("--no-node-snapshot", + "", // It's a debug-only option. + &PerIsolateOptions::no_node_snapshot, + kAllowedInEnvironment); // Explicitly add some V8 flags to mark them as allowed in NODE_OPTIONS. AddOption("--abort-on-uncaught-exception", diff --git a/src/node_options.h b/src/node_options.h index 63892d3c477767..7a4f61a287bc87 100644 --- a/src/node_options.h +++ b/src/node_options.h @@ -171,6 +171,7 @@ class PerIsolateOptions : public Options { public: std::shared_ptr per_env { new EnvironmentOptions() }; bool track_heap_objects = false; + bool no_node_snapshot = false; #ifdef NODE_REPORT bool report_uncaught_exception = false; diff --git a/test/parallel/test-no-node-snapshot.js b/test/parallel/test-no-node-snapshot.js new file mode 100644 index 00000000000000..a636040a4c1ca8 --- /dev/null +++ b/test/parallel/test-no-node-snapshot.js @@ -0,0 +1,5 @@ +'use strict'; + +// Flags: --no-node-snapshot + +require('../common'); diff --git a/test/parallel/test-process-env-allowed-flags-are-documented.js b/test/parallel/test-process-env-allowed-flags-are-documented.js index bb203d94d370d8..0a6034f746784d 100644 --- a/test/parallel/test-process-env-allowed-flags-are-documented.js +++ b/test/parallel/test-process-env-allowed-flags-are-documented.js @@ -79,6 +79,8 @@ const undocumented = difference(process.allowedNodeEnvironmentFlags, // Remove intentionally undocumented options. assert(undocumented.delete('--debug-arraybuffer-allocations')); assert(undocumented.delete('--experimental-worker')); +assert(undocumented.delete('--no-node-snapshot')); + assert.strictEqual(undocumented.size, 0, 'The following options are not documented as allowed in ' + `NODE_OPTIONS in ${cliMd}: ${[...undocumented].join(' ')}`);