RFR: 8305186: Reference.waitForReferenceProcessing should be more accessible to tests [v5]

Roger Riggs rriggs at openjdk.org
Fri Apr 11 21:39:26 UTC 2025


On Fri, 11 Apr 2025 20:09:10 GMT, Brent Christian <bchristi at openjdk.org> wrote:

>> Certain specific types of tests involving GC and reference processing need to account for the delay between a GC completing (during which the GC clears a Reference), and the Reference being added to its associated queue. At present, ad hoc mechanisms (with delays/timeout) are used, but can lead to intermittent test failures ([JDK-8298783](https://bugs.openjdk.org/browse/JDK-8298783)  is a recent example).
>> 
>> A better mechanism already exists in the private `Reference.waitForReferenceProcessing()` method. This PR makes `waitForReferenceProcessing()` available to tests via the `WhiteBox` and `ForceGC` test libraries.
>
> Brent Christian has updated the pull request incrementally with one additional commit since the last revision:
> 
>   wFRP throws InterruptedException, pass through from InvocationTargetException; don't check param count

test/lib/jdk/test/whitebox/WhiteBox.java line 568:

> 566:   private Method getWaitForReferenceProcessingMethod() {
> 567:     Method wfrp = waitForReferenceProcessingMethod;
> 568:     if (wfrp == null) {

Racy initialization is fine, the field can be static and the last one (any racy init would all the same) wins:
Suggestion:

  private static Method waitForReferenceProcessingMethod = getWaitForReferenceProcessingMethod();

  private static Method getWaitForReferenceProcessingMethod() {

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

PR Review Comment: https://git.openjdk.org/jdk/pull/24527#discussion_r2040327180


More information about the core-libs-dev mailing list