[foreign-memaccess+abi] RFR: 8291639: Improve the ability to visualize a MemorySegment in human readable forms [v14]
Per Minborg
duke at openjdk.org
Wed Aug 31 12:32:14 UTC 2022
> This PR improves the ability to visualize a `MemorySegment` in human-readable forms (`ByteBuffer`, `byte[]` or any other memory abstraction can be viewed by means of wrapping).
>
> It exposes a new method via the new utility class `MemoryInspection`
>
>
> /**
> * Returns a human-readable view of the provided {@code memory} abstraction by optionally
> * (if not a {@link MemorySession} and {@link Adapter#ofMemorySegment()} already) copying the contents
> * to a fresh MemorySegment and then view the resulting MemorySegment through the provided {@code layout}.
> * <p>
> * Lines are separated with the system-dependent line separator {@link System#lineSeparator() }.
> * Otherwise, 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");
> *}
> * might be rendered to something like this:
> * {@snippet lang = text:
> * Point {
> * x=1,
> * y=2
> * }
> *}
> * <p>
> * This method is intended to view memory abstractions through small and medium-sized memory layouts.
> *
> * @param memory to be viewed
> * @param adapter to apply to the provided memory to determine the size and content of the memory abstraction.
> * @param layout to use as a layout when viewing the memory segment
> * @param renderer to apply when rendering value layouts
> * @param <M> the memory abstraction type.
> * @return a view of the memory abstraction viewed through the memory layout
> * @throws OutOfMemoryError if the view exceeds the array size VM limit
> */
> public static <M> String toString(M memory,
> Adapter<M> adapter,
> MemoryLayout layout,
> ValueLayoutRenderer renderer) {
>
>
>
> the existing `HexFormat` class will also get two overloads for MemorySegments.
Per Minborg has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 22 commits:
- Add dump method to HexFormat
- Merge branch 'foreign-memaccess+abi' into render
- Rollback unintended reformatting
- MemoryInspect to return Stream of Strings
- Cleanup
- Remove/simplify some methods and overloads
- Add MemorySegment support to HexFormat and remove old public hex feature
- Merge remote-tracking branch 'origin/foreign-memaccess+abi' into render
- Rename and add Adapter.ofIntArray
- Add general MemoryInspection
- ... and 12 more: https://git.openjdk.org/panama-foreign/compare/3e4879f8...7037f8b9
-------------
Changes: https://git.openjdk.org/panama-foreign/pull/695/files
Webrev: https://webrevs.openjdk.org/?repo=panama-foreign&pr=695&range=13
Stats: 1145 lines in 5 files changed: 1141 ins; 0 del; 4 mod
Patch: https://git.openjdk.org/panama-foreign/pull/695.diff
Fetch: git fetch https://git.openjdk.org/panama-foreign pull/695/head:pull/695
PR: https://git.openjdk.org/panama-foreign/pull/695
More information about the panama-dev
mailing list