v8/test/mjsunit/wasm/enter-debug-state.js
Andreas Haas 37e5a28add Reland: "[wasm] Compile debug code lazily"
Three issues were fixed:
* In debug state, only publish debug code.
* When entering debugging in an isolate, only delete the code of
  those NativeModules that aren't in debug state already.
* When async compilation finishes, only throw away code if the debug
  state changed during compilation.

Original message:

Currently V8 recompiles all functions of a WebAssembly module when a
debugging session starts. This is outdated behavior and
causes OOMs for developers. With this CL all compiled code just gets
removed when a debugging session starts, and debugging code gets
compiled lazily.

This behavior may lead to small delays whenever a new function gets
entered by the debugger. However, developers are used to debugging code
being slightly slower, and the small delays should be in the order of
few milliseconds. On the other hand, debug modules can be big,
sometimes even more than 1'000'000 functions, and developers reported
OOMs when debugging.

R=clemensb@chromium.org

Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel
Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_isolates_rel
Bug: v8:13541, chromium:1372621, v8:13224
Change-Id: Ie27388a287cd16a67a483e14fc22c2ab4180962e
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4079190
Reviewed-by: Clemens Backes <clemensb@chromium.org>
Commit-Queue: Andreas Haas <ahaas@chromium.org>
Reviewed-by: Kim-Anh Tran <kimanh@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84873}
2022-12-15 14:59:13 +00:00

53 lines
1.4 KiB
JavaScript

// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const num_functions = 200;
function create_builder(delta = 0) {
const builder = new WasmModuleBuilder();
for (let i = 0; i < num_functions; ++i) {
builder.addFunction('f' + i, kSig_i_v)
.addBody(wasmI32Const(i + delta))
.exportFunc();
}
return builder;
}
function checkForDebugCode(instance) {
for (let i = 0; i < num_functions; ++i) {
// Call the function once because of lazy compilation.
instance.exports['f' + i]();
assertTrue(%IsWasmDebugFunction(instance.exports['f' + i]));
}
}
function check(instance) {
%WasmEnterDebugging();
checkForDebugCode(instance);
for (let i = 0; i < num_functions; ++i) {
%WasmTierUpFunction(instance, i);
}
checkForDebugCode(instance);
}
(function testTierDownToLiftoff() {
print(arguments.callee.name);
const instance = create_builder().instantiate();
check(instance);
})();
// Use slightly different module for this test to avoid sharing native module.
async function testTierDownToLiftoffAsync() {
print(arguments.callee.name);
const instance = await create_builder(num_functions).asyncInstantiate();
check(instance);
}
assertPromiseResult(testTierDownToLiftoffAsync());