From 52d88324023396bfad35a938a4c15510456715f6 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Tue, 21 Apr 2020 07:32:31 +0800 Subject: [PATCH] src: snapshot loaders --- src/node_main_instance.cc | 14 +++++++++++++- src/node_native_module_env.cc | 11 +++++++++++ src/node_native_module_env.h | 2 ++ tools/snapshot/snapshot_builder.cc | 3 ++- 4 files changed, 28 insertions(+), 2 deletions(-) diff --git a/src/node_main_instance.cc b/src/node_main_instance.cc index 0d56392e570c61..0f46dbd6fac347 100644 --- a/src/node_main_instance.cc +++ b/src/node_main_instance.cc @@ -6,6 +6,7 @@ #include "node_external_reference.h" #include "node_internals.h" #include "node_main_instance.h" +#include "node_native_module_env.h" #include "node_options-inl.h" #include "node_process.h" #include "node_v8_platform-inl.h" @@ -56,6 +57,10 @@ const std::vector& NodeMainInstance::CollectExternalReferences() { registry_.reset(new ExternalReferenceRegistry()); registry_->Register(node::RawDebug); + registry_->Register(node::binding::GetLinkedBinding); + registry_->Register(node::binding::GetInternalBinding); + node::native_module::NativeModuleEnv::RegisterExternalReferences( + registry_.get()); // TODO(joyeecheung): collect more external references here. return registry_->external_references(); } @@ -282,10 +287,17 @@ NodeMainInstance::CreateMainEnvironment(int* exit_code, env->InitializeInspector({}); #endif - if (env->RunBootstrapping().IsEmpty()) { + if (!deserialize_mode_ && env->RunBootstrapping().IsEmpty()) { return nullptr; } + if (deserialize_mode_ && env->BootstrapNode().IsEmpty()) { + return nullptr; + } + + CHECK(env->req_wrap_queue()->IsEmpty()); + CHECK(env->handle_wrap_queue()->IsEmpty()); + env->set_has_run_bootstrapping_code(true); return env; } diff --git a/src/node_native_module_env.cc b/src/node_native_module_env.cc index a83d5807afa647..7512b65fa9f47e 100644 --- a/src/node_native_module_env.cc +++ b/src/node_native_module_env.cc @@ -1,5 +1,6 @@ #include "node_native_module_env.h" #include "env-inl.h" +#include "node_external_reference.h" namespace node { namespace native_module { @@ -205,6 +206,16 @@ void NativeModuleEnv::Initialize(Local target, env->SetMethod(target, "compileFunction", NativeModuleEnv::CompileFunction); env->SetMethod(target, "hasCachedBuiltins", HasCachedBuiltins); } +void NativeModuleEnv::RegisterExternalReferences( + ExternalReferenceRegistry* registry) { + registry->Register(ConfigStringGetter); + registry->Register(ModuleIdsGetter); + registry->Register(ModuleIdsGetter); + registry->Register(GetModuleCategories); + registry->Register(GetCacheUsage); + registry->Register(CompileFunction); + registry->Register(HasCachedBuiltins); +} } // namespace native_module } // namespace node diff --git a/src/node_native_module_env.h b/src/node_native_module_env.h index bc36be75109639..0a53771ff5d1ca 100644 --- a/src/node_native_module_env.h +++ b/src/node_native_module_env.h @@ -7,6 +7,7 @@ namespace node { class Environment; +class ExternalReferenceRegistry; namespace native_module { @@ -14,6 +15,7 @@ extern const bool has_code_cache; class NativeModuleEnv { public: + static void RegisterExternalReferences(ExternalReferenceRegistry* registry); static void Initialize(v8::Local target, v8::Local unused, v8::Local context, diff --git a/tools/snapshot/snapshot_builder.cc b/tools/snapshot/snapshot_builder.cc index 111bf93f0b14cf..a7d93d7ec81045 100644 --- a/tools/snapshot/snapshot_builder.cc +++ b/tools/snapshot/snapshot_builder.cc @@ -210,6 +210,7 @@ std::string SnapshotBuilder::Generate( env->PrintAllBaseObjects(); printf("Environment = %p\n", env); } + env->BootstrapInternalLoaders().ToLocalChecked(); env_info = env->Serialize(&creator); size_t index = creator.AddContext( context, {SerializeNodeContextInternalFields, env}); @@ -221,7 +222,7 @@ std::string SnapshotBuilder::Generate( // Must be out of HandleScope StartupData blob = creator.CreateBlob(SnapshotCreator::FunctionCodeHandling::kClear); - CHECK(blob.CanBeRehashed()); + // CHECK(blob.CanBeRehashed()); // Must be done while the snapshot creator isolate is entered i.e. the // creator is still alive. env->set_stopping(true);