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. 老李推荐:第5章7节《MonkeyRunner源码剖析》Monkey原理分析-启动运行: 循环获取并执行事件 - runMonkeyCycles

    老李推荐:第5章7节<MonkeyRunner源码剖析>Monkey原理分析-启动运行: 循环获取并执行事件 - runMonkeyCycles   poptest是国内唯一一家培养测试开 ...

  2. JAVA加密算法系列-AesCBC

    package ***; import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; import javax.cryp ...

  3. Android 调出和隐藏软键盘

    1.弹出软键盘 public static void showSoftInputMode(Context context,View windowToken) { final InputMethodMa ...

  4. package(1):tm

    tm包是R语言中为文本挖掘提供综合性处理的package,进行操作前载入tm包,vignette命令可以让你得到相关的文档说明.使用默认安装的R平台是不带tm  package的,在安装的过程中,它会 ...

  5. Centos7部署Zabbix

    转载于http://www.cnblogs.com/xqzt/p/5124894.html,更正了部分错误,并增加了个别问题处理办法. 一.Zabbix简介 zabbix是一个基于WEB界面的提供分布 ...

  6. 借助case,实现更丰富的分组查询统计

    根据fileD6的前4位分组    分别统计该组  5种企业类型fileD31的数量 create or replace view jyjc_bycity as select substr(fileD ...

  7. Unity调用Android的两个方式:其一、调用jar包

    unity在Android端开发的时候,免不了要调用Java:Unity可以通过两种方式来调用Android:一是调用jar.二是调用aar. 这篇文章主要讲解怎么从无到有的生成一个jar包,然后un ...

  8. java线程控制方法

    一.中断线程 1.Thread.sleep()让线程进入睡眠状态,放弃CPU的占用暂停若干毫秒使用方法: public class runable implements Runnable { @Ove ...

  9. 【2017-04-25】winform公共控件、菜单和工具栏、Tab和无边框窗体制作

    一.公共控件 1. Button   按钮 + 布局 - AutoSize   按钮尺寸自动适应里面内容的长度 - Location    位置 - Margin       控件与控件外边距 - S ...

  10. [Day03] 循环语句、list相关练习题

    用户输入两个数,求平均值. 让用户一直输入数字,如果输入的是'0',终止程序打印所有数字之和. 让用户一直输入数字(只输入数字),如果没输入任何值,终止程序打印所有输入数字的平均值. 求出这个list ...