Closed Bug 1609916 Opened 2 years ago Closed 1 year ago

Implement a callback in JS whenever a SharedArrayBuffer is constructed inside a context

Categories

(Core :: Javascript: WebAssembly, task, P2)

task

Tracking

()

RESOLVED FIXED
mozilla75
Tracking Status
firefox75 --- fixed

People

(Reporter: bas.schouten, Assigned: lth)

References

Details

Attachments

(1 file)

Whenever a structured clone occurs of a SharedArrayBuffer we need a callback into Gecko so that Gecko may optionally decide to use that for throttling in order to prevent high prevision timer. This is needed for bug 1563335.

Priority: -- → P2

P2 because the bug it blocks is P2. Assuming Bas can take this. If not, needinfo?me.

Oops, sorry for forgetting about this. Lars, do you suppose you could help with this?

(I suppose there might also be a need for a callback when a JSContext no longer contains any SABs (so the JSContext no longer needs to be sequentialized). But maybe that's not actually worth the fuss given the rare expected usage of this.)

Component: JavaScript Engine → Javascript: WebAssembly
Flags: needinfo?(lhansen)

It shouldn't be hard to do a callback on cloning, there are choke points in StructuredClone.cpp that we can use for both SABs and wasm memories. Do we want a callback when the object is sent, or when it is received, or both? The subject line suggests only on reading (and this sort of makes the most sense); comment 0 is a little more ambiguous.

At the moment, the expected use of this is "never", right? So I probably wouldn't worry about counting the number of live SABs. That said, we already have a mechanism for counting the number of live SABs, it's JS::ContainsSharedArrayBuffer(JSContext*). So the SAB finalization mechanism could plausibly use the existing reference count to decide whether to trigger a callback for no more live SABs.

Flags: needinfo?(luke)
Flags: needinfo?(bas)

When structured clone reads a SAB and creates a new SAB object, call a
callback that lets the embedder know. The embedder can then adjust
its policy. Concretely, we want to allow the browser to serialize
threads in a process that uses JS shared memory.

Oops, answered in phab comment, but to be clear here: good question, I think we need a callback call on both the sending and receiving sides, so that both JSContexts end up getting serialized.

Flags: needinfo?(luke)
Assignee: nobody → lhansen
Attachment #9124048 - Attachment description: Bug 1609916 - Callback from SC to DOM on SAB creation. → Bug 1609916 - Callback from SC to DOM on SAB creation. r?luke
Status: NEW → ASSIGNED
Attachment #9124048 - Attachment description: Bug 1609916 - Callback from SC to DOM on SAB creation. r?luke → Bug 1609916 - Callback from SC to DOM on SAB cloning. r?luke
Pushed by lhansen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/1dc5c3074b57
Callback from SC to DOM on SAB cloning.  r=luke

Backed out changeset 1dc5c3074b57 (Bug 1609916) for causing spidermonkey bustage

Push with failure: https://treeherder.mozilla.org/#/jobs?repo=autoland&resultStatus=testfailed%2Cbusted%2Cexception&classifiedState=unclassified&revision=1dc5c3074b57fb45d0a94188e69048da993360ca

Failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=287946169&repo=autoland&lineNumber=12698

Backout link: https://treeherder.mozilla.org/#/jobs?repo=autoland&resultStatus=testfailed%2Cbusted%2Cexception&classifiedState=unclassified&revision=62f4ddbaad18cf4b11ca41ec5d1145066bfb97b3

[task 2020-02-07T16:22:11.776Z] TEST-PASS | js/src/jit-test/tests/wasm/ion-lazy-tables.js | Success (code 0, args "--disable-wasm-huge-memory") [0.9 s]
[task 2020-02-07T16:22:11.874Z] /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:11.874Z] Stack:
[task 2020-02-07T16:22:11.874Z]   @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
[task 2020-02-07T16:22:11.874Z] Exit code: 3
[task 2020-02-07T16:22:11.874Z] FAIL - wasm/memory-cloning.js
[task 2020-02-07T16:22:11.875Z] TEST-UNEXPECTED-FAIL | js/src/jit-test/tests/wasm/memory-cloning.js | /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated) (code 3, args "") [0.3 s]
[task 2020-02-07T16:22:11.875Z] INFO exit-status     : 3
[task 2020-02-07T16:22:11.875Z] INFO timed-out       : False
[task 2020-02-07T16:22:11.875Z] INFO stderr         2> /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:11.875Z] INFO stderr         2> Stack:
[task 2020-02-07T16:22:11.875Z] INFO stderr         2> @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
[task 2020-02-07T16:22:11.895Z] TEST-PASS | js/src/jit-test/tests/wasm/memory-aliasing.js | Success (code 0, args "--disable-wasm-huge-memory") [0.3 s]
[task 2020-02-07T16:22:11.975Z] /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:11.976Z] Stack:
[task 2020-02-07T16:22:11.976Z]   @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
[task 2020-02-07T16:22:11.977Z] Exit code: 3
[task 2020-02-07T16:22:11.977Z] FAIL - wasm/memory-cloning.js
[task 2020-02-07T16:22:11.977Z] TEST-UNEXPECTED-FAIL | js/src/jit-test/tests/wasm/memory-cloning.js | /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated) (code 3, args "--wasm-compiler=ion") [0.4 s]
[task 2020-02-07T16:22:11.977Z] INFO exit-status     : 3
[task 2020-02-07T16:22:11.977Z] INFO timed-out       : False
[task 2020-02-07T16:22:11.977Z] INFO stderr         2> /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:11.977Z] INFO stderr         2> Stack:
[task 2020-02-07T16:22:11.977Z] INFO stderr         2> @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
[task 2020-02-07T16:22:12.003Z] /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:12.003Z] Stack:
[task 2020-02-07T16:22:12.003Z]   @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
[task 2020-02-07T16:22:12.003Z] Exit code: 3
[task 2020-02-07T16:22:12.003Z] FAIL - wasm/memory-cloning.js
[task 2020-02-07T16:22:12.003Z] TEST-UNEXPECTED-FAIL | js/src/jit-test/tests/wasm/memory-cloning.js | /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated) (code 3, args "--test-wasm-await-tier2") [0.4 s]
[task 2020-02-07T16:22:12.004Z] INFO exit-status     : 3
[task 2020-02-07T16:22:12.004Z] INFO timed-out       : False
[task 2020-02-07T16:22:12.004Z] INFO stderr         2> /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:12.004Z] INFO stderr         2> Stack:
[task 2020-02-07T16:22:12.004Z] INFO stderr         2> @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
[task 2020-02-07T16:22:12.007Z] /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:12.007Z] Stack:
[task 2020-02-07T16:22:12.007Z]   @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
[task 2020-02-07T16:22:12.007Z] Exit code: 3
[task 2020-02-07T16:22:12.007Z] FAIL - wasm/memory-cloning.js
[task 2020-02-07T16:22:12.007Z] TEST-UNEXPECTED-FAIL | js/src/jit-test/tests/wasm/memory-cloning.js | /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated) (code 3, args "--disable-wasm-huge-memory") [0.3 s]
[task 2020-02-07T16:22:12.007Z] INFO exit-status     : 3
[task 2020-02-07T16:22:12.007Z] INFO timed-out       : False
[task 2020-02-07T16:22:12.007Z] INFO stderr         2> /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:12.007Z] INFO stderr         2> Stack:
[task 2020-02-07T16:22:12.007Z] INFO stderr         2> @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
[task 2020-02-07T16:22:12.010Z] TEST-PASS | js/src/jit-test/tests/wasm/memory-sharing-off.js | Success (code 0, args "--shared-memory=off --wasm-compiler=baseline") [0.3 s]
[task 2020-02-07T16:22:12.013Z] /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:12.013Z] Stack:
[task 2020-02-07T16:22:12.013Z]   @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
[task 2020-02-07T16:22:12.013Z] Exit code: 3
[task 2020-02-07T16:22:12.013Z] FAIL - wasm/memory-cloning.js
[task 2020-02-07T16:22:12.014Z] TEST-UNEXPECTED-FAIL | js/src/jit-test/tests/wasm/memory-cloning.js | /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated) (code 3, args "--wasm-compiler=baseline") [0.4 s]
[task 2020-02-07T16:22:12.014Z] INFO exit-status     : 3
[task 2020-02-07T16:22:12.014Z] INFO timed-out       : False
[task 2020-02-07T16:22:12.014Z] INFO stderr         2> /builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27 InternalError: bad serialized structured data (truncated)
[task 2020-02-07T16:22:12.014Z] INFO stderr         2> Stack:
[task 2020-02-07T16:22:12.014Z] INFO stderr         2> @/builds/worker/workspace/build/src/js/src/jit-test/tests/wasm/memory-cloning.js:27:27
Flags: needinfo?(lhansen)

