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

Kim Barrett kbarrett at openjdk.org
Wed Apr 9 22:36:26 UTC 2025


On Wed, 9 Apr 2025 19:54:55 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:
> 
>   only add wFRP to WhiteBox for now

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

> 572:         Class refClass = Class.forName("java.lang.ref.Reference");
> 573:         Method[] methods = refClass.getDeclaredMethods();
> 574:         wfrp = Arrays.stream(methods).filter((m) -> m.getName().equals("waitForReferenceProcessing")).findFirst().get();

Use `getDeclaredMethod`, as previously suggested by @RogerRiggs in comment for the copy in ForceGC?

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

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


More information about the core-libs-dev mailing list