本文介绍了64 位 JVM 上对象引用的内存要求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对 32 位 JVM(至少在 Hotspot 上)上的对象的引用占用 4 个字节.

A reference to an Object on a 32 bit JVM (at least on Hotspot) takes up 4 bytes.

64 位 Hotspot JVM 需要 8 个字节吗?还是正在进行一些巧妙的压缩?如果不是,每个 Object[] 将需要两倍的堆内存,我认为(希望,期望)不是这种情况.

Does the 64 bit Hotspot JVM need 8 bytes? Or is some clever compression going on?If not, every Object[] would require twice as much heap memory, which I somehow think (hope, expect) is not the case.

更新/额外问题:这真的重要吗,或者这是一个可以忽略不计的增加,因为大多数引用指向比几个字节大得多的对象(而人们可能会争辩说这些对象是反过来主要由对其他对象的引用组成)?

Update/extra question: Does this really matter, or is this a negligible increase, because most references point to objects that are much larger than a few bytes (whereas one might argue that those objects are in turn mostly comprised of references to other objects)?

推荐答案

在 64 位系统中,对象引用通常为 8 字节长.但是在 Sun/Oracle 最近的 JVM 中,您可以启用 压缩的 Oops,以较小的堆大小限制为代价将引用大小减少到 4 个字节.

In a 64-bit system, object references are typically 8-byte long. But in recent JVMs from Sun/Oracle you can enable Compressed Oops, which reduce reference size to 4 bytes at the cost of a smaller limit on heap size.

这篇关于64 位 JVM 上对象引用的内存要求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 13:53