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

Per Minborg pminborg at openjdk.org
Mon May 29 13:33:26 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.

Per Minborg has updated the pull request incrementally with one additional commit since the last revision:

  Use explicit call rather than using a method

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

Changes:
  - all: https://git.openjdk.org/panama-foreign/pull/833/files
  - new: https://git.openjdk.org/panama-foreign/pull/833/files/48e3d8b3..da1f7586

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=panama-foreign&pr=833&range=08
 - incr: https://webrevs.openjdk.org/?repo=panama-foreign&pr=833&range=07-08

  Stats: 18 lines in 1 file changed: 4 ins; 12 del; 2 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