RFR: 8317545: AIX PPC64: Implementation of Foreign Function & Memory API [v2]

Martin Doerr mdoerr at openjdk.org
Fri Oct 13 13:43:01 UTC 2023


On Fri, 13 Oct 2023 13:37:10 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>>> 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.

> Okay, so it sounds like Java double on AIX is still 8-byte aligned, but the native double is 4-byte aligned?

Correct within structures. I believe they are always 8-byte aligned except in structures which are packed more densely.

> In that case, I'd say that passing `JAVA_DOUBLE` as an argument resulting in an exception, is expected behavior. 

Hmm... Should we disallow to pass 8-byte aligned double values? Fixing the tests is a good thing. But, I have a different concern: I guess many developers may use them without testing on AIX. This would cause problems which we could avoid by supporting 8-byte aligned doubles in addition.

What about adding

layouts.put("jdouble", ValueLayout.JAVA_DOUBLE.withByteAlignment(4));
layouts.put("aligneddouble", ValueLayout.JAVA_DOUBLE); // allowed for usage outside of structures

?

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

PR Review Comment: https://git.openjdk.org/jdk/pull/16179#discussion_r1358281371


More information about the hotspot-compiler-dev mailing list