mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
src: generate default snapshot with --predictable
To improve determinism of snapshot generation, add --predictable to the V8 flags used to initialize a process launched to generate snapshot. Also add a kGeneratePredictableSnapshot flag to ProcessInitializationFlags for this and moves the configuration of these flags into node::InitializeOncePerProcess() so that it can be shared by embedders. PR-URL: https://github.com/nodejs/node/pull/48749 Refs: https://github.com/nodejs/build/issues/3043 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
This commit is contained in:
1 parent
81e4d2ec2f
commit
387e2929fe
3 files changed
+10
-3
No files matched your search
@@ -838,6 +838,12 @@ static ExitCode InitializeNodeWithArgsInternal(
|
||||
V8::SetFlagsFromString(NODE_V8_OPTIONS, sizeof(NODE_V8_OPTIONS) - 1);
|
||||
#endif
|
||||
|
||||
if (!!(flags & ProcessInitializationFlags::kGeneratePredictableSnapshot) ||
|
||||
per_process::cli_options->per_isolate->build_snapshot) {
|
||||
v8::V8::SetFlagsFromString("--predictable");
|
||||
v8::V8::SetFlagsFromString("--random_seed=42");
|
||||
}
|
||||
|
||||
// Specify this explicitly to avoid being affected by V8 changes to the
|
||||
// default value.
|
||||
V8::SetFlagsFromString("--rehash-snapshot");
|
||||
|
||||
@@ -265,6 +265,8 @@ enum Flags : uint32_t {
|
||||
// cppgc::InitializeProcess() before creating a Node.js environment
|
||||
// and call cppgc::ShutdownProcess() before process shutdown.
|
||||
kNoInitializeCppgc = 1 << 13,
|
||||
// Initialize the process for predictable snapshot generation.
|
||||
kGeneratePredictableSnapshot = 1 << 14,
|
||||
|
||||
// Emulate the behavior of InitializeNodeWithArgs() when passing
|
||||
// a flags argument to the InitializeOncePerProcess() replacement
|
||||
|
||||
@@ -50,8 +50,6 @@ int main(int argc, char* argv[]) {
|
||||
setvbuf(stderr, nullptr, _IONBF, 0);
|
||||
#endif // _WIN32
|
||||
|
||||
v8::V8::SetFlagsFromString("--random_seed=42");
|
||||
v8::V8::SetFlagsFromString("--harmony-import-assertions");
|
||||
return BuildSnapshot(argc, argv);
|
||||
}
|
||||
|
||||
@@ -65,7 +63,8 @@ int BuildSnapshot(int argc, char* argv[]) {
|
||||
|
||||
std::unique_ptr<node::InitializationResult> result =
|
||||
node::InitializeOncePerProcess(
|
||||
std::vector<std::string>(argv, argv + argc));
|
||||
std::vector<std::string>(argv, argv + argc),
|
||||
node::ProcessInitializationFlags::kGeneratePredictableSnapshot);
|
||||
|
||||
CHECK(!result->early_return());
|
||||
CHECK_EQ(result->exit_code(), 0);
|
||||
|
||||
Reference in new issue
Block a user