[foreign-memaccess+abi] RFR: 8305087: MemoryLayout API checks should be more eager [v2]
Per Minborg
pminborg at openjdk.org
Wed Mar 29 07:37:36 UTC 2023
On Tue, 28 Mar 2023 16:56:39 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.
>
> Maurizio Cimadamore has updated the pull request incrementally with one additional commit since the last revision:
>
> Update src/java.base/share/classes/java/lang/foreign/GroupLayout.java
>
> Co-authored-by: Jorn Vernee <JornVernee at users.noreply.github.com>
Marked as reviewed by pminborg (Committer).
test/jdk/java/foreign/TestLayoutPaths.java line 219:
> 217: ValueLayout.JAVA_CHAR.withBitAlignment(8).withName("1"),
> 218: ValueLayout.JAVA_FLOAT.withBitAlignment(8).withName("2"),
> 219: ValueLayout.JAVA_LONG.withBitAlignment(8).withName("3")
Maybe there should be an alias for `withBitAlignment(8)`? E.g. `JAVA_LONG.withoutAlignment()`.
-------------
PR Review: https://git.openjdk.org/panama-foreign/pull/824#pullrequestreview-1362427415
PR Review Comment: https://git.openjdk.org/panama-foreign/pull/824#discussion_r1151508371
More information about the panama-dev
mailing list