RFR: 8350118: Simplify the layout access VarHandle [v2]

Chen Liang liach at openjdk.org
Fri Feb 21 22:21:53 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

Benchmark results for the latest revision appears performance neutral. bytestacks same as last revision. 11 jobs left in tier 1-3, no failure so far. Also created CSR for this minor behavioral change.

Benchmark                                                (polluteProfile)  Mode  Cnt  Score   Error  Units
LoopOverNonConstantHeap.BB_get                                      false  avgt   30  0.934 ± 0.027  ns/op
LoopOverNonConstantHeap.BB_get                                       true  avgt   30  0.946 ± 0.028  ns/op
LoopOverNonConstantHeap.BB_loop                                     false  avgt   30  0.208 ± 0.004  ms/op
LoopOverNonConstantHeap.BB_loop                                      true  avgt   30  0.211 ± 0.003  ms/op
LoopOverNonConstantHeap.segment_get                                 false  avgt   30  1.123 ± 0.040  ns/op
LoopOverNonConstantHeap.segment_get                                  true  avgt   30  1.120 ± 0.040  ns/op
LoopOverNonConstantHeap.segment_loop                                false  avgt   30  0.205 ± 0.004  ms/op
LoopOverNonConstantHeap.segment_loop                                 true  avgt   30  0.202 ± 0.003  ms/op
LoopOverNonConstantHeap.segment_loop_instance                       false  avgt   30  0.209 ± 0.005  ms/op
LoopOverNonConstantHeap.segment_loop_instance                        true  avgt   30  0.202 ± 0.003  ms/op
LoopOverNonConstantHeap.segment_loop_instance_unaligned             false  avgt   30  0.209 ± 0.004  ms/op
LoopOverNonConstantHeap.segment_loop_instance_unaligned              true  avgt   30  0.210 ± 0.004  ms/op
LoopOverNonConstantHeap.segment_loop_readonly                       false  avgt   30  0.206 ± 0.004  ms/op
LoopOverNonConstantHeap.segment_loop_readonly                        true  avgt   30  0.206 ± 0.005  ms/op
LoopOverNonConstantHeap.segment_loop_slice                          false  avgt   30  0.203 ± 0.002  ms/op
LoopOverNonConstantHeap.segment_loop_slice                           true  avgt   30  0.207 ± 0.004  ms/op
LoopOverNonConstantHeap.segment_loop_unaligned                      false  avgt   30  0.206 ± 0.004  ms/op
LoopOverNonConstantHeap.segment_loop_unaligned                       true  avgt   30  0.209 ± 0.003  ms/op
LoopOverNonConstantHeap.unsafe_get                                  false  avgt   30  0.386 ± 0.017  ns/op
LoopOverNonConstantHeap.unsafe_get                                   true  avgt   30  0.381 ± 0.017  ns/op
LoopOverNonConstantHeap.unsafe_loop                                 false  avgt   30  0.205 ± 0.004  ms/op
LoopOverNonConstantHeap.unsafe_loop                                  true  avgt   30  0.204 ± 0.004  ms/op

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

PR Comment: https://git.openjdk.org/jdk/pull/23720#issuecomment-2675734830


More information about the build-dev mailing list