Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

src: generate snapshot with --predictable #48749

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
2 changes: 2 additions & 0 deletions src/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions tools/snapshot/node_mksnapshot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand All @@ -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);
Expand Down