我不明白 JVM 实现中的这个操作码
我正在写一个JVM。 我一一实现了所有操作码,直到遇到 dup2。 oracle指令集 https: //docs.oracle.com/javase/specs/jvms/se7/html/jvms-6.html#jvms-6.5.dup2 说
复制操作数堆栈顶部的一个或两个值,并将复制的一个或多个值按原始顺序推回操作数堆栈
我应该如何选择要执行的操作? 我如何知道何时应该仅复制顶部值或何时应该复制顶部两个值?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
操作码的描述如下:
类别 2 类型是
long
和double
,类别 1 是其他类型。因此,在 Java 的原始版本中,类别 2 类型表示 64 位类型,类别 1 表示 32 位类型。当 64 位 JVM 推出后,这种区别就不再有效了。现在,解释器或 JIT 编译器需要跟踪从操作栈压入和弹出的值的类别,以便知道堆栈顶部的值是类别 1 还是类别 2。请注意,JVM 需要在以下位置进行此类分析:验证时间以检查
4.10.1.7。类型检查加载和存储指令
The description of the opcode says:
Category 2 types are
long
anddouble
, 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