我引用了下面的oracle jvm doc
https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.pop
pop Operation Pop the top operand stack value
Format
pop Forms pop = 87 (0x57)
Operand Stack ..., value →
...
Description Pop the top value from the operand stack.
The pop instruction must not be used unless value is a value of a category 1 computational type (§2.11.1).
pop2 Operation Pop the top one or two operand stack values
Format
pop2 Forms pop2 = 88 (0x58)
Operand Stack Form 1:
..., value2, value1 →
...
where each of value1 and value2 is a value of a category 1 computational type (§2.11.1).
Form 2:
..., value →
...
where value is a value of a category 2 computational type (§2.11.1).
Description Pop the top one or two values from the operand stack.
“从操作数堆栈中弹出顶部的一两个值”是什么意思?使用 pop2 时的示例是什么?
最佳答案
编写一个包含 main 方法的小 java 程序
System.currentTimeMillis();
不要使用此调用的结果。然后字节码看起来像
INVOKESTATIC java/lang/System.currentTimeMillis()J
POP2
System.currentTimeMillis()
将长值(64 位,宽)放入堆栈。然而,这个堆栈内容不再被使用,所以它必须被弹出,以便其他堆栈内容可以访问。 32 位(正常大小)需要一个简单的 POP
,64 位(宽大小)需要一个 POP2
。
关于java - jvm 中的 pop 和 pop2 指令有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50448093/