v8/test/mjsunit/wasm/worker-running-empty-loop-interruptible.js
Clemens Backes 43232bf024 [wasm] Fix interrupt of empty loop
This includes two fixes:
1. For dynamic tiering, the budget must always be reduced when jumping
   backwards, otherwise we might never trigger tier up, which makes the
   loop non-interruptible (because the tier-up check replaces the stack
   check).
2. The d8 worker implementation also needs to terminate the isolate via
   an interrupt, in addition to scheduling a task, because the worker
   might never return to the event queue.

This CL also fixes one of the failure modes of the inspector fuzzer
(see https://crbug.com/1180018).

R=jkummerow@chromium.org, marja@chromium.org

Bug: v8:12767, chromium:1180018

Cq-Include-Trybots: luci.v8.try:v8_linux64_tsan_rel_ng
Change-Id: Ia01d1725fc14931d2ea54c4769c4ee93f866ed63
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3568470
Reviewed-by: Jakob Kummerow <jkummerow@chromium.org>
Reviewed-by: Marja Hölttä <marja@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#79773}
2022-04-05 10:55:04 +00:00

33 lines
1.0 KiB
JavaScript

// Copyright 2022 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.
d8.file.execute('test/mjsunit/wasm/wasm-module-builder.js');
const builder = new WasmModuleBuilder();
// void main() { for (;;) {} }
builder.addFunction('main', kSig_v_v).addBody([
kExprLoop, kWasmVoid, kExprBr, 0, kExprEnd
]).exportFunc();
const module = builder.toModule();
function workerCode() {
onmessage = function(module) {
print('[worker] Creating instance.');
let instance = new WebAssembly.Instance(module);
print('[worker] Reporting start.');
postMessage('start');
print('[worker] Running main.');
instance.exports.main();
};
}
print('[main] Starting worker.');
const worker = new Worker(workerCode, {type: 'function'});
print('[main] Sending module.');
worker.postMessage(module);
assertEquals('start', worker.getMessage());
print('[main] Terminating worker and waiting for it to finish.');
worker.terminateAndWait();
print('[main] All done.');