Skip to content

Commit f1ba03e

Browse files
ChengJin01pshipton
authored andcommitted
[Jtreg/FFI] Backport layout() for struct from JDK19 to JDK17
The change is to backport the test code of layout() from JDK19 to JDK17 to resolve the padding & alignment issue with struct in tests given layout() in JDK19 proves to work for all downcall && upcall specific test suites on all supported platforms. Fixes: eclipse-openj9/openj9#16408 Signed-off-by: ChengJin01 <[email protected]>
1 parent 6759bf0 commit f1ba03e

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

test/jdk/java/foreign/CallGeneratorHelper.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ MemoryLayout layout(List<StructFieldType> fields) {
145145
if (this == STRUCT) {
146146
long offset = 0L;
147147
List<MemoryLayout> layouts = new ArrayList<>();
148+
long align = 0;
148149
for (StructFieldType field : fields) {
149150
MemoryLayout l = field.layout();
150151
/* Follow the calculation of padding in JDK19 which is based on
@@ -156,8 +157,13 @@ MemoryLayout layout(List<StructFieldType> fields) {
156157
offset += padding;
157158
}
158159
layouts.add(l.withName("field" + offset));
160+
align = Math.max(align, l.bitAlignment());
159161
offset += l.bitSize();
160162
}
163+
long padding = offset % align;
164+
if (padding != 0) {
165+
layouts.add(MemoryLayout.paddingLayout(padding));
166+
}
161167
return MemoryLayout.structLayout(layouts.toArray(new MemoryLayout[0]));
162168
} else {
163169
return layout;

0 commit comments

Comments
 (0)