From 3f409b7ca59f0d656b092bd4b0eef7d0dbbf1d82 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 2 Jun 2021 13:47:40 +0800 Subject: [PATCH] bootstrap: implement --snapshot-blob and --snapshot-main This patch introduces --snapshot-main and --snapshot-blob options for creating and using user land snapshots. At the time of the creation of this patch, user land CJS modules and ESM are not yet supported in the snapshot, but a subset of builtins should already work (in particular modules loaded during bootstrap are shipped in the built-in snapshot, so they should work in user land snapshot as well), and support for more builtins are being added. To generate a snapshot using main.js as entry point and write the snapshot blob to snapshot.blob: $ node --snapshot-main main.js --snapshot-blob snapshot.blob To restore application state from snapshot.blob: $ node --snapshot-blob snapshot.blob --- doc/api/cli.md | 25 ++++++++++ src/node.cc | 73 ++++++++++++++++++++++++++--- src/node_options.cc | 10 ++++ src/node_options.h | 2 + src/node_snapshotable.cc | 63 ++++++++++++++++++++++++- src/node_snapshotable.h | 6 +++ test/fixtures/snapshot/mutate-fs.js | 3 ++ test/parallel/test-snapshot-blob.js | 63 +++++++++++++++++++++++++ 8 files changed, 238 insertions(+), 7 deletions(-) create mode 100644 test/fixtures/snapshot/mutate-fs.js create mode 100644 test/parallel/test-snapshot-blob.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 38f72769d9d7ee..b0edc1e81790b4 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -897,6 +897,30 @@ minimum allocation from the secure heap. The minimum value is `2`. The maximum value is the lesser of `--secure-heap` or `2147483647`. The value given must be a power of two. +### `--snapshot-blob=path` + + +When used with `--snapshot-main`, `--snapshot-blob` specifies the path +where the generated snapshot blob will be written to. If not speficied, +the generated blob will be written, by default, to `snapshot.blob` +in the current working directory. + +When used without `--snapshot-main`, `--snapshot-blob` specifies the +path to the blob that will be used to restore the application state. + +### `--snapshot-main=path` + + +Specifies the path of the entry point file used to build user land +snapshot. If `--snapshot-blob` is not specified, the generated blob +will be written, by default, to `snapshot.blob` in the current working +directory. Otherwise it will be written to the path specified by +`--snapshot-blob`. + ### `--throw-deprecation`