java - JVM 是 32 位还是 64 位?

标签 java performance jvm

在阅读本书时 here .

我可以看到以下部分:

32 OR 64 BIT? If you have a 32-bit operating system, then you must use a 32-bit version of the JVM. If you have a 64-bit operating system, then you can choose to use either the 32- or 64-bit version of Java. Don’t assume that just because you have a 64-bit operating system, you must also use a 64-bit version of Java.

If the size of your heap will be less than about 3 GB, the 32-bit version of Java will be faster and have a smaller footprint. This is because the memory references within the JVM will be only 32-bits, and manipulating those memory references is less expensive than manipulating 64-bit references (even if you have a 64-bit CPU). The 32-bit references also use less memory.

Chapter 8 discusses compressed oops, which is a way that the JVM can use 32-bit addresses even within the 64-bit JVM. However, even with that optimization, the 64-bit JVM will have a larger footprint because the native code it uses will still have 64-bit addresses.

The downside to the 32-bit JVM is that the total process size must be less than 4GB (3GB on some versions of Windows, and 3.5GB on some old versions of Linux). That includes the heap, permgen, and the native code and native memory the JVM uses. Programs that make extensive use of long or double variables will be slower on a 32-bit JVM because they cannot use the CPU’s 64-bit registers, though that is a very exceptional case.

Programs that fit within a 32-bit address space will run anywhere between 5% and 20% faster in a 32-bit JVM than a similarly-configured 64-bit JVM. The stock batching program discussed earlier in this chapter, for example, is 20% faster when run on a 32-bit JVM on my desktop.

这些行说 32 位对于较小的堆大小(小于 3GB)会更快。如果这是真的,我想知道背后的原因,是什么让 32 位 JVM 更快?

最佳答案

我怀疑作者声称使用 32 位版本的 JVM 会带来 5% 到 20% 的性能提升。但是,我不怎么使用 Java,所以我不确定。但为了调查这种说法,我查看了 SPEC 的一些结果。

我搜索了 SPECjEnterprise2010 结果,x86-64 架构的最高分是an Oracle system that used a 64-bit version of the JVM .

我还查看了 SPECjvm2008,以防这些较小的工作负载可能受益于 32 位架构。但又是 best performing x86-64 system, this time from Huawei,使用的是 64 位版本的 JVM。

如果 JVM 的 32 位版本真的更好,我希望提交 SPEC 结果的人在调整工作负载时会选择它(但我可能错了)。

我不怀疑在某些工作负载中 32 位版本的 JVM 将优于 64 位版本。正如其他人所指出的,它使用更多的内存来存储地址。但是,x86-64 架构有更多可用的寄存器,我怀疑 64 位操作模式是大部分优化工作的重点。

系统性能有很多组成部分,我不认为 JVM 的 32 位版本一定会胜过 64 位版本(其中之一,这仅对 CPU 绑定(bind)的工作负载很重要)。我想说的是,如果您在性能调整过程中达到这一点,您会想要检查自己的工作负载是否有两个不同的选项,并使用您自己的测试结果来做出决定,而不是假设使用 32 -bit 优于 64 位,因为根据经验可以节省地址的内存空间,因为还有其他因素可能比这更重要。

关于java - JVM 是 32 位还是 64 位?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27793020/

相关文章:

java - 过滤器和 for 循环哪个是有效且更好的方法

c# - Dictionary<> 中的条目是否有限制?

c# - 一次性将 ReadOnlySpan 复制到 Span

testing - spock:使用闭包作为参数验证交互

java - JVM 垃圾收集器运行时间

java - Java 语言的工作原理

java - 消除MyFaces Tomahawk弹出输入日历中的 "Today is <date>"字符串

java - 无法获取包含在 servlet 中的 <...> 中的文本区域内容

java - 如何在 JSON 中设置参数本地日期

java - 可以使用 JAXB 2.0 验证编码的 XML 吗?