Skip to content

Commit

Permalink
src: enable snapshot with per-isolate data
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
joyeecheung authored and targos committed Apr 27, 2019
1 parent b44323f commit 45d6106
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 1 deletion.
29 changes: 29 additions & 0 deletions node.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@
'deps/acorn/acorn/dist/acorn.js',
'deps/acorn/acorn-walk/dist/walk.js',
],
'node_mksnapshot_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)node_mksnapshot<(EXECUTABLE_SUFFIX)',
'mkcodecache_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)mkcodecache<(EXECUTABLE_SUFFIX)',
'conditions': [
[ 'node_shared=="true"', {
Expand Down Expand Up @@ -430,6 +431,31 @@
'src/node_code_cache_stub.cc'
],
}],
['want_separate_host_toolset==0', {
'dependencies': [
'node_mksnapshot',
],
'actions': [
{
'action_name': 'node_mksnapshot',
'process_outputs_as_sources': 1,
'inputs': [
'<(node_mksnapshot_exec)',
],
'outputs': [
'<(SHARED_INTERMEDIATE_DIR)/node_snapshot.cc',
],
'action': [
'<@(_inputs)',
'<@(_outputs)',
],
},
],
}, {
'sources': [
'src/node_snapshot_stub.cc'
],
}],
],
}, # node_core_target_name
{
Expand Down Expand Up @@ -1038,6 +1064,7 @@
'defines': [ 'NODE_WANT_INTERNALS=1' ],

'sources': [
'src/node_snapshot_stub.cc',
'src/node_code_cache_stub.cc',
'test/cctest/gtest/gtest-all.cc',
'test/cctest/gtest/gtest_main.cc',
Expand Down Expand Up @@ -1131,6 +1158,7 @@
'NODE_WANT_INTERNALS=1'
],
'sources': [
'src/node_snapshot_stub.cc',
'src/node_code_cache_stub.cc',
'tools/code_cache/mkcodecache.cc',
'tools/code_cache/cache_builder.cc',
Expand Down Expand Up @@ -1180,6 +1208,7 @@
'defines': [ 'NODE_WANT_INTERNALS=1' ],

'sources': [
'src/node_snapshot_stub.cc',
'src/node_code_cache_stub.cc',
'tools/snapshot/node_mksnapshot.cc',
'tools/snapshot/snapshot_builder.cc',
Expand Down
15 changes: 14 additions & 1 deletion src/node.cc
Original file line number Diff line number Diff line change
Expand Up @@ -887,11 +887,24 @@ int Start(int argc, char** argv) {

{
Isolate::CreateParams params;
// TODO(joyeecheung): collect external references and set it in
// params.external_references.
std::vector<intptr_t> external_references = {
reinterpret_cast<intptr_t>(nullptr)};
v8::StartupData* blob = NodeMainInstance::GetEmbeddedSnapshotBlob();
const NodeMainInstance::IndexArray* indexes =
NodeMainInstance::GetIsolateDataIndexes();
if (blob != nullptr) {
params.external_references = external_references.data();
params.snapshot_blob = blob;
}

NodeMainInstance main_instance(&params,
uv_default_loop(),
per_process::v8_platform.Platform(),
result.args,
result.exec_args);
result.exec_args,
indexes);
result.exit_code = main_instance.Run();
}

Expand Down
1 change: 1 addition & 0 deletions src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment(
if (deserialize_mode_) {
SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers);
}

CHECK(!context.IsEmpty());
Context::Scope context_scope(context);

Expand Down
5 changes: 5 additions & 0 deletions src/node_main_instance.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ class NodeMainInstance {
// and the environment creation routine in workers somehow.
std::unique_ptr<Environment> CreateMainEnvironment(int* exit_code);

// If nullptr is returned, the binary is not built with embedded
// snapshot.
static const IndexArray* GetIsolateDataIndexes();
static v8::StartupData* GetEmbeddedSnapshotBlob();

private:
NodeMainInstance(const NodeMainInstance&) = delete;
NodeMainInstance& operator=(const NodeMainInstance&) = delete;
Expand Down
13 changes: 13 additions & 0 deletions src/node_snapshot_stub.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "node_main_instance.h"

namespace node {

v8::StartupData* NodeMainInstance::GetEmbeddedSnapshotBlob() {
return nullptr;
}

const NodeMainInstance::IndexArray* NodeMainInstance::GetIsolateDataIndexes() {
return nullptr;
}

} // namespace node

0 comments on commit 45d6106

Please sign in to comment.