RFR: 8264032: Improve thread safety of Runtime.version()
Andrey Turbanov
github.com+741251+turbanoff at openjdk.java.net
Tue Mar 23 12:25:55 UTC 2021
On Tue, 23 Feb 2021 16:59:45 GMT, liach <github.com+7806504+liach at openjdk.org> wrote:
>>>This shouldn't be a problem.
>>
>> What do you mean by "this"? Double racy read?
>> There are 2 separate reads of fields. First can return non-null value, while second still can get `null`
>
>> There are 2 separate reads of fields. First can return non-null value, while second still can get null
>
> Can this really happen? If this `version` field has been updated, its value is definitely no longer `null`. And before the second field read the field is always set to a non-null value on the current thread. I fail to understand why the second read can still yield a null given the fact that the current thread has updated it to a non-null value and other threads may have updated it to a non-null value.
I'm not really a JMM mastermind, but I know that @shipilev knows a thing or two about it :)
See https://shipilev.net/blog/2016/close-encounters-of-jmm-kind/#wishful-benign-is-resilient
-------------
PR: https://git.openjdk.java.net/jdk/pull/2691
More information about the core-libs-dev
mailing list