On Fri, 25 Apr 2025 21:30:10 GMT, Brent Christian <bchri...@openjdk.org> wrote:

>> I propose some cleanups to `FinalizerHistogramTest.java` to hopefully clear 
>> up the intermittent failures:
>> 
>> * run with `othervm`: this test blocks the (global) finalizer thread, and 
>> also requires the (global) finalizer thread to enter the test's `finalize()` 
>> method
>> * The test uses `volatile` ints, but sets them based on their current value, 
>> which is not reliable; convert to `AtomicInteger`
>> * use `PhantomReference`s to ensure that at least two `MyObject`s have 
>> become unreachable. If one is stuck in `finalize()`, at least one is still 
>> waiting to be finalized and should show up in the histogram.
>
> Brent Christian 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 five additional 
> commits since the last revision:
> 
>  - Merge branch 'master' into 8298783
>  - convert to WeakRefs, use a RefQ, print ForceGC results
>  - 'return' not needed in lambda
>  - rename counter variables to use 'Count'
>  - test reliability improvements

Changes requested by kbarrett (Reviewer).

test/jdk/java/lang/ref/FinalizerHistogramTest.java line 84:

> 82:             System.out.println("ref1Cleared: " + refQForTwo.ref1Cleared);
> 83:             System.out.println("ref2Cleared: " + refQForTwo.ref2Cleared);
> 84:             System.out.println("trappedCount.intValue(): " + 
> trappedCount.intValue());

This could be made completely reliable, and much simpler, by using WhiteBox.

Don't introduce RefQForTwo.  (It doesn't provide reliable information.)

Use WhiteBox::fullGC() to trigger finalization, instead of ForceGC.

Use (new) WhiteBox::waitForReferenceProcessing() to wait until the
FinalReferences have been enqueued (and mostly trapped in the queue).

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

PR Review: https://git.openjdk.org/jdk/pull/24143#pullrequestreview-2797589587
PR Review Comment: https://git.openjdk.org/jdk/pull/24143#discussion_r2062584077

Reply via email to