REOPENED Bug 201799
Change WebAssembly calling conventions
https://bugs.webkit.org/show_bug.cgi?id=201799
Summary Change WebAssembly calling conventions
Tadeu Zagallo
Reported 2019-09-14 09:30:01 PDT
...
Attachments
WIP (105.32 KB, patch)
2019-09-14 09:36 PDT, Tadeu Zagallo
no flags
Patch (108.68 KB, patch)
2019-09-14 23:24 PDT, Tadeu Zagallo
no flags
Patch (108.34 KB, patch)
2019-09-15 15:44 PDT, Tadeu Zagallo
no flags
Patch (108.72 KB, patch)
2019-09-15 22:40 PDT, Tadeu Zagallo
no flags
Patch (116.08 KB, patch)
2019-09-16 07:31 PDT, Tadeu Zagallo
no flags
Patch (116.89 KB, patch)
2019-09-16 07:55 PDT, Tadeu Zagallo
no flags
Patch (117.14 KB, patch)
2019-09-16 09:55 PDT, Tadeu Zagallo
no flags
Patch (117.36 KB, patch)
2019-09-16 10:01 PDT, Tadeu Zagallo
no flags
Patch (117.79 KB, patch)
2019-09-16 10:10 PDT, Tadeu Zagallo
no flags
Patch (118.52 KB, patch)
2019-09-17 13:55 PDT, Tadeu Zagallo
no flags
Patch for landing (118.88 KB, patch)
2019-09-17 16:08 PDT, Tadeu Zagallo
no flags
Tadeu Zagallo
Comment 1 2019-09-14 09:36:18 PDT
Tadeu Zagallo
Comment 2 2019-09-14 09:36:48 PDT
It seems like my last refactoring broke everything, but I'll leave this WIP patch here for now.
Tadeu Zagallo
Comment 3 2019-09-14 23:24:29 PDT
Tadeu Zagallo
Comment 4 2019-09-15 15:44:59 PDT
Created attachment 378828 [details] Patch Attaching the rebased patch, but it seems that tests are not starting locally. Investigating.
EWS Watchlist
Comment 5 2019-09-15 18:32:08 PDT
Comment on attachment 378828 [details] Patch Attachment 378828 [details] did not pass jsc-ews (mac): Output: https://webkit-queues.webkit.org/results/13034878 New failing tests: wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above-no-consts.wasm)-wasm-collect-continuously wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-multiple-enclosed-contexts.wasm)-wasm-no-cjit-yes-tls-context wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above-no-consts.wasm)-wasm-no-cjit-yes-tls-context wasm.yaml/wasm/js-api/Instance.imports.exports.unicode.js.wasm-collect-continuously wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-multiple-enclosed-contexts.wasm)-default-wasm wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above.wasm)-wasm-collect-continuously wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above-no-consts.wasm)-wasm-eager-jettison wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above-no-consts.wasm)-wasm-no-call-ic wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop.wasm)-wasm-slow-memory wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-multiple-enclosed-contexts.wasm)-wasm-eager wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop.wasm)-default-wasm wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above.wasm)-wasm-eager-jettison wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above-no-consts.wasm)-wasm-eager wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above.wasm)-wasm-no-tls-context wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above.wasm)-wasm-eager wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop.wasm)-wasm-no-call-ic wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-multiple-enclosed-contexts.wasm)-wasm-no-tls-context wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop.wasm)-wasm-no-cjit-yes-tls-context wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop.wasm)-wasm-collect-continuously wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-multiple-enclosed-contexts.wasm)-wasm-slow-memory wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-multiple-enclosed-contexts.wasm)-wasm-collect-continuously wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-multiple-enclosed-contexts.wasm)-wasm-no-air wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop.wasm)-wasm-eager-jettison wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above.wasm)-wasm-slow-memory wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above-no-consts.wasm)-wasm-no-air wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above-no-consts.wasm)-default-wasm wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above.wasm)-default-wasm wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop.wasm)-wasm-no-air wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-multiple-enclosed-contexts.wasm)-wasm-eager-jettison wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above-no-consts.wasm)-wasm-no-tls-context wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop.wasm)-wasm-eager wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above.wasm)-wasm-no-cjit-yes-tls-context wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop.wasm)-wasm-no-tls-context wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above.wasm)-wasm-no-air wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above.wasm)-wasm-no-call-ic wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-inner-loop-branch-above-no-consts.wasm)-wasm-slow-memory wasm.yaml/wasm/wast-tests/harness.js.(osr-entry-multiple-enclosed-contexts.wasm)-wasm-no-call-ic
Tadeu Zagallo
Comment 6 2019-09-15 22:40:52 PDT
Created attachment 378844 [details] Patch Fix OMG osr entry.
Yusuke Suzuki
Comment 7 2019-09-16 02:31:50 PDT
Comment on attachment 378844 [details] Patch Can you also ensure that this change keeps SamplingProfiler. work? SamplingProfiler relies on that WasmCallee exists on Callee place.
Tadeu Zagallo
Comment 8 2019-09-16 07:31:22 PDT
Created attachment 378859 [details] Patch Fix WebKit build.
Tadeu Zagallo
Comment 9 2019-09-16 07:55:31 PDT
Created attachment 378861 [details] Patch Fix CMake build.
Tadeu Zagallo
Comment 10 2019-09-16 09:55:59 PDT
Created attachment 378867 [details] Patch Fix CMake build (take 2).
Tadeu Zagallo
Comment 11 2019-09-16 10:01:01 PDT
Created attachment 378868 [details] Patch Fix CMake build (take 3).
Tadeu Zagallo
Comment 12 2019-09-16 10:10:03 PDT
Created attachment 378869 [details] Patch Fix CMake build (take 4).
Tadeu Zagallo
Comment 13 2019-09-16 10:36:35 PDT
Comment on attachment 378869 [details] Patch I've confirmed that the sampling profiler still works as expected and the bots seem happy (the wincairo failure seems like an infra failure). I think this is actually good for review now.
Saam Barati
Comment 14 2019-09-17 13:19:23 PDT
Comment on attachment 378869 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=378869&action=review > Source/JavaScriptCore/ChangeLog:16 > + - Callee writes to call frame: wasm-to-wasm stub, JS-to-wasm stub (callee frame), wasm-to-JS stub, OMG osr entry nit: "wasm-to-wasm stub" => "inter-module wasm-to-wasm stub" (since you specify intra above) > Source/JavaScriptCore/ChangeLog:18 > + Additionally, also change it so that the callee keeps track of its callers, instead of having a global mapping "also change" => maybe something like "this patch also changes" > Source/JavaScriptCore/wasm/WasmBBQPlan.cpp:331 > + nit: no newline here > Source/JavaScriptCore/wasm/WasmBBQPlan.h:142 > + const Vector<RefPtr<BBQCallee>>* m_callees { nullptr }; this is never actually null AFAICT. Why not make it a reference? > Source/JavaScriptCore/wasm/WasmBinding.cpp:71 > + // At this point, we have been called, so ReturnPC is on the stack, but have not yet pushed the base pointer, "but have" => "but we have" "base pointer" => "frame pointer" > Source/JavaScriptCore/wasm/WasmBinding.cpp:73 > + jit.storePtr(callee, JIT::Address(JIT::stackPointerRegister, CallFrameSlot::callee * sizeof(Register) - sizeof(CPURegister))); why sizeof(Register) and sizeof(CPURegister) on same line? Why not use one? > Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.cpp:109 > + BBQCallee& targetCallee = m_codeBlock->wasmBBQCalleeFromFunctionIndexSpace(call.targetFunctionIndexSpace); why just BBQ? What if it's already OMG compiled? > Source/JavaScriptCore/wasm/WasmOMGPlan.cpp:122 > + BBQCallee& targetCallee = m_codeBlock->wasmBBQCalleeFromFunctionIndexSpace(call.targetFunctionIndexSpace); why BBQ callee? What if the target is already OMG compiled? > Source/JavaScriptCore/wasm/WasmOperations.cpp:203 > + *(stackPointer + CallFrameSlot::callee - 1) = CalleeBits::boxWasm(&osrEntryCallee); this math relies on sizeof void*. You should instead rely on CPURegister, since this code is wrong for arm64_32. So something like "CPURegister* stackPointer = ...;"
Tadeu Zagallo
Comment 15 2019-09-17 13:33:19 PDT
Comment on attachment 378869 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=378869&action=review Thanks for reviewing it! >> Source/JavaScriptCore/ChangeLog:16 >> + - Callee writes to call frame: wasm-to-wasm stub, JS-to-wasm stub (callee frame), wasm-to-JS stub, OMG osr entry > > nit: "wasm-to-wasm stub" => "inter-module wasm-to-wasm stub" > (since you specify intra above) Fixed. >> Source/JavaScriptCore/ChangeLog:18 >> + Additionally, also change it so that the callee keeps track of its callers, instead of having a global mapping > > "also change" => maybe something like "this patch also changes" Fixed. >> Source/JavaScriptCore/wasm/WasmBBQPlan.h:142 >> + const Vector<RefPtr<BBQCallee>>* m_callees { nullptr }; > > this is never actually null AFAICT. Why not make it a reference? Good point, fixed. >> Source/JavaScriptCore/wasm/WasmBinding.cpp:71 >> + // At this point, we have been called, so ReturnPC is on the stack, but have not yet pushed the base pointer, > > "but have" => "but we have" > "base pointer" => "frame pointer" Fixed. >> Source/JavaScriptCore/wasm/WasmBinding.cpp:73 >> + jit.storePtr(callee, JIT::Address(JIT::stackPointerRegister, CallFrameSlot::callee * sizeof(Register) - sizeof(CPURegister))); > > why sizeof(Register) and sizeof(CPURegister) on same line? Why not use one? Because they might be different. sizeof(Register) is always 8 and sizeof(CPURegister) might be 4 or 8 depending on the arch. ReturnPC is sizeof(CPURegister) while callee, codeblock and argumentCount are sizeof(Register). >> Source/JavaScriptCore/wasm/WasmOMGForOSREntryPlan.cpp:109 >> + BBQCallee& targetCallee = m_codeBlock->wasmBBQCalleeFromFunctionIndexSpace(call.targetFunctionIndexSpace); > > why just BBQ? What if it's already OMG compiled? We call addAndLinkCaller below, which checks if the callee has a replacement. In which case, it will link it against the OMG callee. But it always the BBQ callee who holds the callers. >> Source/JavaScriptCore/wasm/WasmOMGPlan.cpp:122 >> + BBQCallee& targetCallee = m_codeBlock->wasmBBQCalleeFromFunctionIndexSpace(call.targetFunctionIndexSpace); > > why BBQ callee? What if the target is already OMG compiled? Replied above. >> Source/JavaScriptCore/wasm/WasmOperations.cpp:203 >> + *(stackPointer + CallFrameSlot::callee - 1) = CalleeBits::boxWasm(&osrEntryCallee); > > this math relies on sizeof void*. You should instead rely on CPURegister, since this code is wrong for arm64_32. > > So something like "CPURegister* stackPointer = ...;" Fixed.
Tadeu Zagallo
Comment 16 2019-09-17 13:55:46 PDT
Saam Barati
Comment 17 2019-09-17 15:28:08 PDT
Comment on attachment 378986 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=378986&action=review > Source/JavaScriptCore/wasm/WasmOMGPlan.cpp:123 > + BBQCallee& targetCallee = m_codeBlock->wasmBBQCalleeFromFunctionIndexSpace(call.targetFunctionIndexSpace); > + targetCallee.addAndLinkCaller(holder, linkBuffer, call.unlinkedMoveAndCall); this targetCallee is different than the one below. The below is what we're compiling. This targetCallee is what OMG is going to call. It seems wrong to make OMG compile always call BBQ...
Saam Barati
Comment 18 2019-09-17 15:59:52 PDT
Comment on attachment 378986 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=378986&action=review r=me >> Source/JavaScriptCore/wasm/WasmOMGPlan.cpp:123 >> + targetCallee.addAndLinkCaller(holder, linkBuffer, call.unlinkedMoveAndCall); > > this targetCallee is different than the one below. The below is what we're compiling. This targetCallee is what OMG is going to call. It seems wrong to make OMG compile always call BBQ... I see. addAndLinkCaller looks for a replacement. Seems like kinda a weird paradigm, but it's OK
Tadeu Zagallo
Comment 19 2019-09-17 16:01:54 PDT
Comment on attachment 378986 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=378986&action=review >>> Source/JavaScriptCore/wasm/WasmOMGPlan.cpp:123 >>> + targetCallee.addAndLinkCaller(holder, linkBuffer, call.unlinkedMoveAndCall); >> >> this targetCallee is different than the one below. The below is what we're compiling. This targetCallee is what OMG is going to call. It seems wrong to make OMG compile always call BBQ... > > I see. addAndLinkCaller looks for a replacement. Seems like kinda a weird paradigm, but it's OK We could do it explicitly, by passing targetCallee.replacement(), but I thought that seemed unnecessary. I wanted to keep all callers in the BBQCallee so that we don't need to iterate through all callees.
Tadeu Zagallo
Comment 20 2019-09-17 16:08:43 PDT
Created attachment 379003 [details] Patch for landing
WebKit Commit Bot
Comment 21 2019-09-17 16:52:35 PDT
Comment on attachment 379003 [details] Patch for landing Clearing flags on attachment: 379003 Committed r250002: <https://trac.webkit.org/changeset/250002>
WebKit Commit Bot
Comment 22 2019-09-17 16:52:37 PDT
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 23 2019-09-17 16:53:18 PDT
WebKit Commit Bot
Comment 24 2019-09-18 14:00:26 PDT
Re-opened since this is blocked by bug 201943
Note You need to log in before you can comment on or make changes to this bug.