简体   繁体   English

我不明白 JVM 实现中的这个操作码

[英]I don't understand this opcode in JVM Implementation

I am writing a JVM. I was implementing all opcodes one by one, until I faced dup2 .我正在写一个 JVM。我一个一个地实现所有操作码,直到我遇到dup2 The oracle instruction set https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.dup2 says oracle 指令集https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.dup2

Duplicate the top one or two values on the operand stack and push the duplicated value or values back onto the operand stack in the original order复制操作数栈顶部的一个或两个值,并将复制的一个或多个值按原始顺序推回操作数栈

How am I supposed to choose which operation to perform?我应该如何选择要执行的操作? How can I know when I should duplicate only the top or I should duplicate the top two values?我怎么知道什么时候应该只复制顶部或者我应该复制前两个值?

The description of the opcode says:操作码的描述说:

Form 1:表格 1:

..., value2, value1 → ..., 值 2, 值 1 →

..., value2, value1, value2, value1 ...,值 2,值 1,值 2,值 1

where both value1 and value2 are values of a category 1 computational type (§2.11.1).其中 value1 和 value2 都是类别 1 计算类型的值 (§2.11.1)。

Form 2:表格 2:

..., value → ..., 价值 →

..., value, value ...,价值,价值

where value is a value of a category 2 computational type (§2.11.1).其中 value 是类别 2 计算类型 (§2.11.1) 的值。

Category 2 types are long and double , and category 1 are others.类别 2 类型是longdouble ,类别 1 是其他类型。 So in the original versions of Java Category 2 types meant 64 bit type and Category 1 meant 32 bit types.所以在 Java 的原始版本中,类别 2 类型表示 64 位类型,类别 1 表示 32 位类型。 When 64 bit JVMs were introduced, that distinction no longer worked.当引入 64 位 JVM 时,这种区别不再有效。 Now an interpreter or JIT compiler needs to track the categories of values pushed and popped from the opstack to the extent that it knows whether the value on the top of stack is category 1 or 2.现在,解释器或 JIT 编译器需要跟踪从 opstack 中推送和弹出的值的类别,以了解堆栈顶部的值是类别 1 还是类别 2。

Note that the JVM needs to this kind of analysis at verify time in order to check the requirements set out in 4.10.1.7.请注意,JVM 需要在验证时进行此类分析,以检查4.10.1.7 中规定的要求。 Type Checking Load and Store Instructions 类型检查加载和存储指令

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM