From 40a355a42d4a9444dc753c04c6608dade2f06a23 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 03:13:27 +0200 Subject: Adding upstream version 125.0.1. Signed-off-by: Daniel Baumann --- .../growable-sab-memory-barrier-bytelength.js | 67 ++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 js/src/jit-test/tests/sharedbuf/growable-sab-memory-barrier-bytelength.js (limited to 'js/src/jit-test/tests/sharedbuf/growable-sab-memory-barrier-bytelength.js') diff --git a/js/src/jit-test/tests/sharedbuf/growable-sab-memory-barrier-bytelength.js b/js/src/jit-test/tests/sharedbuf/growable-sab-memory-barrier-bytelength.js new file mode 100644 index 0000000000..c2f27d967c --- /dev/null +++ b/js/src/jit-test/tests/sharedbuf/growable-sab-memory-barrier-bytelength.js @@ -0,0 +1,67 @@ +// |jit-test| --enable-arraybuffer-resizable; skip-if: !ArrayBuffer.prototype.resize||!this.SharedArrayBuffer||helperThreadCount()===0 + +function setup() { + // Shared memory locations: + // + // 0: Lock + // 1: Sleep + // 2: Data + // 3: Unused + + function worker(gsab) { + var ta = new Int32Array(gsab); + + // Notify the main thread that the worker is ready. + Atomics.store(ta, 0, 1); + + // Sleep to give the main thread time to execute and tier-up the loop. + Atomics.wait(ta, 1, 0, 500); + + // Modify the memory read in the loop. + Atomics.store(ta, 2, 1); + + // Sleep again to give the main thread time to execute the loop. + Atomics.wait(ta, 1, 0, 100); + + // Grow the buffer. This modifies the loop condition. + gsab.grow(16); + } + + var gsab = new SharedArrayBuffer(12, {maxByteLength: 16}); + + // Pass |gsab| to the mailbox. + setSharedObject(gsab); + + // Start the worker. + evalInWorker(` + (${worker})(getSharedObject()); + `); + + // Wait until worker is ready. + var ta = new Int32Array(gsab); + while (Atomics.load(ta, 0) === 0); + + return gsab; +} + +function testGrowableSharedArrayBufferByteLength() { + var gsab = setup(); + var ta = new Int32Array(gsab); + var r = 0; + + // |gsab.byteLength| is a seq-cst load, so it must prevent reordering any + // other loads, including unordered loads like |ta[2]|. + while (gsab.byteLength <= 12) { + // |ta[2]| is an unordered load, so it's hoistable by default. + r += ta[2]; + } + + // The memory location is first modified and then the buffer is grown, so we + // must observe reads of the modified memory location before exiting the loop. + assertEq( + r > 0, + true, + "gsab.byteLength acts as a memory barrier, so ta[2] can't be hoisted" + ); +} +testGrowableSharedArrayBufferByteLength(); -- cgit v1.2.3