[Java] JDK8 jvm parameter configuration and description

parameter

illustrate

1. Heap memory parameter settings

-Xms

or

-XX:InitialHeapSize=n

Set the initial value of the heap

Command 1:-Xms2g
Command 2:-XX:InitialHeapSize=2048m

-Xmx

-XX:MaxHeapSize=n

Set the maximum size of the heap area
Command 1:-Xmx2g
Command 2: -XX:MaxHeapSize=2048m
-XX:NewSize=n Set young generation size

-Xss

or

-XX:ThreadStackSize=n

Maximum stack size per thread

Command 1: -Xss256k
Command 2: -XX:ThreadStackSize=256k
Note:

The default stack size is 1M. 128K should be enough. For large stacks, 256K is recommended. If the stack setting is too large, it will lead to thread creation reduce. A small stack setting will result in insufficient depth, and deep recursion will causestack overflow.

-Xmn

or

-XX:MaxNewSize=n

New generation memory configuration
Command 1: -Xmn512m
Command 2: -XX:MaxNewSize=512m
-XX:SurvivorRatio=n

The size ratio of the two survivor areas and the Eden area
Command: -XX:SurvivorRatio=8 (default)

The ratio of the Eden area to the two Survivor areas in the young generation. Note that there are two Survivor areas. The ratio of S area and Eden area in the new generation is 1:8, and the two S areas are 2:8.

-XX:NewRatio=n

The proportion of the new generation and the old generation
-XX:NewRatio=2 (default)

Indicates the new generation: old generation = 1:2, that is, the old generation occupies 2/3 of the entire heap; default value = 2

If -Xms==-Xmx and -Xmn is set, there is no need to set this parameter.

-Duser.timezone=GMT+08 Specify time zone
‐Dfile.encoding=UTF‐8 Specify default file encoding

2. Garbage collector settings

-XX:+PrintGC

Simple printing of GC logs
-XX:+PrintGCDetails Print GC logs in detail
-XX:+PrintHeapAtGC Print detailed stack information before and after GC
-XX:+PrintGCTimeStamps When GC occurs, the time when GC occurs is additionally output. This output time is the time offset after the virtual machine is started.
-XX:+PrintGCDateStamps When GC occurs, date printing with time zone
-XX:+PrintGCApplicationConcurrentTime Print the uninterrupted execution time of the application before each garbage collection
-XX:+PrintGCApplicationStoppedTime Print application pause times due to GC
-XX:+PrintReferenceGC Track soft references, weak references, virtual references and Finalize queues within the system

2.1 GC recycling log printing

-Xloggc:log/gc.log

Specify the file path for gc log output.

JDK8 begins to support the use of placeholders such as %p and %t to specify GC output files. Represent the process pid and startup timestamp respectively.

For example: 

-Xloggc:/data/gclog/gc.log fixed path name generation

-Xloggc:/data/gclog/gc-%t.log generated based on time

-Xloggc:/data/gclog/gc-%p.log generated based on process pid

-XX:+UseGCLogFileRotation Rolling log generation
After the log file reaches a certain size, another file will be generated, and -Xloggc must be configured
-XX:NumberOfGCLogFiles=n -XX:NumberOfGCLogFiles=4 Number of rolling GC log files, default 0, no rolling, need to configure UseGCLogFileRotation, set to 0 to indicate triggering only through jcmd command
-XX:GCLogFileSize=n -XX:GCLogFileSize=100k GC file rolling size, UseGCLogFileRotation needs to be configured. Setting it to 0 means it is only triggered by the jcmd command.

2.2 Heap memory overflow configuration

-XX:+HeapDumpOnOutOfMemoryError

Export the entire heap information when memory overflows, allowing the JVM to output heap information when it encounters an OOM exception, and set the file address of the heap memory overflow snapshot output through the (-XX:+HeapDumpPath) parameter

-XX:+HeapDumpOnOutOfMemoryError

-XX:HeapDumpPath=./log/dump/

-XX:HeapDumpPath Specify the storage path of the export heap
-XX:OnOutOfMemoryError=“”

Using this parameter, we can customize a script after the system OOM, which can be used to send email alarm information, restart the system, etc.

-XX:OnOutOfMemoryError="/opt/local/bin/alert.sh"

-XX:+HeapDumpBeforeFullGC Implement dump before Full GC
-XX:HeapDumpPath=/logs/Set the path where Dump is saved
-XX:+HeapDumpAfterFullGC

Implement dump after Full GC

-XX:HeapDumpPath=/logs/Set the path where Dump is saved

2.3 Garbage collector configuration

-XX:+UseSerialGC Enables the use of a serial garbage collector. This is usually the best choice for small and simple applications that don't require any special functionality for garbage collection. By default, this option is disabled and the collector is automatically selected based on the machine's configuration and the type of JVM.
-XX:+UseParallelGC

Allows the use of a parallel cleaning garbage collector (also known as a throughput collector) to improve application performance by utilizing multiple processors.

By default, this option is disabled and the collector is automatically selected based on the computer's configuration and the type of JVM. If enabled, this option is-XX:+UseParallelOldGCautomatically enabled unless you explicitly disable it.

-XX:+UseParalledlOldGC allows the parallel garbage collector to be used for a full GC. By default, this option is disabled. Enabling this will automatically enable this-XX:+UseParallelGCoption.
-XX:+UseConcMarkSweepGC

allows the use of the CMS garbage collector for the old generation. Oracle recommends that you use the CMS garbage collector when the spam (-XX:+UseParallelGC) garbage collector cannot meet the application latency requirements. The G1 garbage collector (-XX:+UseG1GC) is another option.

