Java堆默认大小

PrintFlagsFinal

-XX:+PrintFlagsFinal
打印所有可设置的参数及它们的默认值(从JDK 6 update 21开始才可以用)

示例:16G内存的Centos系统

1
2
3
4
5
6
7
8
9
10
11
12
$ java -XX:+PrintFlagsFinal -version  | grep -E 'HeapSize|PermSize|ThreadStackSize'
intx CompilerThreadStackSize = 0 {pd product}
uintx ErgoHeapSizeLimit = 0 {product}
uintx HeapSizePerGCThread = 87241520 {product}
uintx InitialHeapSize := 264241152 {product}
uintx LargePageHeapSizeThreshold = 134217728 {product}
uintx MaxHeapSize := 4215275520 {product}
intx ThreadStackSize = 1024 {pd product}
intx VMThreadStackSize = 1024 {pd product}
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)

可以看出默认的:
堆最大大小(MaxHeapSize):4215275520/(1024.0 * 1024 * 1024) = 3.93G
初始堆大小(InitialHeapSiz): 266338304/(1024.0 * 1024) = 254M
HeapSizePerGCThread: 87241520 / (1024.0 * 1024) = 83.20M

PrintCommandLineFlags

-XX:+PrintCommandLineFlags

打印出所有出现在命令行上的可选JVM参数。可用来了解JVM的参数设置,例如堆空间大小、垃圾收集器等。默认情况下,此选项是禁用的,并且不打印标记。

示例:

1
2
3
4
5
$ java -XX:+PrintCommandLineFlags -version
-XX:InitialHeapSize=263453376 -XX:MaxHeapSize=4215254016 -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC
java version "1.8.0_152"
Java(TM) SE Runtime Environment (build 1.8.0_152-b16)
Java HotSpot(TM) 64-Bit Server VM (build 25.152-b16, mixed mode)