RFR: 8350118: Simplify the layout access VarHandle
Maurizio Cimadamore
mcimadamore at openjdk.org
Fri Feb 21 10:18:02 UTC 2025
On Fri, 21 Feb 2025 00:01:36 GMT, Chen Liang <liach at openjdk.org> wrote:
> Simplify the layout access var handles to be direct in some common cases. Also made `VarHandle::isAccessModeSupported` report if an access mode is supported for a VH.
>
> Reduces the instructions to execute this code in a simple main by 47%:
>
> long[] arr = new long[8];
> var ms = MemorySegment.ofArray(arr);
> ms.setAtIndex(ValueLayout.JAVA_BYTE, 12, (byte) 3);
>
>
> Main overheads in FFM are identified to be:
> 1. Eager initialization of direct MethodHandle; can be CDS archived
> 2. MH combinator forms via LambdaFormEditor, not cached right now and always have large overhead
>
> Still need other measures to deal with common user patterns of `MethodHandles.insertCoordinates(vh, 1, 0L)` which currently is still very slow.
>
> Tests: 2 unrelated failures on tier 1-3
src/java.base/share/classes/java/lang/invoke/VarHandleSegmentViewBase.java line 34:
> 32: * Base class for memory segment var handle view implementations.
> 33: */
> 34: final class VarHandleSegmentViewBase extends VarHandle {
Should the name of this class change so that we drop `Base` ? It's no longer extended by anything.
src/java.base/share/classes/java/lang/invoke/VarHandles.java line 767:
> 765: // new HandleType(Object.class, long.class),
> 766: //
> 767: // // MS[base][offset]->T
I like how you programmatically generate all guards for all the shapes we care about.
On `MS[base][offset]` I wonder if generating a guard matters (for now) given that such a var handle will be indirect?
src/java.base/share/classes/java/lang/invoke/X-VarHandleSegmentView.java.template line 77:
> 75: }
> 76:
> 77: @ForceInline
Question: can this and the `offset` method go in the `VarHandleSegmentViewBase` class? They don't seem to depend on anything in these classes - so it seems mostly duplicated code?
src/java.base/share/classes/java/lang/invoke/X-VarHandleSegmentView.java.template line 85:
> 83:
> 84: @ForceInline
> 85: static $type$ get(VarHandle ob, Object obb, long base) {
I like this: a fast path for non-strided access, while, at the same time, reusing the impl.
In the future we can also add another variant for when there's only one index (which is by far the most common case).
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23720#discussion_r1965223737
PR Review Comment: https://git.openjdk.org/jdk/pull/23720#discussion_r1965218844
PR Review Comment: https://git.openjdk.org/jdk/pull/23720#discussion_r1965222924
PR Review Comment: https://git.openjdk.org/jdk/pull/23720#discussion_r1965226302
More information about the build-dev
mailing list