[foreign-preview] RFR: 8286306: Upcall wrapper class sharing
Jorn Vernee
jvernee at openjdk.java.net
Fri May 6 15:03:26 UTC 2022
On Fri, 6 May 2022 14:50:53 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> This patch adds upcall wrapper class sharing.
>
> I recently realized that these classes can be shared if they have the same input FunctionDescriptor, but a different target method handle.
>
> This is implemented by generating a wrapper class that takes the target method handles as a leading argument. The target method handle is then inserted into the parameter list using `MethodHandles::insertArguments` to create the final method handle that is returned by the specializer. After MH customization kicks in, the target will be a constant again (so shouldn't affect peak performance).
>
> Doing this doesn't effect peak performance, as verified through the Upcalls benchmark, but does significantly improve linking performance.
>
> Before:
>
> Benchmark Mode Cnt Score Error Units
> LinkUpcall.link_blank avgt 30 69.323 � 2.522 us/op
>
> After:
>
> Benchmark Mode Cnt Score Error Units
> LinkUpcall.link_blank avgt 30 11.787 � 0.744 us/op
src/java.base/share/classes/jdk/internal/foreign/abi/SharedUtils.java line 215:
> 213: // adjust return type so it matches the inferred type of the effective
> 214: // function descriptor
> 215: target = target.asType(target.type().changeReturnType(Addressable.class));
Note that this is needed to prevent a situation on Windows where the effective function descriptor of `()[<some IMR struct>]` is the same as a plain `(a64)a64` function descriptor. The `target` will currently have the type `(MemoryAddress)MemoryAddress` in the former case, but `(MemoryAddress)Addressable` in the latter case. However, they share an upcall wrapper class because they have the same effective function descriptor (which is good), and this leads to a `WrongMethodTypeException` when invoking one of them.
-------------
PR: https://git.openjdk.java.net/panama-foreign/pull/679
More information about the panama-dev
mailing list