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 ...
随机推荐
- 【转】FLEX中SharedObject介绍及应用
ShareObject介绍: 1 ShareObject,顾名思义共享对象,而通常意义上的共享,从B/S结构上来讲,无非是客户端(浏览器端)的共享和服务器端的共享了,不错,ShareObject刚好份 ...
- WSDL/WebService/SOAP/REST/AXIS/CXF 开放式服务
WebService是一种数据交换标准.通过WebService标准,你可以把项目中的方法作为接口提供给其他项目使用. 有时候我们习惯性地将具体提供服务的某个方法称为WebService.比如图书系统 ...
- OS X background process
Types of Background Process 1. login item 2. xpc service 3. daemon/agent (也可以叫 mach service) 4. star ...
- linux awk 命令详解
awk是一个非常棒的数字处理工具.相比于sed常常作用于一整行的处理,awk则比较倾向于将一行分为数个"字段"来处理.运行效率高,而且代码简单,对格式化的文本处理能力超强.先来一个 ...
- jquery 中 eq()遍历方法 和:eq()选择器的区别
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- JavaScript高级内容:原型链、继承、执行上下文、作用域链、闭包
了解这些问题,我先一步步来看,先从基础说起,然后引出这些概念. 本文只用实例验证结果,并做简要说明,给大家增加些印象,因为单独一项拿出来都需要大篇幅讲解. 1.值类型 & 引用类型 funct ...
- 跟着刚哥梳理java知识点——变量之间的类型转换(四)
变量之间的类型转换主要包括自动类型转换和强制类型转换. 1.自动类型转换:当容量小的数据类型与容量大的数据类型做运算时,容量小的会自动的转换成容量大的类型. [知识点]: a)char,byte,sh ...
- React翻译官网文档之JSX
什么是JSX? 看下面的代码它被称为JSX,它既不是字符串也不是HTML,而是一种facebook公司对javascript语法的拓展.虽然写法很奇怪最终仍会会被编译为javascript代码 con ...
- Ajax 与 Comet
Ajax技术的核心是XMLHttpRequest对象(简称XHR). XMLHttpRequest对象 在浏览器中创建XHR对象要像下面这样,使用XMLHttpRequest构造函数. var xhr ...
- 打印Fibonacci数列方法汇总(前20项,每行5个)
NO.1 迭代法 标签:通俗.易懂 思路:先打印第一项.再在循环里面执行fib=fib1+fib2,把fib2赋给fib1,把fib赋给fib2,每行5个可使用if函数(循环次数对5取余). #inc ...