RFR: 8308276: Change layout API to work with bytes, not bits [v2]

Maurizio Cimadamore mcimadamore at openjdk.org
Thu May 18 09:13:20 UTC 2023


> As explained in [1], memory layouts and memory segments describe sizes using different units. Memory layouts use bits, whereas memory segments use bytes. This is historical: memory layouts were designed after the Minimal LDL [2], which allowed layout strings to be used to describe both memory *and* register. In practice that ship has sailed, and the FFM API uses layouts to firmly model the contents of regions of memory. While it would be possible, in principle, to tweak segments to work on bits, changing that would have implications on how easily code that is currently using ByteBuffer can migrate to use MemorySegment.
> 
> For these reasons, this patch fixes the asymmetry so that layouts also model sizes in term of bytes.
> 
> The patch is straightforward, although a bit tedious (as you can imagine), as various uses of bit sizes had to be turned in byte sizes. In practice, the migration had not been too hard, for the following reasons:
> 
> * the `withBitAlignment` and `bitSize` methods are no longer in the API, it is easy to fix any code (mainly tests) using it;
> * most code already uses ready-made constants such as `JAVA_INT` - such code continues to work unchanged;
> * the layout API de facto already required clients to work with bit sizes that are a multiple of 8.
> 
> The only problematic case is the presence of the `MemoryLayout::paddingLayout(long size)` factory. As this factory is changed to deal in bytes instead of bits, all constants passed to this factory will need to be updated. This is not a problem for code using jextract (as jextract will take care of generating padding) but will be an issue for code using the layout API directly.
> 
> [1] - https://mail.openjdk.org/pipermail/panama-dev/2023-May/019059.html

Maurizio Cimadamore has updated the pull request incrementally with five additional commits since the last revision:

 - Update test/jdk/java/foreign/TestLayouts.java
   
   Co-authored-by: Paul Sandoz <paul.d.sandoz at googlemail.com>
 - Update test/jdk/java/foreign/TestLayoutPaths.java
   
   Co-authored-by: Paul Sandoz <paul.d.sandoz at googlemail.com>
 - Update test/jdk/java/foreign/TestLayoutPaths.java
   
   Co-authored-by: Paul Sandoz <paul.d.sandoz at googlemail.com>
 - Update test/jdk/java/foreign/TestLayoutPaths.java
   
   Co-authored-by: Paul Sandoz <paul.d.sandoz at googlemail.com>
 - Update src/java.base/share/classes/jdk/internal/foreign/layout/ValueLayouts.java
   
   Co-authored-by: Paul Sandoz <paul.d.sandoz at googlemail.com>

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

Changes:
  - all: https://git.openjdk.org/jdk/pull/14013/files
  - new: https://git.openjdk.org/jdk/pull/14013/files/0f6f4e29..4fe42c17

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=14013&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=14013&range=00-01

  Stats: 8 lines in 3 files changed: 0 ins; 0 del; 8 mod
  Patch: https://git.openjdk.org/jdk/pull/14013.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/14013/head:pull/14013

PR: https://git.openjdk.org/jdk/pull/14013


More information about the core-libs-dev mailing list