[foreign-memaccess+abi] RFR: 8305087: MemoryLayout API checks should be more eager
Maurizio Cimadamore
mcimadamore at openjdk.org
Tue Mar 28 14:14:34 UTC 2023
On Tue, 28 Mar 2023 14:04:35 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> This patch adds eager check on construction of sequence and group layouts. More specifically:
>
> * sequenceLayout(L) is well-formed iff L.bitAlignment() <= L.bitSize()
> * groupLayout(L1, … Ln) is well-formed iff for-each 1..n, offset(Li) % Li.bitAlignment() == 0
>
> Moreover, this patch also validates the alignment parameter to calls of `MemoryLayout::withBitAlignment` on sequence and group layouts:
>
> * sequenceLayout(L).withBitAlignment(a) is well-formed iff L.bitAlignment() <= a
> * groupLayout(L1, ..., Ln).withBitAlignment(a) is well-formed iff max(L1.bitAlignment(), ..., Ln.bitAlignment()) <= a
>
> These checks prevent bad layouts from being constructed (either with factories, or with bad calls to `withBitAlignment`), w/o restricting the expressiveness of the memory layout API.
> Moreover, since all layouts are now well-formed by construction, we no longer need lazy checks when creating a deferefence var handle.
test/jdk/java/foreign/callarranger/TestRISCV64CallArranger.java line 218:
> 216: },
> 217: // struct __attribute__((__packed__)) s { float a; double b; };
> 218: { MemoryLayout.structLayout(C_FLOAT, C_DOUBLE),
These two tests refer to packed structs, or structs that have extra padding. These cases are no longer supported following this: https://git.openjdk.org/jdk/pull/13164
-------------
PR Review Comment: https://git.openjdk.org/panama-foreign/pull/824#discussion_r1150689519
More information about the panama-dev
mailing list