On Tue, 21 Apr 2026 04:47:06 GMT, Chris Plummer <[email protected]> wrote:

>> Hi all,
>> 
>> Test com/sun/jdi/FinalizerTest.java intermittent fails. This is because 
>> arraylist holdAlot do not clear or set as null before recliam heap memory by 
>> invoke System.gc. This PR add arraylist.clear() before call System.gc() to 
>> avoid OOME in the senond System.runFinalization().
>> 
>> The first System.runFinalization() has a synchronize bug. 
>> System.runFinalization() run in another low priority Finalizer thread. In 
>> the main thread maybe read variable finalizerRun before Finalizer thread 
>> change it. So waitForAFinalizer will run into whille(true) allocation loop 
>> sometimes. This PR add a countdownlatch synchronize to make sure main thread 
>> read the finalizerRun value after Finalizer thread write it.
>> 
>> This PR also remove the unused variable and optimize the imports, and add 
>> -Xmx256M to debuggee jvm process, this will make debuggee throw OOME steady 
>> in large physical memory machine.
>> 
>> Before this PR, test failure probability about 1/30. After this PR test run 
>> 3k times and all passed.
>> 
>> ---------
>> - [x] I confirm that I make this contribution in accordance with the 
>> [OpenJDK Interim AI Policy](https://openjdk.org/legal/ai).
>
> test/jdk/com/sun/jdi/FinalizerTest.java line 88:
> 
>> 86:             throw new RuntimeException(e);
>> 87:         }
>> 88:         // Now, we have to make sure the finalizer
> 
> I think the comments need to make it clear that if System.gc() plus 
> System.runFinalization() did not trigger the finalizer, then 
> FINALIZER_DONE.await() will time out and the code below will be needed as a 
> second attempt to trigger finalization. However, it's not clear to me if you 
> ever actually enter this code below. It seems it was rare in the past and 
> only happened due to a race with reading finalizerRun, which is now fixed. 
> You can also argue that the code above to trigger finalization is not needed. 
> We can just skip right to the loop. You really need FINALIZER_DONE either. 
> Making finalizerRun volatile should fix the race issue.

`finalizerRun` can be probably replaced with just `FINALIZER_DONE.getCount() == 
0`.

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

PR Review Comment: https://git.openjdk.org/jdk/pull/30829#discussion_r3115193772

Reply via email to