[foreign-memaccess+abi] RFR: Add an internal MemoryInspection class

Per Minborg duke at openjdk.org
Wed Sep 7 11:34:45 UTC 2022


This PR adds a way of inspecting a `MemoryLayout` through a `MemoryLayout`.


    /**
     * Returns a human-readable view of the provided {@linkplain MemorySegment memory} viewed
     * through the provided {@linkplain MemoryLayout layout} using the provided {@linkplain ValueLayoutRenderer renderer}.
     * <p>
     * The exact format of the returned view is unspecified and should not
     * be acted upon programmatically.
     * <p>
     * As an example, a MemorySegment viewed though the following memory layout
     * {@snippet lang = java:
     * var layout = MemoryLayout.structLayout(
     *         ValueLayout.JAVA_INT.withName("x"),
     *         ValueLayout.JAVA_INT.withName("y")
     * ).withName("Point");
     *
     * MemoryInspection.inspect(segment, layout, ValueLayoutRenderer.standard())
     *     .forEach(System.out::println);
     *
     *}
     * might be rendered to something like this:
     * {@snippet lang = text:
     * Point {
     *   x=1,
     *   y=2
     * }
     *}
     * <p>
     * This method is intended to view memory segments through small and medium-sized memory layouts.
     *
     * @param segment  to be viewed
     * @param layout   to use as a layout when viewing the memory segment
     * @param renderer to apply when rendering value layouts
     * @return a view of the memory abstraction viewed through the memory layout
     */
    public static Stream<String> inspect(MemorySegment segment,
                                         MemoryLayout layout,
                                         ValueLayoutRenderer renderer) {

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

Commit messages:
 - Add an internal MemoryInspection class

Changes: https://git.openjdk.org/panama-foreign/pull/715/files
 Webrev: https://webrevs.openjdk.org/?repo=panama-foreign&pr=715&range=00
  Stats: 824 lines in 3 files changed: 824 ins; 0 del; 0 mod
  Patch: https://git.openjdk.org/panama-foreign/pull/715.diff
  Fetch: git fetch https://git.openjdk.org/panama-foreign pull/715/head:pull/715

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


More information about the panama-dev mailing list