Closed Bug 1642412 Opened 5 years ago Closed 3 years ago

Optimize table.get/set for anyref tables

Categories

(Core :: JavaScript: WebAssembly, enhancement, P3)

enhancement

Tracking

()

RESOLVED FIXED
100 Branch
Tracking Status
firefox100 --- fixed

People

(Reporter: rhunt, Assigned: rhunt)

References

(Blocks 1 open bug)

Details

Attachments

(9 files)

Our current implementation uses a call to Instance::tableGet/tableSet.

I observed this adding overhead with my interface-types prototype where a rust module using reference-types via wasm-bindgen would frequently use these instructions to manage the anyref heap.

I believe for anyref (not funcref) this should be as simple as a bounds check and load/store from/to array. Unsure if we need a barrier, would need to double check that.

This commit adds a fast path for table.get/set when the table
representation is anyref, and an unconditional fast path for
table.set.

TableTls is changed so that it contains a pointer to elements
when the representation is anyref, not just when it's storing
functions.

This commit adds ion fast paths for table.get/set when the table
representation is anyref. An unconditional fast path is added for
table.size.

Depends on D127311

Posting my WIP patches. They pass tests and should be very close to review, but I need some more time.

Assignee: nobody → rhunt
Attachment #9244000 - Attachment description: WIP: Bug 1642412 - wasm: Optimize baseline table.size/get/set. → Bug 1642412 - wasm: Optimize baseline table.size/get/set. r?lth
Attachment #9244001 - Attachment description: WIP: Bug 1642412 - wasm: Optimize ion table.get/set/size. → Bug 1642412 - wasm: Optimize ion table.get/set/size. r?lth

This commit removes support for anyref in Instance::tableGet/tableSet,
making it clear that these functions are only used for function tables.
Instance::tableSize is removed as no longer needed.

Depends on D127312

Now ready for review.

Depends on: 1745170
Pushed by rhunt@eqrion.net: https://hg.mozilla.org/integration/autoland/rev/40f861f62a0f wasm: Optimize baseline table.size/get/set. r=lth https://hg.mozilla.org/integration/autoland/rev/90fa382b5a20 wasm: Optimize ion table.get/set/size. r=lth https://hg.mozilla.org/integration/autoland/rev/67ae30727ed8 wasm: Remove unnecessary code from Instance for inline table methods. r=lth
Status: NEW → RESOLVED
Closed: 3 years ago
Resolution: --- → FIXED
Target Milestone: --- → 97 Branch
Regressions: 1748602
Status: RESOLVED → REOPENED
Flags: needinfo?(rhunt)
Resolution: FIXED → ---
Target Milestone: 97 Branch → ---
Blocks: 1711412
Flags: needinfo?(rhunt)

Rollup of the previous inline table.get/set patches.

Add test for issue with a post-write barrier that doesn't remove
store buffer entries when used on a table that may grow.

Depends on D141024

The barriered store function emits the post-write barrier directly, but calls
out to a function for the pre-write barrier. We should factor the post-write
barrier out so that we can use a different post-write barrier implementation
depending on requirements more easily.

Depends on D141025

Add a post-write barrier which will remove a previous store buffer entry if the
new value stored in the field would not require it. This requires the previous
value to be loaded before the store and propagated to the post-write barrier
call.

We only require a precise post-write barrier for storing into tables, as they
are implemented using a GCVector<HeapPtr<..>> which requires the invariant
that each write of null/tenured when the previous value was nursery will
remove the existing store buffer entry.

Depends on D141026

Ion has an easier time switching to the precise post-write barrier
as it's already unconditionally doing a call (postBarrierFiltering),
and so there's little extra cost in switching that call to be the
precise post-write barrier everywhere.

We cannot remove the postBarrierFiltering builtin because it is
still used by cranelift.

Depends on D141027

AsmJS will emit a call site line number for call, call indirect, and math builtins.
We currently read from the call site line number array for more operations than
these. This is normally fine, as long as the operations that try the read are
never emitted from AsmJS. If that is not the case, we will get out of sync and
can read outside of the array. This caused an issue when I added a use of
readCallSiteOrBytecode() in TeeGlobal, copying from SetGlobal. This commit
fixes this.

Depends on D141029

I've returned to this work and have posted new patches that fix an issue with barriers so that this can land again.

