JDK-8263818 : Release JNI local references in get/set-InetXXAddress-member helper functions of net_util.c
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 17
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2021-03-18
  • Updated: 2025-01-21
  • Resolved: 2021-03-19
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 17
17 b15Fixed
Related Reports
Duplicate :  
Relates :  
Description
As per the Java Native Interface Specification: "All Java objects returned by JNI functions are local references." [1]. 

The get/set-InetXXAddress-member helper functions in net_util.c retrieve a local reference to the internal `holder` before operating on the InetAddress object. These functions are used in many places by the native code, and should release any local references before returning.

[1] https://docs.oracle.com/en/java/javase/16/docs/specs/jni/design.html#global-and-local-references
Comments
Changeset: 4d51a82b Author: Chris Hegarty <chegar@openjdk.org> Date: 2021-03-19 10:46:05 +0000 URL: https://git.openjdk.java.net/jdk/commit/4d51a82b
19-03-2021

It has been observed that there are > 130 local references being created for a "standard" network configuration on macOS. A separate issue is tackling some of these, specific to the native network interface code, but that only partially addresses the issue - reduces the number of local refs to approx 60-70 on the same system. While there is no "hard" failure resulting from the excessive usage of local refs, it would be best to just avoid unnecessarily expanding the table in the first place.
18-03-2021

It's usually not necessary to explicitly delete local refs, at least not in simple JNI functions. There are cases where local refs are created in a loop where it make be necessary to explicitly delete to avoid the local refs table getting too large. Is there a specific issue/bug here?
18-03-2021