Java Garbage Collectors
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 triggeredMany 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的更多相关文章
- 细述 Java垃圾回收机制→Types of Java Garbage Collectors
细述 Java垃圾回收机制→Types of Java Garbage Collectors 转自:https://segmentfault.com/a/1190000006214497 本文非原创, ...
- 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 ...
- 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 ...
- Java Garbage Collection Basics--转载
原文地址:http://www.oracle.com/webfolder/technetwork/tutorials/obe/java/gc01/index.html Overview Purpose ...
- Java Garbage Collection/垃圾收集 策略查看
Java 的垃圾收集有各种各样的策略,默认的策略也会经常的改变. --比如到底是 serial , parallel, CMS; 具体到 Minor 怎么样,Old 又怎么样? 命令 java -XX ...
- [翻译]Java垃圾收集精粹(Java Garbage Collection Distilled)
source URL: http://www.infoq.com/articles/Java_Garbage_Collection_Distilled Name: Java Garbage Colle ...
- How to Tune Java Garbage Collection--reference
reference:http://architects.dzone.com/articles/how-tune-java-garbage The Performance Zone is support ...
- JVM垃圾收集(Java Garbage Collection / Java GC)
JVM垃圾收集(Java Garbage Collection / Java GC) Java7 Java8 JDK1.8之后将最初的永久代取消了,由元空间取代. 堆内存调优简介 public sta ...
- 四.GC —三分钟认识JAVA回收机制(Java Garbage Collection)
这里以jdk1.8做讲解.Jdk1.8的分代去掉了永久代,只分为新生代(有的也译为年轻代)和年老代. 名词解释: 系统吞吐量:用于处理应用程序处理事务的线程数与用于GC的线程数的比. pause ti ...
随机推荐
- 嵌入javascript脚本的位置
JavaScript脚本可以放在HTML文档任何需要的位置.一般来说,可以在<head>与</head>.<body>与</body>标记对之间按需要放 ...
- jmeter JDBC Request (查询数据库获取数据库数据) 的使用
JDBC Request 这个Sampler可以向数据库发送一个jdbc请求(sql语句),并获取返回的数据库数据进行操作.它经常需要和JDBC Connection Configuration配置原 ...
- 在IntelliJ IDEA中添加repository模板
可以用于快速新建一个repository类,减少开发时间 在IntelliJ IDEA settings设置中(ctrl+alt+s)--Editor--File and Code Templates ...
- Android系统--输入系统(六)模拟输入驱动程序
Android系统--输入系统(六)模拟输入驱动程序 1. 回顾输入子系统 简单字符设备驱动:应用程序通过调用驱动所实现的函数使能硬件. 输入子系统:由于有多个应用程序使用输入子系统,故肯定使用的是早 ...
- Apache+mod_encoding解决URL中文编码问题
我们经常在论坛上看到这样的求救贴: 为什么我看不了网站上中文文件名的文件?这时一定会有好心的大侠告诉说,到IE6的工具,Internet选项, 高级里,把"总是以UTF-8发送URL&qu ...
- 记录一个NPE问题
昨天在做公司项目时,我在一处地方加了一个逻辑校验,之后测了下发现在方法调用深处有一处NPE,来源于另一个同事的代码. 其实NPE本应该是个Java编程中老掉牙的问题,但我觉得这一处错误还是比较典型的, ...
- CF #344 D. Messenger KMP/Z
题目链接:http://codeforces.com/problemset/problem/631/D 给定两个压缩形式的字符串,如a3b5a4k7这样的形式 问A在B中出现次数. 分类讨论,如果A是 ...
- java 解析xml文档---通过XmlPullParser解析方式
package com.zx; import java.io.FileInputStream; import java.io.IOException; import java.util.ArrayLi ...
- 利用Apache POI 实现简单的Excel表格导出
1.利用POI API实现简单的Excel表格导出 首先假设一个学生实体类: package com.sun.poi.domain; import java.io.Serializable; impo ...
- bzoj4800 [Ceoi2015]Ice Hockey World Championship
Description 有n个物品,m块钱,给定每个物品的价格,求买物品的方案数. Input 第一行两个数n,m代表物品数量及钱数 第二行n个数,代表每个物品的价格 n<=40,m<=1 ...