RFR: 8350118: Simplify the layout access VarHandle [v2]
Jorn Vernee
jvernee at openjdk.org
Wed Feb 26 17:26:01 UTC 2025
On Fri, 21 Feb 2025 20:14:19 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
>
> Chen Liang has updated the pull request incrementally with one additional commit since the last revision:
>
> Review remarks, dates, some more simplifications
src/java.base/share/classes/jdk/internal/foreign/LayoutPath.java line 216:
> 214: } else {
> 215: // simpler adaptation
> 216: handle = MethodHandles.insertCoordinates(handle, 2, offset); // (MS, long)
Okay, looking at this code I think I get it: when the offset into the enclosing layout is fixed, we don't have strides (from `sequenceElement()`), so we don't need the extra adaptation.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/23720#discussion_r1972024703
More information about the build-dev
mailing list