2018-06-18 19:02:57 +02:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
// Flags: --expose-internals
|
2018-10-24 17:24:31 +02:00
|
|
|
// This test verifies that if the binary is compiled with code cache,
|
|
|
|
// and the cache is used when built in modules are compiled.
|
|
|
|
// Otherwise, verifies that no cache is used when compiling builtins.
|
2018-06-18 19:02:57 +02:00
|
|
|
|
2019-01-04 23:02:33 +01:00
|
|
|
const { isMainThread } = require('../common');
|
2018-06-18 19:02:57 +02:00
|
|
|
const assert = require('assert');
|
|
|
|
const {
|
2018-06-27 16:31:01 +02:00
|
|
|
cachableBuiltins,
|
2019-01-15 16:12:21 +01:00
|
|
|
cannotBeRequired
|
2018-06-18 19:02:57 +02:00
|
|
|
} = require('internal/bootstrap/cache');
|
2018-11-03 07:26:32 +01:00
|
|
|
|
|
|
|
const {
|
|
|
|
internalBinding
|
|
|
|
} = require('internal/test/binding');
|
|
|
|
const {
|
2018-11-14 15:38:12 +01:00
|
|
|
getCacheUsage
|
2018-11-03 07:26:32 +01:00
|
|
|
} = internalBinding('native_module');
|
|
|
|
|
|
|
|
for (const key of cachableBuiltins) {
|
|
|
|
if (!isMainThread && key === 'trace_events') {
|
|
|
|
continue; // Cannot load trace_events in workers
|
|
|
|
}
|
|
|
|
require(key);
|
|
|
|
}
|
2018-06-18 19:02:57 +02:00
|
|
|
|
2018-11-14 15:38:12 +01:00
|
|
|
// The computation has to be delayed until we have done loading modules
|
|
|
|
const {
|
|
|
|
compiledWithoutCache,
|
|
|
|
compiledWithCache
|
|
|
|
} = getCacheUsage();
|
|
|
|
|
2018-06-18 19:02:57 +02:00
|
|
|
const loadedModules = process.moduleLoadList
|
|
|
|
.filter((m) => m.startsWith('NativeModule'))
|
|
|
|
.map((m) => m.replace('NativeModule ', ''));
|
|
|
|
|
2018-10-24 17:24:31 +02:00
|
|
|
// The binary is not configured with code cache, verifies that the builtins
|
|
|
|
// are all compiled without cache and we are doing the bookkeeping right.
|
|
|
|
if (process.config.variables.node_code_cache_path === undefined) {
|
2018-11-03 07:26:32 +01:00
|
|
|
console.log('The binary is not configured with code cache');
|
2018-12-03 14:47:57 +01:00
|
|
|
if (isMainThread) {
|
|
|
|
assert.deepStrictEqual(compiledWithCache, new Set());
|
|
|
|
for (const key of loadedModules) {
|
|
|
|
assert(compiledWithoutCache.has(key),
|
|
|
|
`"${key}" should've been compiled without code cache`);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// TODO(joyeecheung): create a list of modules whose cache can be shared
|
|
|
|
// from the main thread to the worker thread and check that their
|
|
|
|
// cache are hit
|
|
|
|
assert.notDeepStrictEqual(compiledWithCache, new Set());
|
2018-11-14 15:38:12 +01:00
|
|
|
}
|
2018-10-24 17:24:31 +02:00
|
|
|
} else {
|
2018-11-03 07:26:32 +01:00
|
|
|
console.log('The binary is configured with code cache');
|
2018-10-24 17:24:31 +02:00
|
|
|
assert.strictEqual(
|
|
|
|
typeof process.config.variables.node_code_cache_path,
|
|
|
|
'string'
|
|
|
|
);
|
|
|
|
|
|
|
|
for (const key of loadedModules) {
|
2019-01-15 16:12:21 +01:00
|
|
|
if (cannotBeRequired.includes(key)) {
|
2018-11-03 07:26:32 +01:00
|
|
|
assert(compiledWithoutCache.has(key),
|
|
|
|
`"${key}" should've been compiled without code cache`);
|
|
|
|
} else {
|
|
|
|
assert(compiledWithCache.has(key),
|
|
|
|
`"${key}" should've been compiled with code cache`);
|
|
|
|
}
|
2018-10-24 17:24:31 +02:00
|
|
|
}
|
2018-06-18 19:02:57 +02:00
|
|
|
}
|