查看JVM垃圾收集器类型

1. 使用jcmd

假设java进程id为1000

# Linux
jcmd 1000 PerfCounter.print |grep gc.collector.*name
# Windows
jcmd 1000 PerfCounter.print |findstr gc.collector.*name

以串行收集器(-XX:+UseSerialGC )为例,返回信息如下:

sun.gc.collector.0.name="Copy"
sun.gc.collector.1.name="MSC"

名称与收集器对照表

名称收集器作用区域启用参数
CopySerialYoung-XX:+UseSerialGC
MSCSerial OldOld-XX:+UseSerialGC
PSScavengeParallel ScavengeYoung-XX:+UseParallelGC
PSMarkSweepParallel ScavengeOld-XX:+UseParallelGC -XX:-UseParallelOldGC
PSParallelCompactParallel OldOld-XX:+UseParallelGC
PCopyParNewYoung-XX:+UseConcMarkSweepGC
或者 -XX:+UseParNewGC(JDK9起废除)
CMSConcurrent Mark SweepOld-XX:+UseConcMarkSweepGC (JDK9起标识为过期,由G1接班)
G1 incremental collectionsG1Young或者Young+部分Old-XX:+UseG1GC(JDK9起默认收集器)
G1 stop-the-world full collectionsG1Full-XX:+UseG1GC

各Java版本默认收集器

版本YoungOld
JDK6PSScavenge(Parallel Scavenge)PSMarkSweep (Parallel Scavenge)
JDK7PSScavenge(Parallel Scavenge)PSParallelCompact(Parallel Old)
JDK8PSScavenge(Parallel Scavenge)PSParallelCompact(Parallel Old)
JDK11G1G1

从G1开始分代回收渐渐模糊,最新的ZGC已经没有分代(可能只是暂时的)一说。

    原文作者:faith.huan
    原文地址: https://blog.csdn.net/huanqingdong/article/details/104117799
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