Skip to content

Commit 369f05e

Browse files
committed
Re-enable SharedArrayBuffer for JSC shell and Testers
https://bugs.webkit.org/show_bug.cgi?id=212069 Reviewed by Keith Miller. JSTests: Update tests to align to the latest spec. * stress/SharedArrayBuffer-opt.js: (shouldSucceed): (idx.of.string_appeared_here.a.of.arrays.m.of.atomics): (string_appeared_here.a.of.arrays.m.of.atomics): Deleted. * stress/SharedArrayBuffer.js: (shouldSucceed): (Symbol): * stress/array-buffer-byte-length.js: (shouldThrow): (Symbol): * stress/atomics-add-uint32.js: * stress/atomics-known-int-use.js: * stress/atomics-neg-zero.js: * stress/atomics-store-return.js: * stress/lars-sab-workers.js: (resources): (notify): (wake): Deleted. * stress/regress-170473.js: * stress/regress-189317.js: * stress/shared-array-buffer-sort-while-different-thread-is-modifying.js: Added. (262.agent.waitUntil): (262.agent.start.262.agent.receiveBroadcast): * test262/config.yaml: * test262/expectations.yaml: LayoutTests/imported/w3c: * web-platform-tests/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-failure.https.any-expected.txt: * web-platform-tests/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-failure.https.any.serviceworker-expected.txt: * web-platform-tests/html/webappapis/scripting/processing-model-2/integration-with-the-javascript-agent-formalism/requires-success.any.worker-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any-expected.txt: * web-platform-tests/wasm/jsapi/memory/constructor.any.worker-expected.txt: * web-platform-tests/workers/postMessage_block.https-expected.txt: Source/JavaScriptCore: This patch revives SharedArrayBuffer and Atomics and aligning them to the latest spec. 1. SharedArrayBuffer's sort should be done in JS side. C++ sort is not safe for SharedArrayBuffer since the buffer can be modified by different threads while sorting. 2. Atomics.wait should be renamed to Atomics.notify. 3. Atomics operation should be VarArgs in DFG because DFGSSALoweringPhase assumes that they are VarArgs and they can have another arg for CheckInBounds dependency. 4. For test262, JSC shell should support "--can-block-is-false" flag. If it is true, the main thread's [[CanBlock]] becomes false. This means that `Atomics.wait` cannot be used. * builtins/BuiltinNames.h: * builtins/TypedArrayPrototype.js: (sort): * bytecode/LinkTimeConstant.h: * dfg/DFGAbstractInterpreterInlines.h: (JSC::DFG::AbstractInterpreter<AbstractStateType>::executeEffects): * dfg/DFGByteCodeParser.cpp: (JSC::DFG::ByteCodeParser::handleIntrinsicCall): * dfg/DFGClobberize.h: (JSC::DFG::clobberize): * dfg/DFGFixupPhase.cpp: (JSC::DFG::FixupPhase::fixupNode): * dfg/DFGNode.h: (JSC::DFG::Node::mustGenerate const): (JSC::DFG::Node::hasVarArgs const): (JSC::DFG::Node::mustGenerate): Deleted. * dfg/DFGNodeType.h: * dfg/DFGSSALoweringPhase.cpp: (JSC::DFG::SSALoweringPhase::handleNode): * dfg/DFGSpeculativeJIT64.cpp: (JSC::DFG::SpeculativeJIT::compile): * ftl/FTLLowerDFGToB3.cpp: (JSC::FTL::DFG::LowerDFGToB3::compileAtomicsIsLockFree): * jsc.cpp: (printUsageStatement): (CommandLine::parseArguments): (runJSC): * runtime/AtomicsObject.cpp: (JSC::AtomicsObject::finishCreation): (JSC::JSC_DEFINE_HOST_FUNCTION): (JSC::JSC_DEFINE_JIT_OPERATION): * runtime/CommonIdentifiers.h: * runtime/Intrinsic.cpp: (JSC::intrinsicName): * runtime/Intrinsic.h: * runtime/JSArrayBufferPrototype.cpp: (JSC::arrayBufferSlice): (JSC::arrayBufferByteLength): (JSC::JSC_DEFINE_HOST_FUNCTION): (JSC::JSArrayBufferPrototype::finishCreation): * runtime/JSCJSValue.h: * runtime/JSCJSValueInlines.h: (JSC::JSValue::toIntegerOrInfinity const): * runtime/JSGenericTypedArrayViewPrototypeFunctions.h: (JSC::genericTypedArrayViewProtoFuncReverse): (JSC::genericTypedArrayViewPrivateFuncSort): * runtime/JSGlobalObject.cpp: (JSC::JSGlobalObject::init): * runtime/JSTypedArrayViewPrototype.cpp: (JSC::JSC_DEFINE_HOST_FUNCTION): * runtime/JSTypedArrayViewPrototype.h: * runtime/OptionsList.h: * runtime/SimpleTypedArrayController.cpp: (JSC::SimpleTypedArrayController::SimpleTypedArrayController): (JSC::SimpleTypedArrayController::isAtomicsWaitAllowedOnCurrentThread): * runtime/SimpleTypedArrayController.h: * runtime/SmallStrings.cpp: (JSC::SmallStrings::initializeCommonStrings): (JSC::SmallStrings::visitStrongReferences): * runtime/SmallStrings.h: (JSC::SmallStrings::notEqualString const): (JSC::SmallStrings::timedOutString const): (JSC::SmallStrings::okString const): Source/WTF: * wtf/PlatformEnable.h: Tools: * Scripts/test262/Runner.pm: (getFeatureFlags): * Scripts/webkitpy/layout_tests/run_webkit_tests.py: (main): LayoutTests: * webaudio/dom-exceptions-expected.txt: Canonical link: https://commits.webkit.org/231326@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@269531 268f45cc-cd09-0410-ab3c-d52691b4dbfc
1 parent 9b98de9 commit 369f05e

