java垃圾回收那点事究竟有多少GC
Posted raintungli
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了java垃圾回收那点事究竟有多少GC相关的知识,希望对你有一定的参考价值。
java的gc回收的类型主要有几种 UseSerialGC,UseConcMarkSweepGC,UseParNewGC,UseParallelGC,UseParallelOldGC,UseG1GC,而这几个参数是如何搭配的,实际上只要看下面的代码就非常清楚
bool Arguments::check_gc_consistency()
bool status = true;
// Ensure that the user has not selected conflicting sets
// of collectors. [Note: this check is merely a user convenience;
// collectors over-ride each other so that only a non-conflicting
// set is selected; however what the user gets is not what they
// may have expected from the combination they asked for. It's
// better to reduce user confusion by not allowing them to
// select conflicting combinations.
uint i = 0;
if (UseSerialGC) i++;
if (UseConcMarkSweepGC || UseParNewGC) i++;
if (UseParallelGC || UseParallelOldGC) i++;
if (UseG1GC) i++;
if (i > 1)
jio_fprintf(defaultStream::error_stream(),
"Conflicting collector combinations in option list; "
"please refer to the release notes for the combinations "
"allowed\\n");
status = false;
return status;
我们把GC分成4种类型
1. SerialGC
参数-XX:+UseSerialGC
就是Young区和old区都使用serial 垃圾回收算法,
2. ParallelGC
参数-XX:+UseParallelGC
Young区:使用Parallel scavenge 回收算法
Old 区:可以使用单线程的或者Parallel 垃圾回收算法,由 -XX:+UseParallelOldGC 来控制
3. CMS
参数-XX:+UseConcMarkSweepGC
Young区:可以使用普通的或者parallel 垃圾回收算法,由参数 -XX:+UseParNewGC来控制
Old 区:只能使用Concurrent Mark Sweep
4. G1
参数:-XX:+UseG1GC
没有young/old区
开发者涨薪指南 48位大咖的思考法则、工作方式、逻辑体系以上是关于java垃圾回收那点事究竟有多少GC的主要内容,如果未能解决你的问题,请参考以下文章