RFR: 7903628: Replace ofAddress method in FI classes with a static invoke method

Jorn Vernee jvernee at openjdk.org
Tue Jan 16 16:52:50 UTC 2024


On Tue, 16 Jan 2024 16:44:17 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This patch replaces the factory method in the generated function pointer interfaces with a static invoke method. This avoids clients having to wrap a function pointer in an instance of the interface in order to invoke it, and instead allows invoking function pointers more directly. This aligns with the general jextract strategy of being 'all static' which avoids object allocation overheads.
>> 
>> The new approach also simplifies the handling of function pointers that accept an allocator (because they return a struct by-value), as now we no longer how to infer the allocator, but the client can pass it explicitly when invoking the function pointer.
>
> src/main/java/org/openjdk/jextract/impl/FunctionalInterfaceBuilder.java line 92:
> 
>> 90:             MethodHandle DOWN$MH = Linker.nativeLinker().downcallHandle($DESC);
>> 91: 
>> 92:             static \{methodType.returnType().getSimpleName()} invoke(MemorySegment funcPtr\{allocParam}\{paramStr}) {
> 
> this should be `public` right?

Yes. It's implicitly `public` (due to being inside an interface).

-------------

PR Review Comment: https://git.openjdk.org/jextract/pull/180#discussion_r1453702101


More information about the jextract-dev mailing list