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

Maurizio Cimadamore mcimadamore at openjdk.org
Tue Jan 16 16:48:51 UTC 2024


On Tue, 16 Jan 2024 15:55:16 GMT, Jorn Vernee <jvernee 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.

Looks great - feels a lot more consistent with the rest of the generated code than before.

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?

src/main/java/org/openjdk/jextract/impl/FunctionalInterfaceBuilder.java line 111:

> 109:     }
> 110: 
> 111:     private String paramExprs() {

Nice simplification

test/jtreg/generator/allocCallback/TestAllocCallback.java line 55:

> 53:             var foo = alloc_callback_h.foo$SEGMENT();
> 54: 
> 55:             var barA = Foo.a.invoke(Foo.a(foo), arena);

❤

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

Marked as reviewed by mcimadamore (Reviewer).

PR Review: https://git.openjdk.org/jextract/pull/180#pullrequestreview-1824140611
PR Review Comment: https://git.openjdk.org/jextract/pull/180#discussion_r1453695055
PR Review Comment: https://git.openjdk.org/jextract/pull/180#discussion_r1453696548
PR Review Comment: https://git.openjdk.org/jextract/pull/180#discussion_r1453697109


More information about the jextract-dev mailing list