<div dir="ltr"><div dir="ltr"><br></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Fri, Apr 11, 2025 at 2:39 PM Roger Riggs <<a href="mailto:rriggs@openjdk.org">rriggs@openjdk.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">On Fri, 11 Apr 2025 20:09:10 GMT, Brent Christian <<a href="mailto:bchristi@openjdk.org" target="_blank">bchristi@openjdk.org</a>> wrote:<br>
<br>test/lib/jdk/test/whitebox/WhiteBox.java line 568:<br>
<br>
> 566: private Method getWaitForReferenceProcessingMethod() {<br>
> 567: Method wfrp = waitForReferenceProcessingMethod;<br>
> 568: if (wfrp == null) {<br>
<br>
Racy initialization is fine, the field can be static and the last one (any racy init would all the same) wins:<br></blockquote><div>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.</div><div><br></div><div>Furthermore, it seems to me there is nothing to stop the compiler from moving up the assignment to waitForReferenceProcessingMethod.</div><div><br></div><div>AFAICT, waitForReferenceProcessingMethod needs to be volatile here. Which shouldn't matter that much anymore on most modern hardware.</div><div><br></div><div>Hans</div></div></div>