`
ityun
  • 浏览: 1291 次
  • 性别: Icon_minigender_1
  • 来自: 北京
文章分类
社区版块
存档分类
最新评论

JVM GC Collector

    博客分类:
  • JVM
阅读更多

FROM: https://blogs.oracle.com/jonthecollector/our-collectors

 

I drew this diagram on a white board for some customers recently. They seemed to
like it (or were just being very polite) so I thought I redraw it for your
amusement.

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.

    Using the -XX flags for our collectors for jdk6,

     


  • 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"

    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


  • More predictable GC pauses

  • Better GC ergonomics

  • Low pauses without fragmentation

  • Parallelism and concurrency in collections

  • Better heap utilization

    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

分享到:
评论

相关推荐

    jMM+JVM-GC COLLECTOR+调优.pptx

    一个PPT包含 java内存模型,class运行机制。 java jvm垃圾回收算法 java jvm gc常见垃圾回收算法分析 java jvm调优

    jvm gc

    3. **垃圾收集器(Garbage Collector)**:JVM提供了多种垃圾收集器,如Serial GC、Parallel GC、Parallel Old GC、CMS(Concurrent Mark Sweep)和G1(Garbage-First)GC等。每种收集器有不同的工作策略和性能特点...

    mac mat jvm gc 内存分析

    JVM(Java Virtual Machine)的垃圾收集器(GC,Garbage Collector)扮演着核心角色,负责自动管理应用程序的内存,防止内存泄漏和性能问题。MAT(Memory Analyzer Tool)是由Eclipse基金会提供的一个强大的分析工具...

    用于测试jvm gc调优-share-jvm-gc.zip

    Java虚拟机(JVM)是Java程序运行的基础,它的垃圾收集器(GC)是自动管理内存的核心机制。在Java应用程序中,尤其是对于大型系统或高并发环境,进行JVM GC调优是提升性能、减少系统停顿时间的关键步骤。"用于测试...

    JVM_GC调优

    ### JVM_GC调优详解 #### 一、JVM体系结构概览 Java虚拟机(JVM)作为Java程序的运行环境,其内部结构复杂且高效。为了更好地理解JVM_GC调优,我们首先来了解一下JVM的基本组成部分。 1. **类装载器子系统(Class ...

    JVM体系结构与GC调优

    5. **垃圾收集器(Garbage Collector, GC)**:自动管理内存,回收不再使用的对象,防止内存泄露。 **GC调优** 垃圾收集是JVM内存管理的关键部分,其调优主要包括以下几个方面: 1. **GC算法选择**:常见的GC算法...

    JVM演讲PPT分享

    JVM体系结构是指虚拟机的内部构造,包括类加载器(Class Loader)、运行时数据区(Runtime Data Areas)、执行引擎(Execution Engine)、本地接口(Native Interface)和垃圾回收器(Garbage Collector)等组成部分...

    JVM初探内存分配GC原理与垃圾收集器共16页.pdf.z

    深入理解JVM内存分配、垃圾收集(Garbage Collection, GC)原理以及垃圾收集器的工作方式对于优化程序性能至关重要。 首先,我们要了解JVM内存结构。在Java中,内存主要分为以下几个区域: 1. **堆内存(Heap)**...

    HotSpot GC官网文档截图 - 20200917

    【HotSpot GC官网文档截图 - 20200917】是一个珍贵的资源集合,包含了一系列关于Java HotSpot虚拟机(JVM)垃圾收集器(GC)的官方文档截图。这些截图详细介绍了GC的发展历程、不同版本的特性、选择GC的策略以及调优...

    JVM历史发展和内存回收笔记

    8. **Java 11与ZGC**:2018年,Java 11引入了ZGC(Z Garbage Collector),这是一个低延迟的垃圾回收器,针对大内存场景设计。 9. **Java 17与飞行记录器**:2021年的Java 17,JDK提供了飞行记录器(Flight ...

    Java面试题-内存+GC+类加载器+JVM调优.pdf

    在 Java 中,对象的生命周期是由 GC(Garbage Collector)来管理的。GC 会在堆中搜索无引用的对象,并将其回收,以释放内存空间。 二、Java 垃圾回收机制(GC) 垃圾回收机制是 Java 中的一种自动内存管理机制,...

    jvm详解资料

    - **JVM的垃圾收集策略**:现代JVM提供了多种垃圾收集器,如串行收集器(Serial Collector)、并行收集器(Parallel Collector)、并发标记-清扫收集器(Concurrent Mark-Sweep Collector)等,每种收集器都针对不同...

    jvm 调优建议文档

    - **垃圾收集器介绍**:JVM提供了多种垃圾收集器,包括Serial Collector、Parallel Collector、CMS Collector以及G1 Collector等,每种收集器都有其适用场景和特点。 - **G1垃圾收集器详解**:G1(Garbage First)是一...

    JVM详细解说图.zip

    4. **垃圾收集器(Garbage Collector, GC)**:JVM的重要组成部分,负责自动回收不再使用的对象所占用的内存空间,以防止内存泄漏。GC有多种策略,如标记-清除、复制、标记-整理、分代收集等。 5. **内存管理...

    JVM面试题资源

    - **垃圾收集器(Garbage Collector)**:自动管理内存,避免内存泄露。 - **本地方法接口(Native Method Interface)**:允许JVM调用C/C++代码。 2. **内存区域详解** - **程序计数器**:记录当前线程执行的字节码...

    Sun JVM原理与内存管理

    #### 一、Sun JDK 1.6 GC (Garbage Collector) Sun JDK 1.6 的垃圾收集器(GC)是其内存管理的关键组成部分,它负责自动地回收不再使用的对象所占用的内存。本文将详细介绍Sun JDK 1.6 GC的工作原理、内存管理机制...

    马士兵jvm调优笔记.docx

    ### 马士兵JVM调优笔记知识点梳理 #### 一、Java内存结构 Java程序运行时,其内存被划分为几个不同的区域,包括堆内存(Heap)、方法区(Method Area)、栈(Stack)、程序计数器(Program Counter Register)以及...

    JVM基础知识及性能调优

    - **监控工具**:利用VisualVM、JConsole等工具监控JVM的运行状态,分析GC行为。 - **GC日志分析**:通过配置日志参数(`-XX:+PrintGCDetails`)来记录详细的GC过程,便于分析性能问题。 #### 五、GC日志解析 典型的...

    JVM内存参数详解以及配置调优

    垃圾回收(Garbage Collector,GC)是内存管理的主要组件,它负责回收堆中不再使用的对象,以释放内存。垃圾回收有两种方式:Minor 收集和 Major 收集。Minor 收集主要是对 Young Generation 中的对象进行垃圾回收,...

    JVM详解-淘宝内部资料

    4. **垃圾收集器(Garbage Collector, GC)**:自动管理内存,回收不再使用的对象,防止内存泄漏。GC的策略包括分代收集、标记-清除、复制算法、标记-整理等。GC的性能直接影响到应用的响应速度和稳定性。 5. **...

Global site tag (gtag.js) - Google Analytics