Skip to content

Commit

Permalink
src: snapshot loaders
Browse files Browse the repository at this point in the history
  • Loading branch information
joyeecheung committed Apr 21, 2020
1 parent cae01f6 commit 52d8832
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 2 deletions.
14 changes: 13 additions & 1 deletion src/node_main_instance.cc
Expand Up @@ -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"
Expand Down Expand Up @@ -56,6 +57,10 @@ const std::vector<intptr_t>& 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();
}
Expand Down Expand Up @@ -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;
}

Expand Down
11 changes: 11 additions & 0 deletions 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 {
Expand Down Expand Up @@ -205,6 +206,16 @@ void NativeModuleEnv::Initialize(Local<Object> 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

Expand Down
2 changes: 2 additions & 0 deletions src/node_native_module_env.h
Expand Up @@ -7,13 +7,15 @@

namespace node {
class Environment;
class ExternalReferenceRegistry;

namespace native_module {

extern const bool has_code_cache;

class NativeModuleEnv {
public:
static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
static void Initialize(v8::Local<v8::Object> target,
v8::Local<v8::Value> unused,
v8::Local<v8::Context> context,
Expand Down
3 changes: 2 additions & 1 deletion tools/snapshot/snapshot_builder.cc
Expand Up @@ -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});
Expand All @@ -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);
Expand Down

0 comments on commit 52d8832

Please sign in to comment.