Atomicity of Reference assignment - Java
Java's JVM specifications ( http://docs.oracle.com/javase/specs/jls/se7/jls7.pdf ) claims that writes to and reads of references is atomic on both 32 bit and 64 bit implementation and i happened to have a code which enforced mutual exclusion on the destination variable, public void set(Test ref) { synchronized (this) { // obj is the member variable obj = ref; } } At some point the need for synchronization was in question, as write into a reference is atomic and i started looking at underlying assembly instructions for the above code without synchronized block. I used 64 bit implementation of Open JDK 7 Update 3 on Ubuntu running on Intel x86 64 bit processor. The assembly code turned out as, Decoding compiled method 0x00007f8c5d061110: Code: [Entry Point] [Constants] # {method} 'set' '(LTest;)V' in 'Test' # this: rsi:rsi = 'Test' # parm0: rdx:rdx = 'Test' ...