JDK-8318175 : AIX PPC64: Handle alignment of double in structs
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.lang.foreign
  • Affected Version: 22
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: aix
  • Submitted: 2023-10-16
  • Updated: 2023-11-30
  • Resolved: 2023-11-22
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 22
22 b26Fixed
Description
AIX supports several alignment modes, which can be selected by pragma align specifiers: https://www.ibm.com/docs/en/openxl-c-and-cpp-aix/17.1.1?topic=pragmas-pragma-align
Default is "power" which uses 4-byte alignment for doubles which are not at the beginning of a struct. It is described here: https://www.ibm.com/docs/en/xl-c-and-cpp-aix/16.1?topic=data-using-alignment-modes
"natural" is recommended when compatibility with AIX libraries is not needed, which were built with the default setting.

The current FFI tests don't support the "power" mode. One option is to adapt these tests to use 4-byte alignment on AIX where needed.
Another option is to build the test libraries with "natural" specifier.
Comments
Changeset: bf0a904f Author: suchismith <suchismith1993@gmail.com> Committer: Martin Doerr <mdoerr@openjdk.org> Date: 2023-11-22 13:39:25 +0000 URL: https://git.openjdk.org/jdk/commit/bf0a904f0e2f29e9967c38e437b702d92c096e88
22-11-2023

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/16579 Date: 2023-11-09 09:22:45 +0000
14-11-2023

One possible solution is this (seems like it only works with the normal linker, not with the fallback linker): diff --git a/test/jdk/java/foreign/nested/libNested.c b/test/jdk/java/foreign/nested/libNested.c index a1414d6ed61..3aa55b2f2d0 100644 --- a/test/jdk/java/foreign/nested/libNested.c +++ b/test/jdk/java/foreign/nested/libNested.c @@ -27,6 +27,10 @@ #define EXPORT #endif +#ifdef _AIX +#pragma align (natural) +#endif + struct S1{ double f0; long long f1; double f2; int f3; }; union U1{ short f0; long long f1; short f2; char f3[4][3]; }; union U17{ char f0; char f1; long long f2; double f3; }; @@ -92,3 +96,7 @@ EXPORT struct S13 test_S13(struct S13 arg, struct S13(*cb)(struct S13)) { return EXPORT struct S14 test_S14(struct S14 arg, struct S14(*cb)(struct S14)) { return cb(arg); } EXPORT union U16 test_U16(union U16 arg, union U16(*cb)(union U16)) { return cb(arg); } EXPORT struct S15 test_S15(struct S15 arg, struct S15(*cb)(struct S15)) { return cb(arg); } + +#ifdef _AIX +#pragma align (reset) +#endif diff --git a/test/jdk/java/foreign/shared.h b/test/jdk/java/foreign/shared.h index 1cadc1075d6..3323e4db207 100644 --- a/test/jdk/java/foreign/shared.h +++ b/test/jdk/java/foreign/shared.h @@ -35,6 +35,10 @@ #define EXPORT #endif +#ifdef _AIX +#pragma align (natural) +#endif + struct S_I { int p0; }; struct S_F { float p0; }; struct S_D { double p0; }; @@ -120,3 +124,7 @@ struct S_PPF { void* p0; void* p1; float p2; }; struct S_PPD { void* p0; void* p1; double p2; }; struct S_PPP { void* p0; void* p1; void* p2; }; struct S_FFFF { float p0; float p1; float p2; float p3; }; + +#ifdef _AIX +#pragma align (reset) +#endif
02-11-2023

Hi Martin, I'm triaging and assigning this bug to you. Please, re-assign it if appropriate.
23-10-2023