1.The G1 Garbage Collector(G1垃圾回收器定义)
The Garbage-First (G1) collector is a server-style garbage collector, targeted for multi-processor machines with large memories. It meets garbage collection (GC) pause time goals with a high probability, while achieving high throughput. The G1 garbage collector is fully supported in Oracle JDK 7 update 4 and later releases. The G1 collector is designed for applications that:
- Can operate concurrently with applications threads like the CMS collector.
- Compact free space without lengthy GC induced pause times.
- Need more predictable GC pause durations.
- Do not want to sacrifice a lot of throughput performance.
- Do not require a much larger Java heap.
G1 is planned as the long term replacement for the Concurrent Mark-Sweep Collector (CMS). Comparing G1 with CMS, there are differences that make G1 a better solution. One difference is that G1 is a compacting collector. G1 compacts sufficiently to completely avoid the use of fine-grained free lists for allocation, and instead relies on regions. This considerably simplifies parts of the collector, and mostly eliminates potential fragmentation issues. Also, G1 offers more predictable garbage collection pauses than the CMS collector, and allows users to specify desired pause targets.
释义:G1使用并发和并行阶段实现其目标暂停时间,并保持良好的吞吐量,与CMS收集器不同的是,G1回收算法采取的并发-整理 ;它可以解决传统的parNew+CMS垃圾收集算法中,有很多晋代失败(promotion failed)/并发失败(concurrent mode failure),然后做Full gc的问题;G1提供更可预测的垃圾收集停顿比CMS收集器,并允许用户指定所需的停顿的目标。
2.G1 heap(G1堆)
2.1 G1 Heap Structure
Region size is chosen by the JVM at startup. The JVM generally targets around 2000 regions varying in size from 1 to 32Mb.
2.2 G1 Heap Allocation
The heap is partitioned into a set of equal-sized heap regions, each a contiguous range of virtual memory. Certain region sets are assigned the same roles (eden, survivor, old) as in the older collectors, but there is not a fixed size for them. This provides greater flexibility in memory usage.
2.2 G1 Footprint
If you migrate from the ParallelOldGC or CMS collector to G1, you will likely see a larger JVM process size. This is largely related to "accounting" data structures such as Remembered Sets and Collection Sets.
Remembered Sets or RSets track object references into a given region. There is one RSet per region in the heap. The RSet enables the parallel and independent collection of a region. The overall footprint impact of RSets is less than 5%.
Collection Sets or CSets the set of regions that will be collected in a GC. All live data in a CSet is evacuated (copied/moved) during a GC. Sets of regions can be Eden, survivor, and/or old generation. CSets have a less than 1% impact on the size of the JVM.
2.3 Recommended Use Cases for G1 (推荐使用G1场景)
The first focus of G1 is to provide a solution for users running applications that require large heaps with limited GC latency. This means heap sizes of around 6GB or larger, and stable and predictable pause time below 0.5 seconds.
3.G1 Collection Phases
The G1 collector performs the following phases on the old generation of the heap. Note that some phases are part of a young generation collection.
Phase | Description | 释义 |
(1) Initial Mark (Stop the World Event) |
This is a stop the world event. With G1, it is piggybacked on a normal young GC. Mark survivor regions (root regions) which may have references to objects in old generation. | 初始标记:此阶段,G1GC对根进行标记。该阶段与年轻代垃圾(STW)回收密切相关 |
(2) Root Region Scanning | Scan survivor regions for references into the old generation. This happens while the application continues to run. The phase must be completed before a young GC can occur. | 根区域扫描:G1GC 在初始标记的存活区扫描对老年代的引用,并标记被引用的对象.该阶段与应用程序同时运行,该阶段完成后,才能开始下一次年轻代垃圾回收。 |
(3) Concurrent Marking | Find live objects over the entire heap. This happens while the application is running. This phase can be interrupted by young generation garbage collections. | 并发标记阶段:G1GC 在整个堆中查找存活对象。该阶段与应用程序同时运行,可以被年轻代垃圾回收中断 |
(4) Remark (Stop the World Event) |
Completes the marking of live object in the heap. Uses an algorithm called snapshot-at-the-beginning (SATB) which is much faster than what was used in the CMS collector. | 重新标记阶段:该阶段是 STW 回收,帮助完成标记周期。G1 GC 清空 SATB 缓冲区,跟踪未被访问的存活对象,并执行引用处理。 |
(5) Cleanup (Stop the World Event and Concurrent) |
|
清理阶段:在这个最后阶段,G1 GC 执行统计和 RSet 清理的STW操作。在统计期间,G1GC 会识别完全空闲的区域和可供进行混合垃圾回收的区域。 |
(*) Copying (Stop the World Event) |
These are the stop the world pauses to evacuate or copy live objects to new unused regions. This can be done with young generation regions which are logged as [GC pause (young)] . Or both young and old generation regions which are logged as [GC Pause (mixed)] . |
复制:
|
回收过程按回收区域集合(CollectionSets/CSets)划分.CSets可以包含(Eden,survivor/old)中的region,CSets占用内存一般小于整个jvm的1%;
年轻代垃圾回收:
G1 Young GC同时回收eden区域和上次垃圾回收的存活区域。Eden 和survivor的存活对象被疏散(复制/移动)到新的区域集。
被疏散对象的目标区域取决于对象的年龄,达到晋升年龄的对象疏散到老年代区域,
否则疏散到存活区,并将它包含在下一次年轻代或混合垃圾回收的CSet中。
混合垃圾回收:
G1 Mixd GC同时回收Eden,survivor,old的存活区域。当成功完成并发标记周期后,G1 GC从执行年轻代垃圾回收切换为执行混合垃圾回收。
在混合垃圾回收期间,G1GC 将一些旧的区域添加到 eden 和存活区供将来回收。G1GC 回收了足够的旧区域后(经过多次混合垃圾回收),
G1将恢复执行年轻代垃圾回收,直到下一次标记周期完成。
4.G1 youngGC
4.1 The heap is split into approximately 2000 regions. Minimum size is 1Mb and maximum size is 32Mb. Blue regions hold old generation objects and green regions hold young generation objects.
Note that the regions are not required to be contiguous like the older garbage collectors.
4.2 Live objects are evacuated (i.e., copied or moved) to one or more survivor regions. If the aging threshold is met, some of the objects are promoted to old generation regions.
This is a stop the world (STW) pause. Eden size and survivor size is calculated for the next young GC. Accounting information is kept to help calculate the size. Things like the pause time goal are taken into consideration.
This approach makes it very easy to resize regions, making them bigger or smaller as needed.
4.3
End of a Young GC with G1
Live objects have been evacuated to survivor regions or to old generation regions.
Recently promoted objects are shown in dark blue. Survivor regions in green.
In summary, the following can be said about the young generation in G1:
- The heap is a single memory space split into regions.
- Young generation memory is composed of a set of non-contiguous regions. This makes it easy to resize when needed.
- Young generation garbage collections, or young GCs, are stop the world events. All application threads are stopped for the operation.
- The young GC is done in parallel using multiple threads.
- Live objects are copied to new survivor or old generation regions.
5.g1 oldGC
5.1 Initial Marking Phase
Initial marking of live object is piggybacked on a young generation garbage collection. In the logs this is noted as GC pause (young)(inital-mark)
.
相关推荐
《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虚拟机(JVM)是实现Java技术的关键组件,它为Java程序提供了一个运行环境。Java程序在编写后会被编译成一种称为字节码的中间表示形式,这种字节码可以跨平台运行,因为JVM负责将字节码转换成机器代码。JVM的...
《深入Java虚拟机(原书第2版)》,原书名《Inside the Java Virtual Machine,Second Edition》,作者:【美】Bill Venners,翻译:曹晓钢、蒋靖,出版社:机械工业出版社,ISBN:7111128052,出版日期:2003 年 9 ...
在IT领域,尤其是在操作系统与编程语言的运行时环境中,“运行时堆和栈”(The Run-time Heap and Stack)是理解程序内存管理的核心概念。本文旨在深入解析这一主题,结合提供的部分文档内容,详细阐述堆和栈的区别...
### Java虚拟机的详细原理 #### 一、什么是Java虚拟机 Java虚拟机(Java Virtual Machine,简称JVM)是一种可以执行Java字节码(Bytecode)的虚拟计算机。它为Java程序提供了一个运行环境,使得Java程序可以在任何...
### Java虚拟机(JVM)特性JAVA SE 7 #### 概述 《Java虚拟机特性JAVA SE 7.pdf》是一本详细介绍Java虚拟机(JVM)规范的书籍,针对Java SE 7版本。本书由Tim Lindholm、Frank Yellin、Gilad Bracha和Alex Buckley共同...