Generational Collectors (分代收集器)

  • GC algos optimised based on two hypotheses / observations:

    • Most objects soon become unreachable - short lived.

    • References from old objects to young objects only exist in small numbers

  • The Oracle HotSpot JVM:

    • Objects allocated in the Eden space of the Young Generation (or New Generation年轻代)

    • Once the Eden space is full, a young collection or minor collection occurs

    • Surviving objects live in the survivor space of the young generation

    • When an object is “old enough”, it is promoted to the Old Generation (or tenured space年老代)

    • When the old generation is “full enough”, a major collection occurs.

  • Allocation is usually very fast

    • Thread Local Allocation Buffers

    • Bump of pointer

Java Garbage Collectors

  • Available in the Oracle HotSpot JVM:

    • Serial Collector

    • Parallel (Throughput) Collector

    • Concurrent Mark-Sweep Collector (CMS)

    • G1

  • Others:

    • Oracle JRockit Real Time

    • IBM Websphere Real Time

    • Azul Zing

Serial Collector

  • Single threaded for all collections (minor and major)

  • All collections are Stop-The-World (STW)

  • Collections use a mark-sweep-compact algorithm

  • Suitable for single-threaded apps with low memory footprint (~100MB)

  • Enabled using -XX:+UseSerialGC

Parallel Collector

  • Similar to the serial collector, but uses multiple threads to speed things up

  • Offers highest throughput of all the collectors

  • Enabled using ‑XX:+UseParallelGC

Concurrent Mark Sweep (CMS) Collector

  • Boasts shorter pauses than the serial or parallel collectors at the expense of application throughput

  • Minor collections similar to serial collector

  • Old generation is collected concurrently with the application

  • Not compacting, so can result in old generation fragmentation

  • Enabled using -XX:+UseConcMarkSweepGC

G1 Garbage Collector

  • G1 = Garbage First

  • Default GC in Java 9

  • Aims for low pause times (<0.5s) and good throughput (90%) for large heaps (>6GB)

  • Generational and concurrent

  • Adaptive to meet pause time target

  • Enabled with -XX:+UseG1GC

G1 Layout

  • Unlike other collectors, G1 divides the heap into evenly sized regions

  • Regions can be 1MB to 32MB in size, in power of two increments

  • Regions can be dynamically assigned as:

    • Eden

    • Survivor

    • Old

    • Humongous

  • G1 aims for 2048 regions based on minimum heap size

G1 Minor Collections

  • Also known as Evacuation Pauses

  • A STW event

  • Subset of regions logically assigned as the young generation

  • Minor collection triggered when the young generation is full

  • Live objects “evacuated” to new regions to achieve compaction

  • Objects moved to either old region or survivor region based on age

  • Number of regions in young generation can be changed to meet the pause time target

G1 Concurrent Marking

  • Triggered when the used heap reaches a configurable threshold of total heap

  • Aim is to identify which old generation regions can be collected

  • Multi-phased process, some of which is STW, some concurrent with application

  • Concurrent phase can be stopped by a young collection

G1 Mixed Collections

  • Occurs after the concurrent marking phase

  • Old regions optionally added to the eden and survivor regions to be collected

  • Old regions eligible for collection usually split over multiple collections

  • The number of mixed collections is tunable via flags

  • G1 reverts to minor (young) collections when mixed collections have finished

G1 Humongous Objects

  • Humongous object defined as one greater than 50% the size of a region.

  • Allocated directly to the old generation to avoid copying during young collections

  • Region(s) marked as humongous

  • Don’t want too many, and ideally they should be long lived.

G1 Evacuation Failures and Full GC

  • Evacuation failure is when there is no free space to copy objects to

  • Evacuation failures trigger a full GC - very expensive!

G1 Configuration

  • There are many flags. Advice is to not tune G1 much unless you have to.

  • Some flags are experimental, and require -XX:+UnlockExperimentalVMOptions to be set also

  • Primary flag is to control the pause target:
    -XX:MaxGCPauseMillis=200

  • -XX:InitiatingHeapOccupancyPercent=45
    Percentage of heap occupancy at which the marking phase is triggered

  • Many more options described at http://www.oracle.com/technetwork/articles/java/g1gc-1984535.html

  • Some options for GC logging:

    • -XX:+PrintGCDetails - Enable detailed GC logging

    • -XX:+PrintGCDateStamps - Print absolute date stamps at beginning of GC lines

    • -XX:+PrintGCTimeStamps Print a timestamp reflecting the real time passed in seconds since JVM start

GC Logs

    • New log file every time the JVM starts

