[foreign-memaccess+abi] RFR: 8255903: Enable multi-register return values for native invokers
Jorn Vernee
jvernee at openjdk.java.net
Thu Oct 21 13:29:42 UTC 2021
On Thu, 21 Oct 2021 13:15:39 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> Hi,
>
> This patch implements support for multi-register returns in native invokers, and removes the buffered invocation strategy for downcalls. This is achieved, essentially, by using an in memory return: the caller allocates a bit of memory, and the native invoker stub writes the values of the return register to that memory. Then, the post processing code reads the register values back from there.
>
> Currently, the target address of a downcall is handled separately from the other arguments. I initially implemented passing the IMR address the same way, but I realized the removal of the buffered invocation strategy affords us a better way of doing things: we can just make the target address and the IMR address part of the normal calling sequence, and remove a bunch of special-casing code to handle these. We now just use a binding recipe to unbox these arguments and shuffle them into registers, and the ABIDescriptor tells the native invoker stub which registers to pick up these arguments from.
>
> Thanks,
> Jorn
src/hotspot/cpu/aarch64/universalNativeInvoker_aarch64.cpp line 225:
> 223: assert(!target_uses_register(tmp1->as_VMReg()), "conflict");
> 224: assert(!target_uses_register(tmp2->as_VMReg()), "conflict");
> 225: assert(!target_uses_register(rthread->as_VMReg()), "conflict");
I realized these checks were bogus now that we shuffle arguments as part of the native invoker stub. It is fine for the call to use these registers. Though, if `rthread` is clobbered by the call, we would need to save and restore it (currently that's not the case on any platform though, so we assume it doesn't happen).
src/hotspot/share/prims/foreign_globals.cpp line 103:
> 101: }
> 102:
> 103: int CallRegs::calling_convention(BasicType* sig_bt, VMRegPair *regs, int num_args) const {
Since this was essentially the same as `DownCallNativeConv` after making the target address part of the normal list of arguments, I've removed this implementation of `calling_convetion` and am now using `(DownCall)NativeConv` for both down and up calls.
src/jdk.incubator.foreign/share/classes/jdk/incubator/foreign/CLinker.java line 38:
> 36:
> 37: import java.lang.invoke.MethodHandle;
> 38: import java.lang.invoke.MethodHandles;
Suggestion:
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/603
More information about the panama-dev
mailing list