jvm参数讲解页面:
https://docs.oracle.com/javase/8/docs/technotes/tools/unix/java.html
-Xmxsize
Specifies the maximum size (in bytes) of the memory allocation pool in bytes. This value must be a multiple of 1024 and greater than 2 MB. Append the letter k
or K
to indicate kilobytes, m
or M
to indicate megabytes, g
or G
to indicate gigaby
The -Xmx
option is equivalent to -XX:MaxHeapSize
.
xmx最大堆大小,默认值为物理内存的 1/4。
-Xmssize
Sets the initial size (in bytes) of the heap. This value must be a multiple of 1024 and greater than 1 MB. Append the letter k
or K
to indicate kilobytes, m
or M
to indicate megabytes, g
or G
to indicate gigabytes.
If you do not set this option, then the initial size will be set as the sum of the sizes allocated for the old generation and the young generation. The initial size of the heap for the young generation can be set using the -Xmn
option or the -XX:NewSize
option.
xms为初始堆大小,默认值为物理内存的 1/64.
默认值来源参见
(1)默认值的比例
Ergonomics
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/ergonomics.html#sthref5
On server-class machines, the following are selected by default:
-
Throughput garbage collector
-
Initial heap size of 1/64 of physical memory up to 1 GB
-
Maximum heap size of 1/4 of physical memory up to 1 GB
-
Server runtime compiler
For initial heap and maximum heap sizes for 64-bit systems, see the section Default Heap Size in The Parallel Collector.
(2)默认值的上限
The Parallel Collector
https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/parallel.html#CHDCFBIF
Server JVM Default Initial and Maximum Heap Sizes
The default initial and maximum heap sizes work similarly on the server JVM as it does on the client JVM, except that the default values can go higher. On 32-bit JVMs, the default maximum heap size can be up to 1 GB if there is 4 GB or more of physical memory. On 64-bit JVMs, the default maximum heap size can be up to 32 GB if there is 128 GB or more of physical memory. You can always set a higher or lower initial and maximum heap by specifying those values directly; see the next section.
================================================================================================
关于 OOM 时输出堆数据
-XX:+HeapDumpOnOutOfMemoryError
Enables the dumping of the Java heap to a file in the current directory by using the heap profiler (HPROF) when a java.lang.OutOfMemoryError
exception is thrown. You can explicitly set the heap dump file path and name using the -XX:HeapDumpPath
option. By default, this option is disabled and the heap is not dumped when an OutOfMemoryError
exception is thrown.
-XX:HeapDumpPath=path
Sets the path and file name for writing the heap dump provided by the heap profiler (HPROF) when the -XX:+HeapDumpOnOutOfMemoryError
option is set. By default, the file is created in the current working directory, and it is named java_pid
pid.hprof
where pid is the identifier of the process that caused the error. The following example shows how to set the default file explicitly (%p
represents the current process identificator):
-XX:HeapDumpPath=./java_pid%p.hprof
The following example shows how to set the heap dump file to /var/log/java/java_heapdump.hprof
:
-XX:HeapDumpPath=/var/log/java/java_heapdump.hprof