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: 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>
This commit is contained in:
parent
d701667950
commit
bf5dadeef0
29
node.gyp
29
node.gyp
@ -223,6 +223,7 @@
|
|||||||
'deps/acorn/acorn/dist/acorn.js',
|
'deps/acorn/acorn/dist/acorn.js',
|
||||||
'deps/acorn/acorn-walk/dist/walk.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)',
|
'mkcodecache_exec': '<(PRODUCT_DIR)/<(EXECUTABLE_PREFIX)mkcodecache<(EXECUTABLE_SUFFIX)',
|
||||||
'conditions': [
|
'conditions': [
|
||||||
[ 'node_shared=="true"', {
|
[ 'node_shared=="true"', {
|
||||||
@ -430,6 +431,31 @@
|
|||||||
'src/node_code_cache_stub.cc'
|
'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
|
}, # node_core_target_name
|
||||||
{
|
{
|
||||||
@ -1038,6 +1064,7 @@
|
|||||||
'defines': [ 'NODE_WANT_INTERNALS=1' ],
|
'defines': [ 'NODE_WANT_INTERNALS=1' ],
|
||||||
|
|
||||||
'sources': [
|
'sources': [
|
||||||
|
'src/node_snapshot_stub.cc',
|
||||||
'src/node_code_cache_stub.cc',
|
'src/node_code_cache_stub.cc',
|
||||||
'test/cctest/gtest/gtest-all.cc',
|
'test/cctest/gtest/gtest-all.cc',
|
||||||
'test/cctest/gtest/gtest_main.cc',
|
'test/cctest/gtest/gtest_main.cc',
|
||||||
@ -1131,6 +1158,7 @@
|
|||||||
'NODE_WANT_INTERNALS=1'
|
'NODE_WANT_INTERNALS=1'
|
||||||
],
|
],
|
||||||
'sources': [
|
'sources': [
|
||||||
|
'src/node_snapshot_stub.cc',
|
||||||
'src/node_code_cache_stub.cc',
|
'src/node_code_cache_stub.cc',
|
||||||
'tools/code_cache/mkcodecache.cc',
|
'tools/code_cache/mkcodecache.cc',
|
||||||
'tools/code_cache/cache_builder.cc',
|
'tools/code_cache/cache_builder.cc',
|
||||||
@ -1180,6 +1208,7 @@
|
|||||||
'defines': [ 'NODE_WANT_INTERNALS=1' ],
|
'defines': [ 'NODE_WANT_INTERNALS=1' ],
|
||||||
|
|
||||||
'sources': [
|
'sources': [
|
||||||
|
'src/node_snapshot_stub.cc',
|
||||||
'src/node_code_cache_stub.cc',
|
'src/node_code_cache_stub.cc',
|
||||||
'tools/snapshot/node_mksnapshot.cc',
|
'tools/snapshot/node_mksnapshot.cc',
|
||||||
'tools/snapshot/snapshot_builder.cc',
|
'tools/snapshot/snapshot_builder.cc',
|
||||||
|
15
src/node.cc
15
src/node.cc
@ -887,11 +887,24 @@ int Start(int argc, char** argv) {
|
|||||||
|
|
||||||
{
|
{
|
||||||
Isolate::CreateParams params;
|
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(¶ms,
|
NodeMainInstance main_instance(¶ms,
|
||||||
uv_default_loop(),
|
uv_default_loop(),
|
||||||
per_process::v8_platform.Platform(),
|
per_process::v8_platform.Platform(),
|
||||||
result.args,
|
result.args,
|
||||||
result.exec_args);
|
result.exec_args,
|
||||||
|
indexes);
|
||||||
result.exit_code = main_instance.Run();
|
result.exit_code = main_instance.Run();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -175,6 +175,7 @@ std::unique_ptr<Environment> NodeMainInstance::CreateMainEnvironment(
|
|||||||
if (deserialize_mode_) {
|
if (deserialize_mode_) {
|
||||||
SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers);
|
SetIsolateUpForNode(isolate_, IsolateSettingCategories::kErrorHandlers);
|
||||||
}
|
}
|
||||||
|
|
||||||
CHECK(!context.IsEmpty());
|
CHECK(!context.IsEmpty());
|
||||||
Context::Scope context_scope(context);
|
Context::Scope context_scope(context);
|
||||||
|
|
||||||
|
@ -70,6 +70,11 @@ class NodeMainInstance {
|
|||||||
// and the environment creation routine in workers somehow.
|
// and the environment creation routine in workers somehow.
|
||||||
std::unique_ptr<Environment> CreateMainEnvironment(int* exit_code);
|
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:
|
private:
|
||||||
NodeMainInstance(const NodeMainInstance&) = delete;
|
NodeMainInstance(const NodeMainInstance&) = delete;
|
||||||
NodeMainInstance& operator=(const NodeMainInstance&) = delete;
|
NodeMainInstance& operator=(const NodeMainInstance&) = delete;
|
||||||
|
13
src/node_snapshot_stub.cc
Normal file
13
src/node_snapshot_stub.cc
Normal file
@ -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
|
Loading…
x
Reference in New Issue
Block a user