Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8310159

Bulk copy with Unsafe::arrayCopy is slower compared to memcpy

    XMLWordPrintable

Details

    • b26

    Description

      Consider this benchmark:

      https://github.com/openjdk/jdk/compare/master...mcimadamore:jdk:xor_bench?expand=1

      Here, we compare the performance of code that copies arrays into off-heap storage ahead of a native call. It turns out that doing the copy using Unsafe::arrayCopy is 15-20% slower than using JNI's GetByteArrayRegion function.

      Profiling the benchmark with perfasm reveals that Unsafe::arrayCopy boils down to:

      StubRoutines::jlong_disjoint_arraycopy

      Whereas for JNI we end up with this:

      __memmove_avx_unaligned_erms

      The latter, judging from the name, likely enjoys AVX optimizations, which seems the most likely explanation for the difference in the performance profile of the two code paths.

      Attachments

        Issue Links

          Activity

            People

              vlivanov Vladimir Ivanov
              mcimadamore Maurizio Cimadamore
              Votes:
              0 Vote for this issue
              Watchers:
              9 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: