| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent cc90d11 commit 27bed94
10 files changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -555,6 +555,7 @@ | |||
| 555 | 555 | 'src/node_revert.h', | |
| 556 | 556 | 'src/node_root_certs.h', | |
| 557 | 557 | 'src/node_snapshotable.h', | |
| 558 | + 'src/node_snapshot_builder.h', | ||
| 558 | 559 | 'src/node_sockaddr.h', | |
| 559 | 560 | 'src/node_sockaddr-inl.h', | |
| 560 | 561 | 'src/node_stat_watcher.h', | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -25,8 +25,8 @@ | |||
| 25 | 25 | ||
| 26 | 26 | #include "debug_utils-inl.h" | |
| 27 | 27 | #include "env-inl.h" | |
| 28 | - #include "memory_tracker-inl.h" | ||
| 29 | 28 | #include "histogram-inl.h" | |
| 29 | + #include "memory_tracker-inl.h" | ||
| 30 | 30 | #include "node_binding.h" | |
| 31 | 31 | #include "node_errors.h" | |
| 32 | 32 | #include "node_internals.h" | |
@@ -38,6 +38,7 @@ | |||
| 38 | 38 | #include "node_process-inl.h" | |
| 39 | 39 | #include "node_report.h" | |
| 40 | 40 | #include "node_revert.h" | |
| 41 | + #include "node_snapshot_builder.h" | ||
| 41 | 42 | #include "node_v8_platform-inl.h" | |
| 42 | 43 | #include "node_version.h" | |
| 43 | 44 | ||
@@ -1158,7 +1159,7 @@ int Start(int argc, char** argv) { | |||
| 1158 | 1159 | bool use_node_snapshot = | |
| 1159 | 1160 | per_process::cli_options->per_isolate->node_snapshot; | |
| 1160 | 1161 | const SnapshotData* snapshot_data = | |
| 1161 | - use_node_snapshot ? NodeMainInstance::GetEmbeddedSnapshotData() | ||
| 1162 | + use_node_snapshot ? SnapshotBuilder::GetEmbeddedSnapshotData() | ||
| 1162 | 1163 | : nullptr; | |
| 1163 | 1164 | uv_loop_configure(uv_default_loop(), UV_METRICS_IDLE_TIME); | |
| 1164 | 1165 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,9 +7,11 @@ | |||
| 7 | 7 | namespace node { | |
| 8 | 8 | ||
| 9 | 9 | const std::vector<intptr_t>& ExternalReferenceRegistry::external_references() { | |
| 10 | - CHECK(!is_finalized_); | ||
| 11 | - external_references_.push_back(reinterpret_cast<intptr_t>(nullptr)); | ||
| 12 | - is_finalized_ = true; | ||
| 10 | + if (!is_finalized_) { | ||
| 11 | + external_references_.push_back(reinterpret_cast<intptr_t>(nullptr)); | ||
| 12 | + is_finalized_ = true; | ||
| 13 | + } | ||
| 14 | + | ||
| 13 | 15 | return external_references_; | |
| 14 | 16 | } | |
| 15 | 17 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -4,6 +4,7 @@ | |||
| 4 | 4 | #include "node_external_reference.h" | |
| 5 | 5 | #include "node_internals.h" | |
| 6 | 6 | #include "node_options-inl.h" | |
| 7 | + #include "node_snapshot_builder.h" | ||
| 7 | 8 | #include "node_snapshotable.h" | |
| 8 | 9 | #include "node_v8_platform-inl.h" | |
| 9 | 10 | #include "util-inl.h" | |
@@ -23,8 +24,6 @@ using v8::Isolate; | |||
| 23 | 24 | using v8::Local; | |
| 24 | 25 | using v8::Locker; | |
| 25 | 26 | ||
| 26 | - std::unique_ptr<ExternalReferenceRegistry> NodeMainInstance::registry_ = | ||
| 27 | - nullptr; | ||
| 28 | 27 | NodeMainInstance::NodeMainInstance(Isolate* isolate, | |
| 29 | 28 | uv_loop_t* event_loop, | |
| 30 | 29 | MultiIsolatePlatform* platform, | |
@@ -43,13 +42,6 @@ NodeMainInstance::NodeMainInstance(Isolate* isolate, | |||
| 43 | 42 | SetIsolateMiscHandlers(isolate_, {}); | |
| 44 | 43 | } | |
| 45 | 44 | ||
| 46 | - const std::vector<intptr_t>& NodeMainInstance::CollectExternalReferences() { | ||
| 47 | - // Cannot be called more than once. | ||
| 48 | - CHECK_NULL(registry_); | ||
| 49 | - registry_.reset(new ExternalReferenceRegistry()); | ||
| 50 | - return registry_->external_references(); | ||
| 51 | - } | ||
| 52 | - | ||
| 53 | 45 | std::unique_ptr<NodeMainInstance> NodeMainInstance::Create( | |
| 54 | 46 | Isolate* isolate, | |
| 55 | 47 | uv_loop_t* event_loop, | |
@@ -75,13 +67,8 @@ NodeMainInstance::NodeMainInstance(const SnapshotData* snapshot_data, | |||
| 75 | 67 | snapshot_data_(snapshot_data) { | |
| 76 | 68 | isolate_params_->array_buffer_allocator = array_buffer_allocator_.get(); | |
| 77 | 69 | if (snapshot_data != nullptr) { | |
| 78 | - // TODO(joyeecheung): collect external references and set it in | ||
| 79 | - // params.external_references. | ||
| 80 | - const std::vector<intptr_t>& external_references = | ||
| 81 | - CollectExternalReferences(); | ||
| 82 | - isolate_params_->external_references = external_references.data(); | ||
| 83 | - isolate_params_->snapshot_blob = | ||
| 84 | - const_cast<v8::StartupData*>(&(snapshot_data->blob)); | ||
| 70 | + SnapshotBuilder::InitializeIsolateParams(snapshot_data, | ||
| 71 | + isolate_params_.get()); | ||
| 85 | 72 | } | |
| 86 | 73 | ||
| 87 | 74 | isolate_ = Isolate::Allocate(); | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -65,11 +65,6 @@ class NodeMainInstance { | |||
| 65 | 65 | DeleteFnPtr<Environment, FreeEnvironment> CreateMainEnvironment( | |
| 66 | 66 | int* exit_code); | |
| 67 | 67 | ||
| 68 | - // If nullptr is returned, the binary is not built with embedded | ||
| 69 | - // snapshot. | ||
| 70 | - static const SnapshotData* GetEmbeddedSnapshotData(); | ||
| 71 | - static const std::vector<intptr_t>& CollectExternalReferences(); | ||
| 72 | - | ||
| 73 | 68 | static const size_t kNodeContextIndex = 0; | |
| 74 | 69 | NodeMainInstance(const NodeMainInstance&) = delete; | |
| 75 | 70 | NodeMainInstance& operator=(const NodeMainInstance&) = delete; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -0,0 +1,43 @@ | |||
| 1 | + | ||
| 2 | + #ifndef SRC_NODE_SNAPSHOT_BUILDER_H_ | ||
| 3 | + #define SRC_NODE_SNAPSHOT_BUILDER_H_ | ||
| 4 | + | ||
| 5 | + #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
| 6 | + | ||
| 7 | + #include <cstdint> | ||
| 8 | + #include "node_mutex.h" | ||
| 9 | + #include "v8.h" | ||
| 10 | + | ||
| 11 | + namespace node { | ||
| 12 | + | ||
| 13 | + class ExternalReferenceRegistry; | ||
| 14 | + struct SnapshotData; | ||
| 15 | + | ||
| 16 | + class SnapshotBuilder { | ||
| 17 | + public: | ||
| 18 | + static std::string Generate(const std::vector<std::string> args, | ||
| 19 | + const std::vector<std::string> exec_args); | ||
| 20 | + | ||
| 21 | + // Generate the snapshot into out. | ||
| 22 | + static void Generate(SnapshotData* out, | ||
| 23 | + const std::vector<std::string> args, | ||
| 24 | + const std::vector<std::string> exec_args); | ||
| 25 | + | ||
| 26 | + // If nullptr is returned, the binary is not built with embedded | ||
| 27 | + // snapshot. | ||
| 28 | + static const SnapshotData* GetEmbeddedSnapshotData(); | ||
| 29 | + static void InitializeIsolateParams(const SnapshotData* data, | ||
| 30 | + v8::Isolate::CreateParams* params); | ||
| 31 | + | ||
| 32 | + private: | ||
| 33 | + // Used to synchronize access to the snapshot data | ||
| 34 | + static Mutex snapshot_data_mutex_; | ||
| 35 | + static const std::vector<intptr_t>& CollectExternalReferences(); | ||
| 36 | + | ||
| 37 | + static std::unique_ptr<ExternalReferenceRegistry> registry_; | ||
| 38 | + }; | ||
| 39 | + } // namespace node | ||
| 40 | + | ||
| 41 | + #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | ||
| 42 | + | ||
| 43 | + #endif // SRC_NODE_SNAPSHOT_BUILDER_H_ | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -2,11 +2,11 @@ | |||
| 2 | 2 | // NODE_WANT_INTERNALS, so we define it here manually. | |
| 3 | 3 | #define NODE_WANT_INTERNALS 1 | |
| 4 | 4 | ||
| 5 | - #include "node_main_instance.h" | ||
| 5 | + #include "node_snapshot_builder.h" | ||
| 6 | 6 | ||
| 7 | 7 | namespace node { | |
| 8 | 8 | ||
| 9 | - const SnapshotData* NodeMainInstance::GetEmbeddedSnapshotData() { | ||
| 9 | + const SnapshotData* SnapshotBuilder::GetEmbeddedSnapshotData() { | ||
| 10 | 10 | return nullptr; | |
| 11 | 11 | } | |
| 12 | 12 | ||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ | |||
| 12 | 12 | #include "node_internals.h" | |
| 13 | 13 | #include "node_main_instance.h" | |
| 14 | 14 | #include "node_process.h" | |
| 15 | + #include "node_snapshot_builder.h" | ||
| 15 | 16 | #include "node_v8.h" | |
| 16 | 17 | #include "node_v8_platform-inl.h" | |
| 17 | 18 | ||
@@ -49,7 +50,7 @@ std::string FormatBlob(SnapshotData* data) { | |||
| 49 | 50 | ||
| 50 | 51 | ss << R"(#include <cstddef> | |
| 51 | 52 | #include "env.h" | |
| 52 | - #include "node_main_instance.h" | ||
| 53 | + #include "node_snapshot_builder.h" | ||
| 53 | 54 | #include "v8.h" | |
| 54 | 55 | ||
| 55 | 56 | // This file is generated by tools/snapshot. Do not edit. | |
@@ -78,11 +79,12 @@ SnapshotData snapshot_data { | |||
| 78 | 79 | // -- isolate_data_indices ends -- | |
| 79 | 80 | // -- env_info begins -- | |
| 80 | 81 | )" << data->env_info | |
| 81 | - << R"( | ||
| 82 | + << R"( | ||
| 82 | 83 | // -- env_info ends -- | |
| 83 | 84 | }; | |
| 84 | 85 | ||
| 85 | - const SnapshotData* NodeMainInstance::GetEmbeddedSnapshotData() { | ||
| 86 | + const SnapshotData* SnapshotBuilder::GetEmbeddedSnapshotData() { | ||
| 87 | + Mutex::ScopedLock lock(snapshot_data_mutex_); | ||
| 86 | 88 | return &snapshot_data; | |
| 87 | 89 | } | |
| 88 | 90 | } // namespace node | |
@@ -91,6 +93,19 @@ const SnapshotData* NodeMainInstance::GetEmbeddedSnapshotData() { | |||
| 91 | 93 | return ss.str(); | |
| 92 | 94 | } | |
| 93 | 95 | ||
| 96 | + Mutex SnapshotBuilder::snapshot_data_mutex_; | ||
| 97 | + | ||
| 98 | + const std::vector<intptr_t>& SnapshotBuilder::CollectExternalReferences() { | ||
| 99 | + static auto registry = std::make_unique<ExternalReferenceRegistry>(); | ||
| 100 | + return registry->external_references(); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + void SnapshotBuilder::InitializeIsolateParams(const SnapshotData* data, | ||
| 104 | + Isolate::CreateParams* params) { | ||
| 105 | + params->external_references = CollectExternalReferences().data(); | ||
| 106 | + params->snapshot_blob = const_cast<v8::StartupData*>(&(data->blob)); | ||
| 107 | + } | ||
| 108 | + | ||
| 94 | 109 | void SnapshotBuilder::Generate(SnapshotData* out, | |
| 95 | 110 | const std::vector<std::string> args, | |
| 96 | 111 | const std::vector<std::string> exec_args) { | |
@@ -104,7 +119,7 @@ void SnapshotBuilder::Generate(SnapshotData* out, | |||
| 104 | 119 | ||
| 105 | 120 | { | |
| 106 | 121 | const std::vector<intptr_t>& external_references = | |
| 107 | - NodeMainInstance::CollectExternalReferences(); | ||
| 122 | + CollectExternalReferences(); | ||
| 108 | 123 | SnapshotCreator creator(isolate, external_references.data()); | |
| 109 | 124 | Environment* env; | |
| 110 | 125 | { | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -12,6 +12,7 @@ namespace node { | |||
| 12 | 12 | class Environment; | |
| 13 | 13 | struct EnvSerializeInfo; | |
| 14 | 14 | struct SnapshotData; | |
| 15 | + class ExternalReferenceRegistry; | ||
| 15 | 16 | ||
| 16 | 17 | #define SERIALIZABLE_OBJECT_TYPES(V) \ | |
| 17 | 18 | V(fs_binding_data, fs::BindingData) \ | |
@@ -122,17 +123,6 @@ void SerializeBindingData(Environment* env, | |||
| 122 | 123 | EnvSerializeInfo* info); | |
| 123 | 124 | ||
| 124 | 125 | bool IsSnapshotableType(FastStringKey key); | |
| 125 | - | ||
| 126 | - class SnapshotBuilder { | ||
| 127 | - public: | ||
| 128 | - static std::string Generate(const std::vector<std::string> args, | ||
| 129 | - const std::vector<std::string> exec_args); | ||
| 130 | - | ||
| 131 | - // Generate the snapshot into out. | ||
| 132 | - static void Generate(SnapshotData* out, | ||
| 133 | - const std::vector<std::string> args, | ||
| 134 | - const std::vector<std::string> exec_args); | ||
| 135 | - }; | ||
| 136 | 126 | } // namespace node | |
| 137 | 127 | ||
| 138 | 128 | #endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -7,7 +7,7 @@ | |||
| 7 | 7 | ||
| 8 | 8 | #include "libplatform/libplatform.h" | |
| 9 | 9 | #include "node_internals.h" | |
| 10 | - #include "node_snapshotable.h" | ||
| 10 | + #include "node_snapshot_builder.h" | ||
| 11 | 11 | #include "util-inl.h" | |
| 12 | 12 | #include "v8.h" | |
| 13 | 13 | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments