GC: CMS垃圾回收器一(英文版)
Memory Management in the Java HotSpot™ Virtual Machine
Concurrent Mark-Sweep (CMS) Collector
For many applications, end-to-end throughput is not as important as fast response time. Young generation
collections do not typically cause long pauses. However, old generation collections, though infrequent, can
impose long pauses, especially when large heaps are involved. To address this issue, the HotSpot JVM includes a
collector called the concurrent mark-sweep (CMS) collector, also known as the low-latency collector.
Young Generation Collection Using the CMS Collector
The CMS collector collects the young generation in the same manner as the parallel collector.
Old Generation Collection Using the CMS Collector
Most of the collection of the old generation using the CMS collector is done concurrently with
the execution of the application.
A collection cycle for the CMS collector starts with a short pause, called the initial mark, that
identifies the initial set of live objects directly reachable from the application code. Then,
during the concurrent marking phase, the collector marks all live objects that are transitively
reachable from this set. Because the application is running and updating reference fields while the
marking phase is taking place, not all live objects are guaranteed to be marked at the end of the
concurrent marking phase. To handle this, the application stops again for a second pause, called remark,
which finalizes marking by revisiting any objects that were modified during the concurrent marking
phase. Because the remark pause is more substantial than the initial mark, multiple threads are run in
parallel to increase its efficiency.
At the end of the remark phase, all live objects in the heap are guaranteed to have been marked, so the
subsequent concurrent sweep phase reclaims all the garbage that has been identified. Figure 7
illustrates the differences between old generation collection using the serial mark-sweep-compact
collector and the CMS collector.

Since some tasks, such as revisiting objects during the remark phase, increase the amount of work the
collector has to do, its overhead increases as well. This is a typical trade-off for most collectors that
attempt to reduce pause times.
The CMS collector is the only collector that is non-compacting. That is, after it frees the space that was
occupied by dead objects, it does not move the live objects to one end of the old generation.

