英文:
JVM MaxHeapSize := 0 - what does this mean?
问题
我看到这里有其他类似的问题:https://stackoverflow.com/questions/4667483/how-is-the-default-max-java-heap-size-determined 和 https://stackoverflow.com/questions/26631498/understanding-java-heap
我运行了命令来查看我的堆大小 java -XX:+PrintFlagsFinal -version
,我得到了MaxHeapSize的输出:
uintx MaxHeapSize := 0 {product}
这是什么意思?
英文:
I have seen other questions on here like: https://stackoverflow.com/questions/4667483/how-is-the-default-max-java-heap-size-determined and https://stackoverflow.com/questions/26631498/understanding-java-heap
I run the command to see my heap size java -XX:+PrintFlagsFinal -version
and I get the output for MaxHeapSize:
uintx MaxHeapSize := 0 {product}
What does this mean?
答案1
得分: 6
这是JDK 8中的一个bug。
MaxHeapSize
在HotSpot源代码中被定义为uintx
,代表64位无符号整数。
在JDK 8中,打印uintx
标志值的格式是"%-16lu"
,它将输入视为unsigned long
。
然而,C++中unsigned long
的大小在Windows和Unix上有所不同:
- 大多数类Unix系统是LP64,其中
unsigned long
的大小为64位。 - Windows上的Visual C++是LLP64,其中
unsigned long
的大小为32位。
因此,JDK 8在Windows上仅打印uintx
标志的低32位。这就是为什么如果MaxHeapSize
恰好是4 GiB的整数倍,你会看到uintx MaxHeapSize := 0
。这只是打印错误;实际的最大堆大小是正确的。
这个bug在JDK 9中作为JDK-8042893更改的一部分被修复了:
} else if (is_uintx()) {
- st->print("%-16lu", get_uintx());
+ st->print(UINTX_FORMAT_W(-16), get_uintx());
英文:
This is a bug in JDK 8.
MaxHeapSize
is defined in HotSpot sources as uintx
, which stands for 64-bit unsigned integer.
In JDK 8, the format for printing uintx
flag values is "%-16lu"
, which treats input as unsigned long
.
However, the size of C++ unsigned long
differs on Windows and Unix:
- Most Unix-like systems are LP64, where the size of
unsigned long
is 64 bit. - Visual C++ on Windows is LLP64, where the size of
unsigned long
is 32 bit.
So, JDK 8 on Windows prints only low 32 bits of uintx
flags. That's why if MaxHeapSize
is an exact multiple of 4 GiB, you'll see uintx MaxHeapSize := 0
. This is just the printing error; the actual max heap size is correct.
The bug was fixed in JDK 9 as a part of JDK-8042893 change:
} else if (is_uintx()) {
- st->print("%-16lu", get_uintx());
+ st->print(UINTX_FORMAT_W(-16), get_uintx());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论