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

2022-01-16 00:00:00 jvm java heap-memory

我已读取 32 位 Windows 上的最大堆大小为 ~1.5GB,这是由于 JVM 需要连续内存.有人可以解释连续内存"的概念以及为什么在 Windows 上最多只有 1.5GB 吗?

I've read the 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?

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

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

推荐答案

32位/64位部分与Java无关

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

事实证明,32 位系统中的内存位置由 32 位无符号整数引用.这允许多达 2^32 个可能的内存位置.由于每个位置存储 1 个字节,因此如果您愿意,您可以获得 2^32 个字节或 4 GB.

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.

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

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

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

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.

查看这个问题了解更多关于 32与 64 位相比.

Check out this question for more details on 32 vs 64 bit.

感谢 mrjoltcola 提供 exa 前缀!

Thanks mrjoltcola for the exa prefix!

相关文章