Pushed by rhunt@eqrion.net: https://hg.mozilla.org/integration/autoland/rev/25adf505426d wasm: Rollup of inline table.get/set for anyref. r=lth https://hg.mozilla.org/integration/autoland/rev/3cdc18a4ee38 wasm: Add test for post-write barrier issue. r=jseward https://hg.mozilla.org/integration/autoland/rev/d190ffcf25bf wasm: Refactor the baseline post-write barrier out of the barriered store function. r=jseward https://hg.mozilla.org/integration/autoland/rev/a41351c7413b wasm: Implement a 'precise' post-write barrier in baseline. r=jseward https://hg.mozilla.org/integration/autoland/rev/285174ef42f1 wasm: Switch ion to use the precise post-write barrier. r=jseward https://hg.mozilla.org/integration/autoland/rev/0d1d9fa72512 wasm: Don't read a call site line in operations that AsmJS won't emit one for. r=lth

Backed out 6 changesets (bug 1642412) for causing spider-monkey failures in wasm/ref-types/externref-global-prebarrier.js

Backout link: https://hg.mozilla.org/integration/autoland/rev/9e51620948d8e9f1daa197835367c8332eb86fa5

Push with failures

Failure log

TEST-PASS | js/src/jit-test/tests/wasm/ref-types/externref.js | Success (code 0, args "--ion-eager --ion-offthread-compile=off --more-compartments") [0.3 s]
[task 2022-03-22T20:35:59.554Z] /builds/worker/checkouts/gecko/js/src/jit-test/lib/wasm.js:417:11 Error: no plausible stacks found, observed: /!>/0,!>//0,!>/<,0,!>/GC postbarrier,0,!>/<,0,!>/0,!>/!>/
[task 2022-03-22T20:35:59.555Z] /builds/worker/checkouts/gecko/js/src/jit-test/lib/wasm.js:417:11 Expected one of:
[task 2022-03-22T20:35:59.555Z] /builds/worker/checkouts/gecko/js/src/jit-test/lib/wasm.js:417:11 /!>/0,!>//0,!>/<,0,!>/filtering GC postbarrier,0,!>/<,0,!>/0,!>/!>/
[task 2022-03-22T20:35:59.555Z] /builds/worker/checkouts/gecko/js/src/jit-test/lib/wasm.js:417:11 /!>/0,!>//0,!>/!>/
[task 2022-03-22T20:35:59.555Z] Stack:
[task 2022-03-22T20:35:59.555Z]   WasmHelpers.assertEqPreciseStacks@/builds/worker/checkouts/gecko/js/src/jit-test/lib/wasm.js:417:11
[task 2022-03-22T20:35:59.555Z]   @/builds/worker/checkouts/gecko/js/src/jit-test/tests/wasm/ref-types/externref-global-prebarrier.js:55:22
[task 2022-03-22T20:35:59.555Z] Exit code: 3
[task 2022-03-22T20:35:59.555Z] FAIL - wasm/ref-types/externref-global-prebarrier.js
[task 2022-03-22T20:35:59.555Z] TEST-UNEXPECTED-FAIL | js/src/jit-test/tests/wasm/ref-types/externref-global-prebarrier.js | /builds/worker/checkouts/gecko/js/src/jit-test/lib/wasm.js:417:11 Error: no plausible stacks found, observed: /!>/0,!>//0,!>/<,0,!>/GC postbarrier,0,!>/<,0,!>/0,!>/!>/ (code 3, args "--no-blinterp --no-baseline --no-ion --more-compartments") [1.1 s]
[task 2022-03-22T20:35:59.555Z] INFO exit-status     : 3
Flags: needinfo?(rhunt)

Naming of a builtin changed, this stack trace test needed to be updated. Don't know why this was only encountered in arm32.

[1] https://treeherder.mozilla.org/jobs?repo=try&revision=a577209849cc61a7d5151a288317e24e79df56e1

Flags: needinfo?(rhunt)
Pushed by rhunt@eqrion.net: https://hg.mozilla.org/integration/autoland/rev/ce799cb566ac wasm: Rollup of inline table.get/set for anyref. r=lth https://hg.mozilla.org/integration/autoland/rev/aaf8c5eef48e wasm: Add test for post-write barrier issue. r=jseward https://hg.mozilla.org/integration/autoland/rev/eabb888a0851 wasm: Refactor the baseline post-write barrier out of the barriered store function. r=jseward https://hg.mozilla.org/integration/autoland/rev/89db2f360b8f wasm: Implement a 'precise' post-write barrier in baseline. r=jseward https://hg.mozilla.org/integration/autoland/rev/00b99ec19d1e wasm: Switch ion to use the precise post-write barrier. r=jseward https://hg.mozilla.org/integration/autoland/rev/82ac83afeaea wasm: Don't read a call site line in operations that AsmJS won't emit one for. r=lth
Regressions: 1762171
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: