Sometimes found a JVM parameters, thought found a martial art secret, secretly add parameters in the server, the result of the next day to harvest an accident notification.
This article summarizes the common JVM parameters, but the use of parameters is very complex, this article only provides the common parameter reference, the specific use or need to be based on the specific situation.
The JVM is an open standard for who can implement the JVM, which results in different JVM implementations with different parameters. This article is based on the Hotspot VIRTUAL machine.
JVM parameters are many, and can generally be grouped into three categories:
-
: Standard parameters, such as-verbose:gc
This represents a standard implementation, and all virtual machines are required to implement the function of these parameters and are backward compatible-X
: nonstandard parameters that are implemented by the default JVM but are not guaranteed by all JVM implementations or backward compatibility-XX
: non-stable parameters, which can be implemented differently on different JVMS, are not recommended for use in a build environment and may be removed later- For Boolean arguments:
-XX:+
It means open,-XX:-
For example, -xx :+PrintGCDetails - For other numeric or character arguments:
-XX:
Sets a value
- For Boolean arguments:
General parameters
JDK8 | JDk9 Or Later | note |
---|---|---|
-verbose:class | -verbose:class | Outputs information about classes loaded by the JVM, which can be used to troubleshoot unfound classes or class conflicts |
-verbose:gc | -verbose:gc | Output GC information. This parameter is invalid when logs are saved as files |
-verbose:jni | -verbose:jni | Output the call status of native methods for troubleshooting JNI call problems |
-Xms | -Xms | Initial heap size, 1/64 of the default physical memory |
-Xmx | -Xmx | Maximum heap size. Default is 1/4 of physical memory |
-Xmn | -Xmn | Cenozoic size |
-Xss | -Xss | The stack size, after JDK5, is 1 MB per thread by default |
-Xnoclassgc | -Xnoclassgc | Close the collection of classes |
-XX:MaxMetaspaceSize | -XX:MaxMetaspaceSize | The maximum value of the meta-space |
-XX:MetaspaceSize | -XX:MetaspaceSize | Specifies the threshold at which the Full GC is triggered by the meta-space, which is the default size of the meta-space |
-XX:SurvivorRatio | -XX:SurvivorRatio | In the new generation, the ratio of Eden to Survivor is 8 by default. Survivor has two Spaces, from and to. In fact, the ratio of Eden to Survivor is 8:2 |
-XX:NewRatio | -XX:NewRatio | Cenozoic to old chronospatial ratio |
-XX:LargePageSizeInBytes | -XX:LargePageSizeInBytes | Set the large page size for the Java heap |
-XX:+UseLargePages | -XX:+UseLargePages | Use large page memory |
-XX:MaxHeapFreeRatio | -XX:MaxHeapFreeRatio | The maximum percentage of free Java heap space after GC |
-XX:MinHeapFreeRatio | -XX:MinHeapFreeRatio | The minimum amount of free space in the Java heap after GC |
-XX:NewSize | -XX:NewSize | Default memory usage for generation of new generation objects |
-XX:MaxNewSize | -XX:MaxNewSize | Maximum memory usage of a newly generated object |
-XX:MaxPermSize | -XX:MaxPermSize | The maximum memory that an old generation object can occupy |
-XX:ThreadStackSize | -XX:ThreadStackSize | Set the thread stack size to 0 using the default value |
The GC parameter
After JDK9, all log parameters are unified in -xlog. Note that not only gc logs, but all logs are configured as follows:
-Xlog[:[selector][:output[:[decorators][:output-options]]]]
Copy the code
Where selector is a combination of a tag and a log level, tag is a log type, and GC is only one of the tags. If you want to output GC logs, you can use the following methods:
-Xlog:gc
Copy the code
The value of level can be off, trace, debug, info, warning, or error.
Output is the output form of logs. You can use the following methods:
- stdout
- stderr
- file=
Decorators, called decorators, can add additional information to the GC log to help locate problems. Decorators can be used in more than one place at a time. Here’s a summary of decorators:
The full name | abbreviations | note |
---|---|---|
hostname | hn | The name of the machine |
level | l | The log level |
pid | p | Process identifier |
tid | ti | Thread identifier |
tags | tg | All labels associated with the message |
time | t | The current time and date are in ISO-8601 format (e.g. 2020-07-31T18:42:58.418 + 0000) |
timemillis | tm | The current time is in milliseconds, the same value generated by System.currentTimemillis () |
timenanos | tn | The current time is in nanoseconds, the same value generated by system.nanotime () |
uptime | u | The elapsed time, in seconds, since the JVM started |
uptimemillis | um | The number of milliseconds that have run since the JVM started |
uptimenanos | un | The number of nanoseconds that have run since the JVM started |
utctime | utc | Current time and date in UTC format, e.g. 2020-07-31T12:42:58.418-0600) |
Decorators such as uptime, level, and tags are used by default, or none can be used to close all decorators.
If you want to get the log level info, you need to print the machine name, log level, JVM runtime, tag, and save these logs as a gc.log file as follows:
-Xlog:gc*=info:file=gc.log:hostname,level,uptime,tags
Copy the code
Common GC log parameters are as follows:
GC log parameters
JDK8 | JDk9 Or Later | note |
---|---|---|
-XX:+PrintGC | -Xlog:gc | Printing GC Information |
-XX:+PrintGCDeatils | -Xlog:gc* | Prints GC details |
-XX:+PrintGCTimeStamps | uptime | The decorator prints the specific timestamp during the GC |
-XX:+PrintHeapAtGC | -Xlog:gc+heap=trace | Print the heap details before and after GC |
-XX:+PrintGCApplicationStoppedTime | -Xlog:safepoint | Prints the time when the program is paused during GC |
-XX:+PrintGCApplicationConcurrentTime | -Xlog:safepoint | The uninterruptible execution time of the program before printing GC |
-Xloggc:filename | -Xlog:gc:file=gc.log | The GC logs are saved as files, which default to the project root directory |
-XX:+PrintTenuringDistribution | -Xlog:gc+age*=trace | The view object is the threshold for the number of Minor GC cycles that the new generation has experienced |
-XX:PrintReferenceGC | -Xlog:gc+ref*=debug | Print soft, weak, virtual, and Finallize queues |
-XX:+PrintTLAB | -XX:+PrintTLAB | Print TLAB information |
Other GC parameters
JDK8 | JDk9 Or Later | note |
---|---|---|
-XX:MaxTenuringThreshold | -XX:MaxTenuringThreshold | The maximum number of times an object in a new generation can experience Minor GC |
-XX:PretenureSizeThreshold | -XX:PretenureSizeThreshold | Objects beyond this size are allocated directly in the old age, in bytes |
-XX:+UseSerialGC | -XX:+UseSerialGC | Using serial and Serial Old collectors (default for client VM) |
-XX:+UseParallelGC | -XX:+UseParallelGC | Using Parallel and Parallel Old collectors (default for serverVM) |
-XX:+UseConcMarkSweepGC | -XX:+UseConcMarkSweepGC | Use ParNew and CMS collectors |
-XX:+UseParNewGC | -XX:+UseParNewGC | Using ParNew and Serial old collectors (no longer recommended) |
-XX:ParallelGCThreads | -XX:ParallelGCThreads | The number of threads collected in parallel is ideally the same as the number of cpus |
-XX:GCTimeRatio | -XX:GCTimeRatio | Set the throughput of the parallel collector, for example, 99 means 1 /(1+99) = 1%, which means that the GC can only occupy 1% of the time, otherwise it will reduce the space of the new generation |
-XX:MaxGCPauseMillis | -XX:MaxGCPauseMillis | The maximum time for each young generation garbage collection |
-XX:CMSFullGCsBeforeCompaction | -XX:CMSFullGCsBeforeCompaction | Set a memory collation to be triggered after n CMS garbage collections |
-XX:UseCMSCompactAtFullCollection | -XX:UseCMSCompactAtFullCollection | Memory defragmentation is triggered after each FullGC |
-XX:CMSInitiatingOccupancyFraction | -XX:CMSInitiatingOccupancyFraction | The percentage of memory that triggers CMS collection |
-XX:+DisableExplicitGC | -XX:+DisableExplicitGC | To disable the System. The gc () |
-XX:+CollectGen0First | -XX:+CollectGen0First | Whether to perform YGC before Full GC |
REF
[1] openjdk.java.net/jeps/158
[2] docs.oracle.com/en/java/jav…
[3] www.oracle.com/java/techno…
[4] segmentfault.com/a/119000001…