[foreign-memaccess+abi] RFR: 8310362: Improve composability of handle derived from layouts [v5]
Jorn Vernee
jvernee at openjdk.org
Fri Jun 23 17:22:36 UTC 2023
> Me and Maurizio have been discussing how to better address certain use cases like accessing structs with variable length array members, or matrices that have a dynamic row and column size.
>
> The solution we came up with is captured in this patch. It adds an additional base offset parameter to the handles produced by `MemoryLayout::varHandle`, `MemoryLayout::sliceHandle` and `MemoryLayout::byteOffsetHandle`. This allows these handles to be composed with other offset computations that are not necessarily derived from layouts.
>
> This patch also adds a `scale` method to MemoryLayout, which can be used to scale and index by the size of a layout. Essentially: `offset + layout.byteSize() * index`. This is useful for expressing ad-hoc offset computations. A `scaleHandle` method is also added for convience, which returns a MethodHandle for `scale` bound to the receiver layout.
>
> Both these changes allowed for several simplifications:
> - `MethodHandles::memorySegmentViewVarHandle` can be removed, as it's now exactly the same as calling ML::varHandle on a ValueLayout with an empty layout path. (the former method also didn't take advantage of the access handle cache found on ValueLayouts).
> - `ValueLayout::arrayHandle` is removed, as most use cases can now simply be expressed using ML::varHandle + ML::scaleHandle. e.g.:
>
> MethodHandles.collectCoordinates(layout.varHandle(),
> 1, MethodHandles.insertArguments(layout.scaleHandle(), 0, 0L));
Jorn Vernee has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 12 commits:
- Merge branch 'foreign-memaccess+abi' into ScaleOffset
- var handle doc polish
- add negative index check
- more review comments
- missing changes
- rework offset computation doc
- address most review comments
- add collectCoordinates void filter review changes
- include root layout check review changes
- remove redundant casts
- ... and 2 more: https://git.openjdk.org/panama-foreign/compare/e03c18c7...475eca89
-------------
Changes: https://git.openjdk.org/panama-foreign/pull/840/files
Webrev: https://webrevs.openjdk.org/?repo=panama-foreign&pr=840&range=04
Stats: 858 lines in 42 files changed: 257 ins; 260 del; 341 mod
Patch: https://git.openjdk.org/panama-foreign/pull/840.diff
Fetch: git fetch https://git.openjdk.org/panama-foreign.git pull/840/head:pull/840
PR: https://git.openjdk.org/panama-foreign/pull/840
More information about the panama-dev
mailing list