src: allow building the snapshot on top of a V8 startup blob - #65374
Open
codebytere wants to merge 1 commit into
Open
src: allow building the snapshot on top of a V8 startup blob#65374codebytere wants to merge 1 commit into
codebytere wants to merge 1 commit into
Conversation
CommonEnvironmentSetup::CreateForSnapshotting() always created the SnapshotCreator without a startup blob, so V8 set up its heap from scratch. That is impossible when the V8 that Node.js is linked against only carries the deserializer (external startup data, as Chromium builds it), and it puts the resulting snapshot on a different read-only heap lineage than isolates the embedder creates from its own blob. Embedders in that situation cannot use the snapshot support at all today. Add SnapshotConfig::base_blob, an optional caller-owned v8::StartupData that is handed to the SnapshotCreator so that V8 deserializes its heap from that blob and Node.js adds its isolate data and contexts on top, the way Blink's context snapshot is built. node_mksnapshot accepts --v8-snapshot-blob=<file> for hosts that build Node.js with such a V8; Node.js's own build never passes it and is unchanged. Consuming the result needs no changes. embedtest can create a plain V8 startup blob and build the embedder snapshot on top of one, and a test round-trips argv through a snapshot built that way. Signed-off-by: Shelley Vohr <shelley.vohr@gmail.com>
Collaborator
|
Review requested:
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #65374 +/- ##
==========================================
- Coverage 90.13% 90.12% -0.02%
==========================================
Files 752 752
Lines 251568 251865 +297
Branches 47270 47364 +94
==========================================
+ Hits 226759 226988 +229
- Misses 16168 16186 +18
- Partials 8641 8691 +50
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
CommonEnvironmentSetup::CreateForSnapshotting()always creates theSnapshotCreatorwithout a startup blob, so V8 sets its heap up from scratch. An embedder whose V8 is built with external startup data (Chromium-style: only the deserializer is linked in) can't do that at all, sonode_mksnapshotand the embedder snapshot API are unusable there without patching Node; and even where it works, a from-scratch snapshot sits on a different read-only-heap lineage than the isolates the embedder creates from its own blob, which V8's shared RO heap doesn't allow in one process.This adds
SnapshotConfig::base_blob, an optional caller-ownedv8::StartupDatathat is passed to theSnapshotCreator(CreateParams::snapshot_blob), so V8 deserializes its heap from that blob and Node adds its isolate data and contexts on top - the same way Blink's context snapshot is produced.node_mksnapshotgrows--v8-snapshot-blob=<file>for hosts that build Node against such a V8. Node's own build never sets it and is unchanged; consuming a snapshot built this way needs no changes (EmbedderSnapshotData/Context::FromSnapshotas today).Contract, documented on the field: the blob is a plain V8 startup blob (what
mksnapshotemits), must outlive the setup, and the result loads only into a process on the same RO lineage - the rule V8 already imposes.embedtestgets--create-v8-startup-blob <file>(aSnapshotCreatorwith just a default context) and--embedder-snapshot-base-blob <file>; the new test builds a plain blob, builds the embedder snapshot on top of it, and round-trips argv through the result liketest-embedding-snapshot-as-filedoes.Tests: new
test-embedding-snapshot-base-blob.js; embedding suite and cctest pass. Locally I also generatednode_snapshot.ccwithnode_mksnapshot --v8-snapshot-blob=<plain blob>, linkednodeagainst it and ran the snapshot/process/worker/vm/bootstrap suites on that binary: all pass.Disclosure: the code, test and this description were written by Claude Code, directed and reviewed by @codebytere.