在我们曾经见到的很多书籍或者资料中,代表的都是Parallel Scavenge(新生代) + Serial Old(老年代)。这其实是没有及时更新造成的一个误导。
通过官方网站可以得到证实:
在 JDK 8 的官网有这样的说法:
链接:https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/collectors.html
Parallel compaction is enabled by default if the option -XX:+UseParallelGC has been specified. The option to turn it off is -XX:-UseParallelOldGC.
大致意思就是说-XX:+UseParallelGC 就会开始 Parallel 收集器除非手动关闭。
JDK 源码 commit 记录说到:
Server-class machine ergonomics was introduced in jdk5. If the machine upon which
the jvm is running is powerful enough (currently, at least 2 physical cores plus
at least 2gb of memory), the server jvm is invoked using the parallel scavenger
rather than the serial scavenger. Currently the old gen collector used is
serial mark-sweep-compact. Now that the parallel old gen collector is mature,
we should change to using it instead.
Issue Links
在 JDK 7U4 之前确实 UserParallelGC 用的就是 Serial,在这个版本之后 Parallel 已经很成熟了,所以直接替换了旧的收集器,所以 JDK 7u4 以后的 7 和 JDK 8 老年代默认使用的都是 Parallel 收集器,只是网上很多资料往往人云亦云,没有更新这个细节。
链接:https://bugs.openjdk.java.net/browse/JDK-6679764
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/rev/24cae3e4cbaa
另外:
PS MarkSweep 只是回收器的别名,他可以指代 Serial Old 和 Parallel Old。
-XX:+UseParallelGC 和 -XX:+UseParallelOldGC 结果一样,都是用的 Parallel Old
参考文章:https://blog.csdn.net/weixin_43753797/article/details/106450040