|
| 1 | +//@ requireOptions("--alwaysUseShadowChicken=true", "--slowPathAllocsBetweenGCs=1", "--forceGCSlowPaths=true") |
| 2 | + |
| 3 | +import * as assert from "../assert.js" |
| 4 | + |
| 5 | +// Companion to ref-func-wrapper-alloc-frame-tracer.js, for array.init_elem. |
| 6 | +// |
| 7 | +// array.init_elem copies a funcref elem segment through copyElementSegment, which |
| 8 | +// materializes each element's JS wrapper. Unlike array.new_elem it does not |
| 9 | +// allocate the array itself, so the earlier Wasm GC slow path audit missed it. |
| 10 | +// |
| 11 | +// Kept as bytes rather than WAT: the Wasm GC text format needs gc/wast.js, whose |
| 12 | +// 6.6MB of JS takes ~45s to load under this test's forced-GC options. |
| 13 | +// |
| 14 | +// (module |
| 15 | +// (type $arr (array (mut funcref))) |
| 16 | +// (import "m" "f" (func $import)) |
| 17 | +// (elem $e funcref (ref.func $f0) (ref.func $f1) (ref.func $f2) (ref.func $f3) (ref.func $f4) (ref.func $f5) (ref.func $f6) (ref.func $f7)) |
| 18 | +// (func $f0) |
| 19 | +// (func $f1) |
| 20 | +// (func $f2) |
| 21 | +// (func $f3) |
| 22 | +// (func $f4) |
| 23 | +// (func $f5) |
| 24 | +// (func $f6) |
| 25 | +// (func $f7) |
| 26 | +// (func (export "test") |
| 27 | +// (local $a (ref null $arr)) |
| 28 | +// (local.set $a (array.new_default $arr (i32.const 1))) |
| 29 | +// (call $import) |
| 30 | +// (array.init_elem $arr $e (local.get $a) (i32.const 0) (i32.const 0) (i32.const 1)) |
| 31 | +// (call $import) |
| 32 | +// (array.init_elem $arr $e (local.get $a) (i32.const 0) (i32.const 1) (i32.const 1)) |
| 33 | +// (call $import) |
| 34 | +// (array.init_elem $arr $e (local.get $a) (i32.const 0) (i32.const 2) (i32.const 1)) |
| 35 | +// (call $import) |
| 36 | +// (array.init_elem $arr $e (local.get $a) (i32.const 0) (i32.const 3) (i32.const 1)) |
| 37 | +// (call $import) |
| 38 | +// (array.init_elem $arr $e (local.get $a) (i32.const 0) (i32.const 4) (i32.const 1)) |
| 39 | +// (call $import) |
| 40 | +// (array.init_elem $arr $e (local.get $a) (i32.const 0) (i32.const 5) (i32.const 1)) |
| 41 | +// (call $import) |
| 42 | +// (array.init_elem $arr $e (local.get $a) (i32.const 0) (i32.const 6) (i32.const 1)) |
| 43 | +// (call $import) |
| 44 | +// (array.init_elem $arr $e (local.get $a) (i32.const 0) (i32.const 7) (i32.const 1)) |
| 45 | +// ) |
| 46 | +// ) |
| 47 | + |
| 48 | +const wasmBytes = new Uint8Array([ |
| 49 | + 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x87, 0x80, 0x80, 0x80, 0x00, 0x02, 0x5e, |
| 50 | + 0x70, 0x01, 0x60, 0x00, 0x00, 0x02, 0x87, 0x80, 0x80, 0x80, 0x00, 0x01, 0x01, 0x6d, 0x01, 0x66, |
| 51 | + 0x00, 0x01, 0x03, 0x8a, 0x80, 0x80, 0x80, 0x00, 0x09, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, |
| 52 | + 0x01, 0x01, 0x07, 0x88, 0x80, 0x80, 0x80, 0x00, 0x01, 0x04, 0x74, 0x65, 0x73, 0x74, 0x00, 0x09, |
| 53 | + 0x09, 0x9c, 0x80, 0x80, 0x80, 0x00, 0x01, 0x05, 0x70, 0x08, 0xd2, 0x01, 0x0b, 0xd2, 0x02, 0x0b, |
| 54 | + 0xd2, 0x03, 0x0b, 0xd2, 0x04, 0x0b, 0xd2, 0x05, 0x0b, 0xd2, 0x06, 0x0b, 0xd2, 0x07, 0x0b, 0xd2, |
| 55 | + 0x08, 0x0b, 0x0a, 0xba, 0x81, 0x80, 0x80, 0x00, 0x09, 0x82, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0b, |
| 56 | + 0x82, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0b, 0x82, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0b, 0x82, 0x80, |
| 57 | + 0x80, 0x80, 0x00, 0x00, 0x0b, 0x82, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0b, 0x82, 0x80, 0x80, 0x80, |
| 58 | + 0x00, 0x00, 0x0b, 0x82, 0x80, 0x80, 0x80, 0x00, 0x00, 0x0b, 0x82, 0x80, 0x80, 0x80, 0x00, 0x00, |
| 59 | + 0x0b, 0xfc, 0x80, 0x80, 0x80, 0x00, 0x01, 0x01, 0x63, 0x00, 0x41, 0x01, 0xfb, 0x07, 0x00, 0x21, |
| 60 | + 0x00, 0x10, 0x00, 0x20, 0x00, 0x41, 0x00, 0x41, 0x00, 0x41, 0x01, 0xfb, 0x13, 0x00, 0x00, 0x10, |
| 61 | + 0x00, 0x20, 0x00, 0x41, 0x00, 0x41, 0x01, 0x41, 0x01, 0xfb, 0x13, 0x00, 0x00, 0x10, 0x00, 0x20, |
| 62 | + 0x00, 0x41, 0x00, 0x41, 0x02, 0x41, 0x01, 0xfb, 0x13, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x41, |
| 63 | + 0x00, 0x41, 0x03, 0x41, 0x01, 0xfb, 0x13, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x41, 0x00, 0x41, |
| 64 | + 0x04, 0x41, 0x01, 0xfb, 0x13, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x41, 0x00, 0x41, 0x05, 0x41, |
| 65 | + 0x01, 0xfb, 0x13, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x41, 0x00, 0x41, 0x06, 0x41, 0x01, 0xfb, |
| 66 | + 0x13, 0x00, 0x00, 0x10, 0x00, 0x20, 0x00, 0x41, 0x00, 0x41, 0x07, 0x41, 0x01, 0xfb, 0x13, 0x00, |
| 67 | + 0x00, 0x0b, |
| 68 | +]); |
| 69 | + |
| 70 | +const numFuncs = 8; |
| 71 | +const numInstances = 8; |
| 72 | + |
| 73 | +let calls = 0; |
| 74 | +const imports = { m: { f: () => { ++calls; } } }; |
| 75 | +const module = new WebAssembly.Module(wasmBytes); |
| 76 | + |
| 77 | +for (let i = 0; i < numInstances; ++i) |
| 78 | + new WebAssembly.Instance(module, imports).exports.test(); |
| 79 | + |
| 80 | +assert.eq(calls, numFuncs * numInstances); |
0 commit comments