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

Roger Riggs rriggs at openjdk.org
Tue Apr 8 21:22:28 UTC 2025


On Tue, 8 Apr 2025 20:20:56 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.

test/lib/jdk/test/lib/util/ForceGC.java line 125:

> 123:                 Method[] methods = refClass.getDeclaredMethods();
> 124:                 wfrp = Arrays.stream(methods).filter((m) -> m.getName().equals("waitForReferenceProcessing")).findFirst().get();
> 125:                 wfrp.setAccessible(true);

You don't need the stream.  
Suggestion:

                Method wfrp = Reference.class.getDeclaredMethod("waitForReferenceProcessing");
                wfrp.setAccessible(true);

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

> 567:    * This method should usually be called after a call to WhiteBox.fullGC().
> 568:    */
> 569:   public static void waitForReferenceProcessing() {

Can the code duplication be avoided?

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

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


More information about the core-libs-dev mailing list