<div dir="ltr">On Mon, Jan 4, 2021 at 8:34 AM Peter Levart <<a href="mailto:plevart@openjdk.java.net">plevart@openjdk.java.net</a>> wrote:<br>><br>> On Mon, 4 Jan 2021 15:57:33 GMT, Richard Reingruber <<a href="mailto:rrich@openjdk.org">rrich@openjdk.org</a>> wrote:<br>><br>> >> The bug title and the PR title need to be the same.<br>> >> Editing either one is fine.<br>> ><br>> > But wouldn't it be legal for a compiler (java to bytecode or bytecode to<br>> > machinecode) to replace references of my_local_copy with references to<br>> > static_field?<br>> ><br>> > Foo my_local_copy = static_field;<br>> > if (my_copy == null) {<br>> >    initialize();<br>> >    my_local_copy = static_field;<br>> > }<br>> > return my_local_copy;<br>> ><br>> > Only if static_field was volatile this would be illegal, wouldn't it?<br>><br>> @reinrich I don't think Java compilers may do that. If this was allowed, such variables would not be called "local".<br>><br><br><div>Indeed. Such transformations are allowed in C and C++ (since data races result in undefined behavior, and thus the</div><div>compiler is allowed to assume there are no concurrent writes), but not in Java.</div></div>