RFR: 7903660: Drop layout-inferring varargs invoker + add method handle factory
Maurizio Cimadamore
mcimadamore at openjdk.org
Mon Feb 12 14:22:07 UTC 2024
On Mon, 12 Feb 2024 13:17:31 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:
> This PR removes the layout-inferring variadic invokers that we generate. Instead, users will have to create an instance of the invoker interface first, by specifying the layouts of the variadic args explicitly. This leads to a more WYSIWYG approach, where we don't have to guess what the correct variadic layouts are.
>
> Additionally, a `handle` and `descriptor` factory are added to the invoker interface, which can be used to create specialized method handles and function descriptors for the variadic function. The base descriptor and function address are also exposed as fields.
>
> Open questions:
> 1. Should we try and hide these fields (with another private nested class)? And if not, should we expose the function address for regular functions as well?
> 2. Some layouts are illegal as variadic layouts (e.g. C_FLOAT). The `descriptor` factory currently doesn't reject these. Are we happy with that? On the other hand. Making this factory reject those layouts would be quite some work, and would need to be kept in sync with the linker implementation. This didn't seem worth it, so I've left this.
>
> Finally, I've removed the now unused runtime helper code related to inferring variadic layouts.
Re. (2) - this is tricky, yes. I think perhaps some mention of that in the javadoc for the invoker factory might be a good thing? (e.g. all integral types are promoted to int/long, all floating point types are promoted to double).
src/main/java/org/openjdk/jextract/impl/HeaderFileBuilder.java line 199:
> 197: appendLines(STR."""
> 198: public interface \{invokerClassName} {
> 199: FunctionDescriptor BASE_DESC = \{functionDescriptorString(2, decl.type())};
My 0.02$ (related to your question 1): let's make this a record which takes a method handle and a specialized descriptor, which are then exposed with the record accessors, as usual. Drop the static accessors, after all, a client can access the specialized MH/desc by first creating an instance of this invoker class (which will be likely escaped away if the client only wants the MH). Then, we can hide the non-specialized fields as `private`.
-------------
PR Comment: https://git.openjdk.org/jextract/pull/205#issuecomment-1938761227
PR Review Comment: https://git.openjdk.org/jextract/pull/205#discussion_r1486241864
More information about the jextract-dev
mailing list