Oracle JVM Garbage Collectors Available From JDK 1.7.0_04 And After

Jack Shirazi tells you what garbage collectors and garbage collector combinations are available from the Oracle Java 7 update 4 JVM and onwards, including Java 8 and Java 9.

Published June 2012, Updated September 2015, Author Jack Shirazi

--From http://www.fasterj.com/articles/oraclecollectors1.shtml. Combine Zhou zhiming‘s Understaning JVM with the article to help us practise GC garbage exercises.

Note, this has been updated for changes to Java 8 and Java 9

With G1 finally being officially supported - i.e. no longer an experimental garbage collector - in the 1.7.0_04 (Java 7 update 4) release, it‘s worth taking stock of what we now have available in terms of garbage collectors in the Sun JVM. All the following details are relevant specifically to the Sun JVMs from 1.7.0_04 on.

There are now seven primary garbage collection algorithms, one of which (PS Scavenge) has two modes that are sufficiently different that I would call them two different algorithms (that is, with and without adaptive GC), and another (the concurrent collector) which has a huge number of options that makes it actually at least half a dozen algorithms in one! It‘s useful to list the garbage collectors so that‘s what I‘ll do here.

First I‘ll characterise the actual different primary garbage collectors. There are seven (I‘m counting the G1 collector as one):

Young generation collectors

Copy (enabled with -XX:+UseSerialGC) -
the serial copy collector, uses one thread to copy surviving objects from Eden to Survivor spaces and between Survivor spaces until it decides they‘ve been there long enough, at which point it copies them into the old generation.
PS Scavenge (enabled with -XX:+UseParallelGC) -
the parallel scavenge collector, like the Copy collector, but uses multiple threads in parallel and has some knowledge of how the old generation is collected (essentially written to work with the serial and PS old gen collectors).
ParNew (enabled with -XX:+UseParNewGC) -
the parallel copy collector, like the Copy collector, but uses multiple threads in parallel and has an internal ‘callback‘ that allows an old generation collector to operate on the objects it collects (really written to work with the concurrent collector).
G1 Young Generation (enabled with -XX:+UseG1GC) -
the garbage first collector, uses the ‘Garbage First‘ algorithm which splits up the heap into lots of smaller spaces, but these are still separated into Eden and Survivor spaces in the young generation for G1.

Old generation collectors

MarkSweepCompact (enabled with -XX:+UseSerialGC) -
the serial mark-sweep collector, the daddy of them all, uses a serial (one thread) full mark-sweep garbage collection algorithm, with optional compaction.
PS MarkSweep (enabled with -XX:+UseParallelOldGC) -
the parallel scavenge mark-sweep collector, parallelised version (i.e. uses multiple threads) of the MarkSweepCompact.
ConcurrentMarkSweep (enabled with -XX:+UseConcMarkSweepGC) -
the concurrent collector, a garbage collection algorithm that attempts to do most of the garbage collection work in the background without stopping application threads while it works (there are still phases where it has to stop application threads, but these phases are attempted to be kept to a minimum). Note if the concurrent collector fails to keep up with the garbage, it fails over to the serial MarkSweepCompact collector for (just) the next GC.
G1 Mixed Generation (enabled with -XX:+UseG1GC) -
the garbage first collector, uses the ‘Garbage First‘ algorithm which splits up the heap into lots of smaller spaces.

All of the garbage collection algorithms except ConcurrentMarkSweep are stop-the-world, i.e. they stop all application threads while they operate - the stop is known as ‘pause‘ time. The ConcurrentMarkSweep tries to do most of it‘s work in the background and minimize the pause time, but it also has a stop-the-world phase and can fail into the MarkSweepCompact which is fully stop-the-world. (The G1 collector has a concurrent phase but is currently mostly stop-the-world).

Combinations of Garbage Collectors