Oh, that's very fascinating, this change should have had no functional effects...

Flags: needinfo?(lhansen)

Bad parens for a factored expression.

Attachment #9124048 - Attachment description: Bug 1609916 - Callback from SC to DOM on SAB cloning. r?luke → Bug 1609916 - Callback from SC to DOM on SAB cloning. r=luke

:lth, this mochitests failures seem to be from that push as well:
https://treeherder.mozilla.org/#/jobs?repo=autoland&selectedJob=287948819&searchStr=mochitest&revision=1dc5c3074b57fb45d0a94188e69048da993360ca

Failure log: https://treeherder.mozilla.org/logviewer.html#/jobs?job_id=287948819&repo=autoland&lineNumber=7172

[task 2020-02-07T16:47:43.121Z] 16:47:43     INFO - TEST-START | dom/worklet/tests/test_audioWorklet_WASM.html
[task 2020-02-07T16:47:43.190Z] 16:47:43     INFO - GECKO(3508) | [Child 3564, Main Thread] WARNING: Trying to request nsIHttpChannel from DocumentChannel, this is likely broken: file /builds/worker/workspace/build/src/netwerk/ipc/DocumentChannel.cpp, line 63
[task 2020-02-07T16:47:43.306Z] 16:47:43     INFO - GECKO(3508) | [Child 3564, Main Thread] WARNING: Trying to request nsIHttpChannel from DocumentChannel, this is likely broken: file /builds/worker/workspace/build/src/netwerk/ipc/DocumentChannel.cpp, line 63
[task 2020-02-07T16:47:45.577Z] 16:47:45     INFO - GECKO(3508) | [Child 3564, GraphRunner] WARNING: 'rv.Failed()', file /builds/worker/workspace/build/src/dom/messagechannel/MessagePort.cpp, line 137
[task 2020-02-07T16:53:06.785Z] 16:53:06     INFO - TEST-INFO | started process screentopng
[task 2020-02-07T16:53:06.926Z] 16:53:06     INFO - TEST-INFO | screentopng: exit 0
[task 2020-02-07T16:53:06.927Z] 16:53:06     INFO - Buffered messages logged at 16:47:45
[task 2020-02-07T16:53:06.927Z] 16:53:06     INFO - Checking if we can play with WebAssembly...
[task 2020-02-07T16:53:06.927Z] 16:53:06     INFO - TEST-PASS | dom/worklet/tests/test_audioWorklet_WASM.html | WebAssembly object should exist 
[task 2020-02-07T16:53:06.928Z] 16:53:06     INFO - TEST-PASS | dom/worklet/tests/test_audioWorklet_WASM.html | WebAssembly.compile function should exist 
[task 2020-02-07T16:53:06.928Z] 16:53:06     INFO - TEST-PASS | dom/worklet/tests/test_audioWorklet_WASM.html | The WasmModule has been compiled. 
[task 2020-02-07T16:53:06.928Z] 16:53:06     INFO - TEST-PASS | dom/worklet/tests/test_audioWorklet_WASM.html | WasmModule received 
[task 2020-02-07T16:53:06.929Z] 16:53:06     INFO - Buffered messages finished
[task 2020-02-07T16:53:06.929Z] 16:53:06     INFO - TEST-UNEXPECTED-FAIL | dom/worklet/tests/test_audioWorklet_WASM.html | Test timed out. 
[task 2020-02-07T16:53:06.929Z] 16:53:06     INFO - SimpleTest.ok@https://example.com/tests/SimpleTest/SimpleTest.js:277:18
[task 2020-02-07T16:53:06.929Z] 16:53:06     INFO - reportError@https://example.com/tests/SimpleTest/TestRunner.js:121:22
[task 2020-02-07T16:53:06.929Z] 16:53:06     INFO - TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:142:18
[task 2020-02-07T16:53:06.929Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.929Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.929Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.930Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.930Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.930Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.930Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.930Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.930Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.930Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.931Z] 16:53:06     INFO - setTimeout handler*TestRunner._checkForHangs@https://example.com/tests/SimpleTest/TestRunner.js:170:15
[task 2020-02-07T16:53:06.931Z] 16:53:06     INFO - TestRunner.runTests/<@https://example.com/tests/SimpleTest/TestRunner.js:388:20
[task 2020-02-07T16:53:06.931Z] 16:53:06     INFO - promise callback*TestRunner.runTests@https://example.com/tests/SimpleTest/TestRunner.js:375:50
[task 2020-02-07T16:53:06.931Z] 16:53:06     INFO - RunSet.runtests@https://example.com/tests/SimpleTest/setup.js:201:14
[task 2020-02-07T16:53:06.932Z] 16:53:06     INFO - RunSet.runall@https://example.com/tests/SimpleTest/setup.js:180:12
[task 2020-02-07T16:53:06.933Z] 16:53:06     INFO - hookupTests@https://example.com/tests/SimpleTest/setup.js:273:12
[task 2020-02-07T16:53:06.933Z] 16:53:06     INFO - parseTestManifest@https://example.com/manifestLibrary.js:48:13
[task 2020-02-07T16:53:06.933Z] 16:53:06     INFO - getTestManifest/req.onload@https://example.com/manifestLibrary.js:61:28
Flags: needinfo?(lhansen)
Pushed by lhansen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/5a4eb6758bed
Callback from SC to DOM on SAB cloning.  r=luke

Likely the same problem. Anyway, if it doesn't work please back it out, and I'll get to it whenever.

Flags: needinfo?(lhansen)
Pushed by lhansen@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/5772a4bac3e5
Callback from SC to DOM on SAB cloning.  r=luke
Status: ASSIGNED → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla75
Flags: needinfo?(bas)
You need to log in before you can comment on or make changes to this bug.