- CMS
- G1
- ZGC
You can run the following command to view the usage of garbage collector
$ java -XX:+PrintCommandLineFlags -version
Copy the code
Jdk1.8 is as follows:
-XX:InitialHeapSize=534944128
-XX:MaxHeapSize=8559106048-XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:-UseLargePagesIndividualAllocation -XX:+UseParallelGC openjdk version"1.8.0 comes with _181-1 - the redhat"
OpenJDK Runtime Environment (build 1.8. 0_181- 1-redhat-b13)
OpenJDK 64-Bit Server VM (build 25.181-b13, mixed mode)
Copy the code
Jdk1.8-xx :+UseParallelGC Parallel garbage collector is used by default
Jdk11 is as follows:
-XX:G1ConcRefinementThreads=10 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=534944128 -XX:MaxHeapSize=8559106048 -XX:+PrintCommandLineFlags -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC -XX:-UseLargePagesIndividualAllocation
openjdk version "11.0.6" 2020- 01- 14
OpenJDK Runtime Environment AdoptOpenJDK (build 11.06.+10)
OpenJDK 64-Bit Server VM AdoptOpenJDK (build 11.06.+10, mixed mode)
Copy the code
The default garbage collector for jdk11-XX :+UseG1GC is G1
JVM startup Parameters
Java startup parameters fall into three categories;
The first is the standard parameter (-), which all JVM implementations must implement and be backward compatible.
The second is a nonstandard parameter (-x), which is implemented by the default JVM, but not guaranteed by all JVM implementations and backward compatibility.
The third is the non-stable parameter (-xx), which varies from JVM implementation to JVM implementation and may be cancelled at any time in the future, so it should be used with caution.
Commonly used non-standard parameters
Using Java-x, you can view the supported non-standard parameters
-Xms6g / / the minimum heap
-Xmx6g / / the maximum heap
-Xss1m // Size of thread stack
-Xmn200m // Set the size of the young generation to 200M
Copy the code
Commonly used non-stable parameters
Java -xx :+PrintFlagsFinal -version allows you to view supported non-stable parameters
-XX:+<option>
-XX:-<option>
Copy the code
-XX:+PrintGC
-XX:+PrintGCDetails
Copy the code
G1
G1 is full name garbage-first, which means Garbage is First, and whichever area has the most Garbage is cleaned First.
Commonly used parameters
-XX:+UseG1GC // Use G1 collector
-XX:MaxGCPauseMillis=20 // The maximum pause time is 20ms. Smaller means smaller heap and more frequent collection
Copy the code
ZGC (The Z Garbage Collector) is a low-latency Garbage Collector released in JDK 11. Its design goals include:
- The pause time does not exceed 10ms;
- The pause time does not increase with the size of the heap, or with the size of the active objects;
- Supports 8MB to 4TB heaps (16TB in the future).
-XX:+UnlockExperimentalVMOptions -XX:+UseZGC
-XX:ConcGCThreads=2 -XX:ParallelGCThreads=6
Copy the code
ZGC may not be suitable for scenarios with low latency (TP999 < 20ms) and high latency (TP999 > 200ms) service benefits and throughput priority.
JVM performance viewing tool
jstat
Real-time command-line monitoring of Java application resources and performance using JVM built-in instructions, including heap size and garbage collection monitoring
$ jstat -gc 14724 1000 2 // The interval is 1s
S0C S1C S0U S1U EC EU OC OU MC MU CCSC CCSU YGC YGCT FGC FGCT GCT
19968.0 22528.0 0.0 0.0 429056.0 185319.3 395264.0 33163.2 59160.0 55725.5 7808.0 7049.8 8 0.063 3 0.156 0.219
19968.0 22528.0 0.0 0.0 429056.0 185855.6 395264.0 33163.2 59160.0 55725.5 7808.0 7049.8 8 0.063 3 0.156 0.219
Copy the code
Parameter Meanings:
S0C: Capacity (bytes) of the first survicor of the young generation
S1C: Capacity of the second survicor of the young generation (in bytes)
S0U: The space (bytes) already used by the first survicor of the young generation
S1U: The space (bytes) already used by the second survicor of the young generation
EC: Capacity of Eden in the young generation
EU: Capacity already used by the Een(Eden) in the young generation
OC: Capacity of the aged generation
OU: Indicates the space used by the older generation
MC: the capacity of the metadata
MU: indicates the space used by metadata
CCSC: Compress the size of the class space
CCSU: Compacts the amount of class space used
YG: Number of GC’s in the young generation from application startup to sampling time
YGCT: Time from application startup to GC in the young generation at sampling time (s)
FGC: Number of gc cycles from application startup to sampling time
FGCT: Time from application startup to old generation (full GC) GC at sampling time (s)
GC: Total time taken by GC from application startup to sampling time (s)
jmap
View memory allocation for the JVM
$ jmap -heap 14724
$ jmap -dump:format=b,file=D:\test\heap.hprof 14724
$ jmap -histo:live 14724 // Count only the number of live objects
Copy the code
jstack
View the running status of Java program threads
$ jstack 14724
Copy the code
jinfo
$ jinfo 14724 // View detailed JVM system parameters and environment variables
$ jinfo -flag MaxHeapSize 14724 // Check the maximum heap memory
Copy the code
Best practices
Outputting GC Logs
jdk11
java -Xlog:gc*:file=gc.log,filecount=10,filesize=10m
Copy the code
jdk8
-XX:+PrintGCDetails -Xloggc:<PATH_TO_GC_LOG_FILE>
Copy the code
-END-