Skip to content

Commit

Permalink
src: snapshot loaders
Browse files Browse the repository at this point in the history
This runs `lib/internal/bootstrap/loaders.js` before creating
the builtin snapshot and deserialize the loaders from the
snapshot in deserialization mode.

PR-URL: #32984
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Daniel Bevenius <[email protected]>
  • Loading branch information
joyeecheung committed Jul 18, 2020
1 parent 7ecb285 commit 0b8ae5f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 3 deletions.
11 changes: 10 additions & 1 deletion src/node_binding.cc
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
#include "node_binding.h"
#include "node_errors.h"
#include <atomic>
#include "env-inl.h"
#include "node_errors.h"
#include "node_external_reference.h"
#include "node_native_module_env.h"
#include "util.h"

Expand Down Expand Up @@ -676,5 +677,13 @@ void RegisterBuiltinModules() {
#undef V
}

void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
registry->Register(GetLinkedBinding);
registry->Register(GetInternalBinding);
}

} // namespace binding
} // namespace node

NODE_MODULE_EXTERNAL_REFERENCE(binding,
node::binding::RegisterExternalReferences)
5 changes: 4 additions & 1 deletion src/node_external_reference.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ class ExternalReferenceRegistry {
std::vector<intptr_t> external_references_;
};

#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) V(process_object)
#define EXTERNAL_REFERENCE_BINDING_LIST_BASE(V) \
V(binding) \
V(native_module) \
V(process_object)

#define EXTERNAL_REFERENCE_BINDING_LIST(V) \
EXTERNAL_REFERENCE_BINDING_LIST_BASE(V)
Expand Down
9 changes: 8 additions & 1 deletion src/node_main_instance.cc
Original file line number Diff line number Diff line change
Expand Up @@ -259,10 +259,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
14 changes: 14 additions & 0 deletions src/node_native_module_env.cc
Original file line number Diff line number Diff line change
@@ -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 @@ -216,8 +217,21 @@ void NativeModuleEnv::Initialize(Local<Object> target,
target->SetIntegrityLevel(context, IntegrityLevel::kFrozen).FromJust();
}

void NativeModuleEnv::RegisterExternalReferences(
ExternalReferenceRegistry* registry) {
registry->Register(ConfigStringGetter);
registry->Register(ModuleIdsGetter);
registry->Register(GetModuleCategories);
registry->Register(GetCacheUsage);
registry->Register(CompileFunction);
registry->Register(HasCachedBuiltins);
}

} // namespace native_module
} // namespace node

NODE_MODULE_CONTEXT_AWARE_INTERNAL(
native_module, node::native_module::NativeModuleEnv::Initialize)
NODE_MODULE_EXTERNAL_REFERENCE(
native_module,
node::native_module::NativeModuleEnv::RegisterExternalReferences)
2 changes: 2 additions & 0 deletions src/node_native_module_env.h
Original file line number Diff line number Diff line change
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
1 change: 1 addition & 0 deletions tools/snapshot/snapshot_builder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ std::string SnapshotBuilder::Generate(
nullptr,
node::EnvironmentFlags::kDefaultFlags,
{});
env->BootstrapInternalLoaders().ToLocalChecked();
if (per_process::enabled_debug_list.enabled(DebugCategory::MKSNAPSHOT)) {
env->PrintAllBaseObjects();
printf("Environment = %p\n", env);
Expand Down

0 comments on commit 0b8ae5f

Please sign in to comment.