Unable to increase the java heap size
我使用的是 64 位 Ubuntu 和 java vm 64 位版本。
我有 8GB 内存。
我无法将 java 堆大小更改为 4096m,甚至 2048m。
我试过这些东西:
1 | uname -i |
输出:
x86_64
1 | java -version |
输出:
openjdk version"11.0.4" 2019-07-16
OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3)
OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing)
当我试图改变堆大小时:
1 | java -Xmx:4096m |
输出
Invalid maximum heap size: -Xmx:4096m
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
2048m尺寸也一样
1 | java -XX:+PrintFlagsFinal -version | grep HeapSize |
输出:
1 2 3 4 5 6 7 8 9 10 11 | size_t ErgoHeapSizeLimit = 0 {product} {default} size_t HeapSizePerGCThread = 43620760 {product} {default} size_t InitialHeapSize = 130023424 {product} {ergonomic} size_t LargePageHeapSizeThreshold = 134217728 {product} {default} size_t MaxHeapSize = 2067791872 {product} {ergonomic} uintx NonNMethodCodeHeapSize = 5835340 {pd <p>product} {ergonomic} uintx NonProfiledCodeHeapSize = 122911450 {pd <p>product} {ergonomic} uintx ProfiledCodeHeapSize = 122911450 {pd <p>product} {ergonomic} openjdk version"11.0.4" 2019-07-16 OpenJDK Runtime Environment (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3) OpenJDK 64-Bit Server VM (build 11.0.4+11-post-Ubuntu-1ubuntu218.04.3, mixed mode, sharing) |
先检查默认值:
1 | java -XshowSettings:vm |
然后您需要编辑 JVM 的设置文件:
将此添加到文件的开头:
1 | export _JAVA_OPTIONS=-Xmx(size you want in here)m |
按 ESC,输入
之后你可以执行相同的命令来检查大小是否改变了:
1 | java -XshowSettings:vm |