Java Garbage Collectors的更多相关文章

  1. 细述 Java垃圾回收机制→Types of Java Garbage Collectors

    细述 Java垃圾回收机制→Types of Java Garbage Collectors 转自:https://segmentfault.com/a/1190000006214497 本文非原创, ...

  2. Garbage Collectors – Serial vs. Parallel vs. CMS vs. G1 (and what’s new in Java 8)

    转自:http://blog.takipi.com/garbage-collectors-serial-vs-parallel-vs-cms-vs-the-g1-and-whats-new-in-ja ...

  3. Garbage Collectors - Serial vs. Parallel vs. CMS vs. G1 (and what's new in Java 8)--转

    The 4 Java Garbage Collectors - How the Wrong Choice Dramatically Impacts Performance The year is 20 ...

  4. Java Garbage Collection Basics--转载

    原文地址:http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html Overview Purpose ...

  5. Java Garbage Collection/垃圾收集 策略查看

    Java 的垃圾收集有各种各样的策略,默认的策略也会经常的改变. --比如到底是 serial , parallel, CMS; 具体到 Minor 怎么样,Old 又怎么样? 命令 java -XX ...

  6. [翻译]Java垃圾收集精粹(Java Garbage Collection Distilled)

    source URL: http://www.infoq.com/articles/Java_Garbage_Collection_Distilled Name: Java Garbage Colle ...

  7. How to Tune Java Garbage Collection--reference

    reference:http://architects.dzone.com/articles/how-tune-java-garbage The Performance Zone is support ...

  8. JVM垃圾收集(Java Garbage Collection / Java GC)

    JVM垃圾收集(Java Garbage Collection / Java GC) Java7 Java8 JDK1.8之后将最初的永久代取消了,由元空间取代. 堆内存调优简介 public sta ...

  9. 四.GC —三分钟认识JAVA回收机制(Java Garbage Collection)

    这里以jdk1.8做讲解.Jdk1.8的分代去掉了永久代,只分为新生代(有的也译为年轻代)和年老代. 名词解释: 系统吞吐量:用于处理应用程序处理事务的线程数与用于GC的线程数的比. pause ti ...

随机推荐

  1. 老李分享:QTP的录制原理以及实现

    老李分享:QTP的录制原理以及实现   poptest是国内唯一一家培养测试开发工程师的培训机构,以学员能胜任自动化测试,性能测试,测试工具开发等工作为目标.如果对课程感兴趣,请大家咨询qq:9088 ...

  2. android开发之-Android 开发之4.0界面设计原则-整理

    设计原则: 一.让人着迷: 1.给人惊喜:使用漂亮的界面.精心的动画.适时的音乐. 2.真实的对象比按钮和菜单更有趣   这句话的意思是:使用描述描述性的图标作为快捷方式,界面美观   当然这个快捷方 ...

  3. 设计模式(二)—工厂方法模式

         凡是出现了大量的实例需要创建,而且具有共同的接口时,可以通过工厂方法模式进行创建. 一个接口: Sender public interface Sender{ public void sen ...

  4. html/css/javascript的含义、作用及理解

    HTML(HyperText Markup Language/超文本标记语言) 含义:HTML是一种用于创建网页的标准标记语言. 作用:页面内可以包含图片.链接,甚至音乐.程序等非文字元素. 理解:主 ...

  5. stick footer布局

    需求: 将footer固定到底部.文章内容不足满屏时 footer在底部,超过满屏时footer在内容末尾. 方法一: <div id="wrap"> <div ...

  6. 用MPLAB IDE编程时,软件总是弹出一个窗口提示: “the extended cpu mode configuration bit is enabled,but the program that was loaded was not built using extended cpu instructions. therefore,your code may not work properly

    用MPLAB IDE编程时,软件总是弹出一个窗口提示:"the extended cpu mode configuration bit is enabled,but the program ...

  7. 关于String类和String[]数组的获取长度方法细节

    一.在Java中,以下代码段有错误的是第(  )行 public static void main(String[] args) { String name = "小新";     ...

  8. Mahout源码分析:并行化FP-Growth算法

    FP-Growth是一种常被用来进行关联分析,挖掘频繁项的算法.与Aprior算法相比,FP-Growth算法采用前缀树的形式来表征数据,减少了扫描事务数据库的次数,通过递归地生成条件FP-tree来 ...

  9. IO流程中IO向量iovec

    作者:Younger Liu,本作品采用知识共享署名-非商业性使用-相同方式共享 3.0 未本地化版本许可协议进行许可. 为了提高从磁盘读取数据到内存的效率,引入了IO向量机制,IO向量即struct ...

  10. 纯css实现翻牌特效

    大家有没有看到过网上很炫的翻牌效果,牌正面对着我们,然后点击一下,牌就被翻过来了,效果很酷炫,是不是很想知道是怎么实现的么,代码很简单,跟着小编往下走. 先给大家介绍一下翻牌的原理: 1.父容器设置设 ...