On Fri, 13 Oct 2023 13:02:24 GMT, Jorn Vernee <jver...@openjdk.org> wrote:
>> Not sure how `jdouble` would be used. JNI doesn't support C structures and >> the double alignment is only an issue in structures. Do we support embedding >> `jdouble` in structures? I guess changing it would probably be better? >> Note that we will need something which maps to the 8-Byte aligned `double`. >> Otherwise we get an Exception when passing a `JAVA_DOUBLE` as normal >> argument: >> >> IllegalArgumentException: Unsupported layout: D8 >> at >> java.base/jdk.internal.foreign.abi.AbstractLinker.checkSupported(AbstractLinker.java:244) >> at >> java.base/jdk.internal.foreign.abi.AbstractLinker.checkLayoutRecursive(AbstractLinker.java:185) >> at >> java.base/jdk.internal.foreign.abi.AbstractLinker.checkLayout(AbstractLinker.java:179) >> at java.base/java.lang.Iterable.forEach(Iterable.java:75) >> at >> java.base/jdk.internal.foreign.abi.AbstractLinker.checkLayouts(AbstractLinker.java:171) >> at >> java.base/jdk.internal.foreign.abi.AbstractLinker.downcallHandle0(AbstractLinker.java:98) >> at >> java.base/jdk.internal.foreign.abi.AbstractLinker.downcallHandle(AbstractLinker.java:85) >> at TestDowncall.<clinit>(TestDowncall.java:127) > >> I guess changing it would probably be better? > > Yeah, I think so. > >> Note that we will need something which maps to the 8-Byte aligned double. >> Otherwise we get an Exception when passing a JAVA_DOUBLE as normal argument. > > Okay, so it sounds like Java double on AIX is still 8-byte aligned, but the > native double is 4-byte aligned? > > In that case, I'd say that passing `JAVA_DOUBLE` as an argument resulting in > an exception, is expected behavior. Using `JAVA_DOUBLE` to link native > functions works more or less by coincidence, since it has the same layout as > the native `double`, on all other platforms. The AIX issue with double is not > dissimilar to using JAVA_LONG to link against a function taking a native > `long` on Windows, in which case the size of the type doesn't match. > > The philosophy here is: a client is responsible for passing the right > FunctionDescriptor/layouts, that matches the native function declaration. On > AIX, JAVA_DOUBLE is just never the right layout, and the linker detects this > and throws an exception. > > I understand that some of the existing tests might be lazy and use > JAVA_DOUBLE to link functions. It is fine to update those tests, e.g. to use > C_DOUBLE defined in NativeTestHelper. Just to clarify, is the ABI equal to what is described in this table: https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1?topic=data-using-alignment-modes ? This shows `double` having 8-byte alignment, but being 4-byte aligned when not the first member of an aggregate. ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/16179#discussion_r1358279022