Description of common running parameters of JVM

1) Stack size related settings

Function parameter illustrate
stack size setting -Xms512m Equivalent to -XX:InitialHeapSize, set the JVM initial heap memory to 512M
-Xmx2048m Equivalent to -XX:MaxHeapSize, set the JVM maximum heap memory to 2048M
-Xss256k Equivalent to -XX:ThreadStackSize, set the Java thread stack size
-Xmn Set the space size of the new generation, generally not configured
-XX:-UseAdaptiveSizePolicy Disable adaptive memory allocation strategy
method area JDK7 -XX:PermSize=100m
-XX:MaxPermSize=100m
JDK8 -XX:MetaspaceSize=100m
-XX:MaxMetaspaceSize=100m
Scale settings -XX:SurvivorRatio=8 Set the ratio of the Eden area to the Survivor area in the new generation. The default value is 8, that is, Eden:so:s1=8:1:1
-XX:NewRatio=2 Set the ratio of the young generation to the old generation, the default value is 2

Size description

Generally, -Xms and -Xmx are configured to the same value, in order to improve the performance without re-dividing the calculation heap size after the Java garbage collection mechanism cleans up the heap area.

By default, initial heap size: 1/64 of physical memory size. Maximum heap size: 1/4 or 1G of physical memory size.
Refer to the official documentation: https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gc-ergonomics.html
insert image description here

#示例:
Xms60m -Xmx60m -Xss512k

Adaptive Description

insert image description here

Note:
1) The default SurvivorRatio=8, but during the running process, the JVM may be dynamically adjusted, even if the adaptive parameter (-XX:-UseAdaptiveSizePolicy) is turned off, it will be dynamically adjusted. The solution is to explicitly specify -XX:SurvivorRatio= 8.
2) -Xmn can set the size of the space of the new generation to conflict with the NewRatio parameter. If -Xmn is set, it shall prevail.

2) Output GC log

Function parameter illustrate
output GC log -verbose:gc Print GC brief information
‐XX:+PrintGC output GC log
‐XX:+PrintGCDetails Output detailed log of GC
‐XX:+PrintGCTimeStamps Output timestamp of GC (in the form of base time)
‐XX:+PrintGCDateStamps Output the timestamp of the GC (in the form of a date, such as 2013‐05‐04T21:53:59.234+0800)
‐XX:+PrintHeapAtGC Print out heap information before and after GC
‐Xloggc:../logs/gc.log output path of the log file
#例如:
-XX:+UseG1GC
-XX:MaxGCPauseMillis=100
-Xmx16m
-XX:+PrintGCDetails
-XX:+PrintGCTimeStamps
-XX:+PrintGCDateStamps
-XX:+PrintHeapAtGC
-Xloggc:E://gc.log

3) Output Heap dump when OOM

Function parameter illustrate
Output Heap dump when OOM -XX:+HeapDumpOnOutOfMemoryError Output heap dump file when OOM
-XX:HeapDumpPath=/opt/dump.hprof Specifies the location of the heap dump file
#例如:
-XX:+HeapDumpOnOutOfMemoryError
-XX:HeapDumpPath=/opt/3.hprof

4) Garbage Collection

