On Tue, 3 Sep 2024 07:52:44 GMT, Per Minborg <pminb...@openjdk.org> wrote:
> This PR proposes to handle smaller FFM copy operations with Java code rather > than transitioning to native code. This will improve performance. In this PR, > copy operations involving zero to 63 bytes will be handled by Java code. > > Here is what it looks like for Windows x64: > >  > > Here is another chart for Linux a64: > >  > > Other platforms exhibit similar behavior. It should be noted that the gain > with this PR is pronounced for certain common sizes that are more likely to > appear in code (e.g. 8, 16, 24, and 32) > > It would be possible to use the same code path for the 7arg > `MemorySegment::copy` method if it is similar to: > > > MemorySegment.copy(heapSrcSegment, JAVA_BYTE, 0, heapDstSegment, JAVA_BYTE, > 0, ELEM_SIZE); > > > This could be added in a separate PR. > > This PR has been tested with tier1-3 and passed. Marked as reviewed by mcimadamore (Reviewer). The changes look good, I've tested on my machine and also got a nice bump for small size (which is the goal here). Thanks also for updating the tests to make sure the new code is covered. src/java.base/share/classes/jdk/internal/foreign/AbstractMemorySegmentImpl.java line 625: > 623: if (size <= 0) { > 624: // Do nothing > 625: } else if (size < COPY_NATIVE_THRESHOLD && !src.overlaps(dst)) { This is basically a conservative test - correct? E.g. we might end up cosidering two segments as overlapping even when they are not (because of offsets) - but that's ok, I actually think it's a good pragmatic solution. ------------- PR Review: https://git.openjdk.org/jdk/pull/20829#pullrequestreview-2277168561 PR Comment: https://git.openjdk.org/jdk/pull/20829#issuecomment-2326288310 PR Review Comment: https://git.openjdk.org/jdk/pull/20829#discussion_r1741898334