Java 了解最大 JVM 堆大小 - 32 位与 64 位

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2457514/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 07:57:51  来源:igfitidea点击:

Understanding max JVM heap size - 32bit vs 64bit

javajvmheap

提问by Marcus Leon

I've readthe max heap size on 32bit Windows is ~1.5GB which is due to the fact that the JVM requires contiguous memory. Can someone explain the concept of "contiguous memory" and why you only have max 1.5GB on Windows?

读过32 位 Windows 上的最大堆大小为 ~1.5GB,这是因为 JVM 需要连续内存。有人可以解释“连续内存”的概念以及为什么 Windows 上最多只有 1.5GB?

Secondly, what then is the max heap size on 64 bit Windows and why is this different than what's available on 32 bit?

其次,64 位 Windows 上的最大堆大小是多少,为什么这与 32 位上可用的不同?

采纳答案by Pace

The 32-bit/64-bit part is unrelated to Java

32位/64位部分与Java无关

It turns out that memory locations in a 32-bit system are referenced by 32-bit unsigned integers. This allows up to 2^32 possible memory locations. Since each location stores 1 byte you get 2^32 bytes or 4 GB if you prefer.

事实证明,32 位系统中的内存位置由 32 位无符号整数引用。这允许最多 2^32 个可能的内存位置。由于每个位置存储 1 个字节,因此您可以根据需要获得 2^32 个字节或 4 GB。

On a 64 bit system there are 2^64 locations, or 16 exabytes.

在 64 位系统上有 2^64 个位置,或 16 艾字节。

Now, in Windows, the contiguous part becomes a big issue, but that is just how Windows does things. The idea is that you need to have an entire "uninterrupted" range for your heap. Sadly, Windows allocates some memory somewhere in the middle. This basically leaves you with about half the left side or half the right side, about 1.5-2GB chunks, to allocate your heap.

现在,在 Windows 中,连续部分成为一个大问题,但这正是 Windows 做事的方式。这个想法是你的堆需要有一个完整的“不间断”范围。可悲的是,Windows 在中间的某个地方分配了一些内存。这基本上给你留下了大约一半的左侧或一半的右侧,大约 1.5-2GB 的块,来分配你的堆。

Check out this questionfor more details on 32 vs 64 bit.

查看此问题以了解有关 32 位和 64 位的更多详细信息。

Edit: Thanks mrjoltcola for the exa prefix!

编辑:感谢 mrjoltcola 的 exa 前缀!

回答by codenheim

Contiguous simply means "without gaps", one long single segment. The amount is limited by how large a segment the OS can map for your process. Whether Java requires a contiguous heap or not is an implementation issue specific to JVM and may not exist for other VMs.

连续只是意味着“没有间隙”,一个长的单段。该数量受操作系统可以为您的进程映射的段的大小限制。Java 是否需要连续堆是特定于 JVM 的实现问题,对于其他 VM 可能不存在。

回答by Thiyagarajan Ramasubbu

Contiguous memory is not the problem limiting windows to use only 1.2 GB of heap. Even though min/max heap defined, JVM would occupy max heap from system memory while starting. It will then reference only min heap within the occupied system memory until it had to expand. Contiguous memory of max heap is required to start JVM in most of the implimentation to improve performace.

连续内存不是限制 Windows 仅使用 1.2 GB 堆的问题。即使定义了最小/最大堆,JVM 也会在启动时从系统内存中占用最大堆。然后它将只引用占用的系统内存中的最小堆,直到它必须扩展。在大多数实现中,需要最大堆的连续内存来启动 JVM 以提高性能。

As Marcus explained above the limit of 32 bit hardware is 4GB for a single process(thread). Every operating system address this 4GB diffrenetly. 4GB is majorly split as kernel space and user space. In 32 bit windows the max user space is close to 1.5 GB. There is option to boot windows with /3GB switch to have more userspace.

正如马库斯在上面解释的那样,单个进程(线程)的 32 位硬件的限制是 4GB。每个操作系统都不同地处理这 4GB。4GB 主要分为内核空间和用户空间。在 32 位窗口中,最大用户空间接近 1.5 GB。可以选择使用 /3GB 开关启动窗口以获得更多用户空间。