That‘s the set of garbage collectors available, but they operate in two different heap spaces and it‘s the combination that is what we actually end up with for a particular JVM setting, so I‘ll also list the combinations that are possible. It doesn‘t explode into a dozen combinations because not all of these collectors work with each other. G1 is effectively an antisocial collector that doesn‘t like working with anyone else; the serial collectors are the "last man picked" collectors; the ‘PS‘ collectors like to work with each other; and ParNew and Concurrent like to work together. From Java 9 that‘s pretty much it (with the addition of being able to turn off adaptive sizing policy) Before that it wasn‘t quite as simple as that, so here is the list of what I consider are the main options in terms of garbage collection algorithm options. As an aside for those who like a bit of trivia, we have actually lost one garbage collection algorithm over time, the "train" (incremental) garbage collector which was available in various JVMs as -Xincgc and -XX:+UseTrainGC - these flags are no longer useful, the former flag is just silently converted into using ParNew and Concurrent, while the latter flag will cause a startup error in this JVM, and from Java 9 we also lose the incremental algorithm in the concurrent collector.

The full list of possible GC algorithm combinations that can work are:

Command Options* Resulting Collector Combination
-XX:+UseSerialGC young Copy and old MarkSweepCompact
-XX:+UseG1GC young G1 Young and old G1 Mixed
-XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseAdaptiveSizePolicy young PS Scavenge old PS MarkSweep with adaptive sizing
-XX:+UseParallelGC -XX:+UseParallelOldGC -XX:-UseAdaptiveSizePolicy young PS Scavenge old PS MarkSweep, no adaptive sizing
-XX:+UseParNewGC (deprecated in Java 8 and removed in Java 9 - for ParNew see the line below which is NOT deprecated) young ParNew old MarkSweepCompact
-XX:+UseConcMarkSweepGC -XX:+UseParNewGC young ParNew old ConcurrentMarkSweep**
-XX:+UseConcMarkSweepGC -XX:-UseParNewGC (deprecated in Java 8 and removed in Java 9) young Copy old ConcurrentMarkSweep**
*All the combinations listed here will fail to let the JVM start if you add another GC algorithm not listed, with the exception of -XX:+UseParNewGC which is only combinable with -XX:+UseConcMarkSweepGC
**there are many many options for use with -XX:+UseConcMarkSweepGC which change the algorithm, e.g.

  • -XX:+/-CMSIncrementalMode (deprecated in Java 8 and removed in Java 9) - uses or disables an incremental concurrent GC algorithm
  • -XX:+/-CMSConcurrentMTEnabled - uses or disables parallel (multiple threads) concurrent GC algorithm
  • -XX:+/-UseCMSCompactAtFullCollection - uses or disables a compaction when a full GC occurs

Other options equivalent to one of the above:

Command Options Used On Their Own Equivalent To Entry In Table Above
-XX:+UseParallelGC -XX:+UseParallelGC -XX:+UseParallelOldGC
-XX:+UseParallelOldGC -XX:+UseParallelGC -XX:+UseParallelOldGC
-Xincgc (deprecated in Java 8 and removed in Java 9) -XX:+UseParNewGC -XX:+UseConcMarkSweepGC
-XX:+UseConcMarkSweepGC -XX:+UseParNewGC -XX:+UseConcMarkSweepGC
no option on most Windows -XX:+UseG1GC from Java 9, or before that -XX:+UseSerialGC (see also this page)
no option on most Unix -XX:+UseG1GC from Java 9, or before that -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseAdaptiveSizePolicy (see also this page)
-XX:+AggressiveHeap -XX:+UseParallelGC -XX:+UseParallelOldGC -XX:+UseAdaptiveSizePolicy with a bunch of other options related to sizing memory and threads and how they interact with the OS
时间: 2024-10-11 22:50:05

Oracle JVM Garbage Collectors Available From JDK 1.7.0_04 And After的相关文章

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-java-8/?utm_source=blog&utm_medium=in-post&utm_content=gcmisconceptions&utm_campaign=java The 4 Java Garbage Collectors – How the Wrong Choice Dr

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 2014 and there are two things that still remain a mystery to most developers - Garbage collection and understanding the opposite sex. Since I don’t know

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

