如何实现对java对象的引用? [英] How is reference to java object is implemented?

查看:136
本文介绍了如何实现对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对象对象是类实例或数组。引用
值(通常只是引用)是指向这些对象的
指针,以及
特殊空引用,它将
引用到无对象。

4.3.1 Objects An object is a class instance or an array. The reference values (often just references) are pointers to these objects, and a special null reference, which refers to no object.

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

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对象的引用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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