嘲弄JVM的压缩哎呀 [英] Trick behind JVM's compressed Oops

查看:154
本文介绍了嘲弄JVM的压缩哎呀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我理解现在默认情况下在HotSpot VM中启用了压缩的oops。它从Java SE 6u23开始通过VM选项 -XX:+ UseCompressedOops 支持此功能。我知道它允许有效的CPU缓存利用率,因为CPU缓存可以容纳更多数量的引用,而不是它们必须处理64位大小的引用。但我不明白的是,如何只使用32位JVM可以解决多达2个 64 地址。

So I understand the compressed oops is enabled by default in HotSpot VM now. It has support for this from Java SE 6u23 onwards through the VM option -XX:+UseCompressedOops. I understand that it allows for efficient CPU cache utilization as the CPU caches can hold more number of references than if they had to deal with 64 bit sized references. But what I do not understand is how using only 32 bits JVM can address up to 264 addresses.

为了简化问题我们怎样才能仅使用2位地址最多2个 4 存储器地址?什么可能是这种地址方案的编码/解码?

To simplify the problem how can we address up to 24 memory address's using just 2 bits? What can be a possible encoding/decoding of such an address scheme?

推荐答案

有关压缩oops的详细说明,请参阅< John Rose @ Oracle的一篇文章中的href =https://wiki.openjdk.java.net/display/HotSpot/CompressedOops =nofollow noreferrer>Hotspot JVM中的压缩oops。

For a detailed explanation of compressed oops, see the "Compressed oops in the Hotspot JVM" article by John Rose @ Oracle.

TL; DR版本是:

The TL;DR version is:


  • 在现代计算机体系结构上,内存地址是字节地址,

  • Java对象引用是指向64的字开头的地址 1

  • 位机,字对齐意味着对象引用/地址的底部3位为零 2

  • 因此,通过将地址3位移位到是的,我们可以将一个35位的64位地址压缩成32位字,

  • ,并且可以通过向左移3位来完成解压缩,将这3个零位置回来,

  • 35位的地址sing允许我们使用在64位计算机上适合32位(半)字的压缩oops来表示最多32 GB堆内存的对象指针。

  • on modern computer architectures, memory addresses are byte addresses,
  • Java object references are addresses that point to the start of a word1,
  • on a 64-bit machine, word alignment means that that the bottom 3 bits of an object reference / address are zero2
  • so, by shifting an address 3 bits to the right, we can "compress" up to a 35 bits of a 64 bit address into a 32-bit word,
  • and, decompression can be done by shifting 3 bits to the left, which puts those 3 zero bits back,
  • 35 bits of addressing allows us to represent object pointers for up to 32 GB of heap memory using compressed oops that fit in 32-bit (half-)words on a 64-bit machine.

请注意, only 适用于64位JVM。我们仍然需要能够处理包含(最多)32 GB堆 1 的内存,这意味着64位硬件地址(在现代CPU /计算机体系结构上)。

Note that this only works on a 64-bit JVM. We still need to be able to address the memory containing that (up to) 32 GB heap1, and that means 64-bit hardware addresses (on modern CPUs / computer architectures).

另请注意,执行此操作会受到轻微处罚;即在常规参考和压缩参考之间转换所需的移位指令。然而,另一方面是消耗的实际内存较少 3 ,因此内存缓存通常更有效。

Note also that there is a small penalty in doing this; i.e. the shift instructions required to translate between regular and compressed references. However, the flip side is that less actual memory is consumed3, and memory caches are typically more effective as a consequence.

1 - 这是因为现代计算机架构针对字对齐内存访问进行了优化。

2 - 这假设您没有使用 -XX:ObjectAlignmentInBytes 来将对齐方式从其默认(和最小)值8字节增加。

2 - This assumes that you haven't used -XX:ObjectAlignmentInBytes to increase the alignment from its default (and minimum) value of 8 bytes.

3 - 实际上,内存节省是特定于应用程序的。它取决于平均对象对齐浪费,参考与非参考字段的比率等。如果考虑调整对象对齐,它会变得更复杂。


To简化问题我们如何只使用2位来处理多达2个 4 内存地址?什么可能是这种地址方案的编码/解码?

To simplify the problem how can we address up to 24 memory addresses using just 2 bits? What can be a possible encoding/decoding of such an address scheme?

你不能解决2 4 字节地址。但是可以使用2位字地址来寻址2个 2 字地址(假设32位字)。如果您可以假设所有字节地址都是字对齐的,那么您可以将4位字节地址压缩为2位字地址,方法是将其移位2位。

You can't address 24 byte addresses. But you can address 22 word addresses (assuming 32-bit words) using 2-bit word addresses. If you can assume that all byte addresses are word-aligned, then you can compress a 4-bit byte address as 2-bit word address by shifting it by 2-bit positions.

这篇关于嘲弄JVM的压缩哎呀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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