一、方法一
打印虚拟机所有参数
[root@localhost ~]# java -XX:+PrintCommandLineFlags -version -XX:InitialHeapSize=263475648 -XX:MaxHeapSize=4215610368 -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC openjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-b04) OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode) [root@iZ2ze1224b1em0jij7qlssZ ~]# java -XX:+PrintFlagsFinal -version | grep : intx CICompilerCount := 2 {product} uintx InitialHeapSize := 264241152 {product} uintx MaxHeapSize := 4217372672 {product} uintx MaxNewSize := 1405616128 {product} uintx MinHeapDeltaBytes := 524288 {product} uintx NewSize := 88080384 {product} uintx OldSize := 176160768 {product} bool PrintFlagsFinal := true {product} bool UseCompressedClassPointers := true {lp64_product} bool UseCompressedOops := true {lp64_product} bool UseParallelGC := true {product} openjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-b04) OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
第三列”=”表示第四列是参数的默认值,而”:=” 表明了参数被用户或者JVM赋值了。
二、方法二
[root@localhost ~]# java -XX:+PrintCommandLineFlags -version -XX:InitialHeapSize=263475648 -XX:MaxHeapSize=4215610368 -XX:+PrintCommandLineFlags -XX:+UseCompressedClassPointers -XX:+UseCompressedOops -XX:+UseParallelGC openjdk version "1.8.0_212" OpenJDK Runtime Environment (build 1.8.0_212-b04) OpenJDK 64-Bit Server VM (build 25.212-b04, mixed mode)
针对上述的-XX:UseParallelGC,这边我们引用《深入理解Java虚拟机:JVM高级特性与最佳实践》的介绍:
也就是说,打开此开关,使用的垃圾收集器是:新生代(Parallel Scavenge),老年代(Ps MarkSweep)组合。
jdk1.7 默认垃圾收集器Parallel Scavenge(新生代)+Parallel Old(老年代)
jdk1.8 默认垃圾收集器Parallel Scavenge(新生代)+Parallel Old(老年代)
jdk1.9 默认垃圾收集器G1
三、方法三:
[root@localhost ~]# jmap -heap 25523 Attaching to process ID 25523, please wait... Debugger attached successfully. Server compiler detected. JVM version is 25.212-b04 using thread-local object allocation. Parallel GC with 2 thread(s) Heap Configuration: MinHeapFreeRatio = 0 MaxHeapFreeRatio = 100 MaxHeapSize = 4217372672 (4022.0MB) NewSize = 88080384 (84.0MB) MaxNewSize = 1405616128 (1340.5MB) OldSize = 176160768 (168.0MB) NewRatio = 2 SurvivorRatio = 8 MetaspaceSize = 21807104 (20.796875MB) CompressedClassSpaceSize = 1073741824 (1024.0MB) MaxMetaspaceSize = 17592186044415 MB G1HeapRegionSize = 0 (0.0MB) Heap Usage: PS Young Generation Eden Space: capacity = 39321600 (37.5MB) used = 3902632 (3.7218399047851562MB) free = 35418968 (33.778160095214844MB) 9.924906412760416% used From Space: capacity = 524288 (0.5MB) used = 98304 (0.09375MB) free = 425984 (0.40625MB) 18.75% used To Space: capacity = 524288 (0.5MB) used = 0 (0.0MB) free = 524288 (0.5MB) 0.0% used PS Old Generation capacity = 121634816 (116.0MB) used = 101585632 (96.87960815429688MB) free = 20049184 (19.120391845703125MB) 83.5169035812904% used 11612 interned Strings occupying 947640 bytes.
Concurrent Mark-Sweep GC:CMS回收器
Mark Sweep Compact GC:串行GC(Serial GC)
Parallel GC with 2 thread(s):并行GC(ParNew)
参考:
https://www.cnblogs.com/pc-boke/articles/10247068.html
https://blog.csdn.net/earthhour/article/details/76468084