> Hello,
> 
> In java.instrument native libinstrument JavaExceptions.c, the fallback 
> InternalError static sFallbackInternalError is created during VM or agent 
> initialization and is stored as a JNI local reference (NewObject via HotSpot 
> jni_NewObject to JNIHandles::make_local). Agent initialization runs under 
> JvmtiThreadEventMark in JvmtiExport::post_vm_initialized, which establishes a 
> JNI handle scope that is popped when the mark goes out of scope after the 
> VMInit callback returns. This allows sFallbackInternalError to outlive the 
> local handle block it was allocated in, leaving a dangling reference in a 
> static variable. In low-memory conditions, when creating a new InternalError 
> fails and the code falls back to sFallbackInternalError, the stored handle 
> has likely been cleared or reused, causing fallback exception creation or 
> throwing to fail.
> 
> To make the fallback InternalError persistent, I suggest we allocate it in 
> global storage using JNI's NewGlobalRef. Since this fallback should be always 
> present, I don't think we should deallocate it. Simultaneously, I suggest we 
> enhance the return types a bit by using JNI_FALSE and JNI_TRUE instead of the 
> implicitly converted value from the comparison check. The first NULL-check 
> for the localRef isn't strictly needed as NewGlobalRef is well-defined in 
> taking in NULL as an argument, but I suggest we be explicit here to make it 
> easier for the reader to understand what's going on.
> 
> Testing:
> * Local testing in lldb to see that we always have access to a well-defined 
> fallback in different calls to JPLISAgent.c functions.
> * Running through Oracle's tier1-4

Joel Sikström has updated the pull request incrementally with one additional 
commit since the last revision:

  Update copyright year

-------------

Changes:
  - all: https://git.openjdk.org/jdk/pull/30141/files
  - new: https://git.openjdk.org/jdk/pull/30141/files/3b0c9989..98b90510

Webrevs:
 - full: https://webrevs.openjdk.org/?repo=jdk&pr=30141&range=01
 - incr: https://webrevs.openjdk.org/?repo=jdk&pr=30141&range=00-01

  Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
  Patch: https://git.openjdk.org/jdk/pull/30141.diff
  Fetch: git fetch https://git.openjdk.org/jdk.git pull/30141/head:pull/30141

PR: https://git.openjdk.org/jdk/pull/30141

Reply via email to