RFR: 8305186: Reference.waitForReferenceProcessing should be more accessible to tests
Kim Barrett
kbarrett at openjdk.org
Tue Apr 15 05:46:46 UTC 2025
On Tue, 15 Apr 2025 00:00:35 GMT, Hans Boehm <hboehm at google.com> wrote:
> > 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.
Agreed. I'm pretty sure that all of the places I know of where I want to use
this are single-threaded, but being cautious is better.
-------------
PR Comment: https://git.openjdk.org/jdk/pull/24527#issuecomment-2803873414
More information about the core-libs-dev
mailing list