是的,有一个最大值,但它是系统依赖。尝试看看,加倍,直到你达到极限,然后向下搜索。至少有Sun JRE 1.6 on linux你会得到有趣的,如果不是总是信息性错误消息(peregrino是netbook运行32位ubuntu与2G RAM和没有互换):
peregrino:$ java -Xmx4096M -cp bin WheelPrimes
Invalid maximum heap size: -Xmx4096M
The specified size exceeds the maximum representable size.
Could not create the Java virtual machine.
peregrino:$ java -Xmx4095M -cp bin WheelPrimes
Error occurred during initialization of VM
Incompatible minimum and maximum heap sizes specified
peregrino:$ java -Xmx4092M -cp bin WheelPrimes
Error occurred during initialization of VM
The size of the object heap + VM data exceeds the maximum representable size
peregrino:$ java -Xmx4000M -cp bin WheelPrimes
Error occurred during initialization of VM
Could not reserve enough space for object heap
Could not create the Java virtual machine.
(experiment reducing from 4000M until)
peregrino:$ java -Xmx2686M -cp bin WheelPrimes
(normal execution)
大多数都是自我解释,除了-Xmx4095M这是相当奇怪(可能是一个有符号/无符号比较?),它声称保留2686M在2GB机器没有交换。但它暗示,最大大小是4G不是2G的32位VM,如果操作系统允许你解决这个问题。