On Fri, 21 Feb 2025 10:12:45 GMT, Maurizio Cimadamore <mcimadam...@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/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? Now this will require code update to static import `offset` from `VarHandleSegmentViewBase`. Is that acceptable? > src/java.base/share/classes/jdk/internal/foreign/layout/ValueLayouts.java > line 164: > >> 162: @ForceInline >> 163: public final VarHandle varHandle() { >> 164: record VarHandleCache() implements >> Function<AbstractValueLayout<?>, VarHandle> { > > Can this cache be removed? The var handles created here should be "direct" -- > meaning that we don't expect LayoutPath to add any adaptations on top of > what's already done in the "raw" var handle returned by > `Utils:makeRawSegmentViewVarHandle`? We have two caches, one in `ValueLayouts` and another in `Utils`. Should we remove both? ------------- PR Review Comment: https://git.openjdk.org/jdk/pull/23720#discussion_r1965763775 PR Review Comment: https://git.openjdk.org/jdk/pull/23720#discussion_r1965771047