1. 实验代码
public int calc() {
int a = 100;
int b = 200;
int c = 300;
return (a+b) * c;
}
2. 编译后的字节码片段
public int calc();
descriptor: ()I
flags: ACC_PUBLIC
Code:
stack=2, locals=4, args_size=1
0: bipush 100
2: istore_1
3: sipush 200
6: istore_2
7: sipush 300
10: istore_3
11: iload_1
12: iload_2
13: iadd
14: iload_3
15: imul
16: ireturn
3. 执行过程
javap提示这段代码需要深度为2的操作数栈和4个Slot的局部变量空间。
执行偏移地址为0的指令的情况.png
执行偏移地址为1的指令的情况.png
执行偏移地址为11的指令的情况.png
执行偏移地址为12的指令的情况.png
执行偏移地址为13的指令的情况.png
执行偏移地址为14的指令的情况.png
执行偏移地址为16的指令的情况.png