7中垃圾回收器之间的组合关系

7中垃圾回收器

  • 3b3c42d2.jpg

关系1

  • 参数:-XX:+UseSerialGC
  • image.png

关系2

  • 参数:-XX: +UseParNewGC
  • image.png

关系3

  • 参数:-XX:+UseParallelGC
  • image.png

关系4

  • 参数:-XX:+UseConcMarkSweepGC
  • image.png
  • 老年代:并发标记失败,才是使用Serial Old

关系5

  • 参数:-XX:+UseParallelOldGC
  • image.png

关系6

  • 参数:-XX:+Use1G
  • image.png

关系7

  • 参数:是不存在的
  • image.png
  • cms 和serial 是不能一起使用的

敲黑板

Each blue box represents a collector that is used to collect a generation. The 
young generation is collected by the blue boxes in the yellow region and
the tenured generation is collected by the blue boxes in the gray region.

*   "Serial" is a stop-the-world, copying collector which uses a single GC thread.*   "ParNew" is a stop-the-world, copying collector which uses multiple GC threads. It differs
    from "Parallel Scavenge" in that it has enhancements that make it usable 
    with CMS. For example, "ParNew" does the
    synchronization needed so that it can run during the 
     concurrent phases of CMS.*   "Parallel Scavenge" is a stop-the-world, copying collector 
    which uses multiple GC threads.*   "Serial Old" is a stop-the-world,
    mark-sweep-compact collector that uses a single GC thread.*   "CMS" is a mostly concurrent, low-pause collector.*   "Parallel Old" is a compacting collector that uses multiple GC threads.
     <nl style="margin: 0px; padding: 0px; list-style: none; -webkit-font-smoothing: antialiased;">Using the -XX flags for our collectors for jdk6,</nl> *   UseSerialGC is "Serial" + "Serial Old"*   UseParNewGC is "ParNew" + "Serial Old"*   UseConcMarkSweepGC is "ParNew" + "CMS" + "Serial Old". "CMS" is used most of the time to collect the tenured generation. "Serial Old" is used when a concurrent mode failure occurs.*   UseParallelGC is "Parallel Scavenge" + "Serial Old"*   UseParallelOldGC is "Parallel Scavenge" + "Parallel Old"
     <nl style="margin: 0px; padding: 0px; list-style: none; -webkit-font-smoothing: antialiased;">FAQ

    1) UseParNew and UseParallelGC both collect the young generation using
    multiple GC threads. Which is faster?

    There's no one correct answer for
    this questions. Mostly they perform equally well, but I've seen one
    do better than the other in different situations. If you want to use
    GC ergonomics, it is only supported by UseParallelGC (and UseParallelOldGC)
    so that's what you'll have to use.

    2) Why doesn't "ParNew" and "Parallel Old" work together?

    "ParNew" is written in
    a style where each generation being collected offers certain interfaces for its
    collection. For example, "ParNew" (and "Serial") implements
    space_iterate() which will apply an operation to every object
    in the young generation. When collecting the tenured generation with
    either "CMS" or "Serial Old", the GC can use space_iterate() to 
    do some work on the objects in the young generation. 
    This makes the mix-and-match of collectors work but adds some burden
    to the maintenance of the collectors and to the addition of new
    collectors. And the burden seems to be quadratic in the number
    of collectors.
    Alternatively, "Parallel Scavenge"
    (at least with its initial implementation before "Parallel Old")
    always knew how the tenured generation was being collected and
    could call directly into the code in the "Serial Old" collector.
    "Parallel Old" is not written in the "ParNew" style so matching it with
    "ParNew" doesn't just happen without significant work.
    By the way, we would like to match "Parallel Scavenge" only with
    "Parallel Old" eventually and clean up any of the ad hoc code needed
    for "Parallel Scavenge" to work with both.

    Please don't think too much about the examples I used above. They
    are admittedly contrived and not worth your time.

    3) How do I use "CMS" with "Serial"?

    -XX:+UseConcMarkSweepGC -XX:-UseParNewGC.
    Don't use -XX:+UseConcMarkSweepGC and -XX:+UseSerialGC. Although that's seems like 
    a logical combination, it will result in a message saying something about 
    conflicting collector combinations and the JVM won't start. Sorry about that.
    Our bad.

    4) Is the blue box with the "?" a typo?

    That box represents the new garbage collector that we're currently developing called
    Garbage First or G1 for short. G1 will provide</nl> *   More predictable GC pauses*   Better GC ergonomics*   Low pauses without fragmentation*   Parallelism and concurrency in collections*   Better heap utilization
     <nl style="margin: 0px; padding: 0px; list-style: none; -webkit-font-smoothing: antialiased;">G1 straddles the young generation - tenured generation boundary because it is
    a generational collector only in the logical sense. G1 divides the
    heap into regions and during a GC can collect a subset of the regions.
    It is logically generational because it dynamically selects a set of
    regions to act as a young generation which will then be collected at
    the next GC (as the young generation would be).

    The user can specify a goal for the pauses and G1 
    will do an estimate (based on past collections) of how many 
    regions can be collected in that time (the pause goal). 
    That set of regions is called a collection set and G1 will
    collect it during the next GC.

    G1 can choose the regions with the most garbage to collect first (Garbage First, get it?)
    so gets the biggest bang for the collection buck.

    G1 compacts so fragmentation is much less a problem. Why is it a problem at all?
    There can be internal fragmentation due to partially filled regions.

    The heap is not statically divided into 
    a young generation and a tenured generation so the problem of
    an imbalance in their sizes is not there.

    Along with a pause time goal the user can specify a goal on the fraction of
    time that can be spent on GC during some period (e.g., during the next 100 seconds
    don't spend more than 10 seconds collecting). For such goals (10 seconds of
    GC in a 100 second period) G1 can choose a collection set that it expects it can collect in 10 seconds and schedules the collection 90 seconds (or more) from the previous collection. You can see how an evil user could specify 0 collection
    time in the next century so again, this is just a goal, 
    not a promise.

    If G1 works out as we expect, it will become our low-pause collector in place of 
    "ParNew" + "CMS". And if you're about to ask when will it be ready, please don't
    be offended by my dead silence. It's the highest priority project for our team,
    but it is software development so there are the usual unknowns. It will be out
    by JDK7\. The sooner the better as far as we're concerned.

    **Updated February 4. **Yes, I can edit an already posted blog. Here's
    a reference to the G1 paper if you have ACM portal access.

    [http://portal.acm.org/citation.cfm?id=1029879](http://portal.acm.org/citation.cfm?id=1029879)</nl> 

#### Join the discussion

[](https://blogs.oracle.com/jonthecollector/our-collectors#open)

*   [](http://java.sun.com/j2se/reference/whitepapers/memorymanagement_whitepaper.pdf)

*   [](http://www.michael-bien.com/roller/mbien/entry/garbage_first_the_new_concurrent)

*   [](http://research.sun.com/jtech/pubs/)

*   [](http://www.gossamer-threads.com/lists/lucene/java-user/44286#44286)

    [](http://www-cs.canisius.edu/~hertzm/bc.html)

*   [](http://www-cs.canisius.edu/~hertzm/gcmalloc-oopsla-2005.pdf)

    [](http://www-cs.canisius.edu/~hertzm/)

<form class="comment-form" method="post" action="https://blogs.oracle.com/jonthecollector/post.comment" style="margin: 30px 133.797px; padding: 0px; list-style: none; -webkit-font-smoothing: antialiased;"><label id="comment-form-name-label" style="margin: 0px; padding: 35px 0px 8px; list-style: none; -webkit-font-smoothing: antialiased; display: block; width: 484px;"></label><input type="text" id="comment-form-name" name="commentAuthorName" value="" size="80" style="margin: 0px; padding: 0px; list-style: none; -webkit-font-smoothing: antialiased; border: 1px solid rgb(193, 193, 193); border-radius: 2px; width: 475.797px; height: 1.5em; font-size: 2rem;"><label id="comment-form-email-label" style="margin: 0px; padding: 35px 0px 8px; list-style: none; -webkit-font-smoothing: antialiased; display: block; width: 484px;"></label><input type="text" id="compendiumment-form-email" name="commentAuthorEmail" value="" size="80" style="margin: 0px; padding: 0px; list-style: none; -webkit-font-smoothing: antialiased; border: 1px solid rgb(193, 193, 193); border-radius: 2px; width: 475.797px; height: 1.5em; font-size: 2rem;"><label id="comment-form-comment-label" style="margin: 0px; padding: 35px 0px 8px; list-style: none; -webkit-font-smoothing: antialiased; display: block; width: 484px;"></label><textarea class="field" id="fieldcomment-form-comment" name="commentText" rows="8" cols="60" style="margin: 0px; padding: 0px; list-style: none; -webkit-font-smoothing: antialiased; width: 475.797px; height: 8em; font-size: 2rem;"></textarea><label for="spam-prevent" id="spamPrevent-label" style="margin: 0px; padding: 35px 0px 8px; list-style: none; -webkit-font-smoothing: antialiased; display: block; width: 484px;"></label><input type="text" size="80" class="spam-prevent" name="spamPrevent" style="margin: 0px; padding: 0px; list-style: none; -webkit-font-smoothing: antialiased; border: 1px solid rgb(193, 193, 193); border-radius: 2px; width: 475.797px; height: 1.5em; font-size: 2rem;">[图片上传失败...(image-2bdb5-1518069459511)]

<input type="submit" id="submitcomment-form-submit" name="submitComment" value="Submit" style="margin: 0px; padding: 10px 65px 10px 35px; list-style: none; -webkit-font-smoothing: antialiased; border-width: 1px; border-style: solid; border-color: rgb(245, 245, 245) rgb(245, 245, 245) rgb(212, 212, 212); border-image: initial; border-radius: 0px; width: auto; height: auto; font-size: 1.6rem; color: rgb(31, 79, 130); text-align: center; display: block; background: linear-gradient(rgb(255, 255, 255) 0%, rgb(255, 255, 255) 56%); box-shadow: rgba(0, 0, 0, 0.2) 0px 2px 2px; cursor: pointer;">

</form>

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 199,711评论 5 468
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 83,932评论 2 376
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 146,770评论 0 330
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 53,799评论 1 271
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 62,697评论 5 359
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 48,069评论 1 276
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 37,535评论 3 390
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 36,200评论 0 254
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 40,353评论 1 294
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 35,290评论 2 317
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 37,331评论 1 329
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 33,020评论 3 315
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 38,610评论 3 303
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 29,694评论 0 19
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,927评论 1 255
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 42,330评论 2 346
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 41,904评论 2 341

推荐阅读更多精彩内容