From 5c5dd5b28691f722642ebd4d0147242f13ee777b Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Tue, 26 Jun 2018 14:40:00 -0400 Subject: [PATCH] Atomics: ensure all ArrayBuffer & SharedArrayBuffer sizes are uniform --- .../wait/non-int32-typedarray-throws.js | 10 +++---- .../wait/non-shared-bufferdata-throws.js | 2 +- .../bigint/non-bigint64-typedarray-throws.js | 2 +- .../bigint/non-shared-bufferdata-throws.js | 2 +- .../count-defaults-to-infinity-missing.js | 26 ++++++++++++------- .../count-defaults-to-infinity-undefined.js | 25 +++++++++++------- .../wake/non-int32-typedarray-throws.js | 10 +++---- .../wake/non-shared-bufferdata-throws.js | 2 +- ...hared-bufferdatate-non-shared-int-views.js | 2 +- .../Atomics/wake/non-shared-int-views.js | 2 +- 10 files changed, 49 insertions(+), 34 deletions(-) diff --git a/test/built-ins/Atomics/wait/non-int32-typedarray-throws.js b/test/built-ins/Atomics/wait/non-int32-typedarray-throws.js index b85963ef59..b0de7bcef9 100644 --- a/test/built-ins/Atomics/wait/non-int32-typedarray-throws.js +++ b/test/built-ins/Atomics/wait/non-int32-typedarray-throws.js @@ -23,21 +23,21 @@ const poisoned = { assert.throws(TypeError, function() { const view = new Float64Array( - new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * 8) ); Atomics.wait(view, poisoned, poisoned, poisoned); }, 'Float64Array'); assert.throws(TypeError, function() { const view = new Float32Array( - new SharedArrayBuffer(Float32Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Float32Array.BYTES_PER_ELEMENT * 4) ); Atomics.wait(view, poisoned, poisoned, poisoned); }, 'Float32Array'); assert.throws(TypeError, function() { const view = new Int16Array( - new SharedArrayBuffer(Int16Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Int16Array.BYTES_PER_ELEMENT * 2) ); Atomics.wait(view, poisoned, poisoned, poisoned); }, 'Int16Array'); @@ -51,14 +51,14 @@ assert.throws(TypeError, function() { assert.throws(TypeError, function() { const view = new Uint32Array( - new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT * 4) ); Atomics.wait(view, poisoned, poisoned, poisoned); }, 'Uint32Array'); assert.throws(TypeError, function() { const view = new Uint16Array( - new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * 2) ); Atomics.wait(view, poisoned, poisoned, poisoned); }, 'Uint16Array'); diff --git a/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js b/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js index 5056a28edb..164af59e2b 100644 --- a/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js +++ b/test/built-ins/Atomics/wait/non-shared-bufferdata-throws.js @@ -16,7 +16,7 @@ features: [ArrayBuffer, Atomics, TypedArray] ---*/ const i32a = new Int32Array( - new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT) + new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); const poisoned = { diff --git a/test/built-ins/Atomics/wake/bigint/non-bigint64-typedarray-throws.js b/test/built-ins/Atomics/wake/bigint/non-bigint64-typedarray-throws.js index 719bfa730e..d60d5b6c0d 100644 --- a/test/built-ins/Atomics/wake/bigint/non-bigint64-typedarray-throws.js +++ b/test/built-ins/Atomics/wake/bigint/non-bigint64-typedarray-throws.js @@ -16,7 +16,7 @@ features: [Atomics, BigInt, TypedArray] ---*/ const i64a = new BigUint64Array( - new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(BigUint64Array.BYTES_PER_ELEMENT * 8) ); const poisoned = { diff --git a/test/built-ins/Atomics/wake/bigint/non-shared-bufferdata-throws.js b/test/built-ins/Atomics/wake/bigint/non-shared-bufferdata-throws.js index e1c1b391f9..a50363cd57 100644 --- a/test/built-ins/Atomics/wake/bigint/non-shared-bufferdata-throws.js +++ b/test/built-ins/Atomics/wake/bigint/non-shared-bufferdata-throws.js @@ -15,7 +15,7 @@ info: | features: [ArrayBuffer, Atomics, BigInt, TypedArray] ---*/ const i64a = new BigInt64Array( - new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT) + new ArrayBuffer(BigInt64Array.BYTES_PER_ELEMENT * 8) ); const poisoned = { diff --git a/test/built-ins/Atomics/wake/count-defaults-to-infinity-missing.js b/test/built-ins/Atomics/wake/count-defaults-to-infinity-missing.js index 5601d2fe18..8db6dee17e 100644 --- a/test/built-ins/Atomics/wake/count-defaults-to-infinity-missing.js +++ b/test/built-ins/Atomics/wake/count-defaults-to-infinity-missing.js @@ -16,13 +16,16 @@ includes: [atomicsHelper.js] features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ +const RUNNING = 0 +const WAIT_INDEX = 1; // Index all agents are waiting on const NUMAGENT = 4; // Total number of agents started -const WAKEUP = 0; // Index all agents are waiting on +const BUFFER_SIZE = 5; // Index all agents are waiting on $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { const i32a = new Int32Array(sab); - $262.agent.report("A " + Atomics.wait(i32a, ${WAKEUP}, 0, 50)); + Atomics.add(i32a, ${RUNNING}, 1); + $262.agent.report("A " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50)); $262.agent.leaving(); }); `); @@ -30,7 +33,8 @@ $262.agent.start(` $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { const i32a = new Int32Array(sab); - $262.agent.report("B " + Atomics.wait(i32a, ${WAKEUP}, 0, 50)); + Atomics.add(i32a, ${RUNNING}, 1); + $262.agent.report("B " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50)); $262.agent.leaving(); }); `); @@ -38,7 +42,8 @@ $262.agent.start(` $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { const i32a = new Int32Array(sab); - $262.agent.report("C " + Atomics.wait(i32a, ${WAKEUP}, 0, 50)); + Atomics.add(i32a, ${RUNNING}, 1); + $262.agent.report("C " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50)); $262.agent.leaving(); }); `); @@ -46,22 +51,25 @@ $262.agent.start(` $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { const i32a = new Int32Array(sab); - $262.agent.report("D " + Atomics.wait(i32a, ${WAKEUP}, 0, 50)); + Atomics.add(i32a, ${RUNNING}, 1); + $262.agent.report("D " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50)); $262.agent.leaving(); }); `); const i32a = new Int32Array( - new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) + new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * BUFFER_SIZE) ); $262.agent.broadcast(i32a.buffer); -$262.agent.sleep(100); + +// Wait for agents to be running. +waitUntil(i32a, RUNNING, NUMAGENT); assert.sameValue( - Atomics.wake(i32a, WAKEUP /*, count missing */), + Atomics.wake(i32a, WAIT_INDEX /*, count missing */), NUMAGENT, - 'Atomics.wake(i32a, WAKEUP /*, count missing */) equals the value of `NUMAGENT` (4)' + 'Atomics.wake(i32a, WAIT_INDEX /*, count missing */) equals the value of `NUMAGENT` (4)' ); const sortedReports = []; diff --git a/test/built-ins/Atomics/wake/count-defaults-to-infinity-undefined.js b/test/built-ins/Atomics/wake/count-defaults-to-infinity-undefined.js index 89b7fc223b..cd1e1455a2 100644 --- a/test/built-ins/Atomics/wake/count-defaults-to-infinity-undefined.js +++ b/test/built-ins/Atomics/wake/count-defaults-to-infinity-undefined.js @@ -14,13 +14,16 @@ includes: [atomicsHelper.js] features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ +const RUNNING = 0 +const WAIT_INDEX = 1; // Index all agents are waiting on const NUMAGENT = 4; // Total number of agents started -const WAKEUP = 0; // Index all agents are waiting on +const BUFFER_SIZE = 5; // Index all agents are waiting on $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { const i32a = new Int32Array(sab); - $262.agent.report("A " + Atomics.wait(i32a, ${WAKEUP}, 0, 50)); + Atomics.add(i32a, ${RUNNING}, 1); + $262.agent.report("A " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50)); $262.agent.leaving(); }); `); @@ -28,7 +31,8 @@ $262.agent.start(` $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { const i32a = new Int32Array(sab); - $262.agent.report("B " + Atomics.wait(i32a, ${WAKEUP}, 0, 50)); + Atomics.add(i32a, ${RUNNING}, 1); + $262.agent.report("B " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50)); $262.agent.leaving(); }); `); @@ -36,7 +40,8 @@ $262.agent.start(` $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { const i32a = new Int32Array(sab); - $262.agent.report("C " + Atomics.wait(i32a, ${WAKEUP}, 0, 50)); + Atomics.add(i32a, ${RUNNING}, 1); + $262.agent.report("C " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50)); $262.agent.leaving(); }); `); @@ -44,23 +49,25 @@ $262.agent.start(` $262.agent.start(` $262.agent.receiveBroadcast(function(sab) { const i32a = new Int32Array(sab); - $262.agent.report("D " + Atomics.wait(i32a, ${WAKEUP}, 0, 50)); + Atomics.add(i32a, ${RUNNING}, 1); + $262.agent.report("D " + Atomics.wait(i32a, ${WAIT_INDEX}, 0, 50)); $262.agent.leaving(); }); `); const i32a = new Int32Array( - new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) + new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * BUFFER_SIZE) ); $262.agent.broadcast(i32a.buffer); -$262.agent.sleep(20); // half of timeout +// Wait for agents to be running. +waitUntil(i32a, RUNNING, NUMAGENT); assert.sameValue( - Atomics.wake(i32a, WAKEUP, undefined), + Atomics.wake(i32a, WAIT_INDEX, undefined), NUMAGENT, - 'Atomics.wake(i32a, WAKEUP, undefined) equals the value of `NUMAGENT` (4)' + 'Atomics.wake(i32a, WAIT_INDEX, undefined) equals the value of `NUMAGENT` (4)' ); const sortedReports = []; diff --git a/test/built-ins/Atomics/wake/non-int32-typedarray-throws.js b/test/built-ins/Atomics/wake/non-int32-typedarray-throws.js index 2ca5c7d46f..aea70d3e45 100644 --- a/test/built-ins/Atomics/wake/non-int32-typedarray-throws.js +++ b/test/built-ins/Atomics/wake/non-int32-typedarray-throws.js @@ -23,21 +23,21 @@ const poisoned = { assert.throws(TypeError, function() { const view = new Float64Array( - new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Float64Array.BYTES_PER_ELEMENT * 8) ); Atomics.wake(view, poisoned, poisoned); }, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError'); assert.throws(TypeError, function() { const view = new Float32Array( - new SharedArrayBuffer(Float32Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Float32Array.BYTES_PER_ELEMENT * 4) ); Atomics.wake(view, poisoned, poisoned); }, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError'); assert.throws(TypeError, function() { const view = new Int16Array( - new SharedArrayBuffer(Int16Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Int16Array.BYTES_PER_ELEMENT * 2) ); Atomics.wake(view, poisoned, poisoned); }, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError'); @@ -51,14 +51,14 @@ assert.throws(TypeError, function() { assert.throws(TypeError, function() { const view = new Uint32Array( - new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Uint32Array.BYTES_PER_ELEMENT * 4) ); Atomics.wake(new Uint32Array(), poisoned, poisoned); }, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError'); assert.throws(TypeError, function() { const view = new Uint16Array( - new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT) + new SharedArrayBuffer(Uint16Array.BYTES_PER_ELEMENT * 2) ); Atomics.wake(view, poisoned, poisoned); }, '`Atomics.wake(view), poisoned, poisoned)` throws TypeError'); diff --git a/test/built-ins/Atomics/wake/non-shared-bufferdata-throws.js b/test/built-ins/Atomics/wake/non-shared-bufferdata-throws.js index ddfd3ce87b..894c78efc3 100644 --- a/test/built-ins/Atomics/wake/non-shared-bufferdata-throws.js +++ b/test/built-ins/Atomics/wake/non-shared-bufferdata-throws.js @@ -16,7 +16,7 @@ features: [ArrayBuffer, Atomics, TypedArray] ---*/ const i32a = new Int32Array( - new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT) + new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4) ); const poisoned = { diff --git a/test/built-ins/Atomics/wake/non-shared-bufferdatate-non-shared-int-views.js b/test/built-ins/Atomics/wake/non-shared-bufferdatate-non-shared-int-views.js index 289530bb21..6b46aff513 100644 --- a/test/built-ins/Atomics/wake/non-shared-bufferdatate-non-shared-int-views.js +++ b/test/built-ins/Atomics/wake/non-shared-bufferdatate-non-shared-int-views.js @@ -9,7 +9,7 @@ includes: [testTypedArray.js] features: [ArrayBuffer, Atomics, TypedArray] ---*/ -const nonsab = new ArrayBuffer(16); +const nonsab = new ArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4); const poisoned = { valueOf: function() { diff --git a/test/built-ins/Atomics/wake/non-shared-int-views.js b/test/built-ins/Atomics/wake/non-shared-int-views.js index 64e69bd3b9..04b901edd0 100644 --- a/test/built-ins/Atomics/wake/non-shared-int-views.js +++ b/test/built-ins/Atomics/wake/non-shared-int-views.js @@ -9,7 +9,7 @@ includes: [testTypedArray.js] features: [Atomics, SharedArrayBuffer, TypedArray] ---*/ -const sab = new SharedArrayBuffer(16); +const sab = new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT * 4); const poisoned = { valueOf: function() {