JDK-8175318 : Performance issue regarding local JNI references
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 9
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2017-02-21
  • Updated: 2024-07-23
  • Resolved: 2017-07-21
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 10
10 b21Fixed
Related Reports
Relates :  
Description
At the beginning of JNIHandleBlock::allocate_handle(...), all thread-local JNIHandleBlocks are being iterated by the following code:
if (_top == 0) {
  for (JNIHandleBlock* current = _next; current != NULL; current = current->_next) {
    assert(current->_last == NULL, "only first block should have _last set");
    assert(current->_free_list == NULL, "only first block should have _free_list set");
    current->_top = 0;
    if (ZapJNIHandleArea) current->zap();
  }
  ...
}

If the number of thread-local JNIHandleBlocks is high, this iteration can take a significant amount of time. We particularly observed this issue for the JVMCI method "installCode", where a large number of local JNI references is being created for doing the code installation within HotSpot. With the proposed fix in place (see attachments), certain Graal parts are nearly 3x faster than before.

Another way of resolving the issue particularly for JVMCI / Graal, would be to do something similar to JNI's PushLocalFrame/PopLocalFrame around the JVMCI method "installCode". This also potentially improves the footprint a bit.

To reproduce this issue more easily, a simple example application is attached as well.
Comments
URL: http://hg.openjdk.java.net/jdk10/jdk10/hotspot/rev/0807b715cec5 User: jwilhelm Date: 2017-08-18 18:01:35 +0000
18-08-2017

URL: http://hg.openjdk.java.net/jdk10/hs/hotspot/rev/0807b715cec5 User: kbarrett Date: 2017-07-21 23:28:40 +0000
21-07-2017

I independently noticed this problem recently while inspecting the code as part of other work in this area. The proposed patch is pretty much the same fix I had in mind. Assigning to me.
19-07-2017