@Shark: If optimizations "break your code", it was already broken and just happens-to-work in some cases, e.g. with debug builds that store / reload everything to memory between statements. (Java doesn't have an equivalent to un-optimized builds, so I guess Java programmers never get the wrong idea that they code works in the first place in as many cases. Of course as an answer on the querent's linked previous question indirectly shows, you could by chance get release/acquire synchronization from lack of compile-time reordering on x86, and have it break on ARM / everything else.) —
Peter Cordes 5 secs ago