From cdf337357a62dd52c00e56e75912565e15b6adfd Mon Sep 17 00:00:00 2001 From: Jorn Vernee Date: Mon, 6 Nov 2023 15:09:26 +0000 Subject: [PATCH] 8319316: Clarify text around which layouts a linker supports Reviewed-by: mcimadamore --- .../classes/java/lang/foreign/Linker.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/java.base/share/classes/java/lang/foreign/Linker.java b/src/java.base/share/classes/java/lang/foreign/Linker.java index 1a39f9db3b3..c1304b8fc89 100644 --- a/src/java.base/share/classes/java/lang/foreign/Linker.java +++ b/src/java.base/share/classes/java/lang/foreign/Linker.java @@ -224,8 +224,8 @@ import java.util.stream.Stream; * * *

- * All native linker implementations operate on a subset of memory layouts. More formally, a layout {@code L} - * is supported by a native linker {@code NL} if: + * All native linker implementations support a well-defined subset of layouts. More formally, + * a layout {@code L} is supported by a native linker {@code NL} if: *

* + * Linker implementations may optionally support additional layouts, such as packed struct layouts. + * A packed struct is a struct in which there is at least one member layout {@code L} that has an alignment + * constraint less strict than its natural alignment. This allows avoiding padding between member layouts, + * as well as avoiding padding at the end of the struct layout. For example: + * {@snippet lang = java: + * // No padding between the 2 element layouts: + * MemoryLayout noFieldPadding = MemoryLayout.structLayout( + * ValueLayout.JAVA_INT, + * ValueLayout.JAVA_DOUBLE.withByteAlignment(4)); + * + * // No padding at the end of the struct: + * MemoryLayout noTrailingPadding = MemoryLayout.structLayout( + * ValueLayout.JAVA_DOUBLE.withByteAlignment(4), + * ValueLayout.JAVA_INT); + * } + *

* A native linker only supports function descriptors whose argument/return layouts are layouts supported by that linker * and are not sequence layouts. *