Function parameter illustrate
serial garbage collector -XX:+UseSerialGC When this parameter is turned on, the new generation and the old generation are serial, the default in Client mode
New generation ParNew garbage collector ‐XX:+UseParNewGC The new generation uses the ParNew collector, the old generation uses the serial collector, and the old generation can be used with CMS
-XX:ParallelGCThreads=10 The number of parallel threads in the new generation
Old age CMS garbage collector (low latency) -XX:+UseConcMarkSweepGC The old age uses the CMS garbage collector, which can only be used with Serial and ParNew, but not with Parallel. When CMS is enabled under JDK8, the new generation uses the ParNew collector by default.
-XX:CMSInitiatingOccupancyFraction=-1 Set the threshold value of heap memory usage, and start recycling when the threshold value is reached
-XX:+UseCMSCompactAtFullCollection It is used to specify that the memory space is compressed after performing Full GC to avoid memory fragmentation. However, the memory compaction process cannot be executed concurrently, so the pause time becomes longer.
-XX:CMSFullGCsBeforeCompaction=0 Set how many times to perform Full GC to compact the memory space.
-XX:ConcGCThreads=3 (早期JVM版本也叫-XX:ParallelCMSThreads)定义并发CMS过程运行时的线程数。
ParallelGC垃圾收集器(吞吐量优先) -XX:+UseParallelGC 新生代并行垃圾收集器,JDK8默认
-XX:+UseParallelOldGC 老年代并行垃圾收集器,JDK8默认,这两参数开启一个,另一个自动开启
-XX:ParallelGCThreads=10 新生代并行线程数量
-XX:MaxGCPauseMillis 设置最大的垃圾收集时的停顿时间(STW),单位为毫秒。
注意:ParallelGC为了达到设置的停顿时间,可能会调整堆大小或其他的参数,如果堆的大小设置的较小,就会导致GC工作变得很频繁,反而可能会影响到性能。该参数使用需谨慎。
-XX:GCTimeRatio 设置垃圾回收时间占程序运行时间的百分比,公式为1/(1+n)。 它的值为0~100之间的数字,默认值为99,也就是垃圾回收时间不能超过1%
-XX:+UseAdaptiveSizePolicy 自适应GC模式,垃圾回收器将自动调整年轻代、老年代等参数,达到吞吐量、堆大小、停顿时间之间的平衡。 一般用于,手动调整参数比较困难的场景,让收集器自动进行调整。
G1 -XX:+UseG1GC 使用G1垃圾收集器
-XX:MaxGCPauseMillis=200 设置期望达到的最大GC停顿时间指标(JVM会尽力实现,但不保证达到),默认值是200毫秒。
-XX:G1HeapRegionSize=1048576 设置的G1区域的大小。值是2的幂,范围是1MB到32MB之间。目标是根据最小的Java堆大小划分出约2048 个区域。默认是堆内存的1/2000。
-XX:ParallelGCThreads=10 设置STW工作线程数的值。将n的值设置为逻辑处理器的数量。n的值与逻辑处理器的数量相同,最多为8。
-XX:ConcGCThreads=3 设置并行标记的线程数。将n设置为并行垃圾回收线程数 (ParallelGCThreads) 的1/4左右。
-XX:InitiatingHeapOccupancyPercent=45 Sets the Java heap occupancy threshold that triggers the marking cycle. The default occupancy is 45% of the entire Java heap.
Performance parameters -XX:MaxTenuringThreshold The number of times to enter the retirement area, the default is 15
-XX:+DisableExplicitGC Disable System.gc()

5) Other parameters

Function parameter illustrate
compiler mode -Xint Execute programs entirely in interpreter mode
-Xcomp Fully adopted Even if the compiler executes the program, if there is a problem with the just-in-time compilation, the interpreted compilation will intervene in the execution
-Xmixed Use the mixed mode of the interpreter + the compiler to execute the program together
TLAB -XX:+UseTLAB Enable TLAB, enabled by default
-XX:TLABWasteTargetPercent=1 TLAB accounts for 1% of the Eden area by default
default parameters -XX:+PrintFlagsInitial View default initial values ​​for all parameters
-XX:+PrintFlagsFinal View final values ​​of all parameters
other -XX:+DoEscapeAnalysis Escape analysis, enabled by default
-XX:+EliminateAllocations Scalar replacement, enabled by default
-XX:CompileThreshold=10000 JIT compilation method counter, default is 1500 in client mode and 10000 in server mode
-XX:+PrintCommandLineFlags print command line arguments (including garbage collector)
# 打印命令行参数
D:\JavaEE\JavaEE_2022_0311\JVMTest\src>java -XX:+PrintCommandLineFlags com.studio.Test
-XX:InitialHeapSize=265097920
-XX:MaxHeapSize=4241566720
-XX:+PrintCommandLineFlags
-XX:+UseCompressedClassPointers
-XX:+UseCompressedOops
-XX:-UseLargePagesIndividualAllocation
-XX:+UseParallelGC

insert image description here

Guess you like

Origin blog.csdn.net/fengsheng5210/article/details/123685756