Joyee Cheung
37aee80643
build: add --node-snapshot-main configure option
...
This adds a --build-snapshot runtime option which is currently only
supported by the node_mksnapshot binary, and a --node-snapshot-main
configure option that makes use it to run a custom script when
building the embedded snapshot. The idea is to have this experimental
feature in core as a configure-time feature for now, and investigate
the renaming V8 bugs before we make it available to more users via
making it a runtime option.
PR-URL: https://github.com/nodejs/node/pull/42466
Reviewed-By: Darshan Sen <raisinten@gmail.com >
Reviewed-By: Mohammed Keyvanzadeh <mohammadkeyvanzade94@gmail.com >
Reviewed-By: Khaidi Chu <i@2333.moe >
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2022-03-31 19:29:12 +08:00
Joyee Cheung
bfb4ca8e94
bootstrap: use SnapshotData to pass snapshot data around
...
Instead of passing the snapshot blob, the per-isolate data
indices and the EnvSerializeInfo separately, use the aggregate
type Snapshot to carry these around, and refactor
NodeMainInstance so that it owns the v8::Isolate::CreateParams
when it owns its isolate. This also gets rid of the owns_isolate_
and deserialize_mode_ booleans in NodeMainInstance since
NodeMainInstance can compute these by just checking if it has
pointers to the CreateParams or the SnapshotData.
PR-URL: https://github.com/nodejs/node/pull/42360
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Darshan Sen <raisinten@gmail.com >
2022-03-23 20:20:14 +08:00
Joyee Cheung
30e8b5e2a2
tools: refactor snapshot builder
...
This patch:
- Moves the snapshot building code to src/ so that we can reuse it
later when generating custom snapshots from an entry point accepted
by the node binary.
- Create a SnapshotData struct that incorporates all the data useful
for a snapshot blob, including both the V8 data and the Node.js
data.
PR-URL: https://github.com/nodejs/node/pull/38902
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
2021-06-10 14:17:49 +08:00
Joyee Cheung
308ab8ae4d
tools: use PrintCaughtException in the snapshot builder
...
This prints not only the error message but also the error
source line and the stack trace wherever possible.
PR-URL: https://github.com/nodejs/node/pull/38745
Reviewed-By: Chengzhong Wu <legendecas@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com >
2021-05-26 16:22:33 +08:00
Bradley Farias
8d9d8236b7
bootstrap: mksnapshot should show JS error
...
PR-URL: https://github.com/nodejs/node/pull/38174
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
2021-04-13 14:59:32 -05:00
Joyee Cheung
2e769a92ff
src: put (de)serialization code into node_snapshotable.h/cc
...
So that it's easier to find the corresponding code.
PR-URL: https://github.com/nodejs/node/pull/37114
Refs: https://github.com/nodejs/node/pull/36943
Reviewed-By: Juan José Arboleda <soyjuanarbol@gmail.com >
2021-02-05 20:18:47 +08:00
Daniel Bevenius
0a23d65a62
tools: use using-declaration consistently
...
PR-URL: https://github.com/nodejs/node/pull/36245
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
2020-11-27 05:38:56 +01:00
Anna Henningsen
b5490d02d4
tools: add missing uv_setup_argv() calls
...
Refs: https://github.com/nodejs/node/pull/34751
PR-URL: https://github.com/nodejs/node/pull/35491
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
Reviewed-By: Richard Lau <rlau@redhat.com >
Reviewed-By: Tobias Nießen <tniessen@tnie.de >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
2020-10-06 08:27:10 +00:00
Joyee Cheung
7a447bcd54
src: snapshot node
...
This runs `lib/internal/bootstrap/node.js` before creating
the builtin snapshot and deserialize the loaders from the
snapshot in deserialization mode.
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2020-07-18 11:23:21 +08:00
Joyee Cheung
0b8ae5f2cd
src: snapshot loaders
...
This runs `lib/internal/bootstrap/loaders.js` before creating
the builtin snapshot and deserialize the loaders from the
snapshot in deserialization mode.
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2020-07-18 11:23:15 +08:00
Joyee Cheung
1faf6f459f
src: snapshot Environment upon instantiation
...
This includes the initial Environment (without running bootstrap
scripts) into the builtin snapshot
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2020-07-18 11:15:57 +08:00
Joyee Cheung
f04538761f
tools: enable Node.js command line flags in node_mksnapshot
...
Pass the flags down to node_mksnapshot so that we can use them
when generating the snapshot (e.g. to debug or enable V8 flags)
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2020-07-18 11:03:00 +08:00
Joyee Cheung
ef9964f4c1
src: add an ExternalReferenceRegistry class
...
Add an ExternalReferenceRegistry class for registering static
external references.
To register the external JS to C++ references created in a binding
(e.g. when a FunctionTemplate is created):
- Add the binding name (same as the id used for `internalBinding()`
and `NODE_MODULE_CONTEXT_AWARE_INTERNAL`) to
`EXTERNAL_REFERENCE_BINDING_LIST` in `src/node_external_reference.h`.
- In the file where the binding is implemented, create a registration
function to register the static C++ references (e.g. the C++
functions in `v8::FunctionCallback` associated with the function
templates), like this:
```c++
void RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(cpp_func_1);
}
```
- At the end of the file where `NODE_MODULE_CONTEXT_AWARE_INTERNAL` is
also usually called, register the registration function with
```
NODE_MODULE_EXTERNAL_REFERENCE(binding_name,
RegisterExternalReferences);
```
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com >
2020-07-18 11:02:58 +08:00
Joyee Cheung
3a4d916ea7
doc: add documentation about node_mksnapshot and mkcodecache
...
PR-URL: https://github.com/nodejs/node/pull/30773
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com >
2019-12-05 18:57:33 +08:00
David Carlier
94c944d0d5
tools: fix mksnapshot blob wrong freeing operator
...
PR-URL: https://github.com/nodejs/node/pull/29384
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Richard Lau <riclau@uk.ibm.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com >
2019-09-01 23:52:42 -07:00
Ben Noordhuis
5116a6a9b4
tools: make code cache and snapshot deterministic
...
Use a fixed random seed to ensure that the generated sources are
identical across runs.
The final node binary still reseeds itself on start-up so there should
be no security implications caused by predictable random numbers (e.g.,
`Math.random()`, ASLR, the hash seed, etc.)
Fixes: https://github.com/nodejs/node/issues/29108
PR-URL: https://github.com/nodejs/node/pull/29142
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
2019-08-19 18:03:37 -07:00
GauthamBanasandra
cf929c04b0
src, tools: replace raw ptr with smart ptr
...
NodeMainInstance::Create will now returrn
an instance of NodeMainInstance in a
unique_ptr.
PR-URL: https://github.com/nodejs/node/pull/28577
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-07-12 21:59:36 -07:00
Daniel Bevenius
d9da0a9912
tools: remove unused using declarations
...
PR-URL: https://github.com/nodejs/node/pull/28422
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
2019-06-28 05:13:12 +02:00
Joyee Cheung
b6e41f0602
tools: assert that the snapshot can be rehashed in node_mksnapshot
...
PR-URL: https://github.com/nodejs/node/pull/28181
Refs: https://github.com/nodejs/node/pull/27365
Refs: https://github.com/nodejs/node/issues/17058
Reviewed-By: Michaël Zasso <targos@protonmail.com >
Reviewed-By: Gus Caplan <me@gus.host >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Refael Ackermann (רפאל פלחי) <refack@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-06-17 10:02:03 +08:00
Sam Roberts
02f9a0fe27
src: move DiagnosticFilename inlines into a -inl.h
...
DiagnosticFilename's constructor default values use inlines from
env-inl.h, causing the many users of node_internals.h to include
env-inl.h, even if they never use DiagnosticFilename.
PR-URL: https://github.com/nodejs/node/pull/27839
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
2019-05-26 17:09:45 +02:00
Sam Roberts
60b315c064
src: remove env-inl.h from header files
...
Inline headers should only be included into the .cc files that use them.
PR-URL: https://github.com/nodejs/node/pull/27755
Reviewed-By: Luigi Pinca <luigipinca@gmail.com >
Reviewed-By: Rich Trott <rtrott@gmail.com >
Reviewed-By: Colin Ihrig <cjihrig@gmail.com >
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: James M Snell <jasnell@gmail.com >
2019-05-23 08:51:41 -07:00
Joyee Cheung
d5d9c349d3
src: use std::vector<size_t> instead of IndexArray
...
PR-URL: https://github.com/nodejs/node/pull/27321
Refs: https://github.com/nodejs/node/issues/17058
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2019-04-23 11:26:09 +08:00
Joyee Cheung
eb23b176d8
src: enable context snapshot after running per-context scripts
...
At build time, snapshot the context after running per-context scripts
in the main instance, and in the final build, deserialize the
context in the main instance.
This provides a ~5% in the misc/startup benchmark when the instance
is launched within a process that runs test/fixtures/semicolon.js.
PR-URL: https://github.com/nodejs/node/pull/27321
Refs: https://github.com/nodejs/node/issues/17058
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2019-04-23 11:26:07 +08:00
Joyee Cheung
d701667950
tools: implement node_mksnapshot
...
Implements a node_mksnapshot target that generates a snapshot blob
from a Node.js main instance's isolate, and serializes the data blob
with other additional data into a C++ file that can be embedded into
the Node.js binary.
PR-URL: https://github.com/nodejs/node/pull/27321
Refs: https://github.com/nodejs/node/issues/17058
Reviewed-By: Anna Henningsen <anna@addaleax.net >
Reviewed-By: Refael Ackermann <refack@gmail.com >
Reviewed-By: James M Snell <jasnell@gmail.com >
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl >
2019-04-23 11:26:01 +08:00