Commit efb80afe authored by Andreas Haas's avatar Andreas Haas Committed by V8 LUCI CQ

[wasm] Add flag to disable the wasm native module cache

The native module cache makes it difficult to test deserialization,
because the native module just gets loaded from the cache instead of
deserializing the serialized module. This CL adds a new flag,
--wasm-native-module-cache-enabled, to control whether the native module
cache is enabled or not. The cache gets disabled by handling all modules
like asm.js modules when the cache gets disabled, as the cache is not
used for asm.js.

The name of the flag is positive (i.e.
`enabled` instead of `disabled`) to avoid double negation. The flag is
true by default, and set to false in tests.

R=thibaudm@chromium.org
CC=clemensb@chromium.org

Bug: v8:12964
Change-Id: If2b96a95ccf37f2eb8a868ad1661c3325c1048f6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3703836
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: 's avatarThibaud Michaud <thibaudm@chromium.org>
Cr-Commit-Position: refs/heads/main@{#81132}
parent 8c10f676
......@@ -983,6 +983,8 @@ DEFINE_BOOL(wasm_async_compilation, true,
DEFINE_NEG_IMPLICATION(single_threaded, wasm_async_compilation)
DEFINE_BOOL(wasm_test_streaming, false,
"use streaming compilation instead of async compilation for tests")
DEFINE_BOOL(wasm_native_module_cache_enabled, true,
"enable the native module cache")
DEFINE_UINT(wasm_max_mem_pages, wasm::kV8MaxWasmMemoryPages,
"maximum number of 64KiB memory pages per wasm memory")
DEFINE_UINT(wasm_max_table_size, wasm::kV8MaxWasmTableSize,
......
......@@ -183,6 +183,7 @@ class WeakScriptHandle {
std::shared_ptr<NativeModule> NativeModuleCache::MaybeGetNativeModule(
ModuleOrigin origin, base::Vector<const uint8_t> wire_bytes) {
if (!FLAG_wasm_native_module_cache_enabled) return nullptr;
if (origin != kWasmOrigin) return nullptr;
base::MutexGuard lock(&mutex_);
size_t prefix_hash = PrefixHash(wire_bytes);
......@@ -241,6 +242,7 @@ void NativeModuleCache::StreamingCompilationFailed(size_t prefix_hash) {
std::shared_ptr<NativeModule> NativeModuleCache::Update(
std::shared_ptr<NativeModule> native_module, bool error) {
DCHECK_NOT_NULL(native_module);
if (!FLAG_wasm_native_module_cache_enabled) return native_module;
if (native_module->module()->origin != kWasmOrigin) return native_module;
base::Vector<const uint8_t> wire_bytes = native_module->wire_bytes();
DCHECK(!wire_bytes.empty());
......@@ -273,6 +275,7 @@ std::shared_ptr<NativeModule> NativeModuleCache::Update(
}
void NativeModuleCache::Erase(NativeModule* native_module) {
if (!FLAG_wasm_native_module_cache_enabled) return;
if (native_module->module()->origin != kWasmOrigin) return;
// Happens in some tests where bytes are set directly.
if (native_module->wire_bytes().empty()) return;
......
......@@ -2,7 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax --expose-gc --wasm-dynamic-tiering --liftoff
// Flags: --allow-natives-syntax --wasm-dynamic-tiering --liftoff
// Flags: --no-wasm-native-module-cache-enabled
// Make the test faster:
// Flags: --wasm-tiering-budget=1000
......@@ -41,11 +42,6 @@ function serializeModule() {
};
const serialized_module = serializeModule();
// Do some GCs to make sure the first module got collected and removed from the
// module cache.
gc();
gc();
gc();
(function testSerializedModule() {
print(arguments.callee.name);
......
......@@ -5,7 +5,7 @@
// The test needs --no-liftoff because we can't serialize and deserialize
// Liftoff code.
// Flags: --allow-natives-syntax --wasm-lazy-compilation --expose-gc
// Flags: --no-liftoff
// Flags: --no-liftoff --no-wasm-native-module-cache-enabled
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
......@@ -34,11 +34,6 @@ function serializeModule() {
};
const serialized_module = serializeModule();
// Do some GCs to make sure the first module got collected and removed from the
// module cache.
gc();
gc();
gc();
(function testSerializedModule() {
print(arguments.callee.name);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment