java 15: 查看jdk默认的gc和正在使用的gc
一,查看jdk默认使用的gc
[lhdop@blog ~]$ java -XX:+PrintCommandLineFlags -version -XX:ConcGCThreads=1 -XX:G1ConcRefinementThreads=4 -XX:GCDrainStackTargetSize=64 -XX:InitialHeapSize=251580608 -XX:MarkStackSize=4194304 -XX:MaxHeapSize=4025289728 -XX:MinHeapSize=6815736 -XX:+PrintCommandLineFlags -XX:ReservedCodeCacheSize=251658240 -XX:+SegmentedCodeCache -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseG1GC java version "15" 2020-09-15 Java(TM) SE Runtime Environment (build 15+36-1562) Java HotSpot(TM) 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)可以看到默认的参数使用了 G1GC
说明:刘宏缔的架构森林是一个专注架构的博客,地址:https://www.cnblogs.com/architectforest
对应的源码可以访问这里获取: https://github.com/liuhongdi/
或: https://gitee.com/liuhongdi
说明:作者:刘宏缔 邮箱: 371125307@qq.com
二,查看当前jdk支持的有哪些gc
[lhdop@blog tools]$ java -XX:+PrintFlagsFinal -version | grep 'bool Use' | grep 'GC ' | grep -v java java version "15" 2020-09-15 Java(TM) SE Runtime Environment (build 15+36-1562) Java HotSpot(TM) 64-Bit Server VM (build 15+36-1562, mixed mode, sharing) bool UseAdaptiveSizePolicyWithSystemGC = false {product} {default} bool UseG1GC = true {product} {ergonomic} bool UseMaximumCompactionOnSystemGC = true {product} {default} bool UseParallelGC = false {product} {default} bool UseSerialGC = false {product} {default} bool UseShenandoahGC = false {product} {default} bool UseZGC = false {product} {default}说明:可以看到jdk15已支持zgc,但并未将它设置为默认
三,查看指定进程当前正在使用的gc
[lhdop@blog ~]$ jhsdb jmap --heap --pid 22397 Attaching to process ID 22397, please wait... Debugger attached successfully. Server compiler detected. JVM version is 15+36-1562 using thread-local object allocation. Garbage-First (G1) GC with 4 thread(s) Heap Configuration: MinHeapFreeRatio = 40 MaxHeapFreeRatio = 70 MaxHeapSize = 4026531840 (3840.0MB) NewSize = 1363144 (1.2999954223632812MB) MaxNewSize = 2415919104 (2304.0MB) OldSize = 5452592 (5.1999969482421875MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 MB G1HeapRegionSize = 2097152 (2.0MB) Heap Usage: G1 Heap: regions = 1920 capacity = 4026531840 (3840.0MB) used = 99822592 (95.1982421875MB) free = 3926709248 (3744.8017578125MB) 2.479120890299479% used G1 Young Generation: Eden Space: regions = 29 capacity = 69206016 (66.0MB) used = 60817408 (58.0MB) free = 8388608 (8.0MB) 87.87878787878788% used Survivor Space: regions = 3 capacity = 6291456 (6.0MB) used = 6291456 (6.0MB) free = 0 (0.0MB) 100.0% used G1 Old Generation: regions = 18 capacity = 58720256 (56.0MB) used = 32713728 (31.1982421875MB) free = 26006528 (24.8017578125MB) 55.711146763392854% used
>>Garbage-First (G1) GC with 4 thread(s)
可以看到使用的是G1这个gc四,查看java的版本:
[lhdop@blog tools]$ java --version java 15 2020-09-15 Java(TM) SE Runtime Environment (build 15+36-1562) Java HotSpot(TM) 64-Bit Server VM (build 15+36-1562, mixed mode, sharing)