mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-28 07:14:30 +02:00
8307181: MemoryLayout.structLayout uses undocumented strict alignment constraints
Reviewed-by: jvernee
This commit is contained in:
parent
3f1927a7f3
commit
cecf817f5e
1 changed files with 22 additions and 0 deletions
|
@ -739,6 +739,28 @@ public sealed interface MemoryLayout permits SequenceLayout, GroupLayout, Paddin
|
||||||
* @return a struct layout with the given member layouts.
|
* @return a struct layout with the given member layouts.
|
||||||
* @throws IllegalArgumentException if the sum of the {@linkplain #bitSize() bit sizes} of the member layouts
|
* @throws IllegalArgumentException if the sum of the {@linkplain #bitSize() bit sizes} of the member layouts
|
||||||
* overflows.
|
* overflows.
|
||||||
|
* @throws IllegalArgumentException if a member layout in {@code elements} occurs at an offset (relative to the start
|
||||||
|
* of the struct layout) which is not compatible with its alignment constraint.
|
||||||
|
*
|
||||||
|
* @apiNote This factory does not automatically align element layouts, by inserting additional {@linkplain PaddingLayout
|
||||||
|
* padding layout} elements. As such, the following struct layout creation will fail with an exception:
|
||||||
|
*
|
||||||
|
* {@snippet lang = java:
|
||||||
|
* structLayout(JAVA_SHORT, JAVA_INT)
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* To avoid the exception, clients can either insert additional padding layout elements:
|
||||||
|
*
|
||||||
|
* {@snippet lang = java:
|
||||||
|
* structLayout(JAVA_SHORT, MemoryLayout.ofPadding(16), JAVA_INT)
|
||||||
|
* }
|
||||||
|
*
|
||||||
|
* Or, alternatively, they can use a member layout which features a smaller alignment constraint. This will result
|
||||||
|
* in a <em>packed</em> struct layout:
|
||||||
|
*
|
||||||
|
* {@snippet lang = java:
|
||||||
|
* structLayout(JAVA_SHORT, JAVA_INT.withBitAlignment(16))
|
||||||
|
* }
|
||||||
*/
|
*/
|
||||||
static StructLayout structLayout(MemoryLayout... elements) {
|
static StructLayout structLayout(MemoryLayout... elements) {
|
||||||
Objects.requireNonNull(elements);
|
Objects.requireNonNull(elements);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue