本文介绍了java对象的引用是如何实现的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

指针只是用于实现java引用变量还是它是如何真正实现的?下面是 Java 语言规范中的几行

Is pointer is just used for implementing java reference variable or how it is really implemented?Below are the lines from Java language specification

4.3.1 对象 一个对象是一个类实例或一个数组.参考资料值(通常只是引用)是指向这些对象的指针,以及特殊的空引用,它指的是没有对象.

这是否意味着它一直是指针?

Does that mean it is pointer all the time?

推荐答案

在现代 JVM 中,引用实现为地址.

In modern JVMs, references are implemented as an address.

回到 HotSpot 的第一个版本(以及更早一点的经典 VM"),引用被实现为句柄.那是一个指向指针的固定指针.对于任何特定对象,第一个指针永远不会改变,但是随着对象数据本身的移动,第二个指针会发生变化.显然这会影响使用中的性能,但更容易为其编写 GC.

Going back to the first version of HotSpot (and a bit earlier for the "classic VM"), references were implemented as handles. That is a fixed pointer to a pointer. The first pointer never changes for any particular object, but as the object data itself is moved the second pointer is changed. Obviously this impacts performance in use, but is easier to write a GC for.

在最新版本的 JDK7 中,支持压缩 oops".我相信 BEA JRockit 已经有一段时间了.迁移到 64 位系统需要两倍的内存和地址带宽.压缩 oops"利用地址的最低有效三或四位始终为零.32 位数据左移三或四位,允许 32 或 64 GB 的堆而不是 4 GB.

In the latest builds of JDK7 there is support for "compressed oops". I believe BEA JRockit has had this for some time. Moving to 64 bit systems requires twice as much memory and hence bandwidth for addresses. "Compressed oops" takes advantage of the least significant three or four bits of address always being zero. 32 bits of data are shifted left three or four bits, allowing 32 or 64 GB of heap instead of 4 GB.

这篇关于java对象的引用是如何实现的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-30 21:09