On Fri, Apr 11, 2025 at 2:39 PM Roger Riggs <rri...@openjdk.org> wrote:

> On Fri, 11 Apr 2025 20:09:10 GMT, Brent Christian <bchri...@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

Reply via email to