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

发布于 2025-01-10 08:13:57 字数 373 浏览 0 评论 0 原文

我正在写一个JVM。 我一一实现了所有操作码,直到遇到 dup2。 oracle指令集 https: //docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.dup2

复制操作数堆栈顶部的一个或两个值,并将复制的一个或多个值按原始顺序推回操作数堆栈

我应该如何选择要执行的操作? 我如何知道何时应该仅复制顶部值或何时应该复制顶部两个值?

I am writing a JVM.
I was implementing all opcodes one by one, until I faced dup2.
The oracle instruction set https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.dup2 says

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

独享拥抱 2025-01-17 08:13:57

操作码的描述如下:

表格1:

...,值2,值1 →

...,值2,值1,值2,值1

其中 value1 和 value2 都是类别 1 计算的值
输入(§2.11.1)。

表格2:

...,值 →

...,值,值

其中 value 是类别 2 计算类型的值 (§2.11.1)。

类别 2 类型是 longdouble,类别 1 是其他类型。因此,在 Java 的原始版本中,类别 2 类型表示 64 位类型,类别 1 表示 32 位类型。当 64 位 JVM 推出后,这种区别就不再有效了。现在,解释器或 JIT 编译器需要跟踪从操作栈压入和弹出的值的类别,以便知道堆栈顶部的值是类别 1 还是类别 2。

请注意,JVM 需要在以下位置进行此类分析:验证时间以检查
4.10.1.7。类型检查加载和存储指令

The description of the opcode says:

Form 1:

..., value2, value1 →

..., value2, value1, value2, value1

where both value1 and value2 are values of a category 1 computational
type (§2.11.1).

Form 2:

..., value →

..., value, value

where value is a value of a category 2 computational type (§2.11.1).

Category 2 types are long and double, and category 1 are others. So in the original versions of Java Category 2 types meant 64 bit type and Category 1 meant 32 bit types. When 64 bit JVMs were introduced, that distinction no longer worked. 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.

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. Type Checking Load and Store Instructions

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文