Critical JNI and (Shenandoah) pinning questions
Ioannis Tsakpinis
iotsakp at gmail.com
Fri Aug 23 00:55:05 UTC 2019
Hi David and Zhengyu,
I had time to build the JDK today (at rev/bc14eec6f4bc), with the
"skip_native_trans" patch. Timings on Linux x64, Ryzen 1800X, using the
benchmark [1] I posted:
Unpatched JDK
Standard JNI: ~8.7ns
Critical JNI: ~8.3ns
Patched JDK
Standard JNI: ~8.7ns
Critical JNI: ~7.5ns
(note: the exact timings depend and number/type of arguments and the
benefit of critical JNI on a 32-bit JVM is bigger)
I then did some experiments and was able to identify what has caused
the higher JNI overhead on Java 10; JDK-8178811 [2] and the VZEROUPPER
instructions that were added in various places of the JNI wrapper code.
Running the benchmark with -XX:UseAVX=0 (which effectively disables the
CPU_VZEROUPPER capability in vm_version_x86.hpp):
Patched JDK
Standard JNI: ~7.5ns
Critical JNI: ~4.2ns (!)
For critical JNI, it is also possible to get to this performance by
removing the vzeroupper calls from the following macroAssembler_x86.cpp
functions:
- reset_last_Java_frame
- set_last_Java_frame
- restore_cpu_control_state_after_jni
(note: VZEROUPPER is executed multiple times per JNI call)
The VZEROUPPER situation is anything but simple and it looks like many
runtimes (non-JVM) are struggling with it. What is troubling however is
that these instructions are being emitted unconditionally in JNI code.
There are no checks like those added in the JDK-8190934 [3] follow-up.
It may be a good idea to emit the instruction only on the specific
Intel architectures that would benefit from it. Also, does it ever help
on AMD Ryzen/EPYC?
Thanks,
- Ioannis
[1] https://github.com/Spasi/JDK-8229895
[2] https://bugs.openjdk.java.net/browse/JDK-8178811
[3] https://bugs.openjdk.java.net/browse/JDK-8190934
On Thu, 22 Aug 2019 at 16:40, Zhengyu Gu <zgu at redhat.com> wrote:
>
> Hi Ioannis,
>
> Quick tests look good. I uploaded your patch to CR [1], as well as new
> benchmark results.
>
>
> Thanks,
>
> -Zhengyu
>
> [1] https://bugs.openjdk.java.net/browse/JDK-8229895
>
>
> On 8/22/19 8:47 AM, Ioannis Tsakpinis wrote:
> > Hi Zhengyu,
> >
> > On Thu, 22 Aug 2019 at 14:28, Zhengyu Gu <zgu at redhat.com> wrote:
> >> The failed experiment does suggest that it is worth a close look.
> >> Unfortunately, I am not familiar with this part of code and I have a few
> >> things need to handle right now. If you have a patch, I can do a quick
> >> run, or I have to get back to it later.
> >
> > Sure, attaching the patch.
> >
> > - Ioannis
> >
More information about the shenandoah-dev
mailing list