RFR: 8175318: Performance issue regarding local JNI references

Kim Barrett kim.barrett at oracle.com
Tue Jul 18 23:39:56 UTC 2017

Please review this fix of a performance bug in the handling of local
JNI references.

When allocating the first local handle for a call, we walk any
following blocks to clear them.  All blocks after a non-full block are
empty, as an invariant, but clearing them may be deferred.

The problem is that on the next call we again walk and clear the
entire list, even if most of it was never touched by the preceeding
call.  If some call allocates a lot of local references, the
performance of subsequent calls can be affected.

The performance impact can be quite bad in debug builds, where the
blocks are not only marked empty, but also have their contents zapped
(scribbled over).  But even in release builds the difference is easily
measurable.  See the JNIPerformance test attached to the CR.

The solution is to only perform the clearing walk up to the next
already cleared block (e.g. _top is 0).  Any subsequent blocks have
already been cleared and don't need to be revisited.

Although the same code is used for global and weak global JNI
references, those aren't affected by the problem because we don't ever
clear blocks in the global lists. For the global lists, only the last
block in the list ever has a non-full _top value. This means there are
no trailing blocks to be repeatedly walked.



rbt hs-tier[1,3], jdk-tier[1,3]
various tonga test lists that include some jni coverage:
nsk.jvmti, nsk.coverage, vm.runtime, vm.g1classunloading

More information about the hotspot-runtime-dev mailing list