58 files changed

Lines changed: 697 additions & 265 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

JSTests/ChangeLog

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,38 @@
1+
2020-11-06 Yusuke Suzuki <ysuzuki@apple.com>
2+
3+
Re-enable SharedArrayBuffer for JSC shell and Testers
4+
https://bugs.webkit.org/show_bug.cgi?id=212069
5+
6+
Reviewed by Keith Miller.
7+
8+
Update tests to align to the latest spec.
9+
10+
* stress/SharedArrayBuffer-opt.js:
11+
(shouldSucceed):
12+
(idx.of.string_appeared_here.a.of.arrays.m.of.atomics):
13+
(string_appeared_here.a.of.arrays.m.of.atomics): Deleted.
14+
* stress/SharedArrayBuffer.js:
15+
(shouldSucceed):
16+
(Symbol):
17+
* stress/array-buffer-byte-length.js:
18+
(shouldThrow):
19+
(Symbol):
20+
* stress/atomics-add-uint32.js:
21+
* stress/atomics-known-int-use.js:
22+
* stress/atomics-neg-zero.js:
23+
* stress/atomics-store-return.js:
24+
* stress/lars-sab-workers.js:
25+
(resources):
26+
(notify):
27+
(wake): Deleted.
28+
* stress/regress-170473.js:
29+
* stress/regress-189317.js:
30+
* stress/shared-array-buffer-sort-while-different-thread-is-modifying.js: Added.
31+
(262.agent.waitUntil):
32+
(262.agent.start.262.agent.receiveBroadcast):
33+
* test262/config.yaml:
34+
* test262/expectations.yaml:
35+
136
2020-11-05 Yusuke Suzuki <ysuzuki@apple.com>
237

338
toLocaleDateString() resolves incorrect date for some old dates

