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

Steve Dohrmann duke at openjdk.org
Tue Nov 14 01:23:34 UTC 2023


On Mon, 13 Nov 2023 08:36:44 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:

>> Below is baseline data collected using a modified version of the java.lang.foreign.xor micro benchmark referenced by @mcimadamore  in the bug report.  I collected data on an Ubuntu 22.04 laptop with a Tigerlake i7-1185G7, which does support AVX512. 
>> 
>> Baseline data
>> Benchmark     (arrayKind)  (sizeKind)  Mode  Cnt           Score          Error  Units
>> --------------------------------------------------------------------------------------
>> XorTest.copy     ELEMENTS       SMALL  avgt   30   584737355.767 ± 60414308.540  ns/op
>> XorTest.copy     ELEMENTS      MEDIUM  avgt   30   272248995.683 ±  2924954.498  ns/op
>> XorTest.copy     ELEMENTS       LARGE  avgt   30  1019200210.900 ± 28334453.652  ns/op
>> XorTest.copy       REGION       SMALL  avgt   30     7399944.164 ±   216821.819  ns/op
>> XorTest.copy       REGION      MEDIUM  avgt   30    20591454.558 ±   147398.572  ns/op
>> XorTest.copy       REGION       LARGE  avgt   30    21649266.051 ±   179263.875  ns/op
>> XorTest.copy     CRITICAL       SMALL  avgt   30       51079.357 ±      542.482  ns/op
>> XorTest.copy     CRITICAL      MEDIUM  avgt   30        2496.961 ±       11.375  ns/op
>> XorTest.copy     CRITICAL       LARGE  avgt   30         515.454 ±        5.831  ns/op
>> XorTest.copy      FOREIGN       SMALL  avgt   30     7558432.075 ±    79489.276  ns/op
>> XorTest.copy      FOREIGN      MEDIUM  avgt   30    19730666.341 ±   500505.099  ns/op
>> XorTest.copy      FOREIGN       LARGE  avgt   30    34616758.085 ±   340300.726  ns/op
>> XorTest.xor      ELEMENTS       SMALL  avgt   30   219832692.489 ±  2329417.319  ns/op
>> XorTest.xor      ELEMENTS      MEDIUM  avgt   30   505138197.167 ±  3818334.424  ns/op
>> XorTest.xor      ELEMENTS       LARGE  avgt   30  1189608474.667 ±  5877981.900  ns/op
>> XorTest.xor        REGION       SMALL  avgt   30    64093872.804 ±   599704.491  ns/op
>> XorTest.xor        REGION      MEDIUM  avgt   30    81544576.454 ±  1406342.118  ns/op
>> XorTest.xor        REGION       LARGE  avgt   30    90091424.883 ±   775577.613  ns/op
>> XorTest.xor      CRITICAL       SMALL  avgt   30    57231375.744 ±   438223.342  ns/op
>> XorTest.xor      CRITICAL      MEDIUM  avgt   30    58583884.930 ±   375355.215  ns/op
>> XorTest.xor      CRITICAL       LARGE  avgt   30    60644832.949 ±   588120.738  ns/op
>> XorTest.xor       FOREIGN       SMALL  avgt   30    73868679.405 ±   819965.524  ns/op
>> XorTest.xor       FOREIGN      MEDIUM  avgt   30    88156275.944 ±  1051257.152  ns/op
>> Xo...
>
> I submitted some quick testing and I'm seeing the following failure with multiple tests:
> 
> 
> # A fatal error has been detected by the Java Runtime Environment:
> #
> #  Internal Error (/workspace/open/src/hotspot/cpu/x86/stubGenerator_x86_64_arraycopy.cpp:1201), pid=24136, tid=24139
> #  assert(MaxVectorSize == 64) failed: vector length != 64
> #
> # JRE version:  (22.0) (fastdebug build )
> # Java VM: Java HotSpot(TM) 64-Bit Server VM (fastdebug 22-internal-2023-11-13-0750559.tobias.hartmann.jdk2, mixed mode, sharing, compressed oops, compressed class ptrs, g1 gc, linux-amd64)
> # Problematic frame:
> # V  [libjvm.so+0x16c00e6]  StubGenerator::copy64_masked_avx(Register, Register, XMMRegister, KRegister, Register, Register, Register, int, int, bool)+0x366
> 
> Stack: [0x00007f0b5e919000,0x00007f0b5ea1a000],  sp=0x00007f0b5ea17150,  free space=1016k
> Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
> V  [libjvm.so+0x16c00e6]  StubGenerator::copy64_masked_avx(Register, Register, XMMRegister, KRegister, Register, Register, Register, int, int, bool)+0x366  (stubGenerator_x86_64_arraycopy.cpp:1201)
> V  [libjvm.so+0x16c0ecd]  StubGenerator::arraycopy_avx3_special_cases_256(XMMRegister, KRegister, Register, Register, Register, int, Register, Register, Label&, Label&)+0x19d  (stubGenerator_x86_64_arraycopy.cpp:1055)
> V  [libjvm.so+0x16c16c1]  StubGenerator::arraycopy_avx3_large(Register, Register, Register, Register, Register, Register, Register, XMMRegister, XMMRegister, XMMRegister, XMMRegister, int)+0x3f1  (stubGenerator_x86_64_arraycopy.cpp:790)
> V  [libjvm.so+0x16c22f0]  StubGenerator::generate_disjoint_copy_avx3_masked(unsigned char**, char const*, int, bool, bool, bool)+0xa90  (stubGenerator_x86_64_arraycopy.cpp:728)
> V  [libjvm.so+0x16c4b85]  StubGenerator::generate_disjoint_byte_copy(bool, unsigned char**, char const*)+0x965  (stubGenerator_x86_64_arraycopy.cpp:1277)
> V  [libjvm.so+0x16cb309]  StubGenerator::generate_arraycopy_stubs()+0x29  (stubGenerator_x86_64_arraycopy.cpp:88)
> V  [libjvm.so+0x16a1089]  StubGenerator::generate_final_stubs()+0xb9  (stubGenerator_x86_64.cpp:4051)
> V  [libjvm.so+0x16a22a5]  StubGenerator_generate(CodeBuffer*, StubCodeGenerator::StubsKind)+0x105  (stubGenerator_x86_64.cpp:4296)
> V  [libjvm.so+0x16f349e]  initialize_stubs(StubCodeGenerator::StubsKind, int, int, char const*, char const*, char const*)+0x13e  (stubRoutines.cpp:241)
> V  [libjvm.so+0x16f500d]  final_stubs_init()+0x3d  (stubRoutines.cpp:288)
> V  [libjvm.so+0xe30c59]...

Thank you @TobiHartmann for the feedback.  I'm working on the issue.

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

PR Comment: https://git.openjdk.org/jdk/pull/16575#issuecomment-1809390162


More information about the hotspot-compiler-dev mailing list