On Tue, 11 Aug 2026 19:03:17 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 incrementally with one additional 
> commit since the last revision:
> 
>   enable gc logging in the test

test/hotspot/jtreg/serviceability/jvmti/HeapMonitor/MyPackage/HeapMonitorThreadTest.java
 line 33:

> 31:  * @requires vm.jvmti
> 32:  * @compile HeapMonitorThreadTest.java
> 33:  * @run main/othervm/native/timeout=480 -Xmx1g -Xlog:gc 
> -agentlib:HeapMonitorTest MyPackage.HeapMonitorThreadTest

I'd suggest that we add a little bit more detailed gc logging, check this in, 
and deal with this again when we have full logs.
Suggestion:

 * @run main/othervm/native/timeout=480 -Xmx1g -Xlog:gc* 
-agentlib:HeapMonitorTest MyPackage.HeapMonitorThreadTest

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

PR Review Comment: https://git.openjdk.org/jdk/pull/32229#discussion_r3765085143

Reply via email to