Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8308952

Improve the ability to visualize a MemorySegment in human readable forms

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Withdrawn
    • Icon: P3 P3
    • 21
    • core-libs
    • None
    • minimal
    • This is a new feature.
    • Java API
    • SE

      Summary

      Provide a Record mapper for MemorySegments/MemoryLayout pairs whereby given MemorySegment instances can be projected onto new Record instances.

      Problem

      There is a need to view MemorySegments using MemoryLayouts in a more structured way. Currently, a MemorySegment is just a bag of bytes. Initially, it was thought a view should be a String representation but we arrived at a better solution with a more general mapping capability.

      Solution

      Given a GroupLayout, the elements in the group are matched with RecordComponents. This can be done for arbitrary element types of arbitrary depth. As a simple example, one can extract a Point like so:

          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]

      Specification

      A proposed API is documented here: https://cr.openjdk.org/~pminborg/panama/21/v3/javadoc/api/java.base/java/lang/foreign/GroupLayout.html#recordMapper(java.lang.Class)

            pminborg Per-Ake Minborg
            pminborg Per-Ake Minborg
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved: