Skip to content

Commit 45d6106

Browse files
joyeecheungtargos
authored andcommitted
src: enable snapshot with per-isolate data
Enable serializing the isolate from an isolate snapshot generated by node_mksnapshot with per-isolate data. PR-URL: #27321 Refs: #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>
1 parent b44323f commit 45d6106

File tree

5 files changed

+62
-1
lines changed

5 files changed

+62
-1
lines changed

node.gyp

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@
223223
'deps/acorn/acorn/dist/acorn.js',
224224
'deps/acorn/acorn-walk/dist/walk.js',
225225
],
226+
'node_mksnapshot_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_mksnapshot<(EXECUTABLE_SUFFIX)',
226227
'mkcodecache_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)mkcodecache<(EXECUTABLE_SUFFIX)',
227228
'conditions': [
228229
[ 'node_shared=="true"', {
@@ -430,6 +431,31 @@
430431
'src/node_code_cache_stub.cc'
431432
],
432433
}],
434+
['want_separate_host_toolset==0', {
435+
'dependencies': [
436+
'node_mksnapshot',
437+
],
438+
'actions': [
439+
{
440+
'action_name': 'node_mksnapshot',
441+
'process_outputs_as_sources': 1,
442+
'inputs': [
443+
'<(node_mksnapshot_exec)',
444+
],
445+
'outputs': [
446+
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
447+
],
448+
'action': [
449+
'<@(_inputs)',
450+
'<@(_outputs)',
451+
],
452+
},
453+
],
454+
}, {
455+
'sources': [
456+
'src/node_snapshot_stub.cc'
457+
],
458+
}],
433459
],
434460
}, # node_core_target_name
435461
{
@@ -1038,6 +1064,7 @@
10381064
'defines': [ 'NODE_WANT_INTERNALS=1' ],
10391065

10401066
'sources': [
1067+
'src/node_snapshot_stub.cc',
10411068
'src/node_code_cache_stub.cc',
10421069
'test/cctest/gtest/gtest-all.cc',
10431070
'test/cctest/gtest/gtest_main.cc',
@@ -1131,6 +1158,7 @@
11311158
'NODE_WANT_INTERNALS=1'
11321159
],
11331160
'sources': [
1161+
'src/node_snapshot_stub.cc',
11341162
'src/node_code_cache_stub.cc',
11351163
'tools/code_cache/mkcodecache.cc',
11361164
'tools/code_cache/cache_builder.cc',
@@ -1180,6 +1208,7 @@
11801208
'defines': [ 'NODE_WANT_INTERNALS=1' ],
11811209

11821210
'sources': [
1211+
'src/node_snapshot_stub.cc',
11831212
'src/node_code_cache_stub.cc',
11841213
'tools/snapshot/node_mksnapshot.cc',
11851214
'tools/snapshot/snapshot_builder.cc',

src/node.cc

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -887,11 +887,24 @@ int Start(int argc, char** argv) {
887887

888888
{
889889
Isolate::CreateParams params;
890+
// TODO(joyeecheung): collect external references and set it in
891+
// params.external_references.
892+
std::vector<intptr_t> external_references = {
893+
reinterpret_cast<intptr_t>(nullptr)};
894+
v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob();
895+
const NodeMainInstance::IndexArray* indexes =
896+
NodeMainInstance::GetIsolateDataIndexes();
897+
if (blob != nullptr) {
898+
params.external_references = external_references.data();
899+
params.snapshot_blob = blob;
900+
}
901+
890902
NodeMainInstance main_instance(&params,
891903
uv_default_loop(),
892904
per_process::v8_platform.Platform(),
893905
result.args,
894-
result.exec_args);
906+
result.exec_args,
907+
indexes);
895908
result.exit_code = main_instance.Run();
896909
}
897910

src/node_main_instance.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment(
175175
if (deserialize_mode_) {
176176
SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers);
177177
}
178+
178179
CHECK(!context.IsEmpty());
179180
Context::Scope context_scope(context);
180181

src/node_main_instance.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ class NodeMainInstance {
7070
// and the environment creation routine in workers somehow.
7171
std::unique_ptr<Environment> CreateMainEnvironment(int* exit_code);
7272

73+
// If nullptr is returned, the binary is not built with embedded
74+
// snapshot.
75+
static const IndexArray* GetIsolateDataIndexes();
76+
static v8::StartupData* GetEmbeddedSnapshotBlob();
77+
7378
private:
7479
NodeMainInstance(const NodeMainInstance&) = delete;
7580
NodeMainInstance& operator=(const NodeMainInstance&) = delete;

src/node_snapshot_stub.cc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#include "node_main_instance.h"
2+
3+
namespace node {
4+
5+
v8::StartupData* NodeMainInstance::GetEmbeddedSnapshotBlob() {
6+
return nullptr;
7+
}
8+
9+
const NodeMainInstance::IndexArray* NodeMainInstance::GetIsolateDataIndexes() {
10+
return nullptr;
11+
}
12+
13+
} // namespace node

0 commit comments

Comments
 (0)