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"
名称与收集器对照表
名称 | 收集器 | 作用区域 | 启用参数 |
---|---|---|---|
Copy | Serial | Young | -XX:+UseSerialGC |
MSC | Serial Old | Old | -XX:+UseSerialGC |
PSScavenge | Parallel Scavenge | Young | -XX:+UseParallelGC |
PSMarkSweep | Parallel Scavenge | Old | -XX:+UseParallelGC -XX:-UseParallelOldGC |
PSParallelCompact | Parallel Old | Old | -XX:+UseParallelGC |
PCopy | ParNew | Young | -XX:+UseConcMarkSweepGC 或者 -XX:+UseParNewGC(JDK9起废除) |
CMS | Concurrent Mark Sweep | Old | -XX:+UseConcMarkSweepGC (JDK9起标识为过期,由G1接班) |
G1 incremental collections | G1 | Young或者Young+部分Old | -XX:+UseG1GC(JDK9起默认收集器) |
G1 stop-the-world full collections | G1 | Full | -XX:+UseG1GC |
各Java版本默认收集器
版本 | Young | Old |
---|---|---|
JDK6 | PSScavenge(Parallel Scavenge) | PSMarkSweep (Parallel Scavenge) |
JDK7 | PSScavenge(Parallel Scavenge) | PSParallelCompact(Parallel Old) |
JDK8 | PSScavenge(Parallel Scavenge) | PSParallelCompact(Parallel Old) |
JDK11 | G1 | G1 |
从G1开始分代回收渐渐模糊,最新的ZGC已经没有分代(可能只是暂时的)一说。