demo:
public class T1 {
volatile int n = 0;
public void add() {
n++;
}
}
Compiled from "T1.java"
public class com.shishi.jmm.T1 {
volatile int n;
public com.shishi.jmm.T1();
Code:
0: aload_0
1: invokespecial #1 // Method java/lang/Object."<init>":()V
4: aload_0
5: iconst_2
6: putfield #2 // Field n:I
9: return
public void add();
Code:
0: aload_0
1: dup
2: getfield #2 // Field n:I
5: iconst_1
6: iadd
7: putfield #2 // Field n:I
10: return
public static void main(java.lang.String[]);
Code:
0: return
}
https://www.cnblogs.com/noteless/p/9556928.html, 参考这个指令集对照,也可去Oracle获取这个指令集对照表
分析add方法:
即:
从局部变量0中装载引用类型值,压栈,获取值,将int型(1)推送至栈顶,加法指令,设置值,返回