diff options
author | Joyee Cheung <joyeec9h3@gmail.com> | 2020-04-21 23:10:10 +0300 |
---|---|---|
committer | Joyee Cheung <joyeec9h3@gmail.com> | 2020-07-18 06:23:13 +0300 |
commit | 7ecb285842361de721a9d7c7d2a0535170b132dd (patch) | |
tree | 6b9b4c90ec7cfd3c8b9e7cbe41461d1dc1258a74 /src | |
parent | 1faf6f459f220bb67866f12b30626ef7856876ee (diff) |
src: make code cache test work with snapshots
Keep track of snapshotted modules in JS land, and move
bootstrap switches into StartExecution() so that
they are not included into part of the environment-independent
bootstrap process.
PR-URL: https://github.com/nodejs/node/pull/32984
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/env.cc | 21 | ||||
-rw-r--r-- | src/env.h | 4 | ||||
-rw-r--r-- | src/node.cc | 1 | ||||
-rw-r--r-- | src/node_config.cc | 3 | ||||
-rw-r--r-- | src/node_native_module_env.cc | 14 |
5 files changed, 39 insertions, 4 deletions
diff --git a/src/env.cc b/src/env.cc index e30e7d6e1da..1cf37d4fa91 100644 --- a/src/env.cc +++ b/src/env.cc @@ -1208,6 +1208,11 @@ EnvSerializeInfo Environment::Serialize(SnapshotCreator* creator) { EnvSerializeInfo info; Local<Context> ctx = context(); + // Currently all modules are compiled without cache in builtin snapshot + // builder. + info.native_modules = std::vector<std::string>( + native_modules_without_cache.begin(), native_modules_without_cache.end()); + info.async_hooks = async_hooks_.Serialize(ctx, creator); info.immediate_info = immediate_info_.Serialize(ctx, creator); info.tick_info = tick_info_.Serialize(ctx, creator); @@ -1257,11 +1262,24 @@ std::ostream& operator<<(std::ostream& output, return output; } +std::ostream& operator<<(std::ostream& output, + const std::vector<std::string>& vec) { + output << "{\n"; + for (const auto& info : vec) { + output << " \"" << info << "\",\n"; + } + output << "}"; + return output; +} + std::ostream& operator<<(std::ostream& output, const EnvSerializeInfo& i) { output << "{\n" + << "// -- native_modules begins --\n" + << i.native_modules << ",\n" + << "// -- native_modules ends --\n" << "// -- async_hooks begins --\n" << i.async_hooks << ",\n" - << "// -- async_hooks begins --\n" + << "// -- async_hooks ends --\n" << i.tick_info << ", // tick_info\n" << i.immediate_info << ", // immediate_info\n" << "// -- performance_state begins --\n" @@ -1284,6 +1302,7 @@ std::ostream& operator<<(std::ostream& output, const EnvSerializeInfo& i) { void Environment::DeserializeProperties(const EnvSerializeInfo* info) { Local<Context> ctx = context(); + native_modules_in_snapshot = info->native_modules; async_hooks_.Deserialize(ctx); immediate_info_.Deserialize(ctx); tick_info_.Deserialize(ctx); diff --git a/src/env.h b/src/env.h index c6f6ac48154..d475fc78fb9 100644 --- a/src/env.h +++ b/src/env.h @@ -899,6 +899,7 @@ struct PropInfo { }; struct EnvSerializeInfo { + std::vector<std::string> native_modules; AsyncHooks::SerializeInfo async_hooks; TickInfo::SerializeInfo tick_info; ImmediateInfo::SerializeInfo immediate_info; @@ -1086,6 +1087,9 @@ class Environment : public MemoryRetainer { std::set<std::string> native_modules_with_cache; std::set<std::string> native_modules_without_cache; + // This is only filled during deserialization. We use a vector since + // it's only used for tests. + std::vector<std::string> native_modules_in_snapshot; std::unordered_multimap<int, loader::ModuleWrap*> hash_to_module_map; std::unordered_map<uint32_t, loader::ModuleWrap*> id_to_module_map; diff --git a/src/node.cc b/src/node.cc index ce2834448e9..f14ff44be80 100644 --- a/src/node.cc +++ b/src/node.cc @@ -350,6 +350,7 @@ MaybeLocal<Value> Environment::BootstrapNode() { return scope.EscapeMaybe(result); } + // TODO(joyeecheung): skip these in the snapshot building for workers. auto thread_switch_id = is_main_thread() ? "internal/bootstrap/switches/is_main_thread" : "internal/bootstrap/switches/is_not_main_thread"; diff --git a/src/node_config.cc b/src/node_config.cc index 6ee3164a134..2d8ad25bbe9 100644 --- a/src/node_config.cc +++ b/src/node_config.cc @@ -84,9 +84,6 @@ static void Initialize(Local<Object> target, #if defined HAVE_DTRACE || defined HAVE_ETW READONLY_TRUE_PROPERTY(target, "hasDtrace"); #endif - - READONLY_PROPERTY(target, "hasCachedBuiltins", - v8::Boolean::New(isolate, native_module::has_code_cache)); } // InitConfig } // namespace node diff --git a/src/node_native_module_env.cc b/src/node_native_module_env.cc index a3a42a3ec4b..e38529eefae 100644 --- a/src/node_native_module_env.cc +++ b/src/node_native_module_env.cc @@ -94,6 +94,14 @@ void NativeModuleEnv::GetCacheUsage(const FunctionCallbackInfo<Value>& args) { OneByteString(isolate, "compiledWithoutCache"), ToJsSet(context, env->native_modules_without_cache)) .FromJust(); + + result + ->Set(env->context(), + OneByteString(isolate, "compiledInSnapshot"), + ToV8Value(env->context(), env->native_modules_in_snapshot) + .ToLocalChecked()) + .FromJust(); + args.GetReturnValue().Set(result); } @@ -155,6 +163,11 @@ MaybeLocal<Function> NativeModuleEnv::LookupAndCompile( return maybe; } +void HasCachedBuiltins(const FunctionCallbackInfo<Value>& args) { + args.GetReturnValue().Set( + v8::Boolean::New(args.GetIsolate(), has_code_cache)); +} + // TODO(joyeecheung): It is somewhat confusing that Class::Initialize // is used to initialize to the binding, but it is the current convention. // Rename this across the code base to something that makes more sense. @@ -198,6 +211,7 @@ void NativeModuleEnv::Initialize(Local<Object> target, env->SetMethod(target, "getCacheUsage", NativeModuleEnv::GetCacheUsage); env->SetMethod(target, "compileFunction", NativeModuleEnv::CompileFunction); + env->SetMethod(target, "hasCachedBuiltins", HasCachedBuiltins); // internalBinding('native_module') should be frozen target->SetIntegrityLevel(context, IntegrityLevel::kFrozen).FromJust(); } |