[foreign-memaccess+abi] RFR: 8255903: Enable multi-register return values for native invokers
Jorn Vernee
jvernee at openjdk.java.net
Thu Oct 21 13:37:26 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/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/ProgrammableInvoker.java line 272:
> 270: private record InvocationData(MethodHandle leaf, Map<VMStorage, Integer> argIndexMap, Map<VMStorage, Integer> retIndexMap) {}
> 271:
> 272: Object invokeInterpBindings(SegmentAllocator allocator, Object[] args, InvocationData invData) throws Throwable {
I kept changing the parameters of this method, and it became annoying to have to keep update the signature in multiple places, so I folded the 'customization' parameters into a record (`InvocationData`). In the end no new parameters were added, but I've kept the record since I think it's nice that the customization data is bundled together.
src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/SharedUtils.java line 398:
> 396: // downcalls get the leading NativeSymbol/SegmentAllocator param as well
> 397: if (!upcall) {
> 398: closer = collectArguments(closer, insertPos++, reachabilityFenceHandle(NativeSymbol.class));
This reachability fence for the target address is no longer needed I think. It is already being handled by the wrapper that acquires the scope of the target address. (https://github.com/openjdk/panama-foreign/blob/451eead47e7a1b6a0aedeca5cb2f32427b9c46dc/src/jdk.incubator.foreign/share/classes/jdk/internal/foreign/abi/SharedUtils.java#L511)
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/603
More information about the panama-dev
mailing list