新建Decompilation.java文件
public class Decompilation {
private Object object = new Object();
public void insert(Thread thread) {
synchronized (object) {
}
}
}
编译
javac Decompilation.java
反编译获得字节码指令
javap -verbose Decompilation.class
public void insert(java.lang.Thread);
descriptor: (Ljava/lang/Thread;)V
flags: ACC_PUBLIC
Code:
stack=2, locals=4, args_size=2
0: aload_0
1: getfield #3 // Field object:Ljava/lang/Object;
4: dup
5: astore_2
6: monitorenter // 要获取到锁
7: aload_2
8: monitorexit // 释放锁
9: goto 17
12: astore_3
13: aload_2
14: monitorexit // 释放锁,第二个出口。一个锁入口,两个锁出口(正常退出 + 异常退出)
15: aload_3
16: athrow
17: return
Exception table:
from to target type
7 9 12 any
12 15 12 any
LineNumberTable:
line 5: 0
line 7: 7
line 8: 17
StackMapTable: number_of_entries = 2
frame_type = 255 /* full_frame */
offset_delta = 12
locals = [ class Decompilation, class java/lang/Thread, class java/lang/Object ]
stack = [ class java/lang/Throwable ]
frame_type = 250 /* chop */
offset_delta = 4