Skip to content

Commit 5aaf666

Browse files
committed
build: improve embedded code-cache detection
PR-URL: #27311 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 49d3d11 commit 5aaf666

File tree

9 files changed

+21
-8
lines changed

9 files changed

+21
-8
lines changed

‎configure.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,9 @@ def configure_node(o):
10511051
o['variables']['debug_nghttp2'] ='false'
10521052

10531053
o['variables']['node_no_browser_globals'] =b(options.no_browser_globals)
1054-
o['variables']['node_code_cache_path'] ='yes'
1054+
# TODO(refack): fix this when implementing embedded code-cache when cross-compiling.
1055+
ifo['variables']['want_separate_host_toolset'] ==0:
1056+
o['variables']['node_code_cache_path'] ='yes'
10551057
o['variables']['node_shared'] =b(options.shared)
10561058
node_module_version=getmoduleversion.get_version()
10571059

‎lib/internal/bootstrap/node.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,8 @@ Object.defineProperty(process, 'features',{
244244
tls_alpn: hasOpenSSL,
245245
tls_sni: hasOpenSSL,
246246
tls_ocsp: hasOpenSSL,
247-
tls: hasOpenSSL
247+
tls: hasOpenSSL,
248+
cached_builtins: config.hasCachedBuiltins,
248249
}
249250
});
250251

‎src/node_code_cache_stub.cc‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
#include"node_native_module_env.h"
32

43
// This is supposed to be generated by tools/generate_code_cache.js
@@ -7,6 +6,8 @@
76
namespacenode{
87
namespacenative_module{
98

9+
constbool has_code_cache = false;
10+
1011
// The generated source code would insert <std::string, UnionString> pairs
1112
// into NativeModuleLoader::instance.code_cache_.
1213
voidNativeModuleEnv::InitializeCodeCache(){}

‎src/node_config.cc‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include"env-inl.h"
22
#include"node.h"
33
#include"node_i18n.h"
4+
#include"node_native_module_env.h"
45
#include"node_options.h"
56
#include"util-inl.h"
67

@@ -73,11 +74,14 @@ static void Initialize(Local<Object> target,
7374

7475
READONLY_PROPERTY(target,
7576
"bits",
76-
Number::New(env->isolate(), 8 * sizeof(intptr_t)));
77+
Number::New(isolate, 8 * sizeof(intptr_t)));
7778

7879
#if defined HAVE_DTRACE || defined HAVE_ETW
7980
READONLY_TRUE_PROPERTY(target, "hasDtrace");
8081
#endif
82+
83+
READONLY_PROPERTY(target, "hasCachedBuiltins",
84+
v8::Boolean::New(isolate, native_module::has_code_cache));
8185
} // InitConfig
8286

8387
} // namespace node

‎src/node_native_module_env.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ class Environment;
1010

1111
namespacenative_module{
1212

13+
externconstbool has_code_cache;
14+
1315
classNativeModuleEnv{
1416
public:
1517
staticvoidInitialize(v8::Local<v8::Object> target,

‎test/parallel/test-code-cache.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ const loadedModules = process.moduleLoadList
3131

3232
// Cross-compiled binaries do not have code cache, verifies that the builtins
3333
// are all compiled without cache and we are doing the bookkeeping right.
34-
if(process.config.variables.want_separate_host_toolset===1){
34+
if(!process.features.cached_builtins){
3535
console.log('The binary is not configured with code cache');
3636
if(isMainThread){
3737
assert.deepStrictEqual(compiledWithCache,newSet());

‎test/parallel/test-process-features.js‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ assert.deepStrictEqual(keys, new Set([
1313
'tls_alpn',
1414
'tls_sni',
1515
'tls_ocsp',
16-
'tls'
16+
'tls',
17+
'cached_builtins',
1718
]));
1819

1920
for(constkeyofkeys){

‎test/sequential/test-cpu-prof.js‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
// This tests that --cpu-prof, --cpu-prof-dir and --cpu-prof-name works.
44

55
constcommon=require('../common');
6-
if(process.features.debug&&
7-
process.config.variables.node_code_cache_path==='yes'){
6+
if(process.features.debug&&process.features.cached_builtins){
87
// FIXME(joyeecheung): the profiler crashes when code cache
98
// is enabled in debug builds.
109
common.skip('--cpu-prof does not work in debug builds with code cache');

‎tools/code_cache/cache_builder.cc‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ static std::string GenerateCodeCache(
7878
7979
namespace node{
8080
namespace native_module{
81+
82+
const bool has_code_cache = true;
83+
8184
)";
8285

8386
size_t total = 0;

0 commit comments

Comments
(0)