JSTests/stress/SharedArrayBuffer-opt.js

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ skip
21
var dv = new DataView(new SharedArrayBuffer(128));
32
var i8a = new Int8Array(new SharedArrayBuffer(128));
43
var i16a = new Int16Array(new SharedArrayBuffer(128));
@@ -104,6 +103,11 @@ function shouldFail(f, name)
104103
throw new Error(f + " succeeded!");
105104
}
106105

106+
function shouldSucceed(f)
107+
{
108+
f();
109+
}
110+
107111
for (var bad of [void 0, null, false, true, 1, 0.5, Symbol(), {}, "hello", dv, u8ca, f32a, f64a]) {
108112
shouldFail(() => genericAtomics.get("add")(bad, 0, 0), TypeError);
109113
shouldFail(() => genericAtomics.get("and")(bad, 0, 0), TypeError);
@@ -116,7 +120,7 @@ for (var bad of [void 0, null, false, true, 1, 0.5, Symbol(), {}, "hello", dv, u
116120
shouldFail(() => genericAtomics.get("xor")(bad, 0, 0), TypeError);
117121
}
118122

119-
for (var idx of [-1, -1000000000000, 10000, 10000000000000, "hello"]) {
123+
for (var idx of [-1, -1000000000000, 10000000000000, 10000]) {
120124
for (var a of arrays) {
121125
for (var m of [atomics.get(a), genericAtomics]) {
122126
shouldFail(() => m.get("add")(a, idx, 0), RangeError);
@@ -132,3 +136,19 @@ for (var idx of [-1, -1000000000000, 10000, 10000000000000, "hello"]) {
132136
}
133137
}
134138

139+
for (var idx of ["hello"]) {
140+
for (var a of arrays) {
141+
for (var m of [atomics.get(a), genericAtomics]) {
142+
shouldSucceed(() => m.get("add")(a, idx, 0));
143+
shouldSucceed(() => m.get("and")(a, idx, 0));
144+
shouldSucceed(() => m.get("compareExchange")(a, idx, 0, 0));
145+
shouldSucceed(() => m.get("exchange")(a, idx, 0));
146+
shouldSucceed(() => m.get("load")(a, idx));
147+
shouldSucceed(() => m.get("or")(a, idx, 0));
148+
shouldSucceed(() => m.get("store")(a, idx, 0));
149+
shouldSucceed(() => m.get("sub")(a, idx, 0));
150+
shouldSucceed(() => m.get("xor")(a, idx, 0));
151+
}
152+
}
153+
}
154+

JSTests/stress/SharedArrayBuffer.js

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ skip
21
// This is a basic test of SharedArrayBuffer API as we understand it.
32

43
if (SharedArrayBuffer == ArrayBuffer)
@@ -35,11 +34,11 @@ checkAtomics("compareExchange", 4);
3534
checkAtomics("exchange", 3);
3635
checkAtomics("isLockFree", 1);
3736
checkAtomics("load", 2);
37+
checkAtomics("notify", 3);
3838
checkAtomics("or", 3);
3939
checkAtomics("store", 3);
4040
checkAtomics("sub", 3);
4141
checkAtomics("wait", 4);
42-
checkAtomics("wake", 3);
4342
checkAtomics("xor", 3);
4443

4544
// These should all succeed.
@@ -66,6 +65,11 @@ function shouldFail(f, name)
6665
throw new Error(f + " succeeded!");
6766
}
6867

68+
function shouldSucceed(f)
69+
{
70+
f();
71+
}
72+
6973
for (bad of [void 0, null, false, true, 1, 0.5, Symbol(), {}, "hello", dv, u8ca, f32a, f64a]) {
7074
shouldFail(() => Atomics.add(bad, 0, 0), TypeError);
7175
shouldFail(() => Atomics.and(bad, 0, 0), TypeError);
@@ -79,11 +83,11 @@ for (bad of [void 0, null, false, true, 1, 0.5, Symbol(), {}, "hello", dv, u8ca,
7983
}
8084

8185
for (bad of [void 0, null, false, true, 1, 0.5, Symbol(), {}, "hello", dv, i8a, i16a, u8a, u8ca, u16a, u32a, f32a, f64a]) {
86+
shouldFail(() => Atomics.notify(bad, 0, 0), TypeError);
8287
shouldFail(() => Atomics.wait(bad, 0, 0), TypeError);
83-
shouldFail(() => Atomics.wake(bad, 0, 0), TypeError);
8488
}
8589

86-
for (idx of [-1, -1000000000000, 10000, 10000000000000, "hello"]) {
90+
for (idx of [-1, -1000000000000, 10000, 10000000000000]) {
8791
for (a of [i8a, i16a, i32a, u8a, u16a, u32a]) {
8892
shouldFail(() => Atomics.add(a, idx, 0), RangeError);
8993
shouldFail(() => Atomics.and(a, idx, 0), RangeError);
@@ -95,8 +99,24 @@ for (idx of [-1, -1000000000000, 10000, 10000000000000, "hello"]) {
9599
shouldFail(() => Atomics.sub(a, idx, 0), RangeError);
96100
shouldFail(() => Atomics.xor(a, idx, 0), RangeError);
97101
}
102+
shouldFail(() => Atomics.notify(i32a, idx, 0), RangeError);
98103
shouldFail(() => Atomics.wait(i32a, idx, 0), RangeError);
99-
shouldFail(() => Atomics.wake(i32a, idx, 0), RangeError);
104+
}
105+
106+
for (idx of ["hello"]) {
107+
for (a of [i8a, i16a, i32a, u8a, u16a, u32a]) {
108+
shouldSucceed(() => Atomics.add(a, idx, 0));
109+
shouldSucceed(() => Atomics.and(a, idx, 0));
110+
shouldSucceed(() => Atomics.compareExchange(a, idx, 0, 0));
111+
shouldSucceed(() => Atomics.exchange(a, idx, 0));
112+
shouldSucceed(() => Atomics.load(a, idx));
113+
shouldSucceed(() => Atomics.or(a, idx, 0));
114+
shouldSucceed(() => Atomics.store(a, idx, 0));
115+
shouldSucceed(() => Atomics.sub(a, idx, 0));
116+
shouldSucceed(() => Atomics.xor(a, idx, 0));
117+
}
118+
shouldSucceed(() => Atomics.notify(i32a, idx, 0));
119+
shouldSucceed(() => Atomics.wait(i32a, idx, 0, 1));
100120
}
101121

102122
function runAtomic(array, index, init, name, args, expectedResult, expectedOutcome)

JSTests/stress/array-buffer-byte-length.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ skip
21
function shouldBe(actual, expected)
32
{
43
if (actual !== expected)
@@ -42,25 +41,25 @@ function shouldThrow(func, errorMessage)
4241

4342
shouldThrow(() => {
4443
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get.call(sharedArrayBuffer);
45-
}, `TypeError: Receiver should not be a shared array buffer`);
44+
}, `TypeError: Receiver must be ArrayBuffer`);
4645

4746
shouldThrow(() => {
4847
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get.call(arrayBuffer);
49-
}, `TypeError: Receiver should be a shared array buffer`);
48+
}, `TypeError: Receiver must be SharedArrayBuffer`);
5049

5150
for (let value of [ 0, true, "Cocoa", null, undefined, Symbol("Cappuccino") ]) {
5251
shouldThrow(() => {
5352
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get.call(value);
54-
}, `TypeError: Receiver should be an array buffer but was not an object`);
53+
}, `TypeError: Receiver must be ArrayBuffer`);
5554
shouldThrow(() => {
5655
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get.call(value);
57-
}, `TypeError: Receiver should be an array buffer but was not an object`);
56+
}, `TypeError: Receiver must be SharedArrayBuffer`);
5857
}
5958

6059
shouldThrow(() => {
6160
Object.getOwnPropertyDescriptor(ArrayBuffer.prototype, 'byteLength').get.call({});
62-
}, `TypeError: Receiver should be an array buffer`);
61+
}, `TypeError: Receiver must be ArrayBuffer`);
6362
shouldThrow(() => {
6463
Object.getOwnPropertyDescriptor(SharedArrayBuffer.prototype, 'byteLength').get.call({});
65-
}, `TypeError: Receiver should be an array buffer`);
64+
}, `TypeError: Receiver must be SharedArrayBuffer`);
6665
}

