Atomics: ensure all ArrayBuffer & SharedArrayBuffer sizes are uniform

This commit is contained in:
Rick Waldron 2018-06-26 14:40:00 -04:00
parent a93262428f
commit 5c5dd5b286
10 changed files with 49 additions and 34 deletions

View File

@ -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');

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 = {

View File

@ -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 = [];

View File

@ -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 = [];

View File

@ -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');

View File

@ -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 = {

View File

@ -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() {

View File

@ -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() {