On Fri, 4 Dec 2026 08:06:06 GMT, Shiv Shah <[email protected]> wrote:

>> The test can run out of heap with -Xcheck:jni and ZGC. The cause is in the 
>> checked IsSameObject, not in the test.
>> 
>> The checked wrapper validates its arguments by resolving them, and for a 
>> weak global ref that keeps the referent alive while a GC is marking. The 
>> unchecked IsSameObject has not done that since JDK 12. The HeapMonitor agent 
>> keeps a weak global ref for every sampled object and compares them against 
>> null after a GC. With -Xcheck:jni those compares kept the sampled objects 
>> alive.
>> 
>> Now the wrapper only checks that the handles are valid. It does not resolve 
>> them. A bad handle gets the same fatal error as before.
>> 
>> Added TestCheckedIsSameObject. It compares a weak global ref against null in 
>> both argument positions while a concurrent GC is marking, then checks the 
>> ref is cleared when the GC is done.
>> 
>> The heap in HeapMonitorThreadTest is back to 512m. The gc logging stays in.
>> 
>> ---
>> 
>> Testing:
>> - [x] The new test fails without the fix and passes with it. It ran with G1 
>> and ZGC on linux-x64, linux-aarch64, macosx-aarch64 and windows-x64 debug 
>> builds, and with -Xcomp and -Xint on linux-x64. HeapMonitorThreadTest with 
>> -Xcheck:jni -XX:+UseZGC passed 500 of 500 runs on linux-x64, it failed 6 of 
>> 500 without the fix. It also passed 50 runs on linux-aarch64 and 20 each on 
>> macosx-aarch64 and windows-x64. serviceability/jvmti, runtime/jni, 
>> runtime/SameObject, gc/TestJNIWeak and 
>> runtime/valhalla/valuetypes/TestJNIIsSameObject.java passed with -Xcheck:jni 
>> on linux-x64. tier1-3.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> Shiv Shah has updated the pull request with a new target base due to a merge 
> or a rebase. The incremental webrev excludes the unrelated changes brought in 
> by the merge/rebase. The pull request contains six additional commits since 
> the last revision:
> 
>  - Merge remote-tracking branch 'upstream/master' into JDK-8323421
>  - check only the handles in checked IsSameObject, add a test, heap back to 
> 512m
>  - Merge remote-tracking branch 'upstream/master' into JDK-8323421
>  - enable gc logging in the test
>  - Remove bug tag and update copyright year
>  - 8323421: 
> serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorThreadTest.java fails 
> with OOME

There's to parts of reviewing this:
1) Is this a limitation that we want to make for JNI checking?
2) Is the change doing what it is supposed to do?

I've reviewed this code with eyes for (2), leaving the review of (1) to the 
Runtime developers that maintain the JNI checking code.

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

Marked as reviewed by stefank (Reviewer).

PR Review: https://git.openjdk.org/jdk/pull/32229#pullrequestreview-4914877110

Reply via email to