[foreign-memaccess+abi] RFR: 8305087: MemoryLayout API checks should be more eager [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu Mar 30 10:55:34 UTC 2023


On Wed, 29 Mar 2023 07:29:57 GMT, Per Minborg <pminborg at openjdk.org> wrote:

>> 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>
>
> src/java.base/share/classes/jdk/internal/foreign/layout/AbstractGroupLayout.java line 143:
> 
>> 141:             long size = 0;
>> 142:             for (MemoryLayout elem : elems) {
>> 143:                 if (this == STRUCT && (size % elem.bitAlignment() != 0)) {
> 
> We might drop `sizeOp` and instead have two different `sizeof` implementations in a more OO style.

I've did another pass on the impl, where I've greatly simplified AbstractGroupLayoutImpl, StructLayoutImpl and UnionLayoutImpl. Now all the computation occurs in their factories (which is better, as the stack trace in case of an issue is more readable), rather than inside the enum methods. Also, the new classes avoid any kind of re-computation: for each group, we compute size and alignment upfront. We then store the original alignment into a new field (`minBitAlignment`) so that we can use that to determine validity of subsequent `withBitAlignment` operations.

-------------

PR Review Comment: https://git.openjdk.org/panama-foreign/pull/824#discussion_r1153080139


More information about the panama-dev mailing list