关于JVM规范中引用大小的困惑 [英] Confusion about the size of references in the JVM spec

查看:75
本文介绍了关于JVM规范中引用大小的困惑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

JVM规范指出,引用仅占用一个局部变量插槽(jvms12 2.6.1).此外,它指出doublelong占用了两个局部变量插槽,因为它们是64位的.

The JVM spec states that references only take up one local variable slot( jvms12 2.6.1). Additionally it states that double and long, take up two local variable slots because they are 64-bit.

这是否意味着所有符合JVM的实现都必须使用32位寻址? 64位JVM如何处理此问题?他们使用64位局部变量插槽还是使用2个插槽作为引用?

Does this mean that all JVM compliant implementations must use 32-bit addressing? How do 64-bit JVMs handle this? Do they use 64 bit local variable slots, or do they use 2 slots for references?

推荐答案

这是否意味着所有符合JVM的实现都必须使用32位寻址? 64位JVM如何处理此问题?他们使用64位局部变量插槽还是使用2个插槽作为引用?

Does this mean that all JVM compliant implementations must use 32-bit addressing? How do 64-bit JVMs handle this? Do they use 64 bit local variable slots, or do they use 2 slots for references?

不.

插槽是一种抽象,其目的是允许指定字节码的行为. JVM解释器和JIT编译器做了一些聪明的事情,可以将插槽映射到虚拟内存地址.这些映射考虑到引用可能是32位或64位地址(或32位压缩的OOP)的事实

The slots are an abstraction whose purpose is to allow the behavior of the bytecodes to be specified. The JVM interpreter and JIT compiler do some clever things to map the slots to virtual memory addresses. These mappings take account of the fact that a reference may be a 32 or 64 bit address (or a 32 bit compressed OOP)

一个(抽象的)插槽用于引用指针的实际大小.

One (abstract) slot is used for a reference irrespective of the actual size of pointers.

问:为什么他们要这样定义广告位?

Q: Why did they define slots like this?

A:因此相同的字节码在32位和64位Java平台上具有相同的含义!

A: So that the same bytecodes have the same meaning on 32 and 64 bit Java platforms!

问:如果您尝试将某个插槽的内容视为另一种类型,为什么它不会崩溃?

Q: Why doesn't it fall apart if you try to look at the contents a slot as a different type?

A:因为JVM的字节码分析器不允许您这样做!

A: Because the JVM's bytecode analyser won't let you do that!

这篇关于关于JVM规范中引用大小的困惑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