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

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


> 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 two additional commits since the last revision:

 - Drop spurious import
 - Simplify struct/union layout code

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

Changes:
  - all: https://git.openjdk.org/panama-foreign/pull/824/files
  - new: https://git.openjdk.org/panama-foreign/pull/824/files/49b83016..57b189cd

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=panama-foreign&pr=824&range=02
 - incr: https://webrevs.openjdk.org/?repo=panama-foreign&pr=824&range=01-02

  Stats: 64 lines in 3 files changed: 17 ins; 32 del; 15 mod
  Patch: https://git.openjdk.org/panama-foreign/pull/824.diff
  Fetch: git fetch https://git.openjdk.org/panama-foreign.git pull/824/head:pull/824

PR: https://git.openjdk.org/panama-foreign/pull/824


More information about the panama-dev mailing list