反编译
指令
javac SyncTest.java 生成字节码文件(打开:文件所在目录,cmd)
javap -v SyncTest.class 反编译
代码
/**
* @author jc
* @date 2024/1/19 10:24
*/
public class SyncTest {
public void syncTest() {
synchronized (this) {
}
}
}
编译结果
3: monitorenter
4: monitorexit
这两个指令分别表示进入和退出同步块。- 当一个线程进入同步块时,它会获取monitor的所有权,并阻止其他线程进入该同步块,直到它退出同步块并释放monitor。
Last modified 2024-1-19; size 368 bytes
MD5 checksum f57225b2e84f7f4620a3498a0132ff60
Compiled from "SyncTest.java"
public class com.mytest.test.SyncTest
minor version: 0
major version: 52
flags: ACC_PUBLIC, ACC_SUPER
注:常量池
Constant pool:
#1 = Methodref #3.#15 // java/lang/Object."<init>":()V 注:类先加载父类,所有的父类为Object
#2 = Class #16 // com/mytest/test/SyncTest
#3 = Class #17 // java/lang/Object
#4 = Utf8 <init>
#5 = Utf8 ()V
#6 = Utf8 Code
#7 = Utf8 LineNumberTable
#8 = Utf8 s