RFR: 7904115: Fix for AIX test case failures due to incorrect alignment for double and pointer [v2]

Varada M varadam at openjdk.org
Tue Nov 25 18:41:16 UTC 2025


On Fri, 21 Nov 2025 15:40:01 GMT, Jorn Vernee <jvernee at openjdk.org> wrote:

>> Varada M has updated the pull request incrementally with two additional commits since the last revision:
>> 
>>  - addition of  -m64 at right place
>>  - addition of  -m64 at right place
>
> @varada1110 
> 
> You could also try the following patch:
> 
> 
> diff --git a/src/main/java/org/openjdk/jextract/impl/ClassSourceBuilder.java b/src/main/java/org/openjdk/jextract/impl/ClassSourceBuilder.java
> index 7c1ae3a..a317dc5 100644
> --- a/src/main/java/org/openjdk/jextract/impl/ClassSourceBuilder.java
> +++ b/src/main/java/org/openjdk/jextract/impl/ClassSourceBuilder.java
> @@ -30,7 +30,6 @@ import org.openjdk.jextract.Type.Declared;
>  import org.openjdk.jextract.Type.Delegated;
>  import org.openjdk.jextract.Type.Function;
>  import org.openjdk.jextract.Type.Primitive;
> -import org.openjdk.jextract.impl.DeclarationImpl.ClangAlignOf;
>  import org.openjdk.jextract.impl.DeclarationImpl.ClangEnumType;
>  import org.openjdk.jextract.impl.DeclarationImpl.DeclarationString;
>  import org.openjdk.jextract.impl.DeclarationImpl.JavaName;
> @@ -201,19 +200,25 @@ abstract class ClassSourceBuilder {
>          throw new IllegalArgumentException("Not handled: " + type);
>      }
>  
> +    private static final int NO_ALIGN_REQUIRED_MARKER = -1;
> +
>      String layoutString(Type type) {
> -        return layoutString(type, Long.MAX_VALUE);
> +        return fieldLayoutString(type, -1, NO_ALIGN_REQUIRED_MARKER);
>      }
>  
> -    String layoutString(Type type, long align) {
> +    String fieldLayoutString(Type type, long typeAlign, long expectedAlign) {
>          return switch (type) {
> -            case Primitive p -> primitiveLayoutString(p, align);
> -            case Declared d when Utils.isEnum(d) -> layoutString(ClangEnumType.get(d.tree()).get(), align);
> -            case Declared d when Utils.isStructOrUnion(d) -> alignIfNeeded(JavaName.getFullNameOrThrow(d.tree()) + ".layout()", ClangAlignOf.getOrThrow(d.tree()) / 8, align);
> -            case Delegated d when d.kind() == Delegated.Kind.POINTER -> alignIfNeeded(runtimeHelperName() + ".C_POINTER", 8, align);
> -            case Delegated d -> layoutString(d.type(), align);
> -            case Function _ -> alignIfNeeded(runtimeHelperName() + ".C_POINTER", 8, align);
> -            case Array a -> String.format("MemoryLayout.sequenceLayout(%1$d, %2$s)", a.elementCount().orElse(0L), layoutString(a.elementType(), align));
> +            case Primitive p -> primitiveLayoutString(p, typeAlign, expectedAlign);
> +            case Declared d when Utils.isEnum(d) ->
> +                    fieldLayoutString(ClangEnumType.get(d.tree()).get(), typeAlign, expectedAlign);
> +            case Declared d when Utils.isStructOrUnion(d) ->
> +                    alignIfNeeded(JavaName.getFull...

Thank you @JornVernee @mcimadamore .
I understood the part; instead of using the struct-level alignment globally, we should compute the alignment of each individual field !
I have tried out the code changes @JornVernee has shared! I do see the same two tests failing again with "Invalid alignment constraint for member layout: D(8)" this time the default and expected alignment is of same value which is 4. I am currently looking into that!

I have reverted the changes of C_DOUBLE alignment changes to create separate PR

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

PR Comment: https://git.openjdk.org/jextract/pull/296#issuecomment-3577025565


More information about the jextract-dev mailing list