一、方法一
打印虚拟机所有参数
[root@localhost ~]# java -XX:+PrintFlagsFinal -version | grep :
uintx InitialHeapSize := 258689024 {product}
uintx MaxHeapSize := 4139778048 {product}
bool PrintFlagsFinal := true {product}
bool UseCompressedOops := true {lp64_product}
bool UseParallelGC := true {product}
二、方法二
[root@localhost ~]# java -XX:+PrintCommandLineFlags -version
-XX:InitialHeapSize=258689024 -XX:MaxHeapSize=4139024384 -XX:+PrintCommandLineFlags -XX:+UseCompressedOops-XX:+UseParallelGC
参数解读:
针对上述的-XX:UseParallelGC,这边我们引用《深入理解Java虚拟机:JVM高级特性与最佳实践》的介绍:
也就是说,打开此开关,使用的垃圾收集器是:新生代(Parallel Scavenge),老年代(Ps MarkSweep)组合。
jdk1.7 默认垃圾收集器Parallel Scavenge(新生代)+Parallel Old(老年代)
jdk1.8 默认垃圾收集器Parallel Scavenge(新生代)+Parallel Old(老年代)
jdk1.9 默认垃圾收集器G1
三、方法三:
[root@iZ2zeapchxZ tomcat7]# jmap -heap 13297
Attaching to process ID 13297, please wait...
Debugger attached successfully.
Server compiler detected.
JVM version is 25.77-b03
using parallel threads in the new generation.
using thread-local object allocation.
Concurrent Mark-Sweep GC
Heap Configuration:
MinHeapFreeRatio = 40
MaxHeapFreeRatio = 70
MaxHeapSize = 1073741824 (1024.0MB)
NewSize = 87228416 (83.1875MB)
MaxNewSize = 87228416 (83.1875MB)
OldSize = 986513408 (940.8125MB)
NewRatio = 2
SurvivorRatio = 8
MetaspaceSize = 21807104 (20.796875MB)
CompressedClassSpaceSize = 1073741824 (1024.0MB)
MaxMetaspaceSize = 17592186044415 MB
G1HeapRegionSize = 0 (0.0MB)
Heap Usage:
New Generation (Eden + 1 Survivor Space):
capacity = 78512128 (74.875MB)
used = 17016048 (16.227767944335938MB)
free = 61496080 (58.64723205566406MB)
21.673145835507096% used
Eden Space:
capacity = 69795840 (66.5625MB)
used = 10923608 (10.417564392089844MB)
free = 58872232 (56.144935607910156MB)
15.650800964642018% used
From Space:
capacity = 8716288 (8.3125MB)
used = 6092440 (5.810203552246094MB)
free = 2623848 (2.5022964477539062MB)
69.89718559093045% used
To Space:
capacity = 8716288 (8.3125MB)
used = 0 (0.0MB)
free = 8716288 (8.3125MB)
0.0% used
concurrent mark-sweep generation:
capacity = 986513408 (940.8125MB)
used = 41311272 (39.397499084472656MB)
free = 945202136 (901.4150009155273MB)
4.187603702594583% used
19916 interned Strings occupying 2422360 bytes.
Concurrent Mark-Sweep GC:CMS回收器
Mark Sweep Compact GC:串行GC(Serial GC)
Parallel GC with 2 thread(s):并行GC(ParNew)
如何修改GC回收器:设置 JAVA_OPTS