By default, this option is disabled and the collector is automatically selected based on the computer's configuration and the type of JVM. When this option is enabled, this option will-XX:+UseParNewGCbe set automatically and you should not disable this option as the following option combination has been deprecated in JDK 8:-XX:+UseConcMarkSweepGC -XX:-UseParNewGC

-XX:+UseParNewGC allows the use of parallel threads for collection in the young generation. By default, this option is disabled. It is automatically enabled when setting the-XX:+UseConcMarkSweepGC option. Use-XX:+UseParNewGCwithout option-XX:+UseConcMarkSweepGC option is deprecated in JDK 8
-XX:+UseG1GC Allows the use of a garbage-first (G1) garbage collector. It is a server-style garbage collector targeted at multi-processor machines with large amounts of RAM. It meets GC pause time targets with high probability while maintaining good throughput. The G1 collector is recommended for applications requiring large heaps (approximately 6 GB in size or larger) and limited GC latency requirements (stable and predictable pause times below 0.5 seconds)
-XX:ParallelGCThreads=n

Number of GC parallel execution threads

-XX:ParallelGCThreads=16

3. Auxiliary instructions (view or modify a certain configuration of the running JVM)

jinfo -flag parameter pid

Check whether the HeapDumpOnOutOfMemoryError configuration is enabled

jinfo -flag HeapDumpOnOutOfMemoryError 10001

Modify HeapDumpOnOutOfMemoryError configuration (-off + on)

jinfo -flag +HeapDumpOnOutOfMemoryError 10001

-XX:+PrintFlagsFinal

View jvm parameter configuration

-XX:+PrintFlagsFinal |grep GC View GC related parameter configurations

-XX:+PrintCommandLineFlags

Print parameters that have been set by the user or the current virtual machine

-XX:+PrintCommandLineFlags -version View the initial size of the GC heap and the GC collector type

4.Default configuration of JVM startup parameters for JDK8

  • -Xms2g -Xmx2g (按不同容器,4G及以下建议为50%,6G以上,建议设置为70%)
  • -XX:MetaspaceSize=128m
  • -XX:MaxMetaspaceSize=512m
  • -Xss256k
  • -XX:+UseG1GC
  • -XX:MaxGCPauseMillis=200
  • -XX:AutoBoxCacheMax=20000
  • -XX:+HeapDumpOnOutOfMemoryError (当JVM发生OOM时,自动生成DUMP文件)
  • -XX:HeapDumpPath=/data/logs/gc/
  • -XX:ErrorFile=/data/logs/gc/hs_err_%p.log (当JVM发生崩溃时,自动生成错误日志)
  • -XX:+PrintGCApplicationStoppedTime
  • -XX:+PrintGCDetails
  • -XX:+PrintGCDateStamps
  • -Xloggc:/data/logs/gc/gc-ePrint-service.log

4. Disable and discard parameter options

-Xincgc

Enable incremental garbage collection. This option is deprecated in JDK 8 and does not need to be replaced.

-Xrun libname

Loads the specified debugging/analysis library. This option has been superseded by this option-agentlib.

-XX: CMSIncrementalDutyCycle = Percentage

Sets the percentage of time (0 to 100) between secondary collections that the concurrent collector is allowed to run. This option has been deprecated in JDK 8 without replacement after the option was deprecated. -XX:+CMSIncrementalMode

-XX: CMSIncrementalDutyCycleMin = Percentage

Sets the percentage of time between secondary collections (0 to 100), which -XX:+CMSIncrementalPacing is the lower limit of the duty cycle when enabled. This option has been deprecated in JDK 8 without replacement after the option was deprecated. -XX:+CMSIncrementalMode

-XX:+ CMSIncrementalMode

Enables the incremental mode of the CMS collector. This option is deprecated in JDK 8 and has no replacement, along with other optionsCMSIncremental.

-XX: CMSIncrementalOffset = Percentage

Sets the percentage of time (0 to 100) that the incremental mode duty cycle shifts to the right during the period between minor sets. This option has been deprecated in JDK 8 without replacement after the option was deprecated. -XX:+CMSIncrementalMode

-XX:+ CMSIncrementalPacing

Enables automatic adjustment of the incremental mode duty cycle based on statistics collected while the JVM is running. This option has been deprecated in JDK 8 without replacement after the option was deprecated. -XX:+CMSIncrementalMode

-XX: CMSIncrementalSafetyFactor = Percentage

Sets the percentage of time (0 to 100) used to add conservatism when calculating duty cycle. This option has been deprecated in JDK 8 without replacement after the option was deprecated. -XX:+CMSIncrementalMode

-XX:CMSInitiatingPermOccupancyFraction = Percentage

Set the percentage of permanent generation occupancy (0 to 100) that starts GC. This option is deprecated in JDK 8 and does not need to be replaced.

-XX:MaxPermSize = size

Sets the maximum permanent generation space size in bytes. This option is deprecated in JDK 8 and replaced by the -XX:MaxMetaspaceSize option.

-XX:PermSize = size

Sets the space (in bytes) allocated for permanent generation, which will trigger garbage collection if exceeded. This option is deprecated in JDK 8 and replaced by this option. -XX:MetaspaceSize

-XX:+ UseSplitVerifier

Allows splitting the verification process. By default, this option was enabled in previous versions, and verification is divided into two phases: type reference (performed by the compiler) and type checking (performed by the JVM runtime). This option was deprecated in JDK 8 and validation is now split by default and cannot be disabled.

-XX:+ UseStringCache

Enable caching of commonly allocated strings. This option has been removed from JDK 8 and does not need to be replaced.

Guess you like

Origin blog.csdn.net/smallbirdnq/article/details/132967867