JSTests/stress/atomics-add-uint32.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ skip
21
var sab = new SharedArrayBuffer(4);
32
var a = new Uint32Array(sab);
43
var result = Atomics.add(a, 0, 4000000000);

JSTests/stress/atomics-known-int-use.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ skip
21
// Break type inference.
32
var o = {f: 42.5};
43

JSTests/stress/atomics-neg-zero.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ skip
21
var sab = new SharedArrayBuffer(4);
32
var a = new Int32Array(sab);
43
Atomics.add(a, -0, 1); // This should not throw.

JSTests/stress/atomics-store-return.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ skip
21
var sab = new SharedArrayBuffer(1);
32
var a = new Int8Array(sab);
43
var result = Atomics.store(a, 0, 1000);

JSTests/stress/lars-sab-workers.js

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
//@ skip
2-
31
var sab = new SharedArrayBuffer(100 * 4);
42

53
var memory = new Int32Array(sab);
@@ -14,7 +12,7 @@ function startWorker(code)
1412
}
1513

1614
resources = `
17-
function wait(memory, index, waitCondition, wakeCondition)
15+
function wait(memory, index, waitCondition, notifyCondition)
1816
{
1917
while (memory[index] == waitCondition) {
2018
var result = Atomics.wait(memory, index, waitCondition);
@@ -28,23 +26,23 @@ function wait(memory, index, waitCondition, wakeCondition)
2826
break;
2927
}
3028
var value = memory[index];
31-
if (value != wakeCondition) {
29+
if (value != notifyCondition) {
3230
$.agent.report("Error: wait returned not-equal but the memory has a bad value: " + value);
3331
$.agent.report("error");
3432
}
3533
}
3634
var value = memory[index];
37-
if (value != wakeCondition) {
35+
if (value != notifyCondition) {
3836
$.agent.report("Error: done waiting but the memory has a bad value: " + value);
3937
$.agent.report("error");
4038
}
4139
}
4240
43-
function wake(memory, index)
41+
function notify(memory, index)
4442
{
45-
var result = Atomics.wake(memory, index, 1);
43+
var result = Atomics.notify(memory, index, 1);
4644
if (result != 0 && result != 1) {
47-
$.agent.report("Error: bad result from wake: " + result);
45+
$.agent.report("Error: bad result from notify: " + result);
4846
$.agent.report("error");
4947
}
5048
}
@@ -66,7 +64,7 @@ startWorker(
6664
$.agent.report("1: It started!");
6765
6866
memory[shouldGoIdx] = 1;
69-
wake(memory, shouldGoIdx);
67+
notify(memory, shouldGoIdx);
7068
7169
wait(memory, didEndIdx, 0, 1);
7270
@@ -88,12 +86,12 @@ startWorker(
8886
$.agent.report("2: Memory: " + memory);
8987
9088
Atomics.store(memory, didStartIdx, 1);
91-
wake(memory, didStartIdx);
89+
notify(memory, didStartIdx);
9290
9391
wait(memory, shouldGoIdx, 0, 1);
9492
9593
Atomics.store(memory, didEndIdx, 1);
96-
wake(memory, didEndIdx, 1);
94+
notify(memory, didEndIdx, 1);
9795
9896
$.agent.report("2: Memory: " + memory);
9997
$.agent.report("done");

JSTests/stress/regress-170473.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
//@ skip
21
var heap = new SharedArrayBuffer(4096);
32
var Uint8ArrayView = new Uint8Array(heap);
43

0 commit comments

Comments
 (0)