RFR: 8305186: Reference.waitForReferenceProcessing should be more accessible to tests [v5]
Hans Boehm
hboehm at google.com
Mon Apr 14 23:59:13 UTC 2025
On Fri, Apr 11, 2025 at 2:39 PM Roger Riggs <rriggs at openjdk.org> wrote:
> On Fri, 11 Apr 2025 20:09:10 GMT, Brent Christian <bchristi at openjdk.org>
> wrote:
>
> 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:
>
How did you conclude that? From what I can see, Method has non-final
fields. If another thread reads waitForReferenceProcessingMethod shortly
after it is set, wfrp may be non-null, but its fields may not appear to be
set correctly.
Furthermore, it seems to me there is nothing to stop the compiler from
moving up the assignment to waitForReferenceProcessingMethod.
AFAICT, waitForReferenceProcessingMethod needs to be volatile here. Which
shouldn't matter that much anymore on most modern hardware.
Hans
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/core-libs-dev/attachments/20250414/bd6c87e5/attachment.htm>
More information about the core-libs-dev
mailing list