关于 synchronized 实现原理的建议
For synchronous code blocks, the result generated by decompilation is consistent with the author's intention. The monitorenter instruction is inserted at the beginning of the synchronous code block, and the monitorexit instruction is inserted at the end of the synchronous code block. However, for synchronous methods, it is not implemented through monitor. A synchronous method written by decompilation shows that the method is implemented through the invokevirtual instruction. At the VM bytecode level, there are no special instructions to implement methods marked with synchronized. Instead, in the method table of the Class file, the synchronized flag in the accessflags field of the method is set to 1, indicating that the method is a synchronized method and that the object calling the method or the Klass object belonging to the method is used as the lock object in the JVM.
内容来源: crossoverJie/JCSprout