[foreign-memaccess+abi] RFR: 8291639: Improve the ability to visualize a MemorySegment in human readable forms

Per Minborg pminborg at openjdk.org
Fri May 26 12:39:44 UTC 2023


This PR proposes to add a "Record Mapper" that allows `MemorySegment` instances to be projected onto `Record` types given `GroupLayout` instances.

Here is a simple example of how to use the mapper:


    private static final GroupLayout POINT_LAYOUT = MemoryLayout.structLayout(
            JAVA_INT.withName("x"),
            JAVA_INT.withName("y"));

    MemorySegment segment =  MemorySegment.ofArray(new int[]{3, 4});

    Point point = POINT_LAYOUT.recordMapper(Point.class)
          .apply(segment); // Point[x=3, y=4]


I think the implementation can be improved later, for example by de-duplicating handling of arrays and maybe add recursive "un-pealing" of multidimensional arrays.

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

Commit messages:
 - Fix typos
 - Clean up toString methods
 - Add support for MemoryAddress arrays and improve docs
 - Improve javadoc
 - Change to IAE if mapper fails
 - Remove caching
 - Add tests for initial issue examples
 - Clean up and optimize
 - Add support for multidimensional records
 - Clean up mapper
 - ... and 18 more: https://git.openjdk.org/panama-foreign/compare/139a8d26...2d826bfe

Changes: https://git.openjdk.org/panama-foreign/pull/833/files
 Webrev: https://webrevs.openjdk.org/?repo=panama-foreign&pr=833&range=00
  Issue: https://bugs.openjdk.org/browse/JDK-8291639
  Stats: 1955 lines in 6 files changed: 1954 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/panama-foreign/pull/833.diff
  Fetch: git fetch https://git.openjdk.org/panama-foreign.git pull/833/head:pull/833

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


More information about the panama-dev mailing list