[foreign-memaccess+abi] RFR: 8307253: Make FunctionDescriptor::toMethodType an instance method of Linker [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu May 4 09:55:46 UTC 2023


On Thu, 4 May 2023 09:50:44 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:

>> This patch moves `FunctionDescriptor::toMethodType` as an instance method of `Linker`. This allows linker implementations to be more opinionated on how the function descriptor -> method type conversion should behave.
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
> 
>   Revert changes.
>   Fix javadoc and impl for FunctionDescriptor::toMethodType to allow sequence layouts.

After some offline discussion, we realized that the current API is actually good enough: FunctionDescriptor::toMethodType defines the "lowest common denominator" for turning a function descriptor into a MethodType. In doing this conversion, we follow the carrier types indicated by value layouts. For structs/unions/sequences we assume the carrier is MemorySegment (it is possible that in the future we will also add a carrier() accessor on composite layouts that can be overridden). Finally, for padding layout we just throw (after all, a padding argument/return doesn't seem to make much sense). Capturing this conversion at the level of FunctionDescription still seems like the right thing to do.

However, there is a small detail which this patch fixes: FunctionDescriptor::toMethodType currently rejects sequence layouts. While it is certainly the case that the C ABI does not allow to pass arrays by value. And even if this is the most common choice, this is not the only possible choice (for instance, Pascal has special convention for passing arrays to functions where the size of the array is known). As such, I think we should not bias the conversion with what we know the native linker will and will not support.

For this reason, I've tweaked the checks in the conversion, and then made some checks stricter in the linker - so that now sequence layouts are rejected at the level of the linker.

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

PR Comment: https://git.openjdk.org/panama-foreign/pull/830#issuecomment-1534442683


More information about the panama-dev mailing list