JVM - 基于栈的解释器的执行过程
2018-08-29 本文已影响0人
HRocky
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的局部变量空间。
![](https://img.haomeiwen.com/i13096591/2b60779f9f5ced94.png)
![](https://img.haomeiwen.com/i13096591/f5647c7d69c4fc2e.png)
![](https://img.haomeiwen.com/i13096591/977a0a5ef02c2a3a.png)
![](https://img.haomeiwen.com/i13096591/d4e8bc814e88bf84.png)
![](https://img.haomeiwen.com/i13096591/dd085bd97f696edc.png)
![](https://img.haomeiwen.com/i13096591/7d6ca8193a0f8b4c.png)
![](https://img.haomeiwen.com/i13096591/5e0e27cacf0c095f.png)