Skip to content

Commit 0a09c02

Browse files
chicoxyzzyConstellation
authored andcommitted
[JSC][Wasm] Initialize ref arrays with gcSafeMemfill
https://bugs.webkit.org/show_bug.cgi?id=323865 Reviewed by Yusuke Suzuki. operationWasmArrayFillRefs filled already-visible ref arrays with a volatile store loop so the concurrent marker would not see a torn JSValue. Use gcSafeMemfill, the same helper JSWebAssemblyArray::fill already uses. The constructor still uses std::ranges::fill. The cell is not visible to concurrent markers until finishCreation. * Source/JavaScriptCore/wasm/WasmOperations.cpp: * JSTests/wasm/gc/bulk-array-element-types.js: Canonical link: https://commits.webkit.org/320951@main
1 parent e68d094 commit 0a09c02

2 files changed

Lines changed: 18 additions & 4 deletions

File tree

‎JSTests/wasm/gc/bulk-array-element-types.js‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,23 @@ for (const [offset, size] of [[1, -1], [-1, 1], [-1, -1], [0, 9], [8, 1], [9, 0]
311311
}
312312
}
313313

314+
{
315+
for (const length of [0, 1, 9, 32]) {
316+
const m = instantiate(`
317+
(module
318+
(type $arr (array (mut anyref)))
319+
(global $a (ref $arr) (array.new_default $arr (i32.const ${length})))
320+
(func (export "len") (result i32)
321+
(array.len (global.get $a)))
322+
(func (export "isNull") (param i32) (result i32)
323+
(ref.is_null (array.get $arr (global.get $a) (local.get 0)))))
324+
`).exports;
325+
assert.eq(m.len(), length);
326+
for (let i = 0; i < length; ++i)
327+
assert.eq(m.isNull(i), 1);
328+
}
329+
}
330+
314331
{
315332
for (const length of [1, 9, 32]) {
316333
const m = instantiate(`

‎Source/JavaScriptCore/wasm/WasmOperations.cpp‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1799,10 +1799,7 @@ JSC_DEFINE_NOEXCEPT_JIT_OPERATION(operationWasmArrayFill16B, void, (void* payloa
17991799

18001800
JSC_DEFINE_NOEXCEPT_JIT_OPERATION(operationWasmArrayFillRefs, void, (uint64_t* payload, uint64_t value, size_t elementCount))
18011801
{
1802-
// A reference is stored whole so the concurrent collector cannot observe a torn JSValue.
1803-
volatile uint64_t* cursor = payload;
1804-
for (size_t i = 0; i < elementCount; ++i)
1805-
cursor[i] = value;
1802+
gcSafeMemfill(payload, value, elementCount * sizeof(uint64_t));
18061803
}
18071804

18081805
JSC_DEFINE_NOEXCEPT_JIT_OPERATION(operationWasmArrayCopyRefs, void, (uint64_t* dst, const uint64_t* src, size_t byteCount))

0 commit comments

Comments
 (0)