1.Reviewing Generational GC and CMS
The Concurrent Mark Sweep (CMS) collector (also referred to as the concurrent low pause collector) collects the tenured generation. It attempts to minimize the pauses due to garbage collection by doing most of the garbage collection work concurrently with the application threads. Normally the concurrent low pause collector does not copy or compact the live objects. A garbage collection is done without moving the live objects. If fragmentation becomes a problem, allocate a larger heap.
大致意思:CMS垃圾回收器是回收堆中老年代对象。它与应用线程并行做垃圾回收以减少最小停顿时间,它的最小停顿时间不是因为 复制或整理存活对象,最主要问题是因为碎片化,所以需要分配一个较大的堆。
Heap Structure for CMS Collector:(cms垃圾回收器堆结构)
2.CMS Collection Phases (CMS收集阶段)
CMS以牺牲吞吐量为代价来获得最短回收停顿时间的垃圾回收器.
The CMS collector performs the following phases on the old generation of the heap:
Phase |
Description |
译 |
(1) Initial Mark (Stop the World Event)
|
Objects in old generation are “marked” as reachable including those objects which may be reachable from young generation. Pause times are typically short in duration relative to minor collection pause times. |
初始化标记:这个阶段从垃圾回收的"根对象"开始,只扫描到能够和"根对象"直接关联的对象,并作标记,在做youngGC会消耗很短的停顿时间,1-10ms级别 |
(2) Concurrent Marking |
Traverse the tenured generation object graph for reachable objects concurrently while Java application threads are executing. Starts scanning from marked objects and transitively marks all objects reachable from the roots. The mutators are executing during the concurrent phases 2, 3, and 5 and any objects allocated in the CMS generation during these phases (including promoted objects) are immediately marked as live. |
并发标记:这个阶段紧随初始标记阶段,在初始标记的基础上继续向下追溯标记,应用程序的线程和并发标记的线程并发执行,用户不会感受到停顿。
并发预清理:并发预清理阶段仍然是并发的。在这个阶段,虚拟机查找在执行并发标记阶段新进入老年代的对象(可能会有一些对象从新生代晋升到老年代, 或者有一些对象被分配到老年代)。通过重新扫描,减少下一个阶段"重新标记"的工作,因为下一个阶段会Stop The World。
|
(3) Remark (Stop the World Event)
|
Finds objects that were missed by the concurrent mark phase due to updates by Java application threads to objects after the concurrent collector had finished tracing that object. |
重新标记:这个阶段会暂停虚拟机,收集器线程扫描在CMS堆中剩余的对象。扫描从"跟对象"开始向下追溯,并处理对象关联。
|
(4) Concurrent Sweep |
Collects the objects identified as unreachable during marking phases. The collection of a dead object adds the space for the object to a free list for later allocation. Coalescing of dead objects may occur at this point. Note that live objects are not moved. |
并发清理:清理垃圾对象,这个阶段收集器线程和应用程序线程并发执行。 |
(5) Resetting |
Prepare for next concurrent collection by clearing data structures. |
并发重置:这个阶段,重置CMS收集器的数据结构,等待下一次垃圾回收. |
3.How Young GC works in CMS(CMS年轻代回收过程)
3.1 The young generation is colored light green and the old generation in blue. This is what the CMS might look like if your application has been running for a while. Objects are scattered around the old generation area.
3.2 Live objects are copied from the Eden space and survivor space to the other survivor space. Any older objects that have reached their aging threshold are promoted to old generation.
3.3 After a young GC, the Eden space is cleared and one of the survivor spaces is cleared.
Newly promoted objects are shown in dark blue on the diagram. The green objects are surviving young generation objects that have not yet been promoted to old generation.
4.Old Generation Collection with CMS(CMS老年代垃圾回收)
4.1 Two stop the world events take place: initial mark and remark. When the old generation reaches a certain occupancy rate, the CMS is kicked off.
(1) Initial mark is a short pause phase where live (reachable) objects are marked. (2) Concurrent marking finds live objects while the application continues to execute. Finally, in the (3) remark phase, objects are found that were missed during (2) concurrent marking in the previous phase.
4.2 Objects that were not marked in the previous phase are deallocated in place. There is no compaction.
Note: Unmarked objects == Dead Objects
4.3 After the (4) Sweeping phase, you can see that a lot of memory has been freed up. You will also notice that no compaction has been done.
Finally, the CMS collector will move through the (5) resetting phase and wait for the next time the GC threshold is reached.
5.CMS 相关参数解释
参数 |
含义 |
-XX:+UseConcMarkSweepGC
|
激活CMS收集器。默认HotSpot JVM使用的是并行收集器 |
-XX:UseParNewGC
|
当使用-XX:+UseConcMarkSweepGC时,-XX:UseParNewGC会自动开启。因此,
如果年轻代的并行GC不想开启,可以通过设置-XX:-UseParNewGC来关掉
|
-XX:+CMSConcurrentMTEnabled
|
当该标志被启用时,并发的CMS阶段将以多线程执行
(因此,多个GC线程会与所有的应用程序线程并行工作)。该标志已经默认开启,
如果顺序执行更好,这取决于所使用的硬件,多线程执行可以通过-XX:-CMSConcurremntMTEnabled禁用。
|
-XX:ConcGCThreads
|
标志-XX:ConcGCThreads=<value>(早期JVM版本也叫-XX:ParallelCMSThreads)定义并发CMS过程运行时的线程数。比如value=4意味着CMS周期的所有阶段都以4个线程来执行。尽管更多的线程会加快并发CMS过程,但其也会带来额外的同步开销。因此,对于特定的应用程序,应该通过测试来判断增加CMS线程数是否真的能够带来性能的提升。如果还标志未设置,JVM会根据并行收集器中的-XX:ParallelGCThreads参数的值来计算出默认的并行CMS线程数。该公式是ConcGCThreads = (ParallelGCThreads + 3)/4。因此,对于CMS收集器, -XX:ParallelGCThreads标志不仅影响“stop-the-world”垃圾收集阶段,还影响并发阶段。 |
-XX:CMSInitiatingOccupancyFraction
|
当堆满之后,并行收集器便开始进行垃圾收集,例如,当没有足够的空间来容纳新分配或提升的对象,JVM会在一开始执行CMS周期前作一些线索查找。该线索由 -XX:CMSInitiatingOccupancyFraction=<value>来设置,该值代表老年代堆空间的使用率. |
-XX:+UseCMSInitiatingOccupancyOnly
|
|
-XX:+CMSClassUnloadingEnabled
|
相对于并行收集器,CMS收集器默认不会对永久代进行垃圾回收。如果希望对永久代进行垃圾回收,可用设置标志-XX:+CMSClassUnloadingEnabled。 |
-XX:+UseCMSCompactAtFullCollection
|
打开对年老代的压缩.可能会影响性能,但是可以消除碎片,由于并发收集器不对内存空间进行压缩,整理,所以运行一段时间以后会产生"碎片",使得运行效率降低.此值设置运行多少次GC以后对内存空间进行压缩,整理. |
-XX:+ExplicitGCInvokesConcurrent and -XX:+ExplicitGCInvokesConcurrentAndUnloadsClasses
|
|
-XX:+DisableExplicitGC
|
该标志将告诉JVM完全忽略系统的GC调用(不管使用的收集器是什么类型) |
参考oracle官网 CMS和G1 垃圾回收器
相关文章:
- 大小: 74.3 KB
分享到:
相关推荐
《API-MS-WIN-CORE-HEAP-L2-1-0.DLL:64位系统的核心内存管理组件解析》 在Windows操作系统中,DLL(Dynamic Link Library)文件扮演着至关重要的角色,它们包含了可被多个程序共享的代码和数据。"api-ms-win-core-...
《深入理解API-MS-WIN-CORE-HEAP-L2-1-0.dll:64位系统的内存管理关键组件》 在Windows操作系统中,API-MS-WIN-CORE-HEAP-L2-1-0.dll是核心堆管理库的一个重要组成部分,主要负责64位系统中的内存分配和管理。这个...
《api-ms-win-core-heap-l2-1-0.dll:操作系统核心堆管理库解析》 在Windows操作系统中,`api-ms-win-core-heap-l2-1-0.dll`是一个至关重要的动态链接库文件,它是系统核心堆管理的一部分,用于32位和64位系统。该...
《API-MS-WIN-CORE-HEAP-L2-1-0.DLL:64位Windows 10系统的关键组件》 在计算机操作系统中,动态链接库(DLL)是实现功能模块化的重要部分,它们允许多个程序共享同一段代码和数据,节省内存并提高效率。"api-ms-...
标题中的"api-ms-win-core-heap-l2-1-0.zip"是一个压缩包文件,它包含了一个名为"api-ms-win-core-heap-l2-1-0.dll"的动态链接库(DLL)文件以及一个"说明.txt"的文本文件。这个压缩包主要是为了解决系统中缺失"api-...
api-ms-win-core-heap-l2-1-0.dll
Java 虚拟机的内存结构包括方法区(method area)和堆(heap)。方法区保存了从类文件中解析出来的信息。堆保存了程序执行时创建的对象。每一个线程都有自己的 PC 寄存器(程序计数器)和 Java 堆栈(Java stack)。...
Java虚拟机(JVM)是Java程序运行的核心,它负责管理程序的内存,包括内存的分配、使用和回收。在深入理解JVM内存管理和垃圾收集器之前,我们需要先了解JVM内存模型的基本结构。 内存模型主要包括以下几个部分: 1...
api-ms-win-core-heap-l1-1-0
java虚拟机OutOfMemoryError:Java heap space堆dump文件,可以直接用来分析。
本文主要关注的是Java虚拟机(JVM),它是实现Java语言跨平台特性的关键。JVM定义了Java程序运行所需的一套指令集和一个相应的运行时环境。它能够将Java源代码编译成与平台无关的字节码,然后在不同的操作系统上通过...
丢失api-ms-win-crt-heap-l1-1-0.dll 错误的解决办法,在线等
Java虚拟机(JVM)是Java程序运行的核心,它负责解释和执行字节码,管理内存,以及优化代码性能。本资源"java虚拟机调优--某培训班的课件与源码"提供了一套全面的培训材料,旨在帮助开发者深入理解和优化JVM的工作...
《实战Java虚拟机——JVM故障诊断与性能优化》是一本深入探讨Java开发人员和运维人员必备技能的书籍。本书作者葛一鸣以其丰富的实战经验,详细阐述了JVM(Java Virtual Machine)的工作原理,以及如何有效地进行故障...
《深入Java虚拟机(原书第2版)》,原书名《Inside the Java Virtual Machine,Second Edition》,作者:【美】Bill Venners,翻译:曹晓钢、蒋靖,出版社:机械工业出版社,ISBN:7111128052,出版日期:2003 年 9 ...
Java虚拟机(JVM)是实现Java技术的关键组件,它为Java程序提供了一个运行环境。Java程序在编写后会被编译成一种称为字节码的中间表示形式,这种字节码可以跨平台运行,因为JVM负责将字节码转换成机器代码。JVM的...
在IT领域,尤其是在操作系统与编程语言的运行时环境中,“运行时堆和栈”(The Run-time Heap and Stack)是理解程序内存管理的核心概念。本文旨在深入解析这一主题,结合提供的部分文档内容,详细阐述堆和栈的区别...
Java虚拟机的生命周期包括启动、执行和终止三个主要阶段: 1. **启动**:当一个包含`public static void main(String[] args)`方法的类被加载时,Java虚拟机就会启动。`main()`方法是程序的入口点,Java虚拟机通过...
### Java虚拟机(JVM)特性JAVA SE 7 #### 概述 《Java虚拟机特性JAVA SE 7.pdf》是一本详细介绍Java虚拟机(JVM)规范的书籍,针对Java SE 7版本。本书由Tim Lindholm、Frank Yellin、Gilad Bracha和Alex Buckley共同...