JDK-8194309 : JNI handle allocation failure not reported correctly
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 10
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2018-01-02
  • Updated: 2023-08-07
  • Resolved: 2020-07-24
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 16
16 b08Fixed
Related Reports
Relates :  
Relates :  
Description
Failure to allocate a JNI handle (due to malloc failure) is presently reported using vm_exit_out_of_memory (when creating a new JNIHandleBlock in JNIHandles::allocate_block).  That's not the behavior described in the JNI specification, which says that for out of memory failures

- NewGlobalRef will return NULL.

- NewLocalRef may return NULL.

- NewWeakGlobalRef will return NULL and throw OutOfMemoryError.

- PushLocalFrame will return a negative number and a pending OutOfMemoryError.

Note that OutOfMemoryError doesn't really seem like the right exception for running out of system memory, but that's what the JNI spec says.

Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/9677b4007a09 User: dholmes Date: 2020-07-24 01:47:28 +0000
24-07-2020

There is a general problem with the JNI specification when it comes to dealing with out-of-memory conditions with local references. Nearly all methods that return references do so using: return JNIHandles::make_local(thread, obj); and if make_local can return NULL when there is an out-of-memory condition, then those JNI functions will also return NULL. But they may not be specified to return NULL! Most of them are oblivious to the possibility of an out-of-memory condition related to the creation of the local reference. Given that the only out-of-memory condition possible for local references is C-heap exhaustion when allocating a new JNIHandleBlock, I am tempted to just leave the default behaviour as vm_exit_out_of_memory, only deal with NewLocalRef itself.
17-07-2020

JDK-8194312 changed JNIHandles::make_global and JNIHandles::make_weak_global to have an argument for controlling the allocation failure behavior. However, NewGlobalRef and NewWeakGlobalRef have not yet been updated to make use of that feature.
16-05-2018