细述 Java垃圾回收机制→Types of Java Garbage Collectors 转自:https://segmentfault.com/a/1190000006214497 本文非原创,翻译自Types of Java Garbage Collectors在Java中为对象分配和释放内存空间都是由垃圾回收线程自动执行完成的.和C语言不一样的是Java程序员不需要手动写垃圾回收相关的代码.这是使得Java如此流行,同时也是Java能帮助程序员写出更好的Java应用的优点之一. 本文将

oracle官网下载老版本jdk + 如何命令行下wget下载jdk

一.文章由来 1.前天有人再去你咨询如何下载jdk的老版本,在oracle官网上找了老半天,找不到相应的选项~ 2.等待问题解决了之后,又抛出来一个新的问题,如何wget直接下载,毕竟百十来兆的文件,下载下来再上传对于我们这种蜗牛带宽来说也是一件苦逼的事情~ 二.如何下载jdk的历史版本 1.访问http://www.oracle.com 2.点击Downloads---->Java for Developers 3.在弹出的的页面中,下拉页面到最下面,点击历史归档 4.点击进去,同意协议,然后

Oracle Fusion Middleware Supported System check,jdk,java .etc requirements

http://www.oracle.com/technetwork/middleware/ias/downloads/fusion-certification-100350.html 在oracle官方网站默认下载的jdk是最新的,目前正式版1.8beta版也已经放出. 但有些项目要求是1.6的jdk,费了九牛二虎之力终于找到了1.6的官方版本,链接如下: http://www.oracle.com/technetwork/java/javase/archive-139210.htmlhttp:

如何在Oracle官网下载java的JDK最新版本和历史版本

官网上最显眼位置只显示了Java SE的JDK的最新版本下载链接,因为都是英文,如果英文不是很好,寻找之前的JDK版本需要很长时间,而且未必能在那个隐蔽的位置找到之前版本列表. 今天小编来给你详细讲解下如何在ORACLE官网下载JDK 步骤: 1.打开Oracle官网,准备下载JDK(下载时需要使用注册用户登陆,可以免费注册) 官网地址:http://www.oracle.com/ 2.有账户的直接登录下载,没有的注册一下就可以下载了 3.开始下载JDK.用鼠标将网页拉到最下面 4.进去后,默认

tomcat jvm 内存调优 适用于 JDK 6 & 7

参考:https://blog.csdn.net/m0_37327416/article/details/76185051 1.jvm内存管理机制: 1)堆(Heap)和非堆(Non-heap)内存 按照官方的说法:"Java 虚拟机具有一个堆,堆是运行时数据区域,所有类实例和数组的内存均从此处分配.堆是在 Java 虚拟机启动时创建的.""在JVM中堆之外的内存称为非堆内存(Non-heap memory)". 可以看出JVM主要管理两种类型的内存:堆和非堆.简单

JDK、JRE、JVM之间的关系及JDK安装

JRE (Java Runtime Environment) :是Java程序的运行时环境,包含 JVM 和运行时所需要的 核心类库 .JDK (Java Development Kit):是Java程序开发工具包,包含 JRE 和开发人员使用的工具.我们想要运行一个已有的Java程序,那么只需安装 JRE 即可.我们想要开发一个全新的Java程序,那么必须安装 JDK . JDK下载与安装: 下载地址:https://www.oracle.com/ 环境变量配置(win10): 原文地址:ht

详解 JVM Garbage First(G1) 垃圾收集器

前言    Garbage First(G1)是垃圾收集领域的最新成果,同时也是HotSpot在JVM上力推的垃圾收集器,并赋予取代CMS的使命.如果使用Java 8/9,那么有很大可能希望对G1收集器进行评估.本文详细首先对JVM其他的垃圾收集器进行总结,并与G1进行了简单的对比:然后通过G1的内存模型.G1的活动周期,对G1的工作机制进行了介绍:同时还在介绍过程中,描述了可能需要引起注意的优化点.笔者希望通过本文,让有一定JVM基础的读者能尽快掌握G1的知识点. 第一章 概述 G1(Garb