This saves time, but since the free space is not contiguous, the collector can no longer use a simple
pointer indicating the next free location into which the next object can be allocated. Instead, it now
needs to employ free lists. That is, it creates some number of lists linking together unallocated regions
of memory, and each time an object needs to be allocated, the appropriate list (based on the amount of
memory needed) must be searched for a region large enough to hold the object As a result, allocations
into the old generation are more expensive than they are with a simple bump-the-pointer technique.
This also imposes extra overhead to young generation collections, as most allocations in the old
generation occur when objects are promoted during young generation collections.
Another disadvantage the CMS collector has is a requirement for larger heap sizes than the other
collectors. Given that the application is allowed to run during the marking phase, it can continue to
allocate memory, thereby potentially continuing to grow the old generation. Additionally, although the
collector guarantees to identify all live objects during a marking phase, some objects may become
garbage during that phase and they will not be reclaimed until the next old generation collection. Such
objects are referred to as floating garbage.
Finally, fragmentation may occur due to lack of compaction. To deal with fragmentation, the CMS
collector tracks popular object sizes, estimates future demand, and may split or join free blocks to
meet demand.
Unlike the other collectors, the CMS collector does not start an old generation collection when the old
generation becomes full. Instead, it attempts to start a collection early enough so that it can complete
before that happens. Otherwise, the CMS collector reverts to the more time-consuming stop-the-world
mark-sweep-compact algorithm used by the parallel and serial collectors. To avoid this, the CMS
collector starts at a time based on statistics regarding previous collection times and how quickly the old
generation becomes occupied. The CMS collector will also start a collection if the occupancy of the old
generation exceeds something called the initiating occupancy. The value of the initiating occupancy is
set by the command line option –XX:CMSInitiatingOccupancyFraction=n, where n is a
percentage of the old generation size. The default is 68.
In summary, compared to the parallel collector, the CMS collector decreases old generation pauses—
sometimes dramatically—at the expense of slightly longer young generation pauses, some reduction in
throughput, and extra heap size requirements.
Incremental Mode
The CMS collector can be used in a mode in which the concurrent phases are done incrementally. This
mode is meant to lessen the impact of long concurrent phases by periodically stopping the concurrent
phase to yield back processing to the application. The work done by the collector is divided into small
chunks of time that are scheduled between young generation collections. This feature is useful when
applications that need the low pause times provided by the concurrent collector are run on machines
with small numbers of processors (e.g., 1 or 2). For more information on usage of this mode, see the
“Tuning Garbage Collection with the 5.0 Java™ Virtual Machine” paper referred to in Section 9.
When to Use the CMS Collector
Use the CMS collector if your application needs shorter garbage collection pauses and can afford to
share processor resources with the garbage collector when the application is running. (Due to its
concurrency, the CMS collector takes CPU cycles away from the application during a collection cycle.)
Typically, applications that have a relatively large set of long-lived data (a large old generation), and that
run on machines with two or more processors, tend to benefit from the use of this collector. An example
would be web servers. The CMS collector should be considered for any application with a low pause time
requirement. It may also give good results for interactive applications with old generations of a modest
size on a single processor.
CMS Collector Selection
If you want the CMS collector to be used, you must explicitly select it by specifying the command line
option -XX:+UseConcMarkSweepGC. If you want it to be run in incremental mode, also enable that
mode via the –XX:+CMSIncrementalMode option.
GC: CMS垃圾回收器一(英文版)的更多相关文章
- GC: CMS垃圾回收器三(实践)
jstat -gc -t [pid] 1000 监控日志... ,抽取其中关键记录不一定连续 应用启动时间 2015-06-23 10:22:27 ,换算后,第二条记录时间是2015-06-24 22 ...
- 探索ParNew和CMS垃圾回收器
前言 上篇文章我们一起分析了JVM的垃圾回收机制,了解了新生代的内存模型,老年代的空间分配担保原则,并简单的介绍了几种垃圾回收器.详细内容小伙伴们可以去看一下我的上篇文章:秒懂JVM的垃圾回收机制. ...
- 关于 CMS 垃圾回收器,你真的懂了吗?
大家好,我是树哥. 前段时间有个小伙伴去面试,被问到了 CMS 垃圾回收器的详细内容,没答出来.实际上,CMS 垃圾回收器是回收器历史上很重要的一个节点,其开启了 GC 回收器关注 GC 停顿时间的历 ...
- 【JVM】CMS垃圾回收器
一.简介 Concurrent Mark Sweep,是一种以获取最短回收停顿时间为目标的收集器,尤其重视服务的响应速度. CMS是老年代垃圾回收器,基于标记-清除算法实现.新生代默认使用ParNew ...
- 浅析CLR的GC(垃圾回收器)
文章目录: 了解托管堆和GC GC高效的处理方式—代 特殊类型的清理 手动监控和控制对象生命周期 1.了解托管堆和GC 在面向对象环境中,每一个类型都代表了一种资源.我们要使用这些资源,就要为这些代表 ...
- GC:垃圾回收器简介
Java堆内存被划分为新生代和年老代两部分,新生代主要使用复制和标记-清除垃圾回收算法,年老代主要使用标记-整理垃圾回收算法,因此java虚拟中针对新生代和年老代分别提供了多种不同的垃圾收集器,JDK ...
- JVM GC算法 垃圾回收器
JVM的垃圾回收算法有三种: 1.标记-清除(mark-sweep):啥都不说,直接上图 2.标记-整理(mark-compact) 3.复制(copy) 分代收集算法 ...
- jvm——CMS 垃圾回收器(未完)
https://matt33.com/2018/07/28/jvm-cms/ 阶段1:Initial Mark stop-the-wolrd 标记那些直接被 GC root 引用或者被年轻代存活对象所 ...
- Visual GC(监控垃圾回收器)
Java VisualVM默认没有安装Visual GC插件,需要手动安装,JDK的安装目录的bin目露下双击jvisualvm.exe,即可打开Java VisualVM,点击菜单栏 工具-> ...
随机推荐
- HDU 1372 Knight Moves【BFS】
题意:给出8*8的棋盘,给出起点和终点,问最少走几步到达终点. 因为骑士的走法和马的走法是一样的,走日字形(四个象限的横竖的日字形) 另外字母转换成坐标的时候仔细一点(因为这个WA了两次---@_@) ...
- 02.C语言关于指针的学习笔记
指针是一个特殊的变量,它里面存储的数值被解释成为内存里的一个地址. 要搞清一个指针需要搞清指针的四方面的内容: 指针的类型,指针所指向的 类型,指针的值或者叫指针所指向的内存区,还有指针本身所占据的内 ...
- memcached内存管理及key value长度限制
1)什么是内存碎片?内存是大小有限的资源.例如把内存比作一张小床,来了一个小伙伴,可以睡下,再来一个小伙伴也能睡下.现在两个人了,他们点了差不多的大小的位置(资源),位置还有剩下.然后再来一个小胖子, ...
- 记录一次Spring boot 搭建框架连接Mysql数据库注解事务不回滚的故障
搭建了一个新框架,使用了spring boot 替换以简化原来繁杂的spring配置,使用Spring注解管理事务,持久层使用mybatis. 连接mysql数据库完成项目的过程中发现不支持事务,因为 ...
- php的webservice的soapheader认证问题
参数通过类传输:class authentication_header { private $username; private $password; public ...
- RAC 环境下修改归档模式
RAC环境下的归档模式切换与单实例稍有不同,主要是共享存储所产生的差异.在这种情况下,我们可以将RAC数据库切换到非集群状态下,仅仅在一个实例上来实施归档模式切换即可完成RAC数据库的归档模式转换问题 ...
- yeoman bower grunt等安装
grunt-beginner前端自动化工具:http://www.imooc.com/learn/30 grunt的安装 官方站点:http://gruntjs.com/ 安装指令: sudo npm ...
- appdata文件夹有什么用途?C盘appdata可以删除吗?
在内存紧张的时候,我们都会选择删除一些无关紧要的大文件来释放内存,有不少网友发现在系统C盘下有一个appdata文件夹,而且体积挺大的,不知道能不能删除,针对此问题,本文就为大家介绍appdata文件 ...
- 配置apache以fastcgi运行php
apache默认是用自带的mod_php模块运行php,现在我们介绍使用fastcgi来执行php脚本.先说下fastcgi的优点: Fastcgi的优点: 从稳定性上看, fastcgi是以独立的进 ...
- Javascript的匿名函数
一.什么是匿名函数?在Javascript定义一个函数一般有如下三种方式:函数关键字(function)语句:function fnMethodName(x){alert(x);}函数字面量(Func ...