Explain how JIT reordering works
问题 I have been reading a lot about synchronization in Java and all the problems that can occur. However, what I'm still slightly confused about is how the JIT can reorder a write. For instance, a simple double check lock makes sense to me: class Foo { private volatile Helper helper = null; // 1 public Helper getHelper() { // 2 if (helper == null) { // 3 synchronized(this) { // 4 if (helper == null) // 5 helper = new Helper(); // 6 } } return helper; } } We use volatile on line 1 to enforce a