RFR: 8166842: String.hashCode() has a non-benign data race
aph at redhat.com
Thu Sep 29 08:59:30 UTC 2016
On 29/09/16 05:31, David Holmes wrote:
> On 29/09/2016 10:49 AM, Carsten Varming wrote:
>> Because String has final fields there is a freeze action at the end
>> of construction so that String instances are always safely published
>> even if not "safely published".
>> I always thought that the freeze action only freezes final fields. The
>> hash field in String is not final and example 17.5-1 is applicable as
>> far as I can see
>> (https://docs.oracle.com/javase/specs/jls/se8/html/jls-17.html#jls-17.5). Has
>> the memory model changed in JDK9 to invalidate example 17.5-1 or I am
>> missing something about String.
> Sorry - I was confusing what the spec says versus what the VM actually
> does - as Vitaly pointed out.
A HotSpot back end could rewrite the constructor so that the last
final field to be written used a store release instruction. Whether
it should is another matter: I suppose it would be rather risky.
More information about the core-libs-dev