原文https://docs.oracle.com/javase/8/docs/technotes/guides/vm/gctuning/g1_gc.html

9 Garbage-First Garbage Collector

The Garbage-First(G1) garbage collector is a server-style garbage collector, targeted for multiprocessor machines with large memories. It attempts to meet garbage collection (GC) pause time goals with high probability while achieving high throughput. Whole-heap operations, such as global marking, are performed concurrently with the application threads. This prevents interruptions proportional to heap or live-data size.

The G1 collector achieves high performance and pause time goals through several techniques.

The heap is partitioned into a set of equally sized heap regions, each a contiguous range of virtual memory. G1 performs a concurrent global marking phase to determine the liveness of objects throughout the heap. After the marking phase completes, G1 knows which regions are mostly empty. It collects these regions first, which often yields a large amount of free space. This is why this method of garbage collection is called Garbage-First. As the name suggests, G1 concentrates its collection and compaction activity on the areas of the heap that are likely to be full of reclaimable objects, that is, garbage. G1 uses a pause prediction model to meet a user-defined pause time target and selects the number of regions to collect based on the specified pause time target.

G1 copies objects from one or more regions of the heap to single region on the heap, and in the process both compacts and frees up memory. This evacuation is performed in parallel on multiprocessors to decrease pause times and increase throughput. Thus, with each garbage collection, G1 continuously works to reduce fragmentation. This is beyond the capability of both of the previous methods. CMS (Concurrent Mark Sweep) garbage collection does not do compaction. Parallel compaction performs only whole-heap compaction, which results in considerable pause times.

It is important to note that G1 is not a real-time collector. It meets the set pause time target with high probability but not absolute certainty. Based on data from previous collections, G1 estimates how many regions can be collected within the target time. Thus, the collector has a reasonably accurate model of the cost of collecting the regions, and it uses this model to determine which and how many regions to collect which staying within the pause time target.

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 6 GB or larger, and a stable and predictable pause time below 0.5 seconds.

Applications running today with either the CMS or the with parallel compaction would benefit from switching to G1 if the application has one or more of the following traits.

  • More than 50% of the Java heap is occupied with live data.
  • The rate of object allocation rate or promotion varies significantly.
  • The application is experiencing undesired long garbage collection or compaction pauses (long than 0.5 to 1 second).

G1 is planned as the long-term replacement for the Concurrent Mark-Sweep Collector (CMS). Comparing G1 with CMS reveals differences that make G1 a better solution. One difference is that G1 is a compacting collector. Also, G1 offers more predictable garbage collection pauses than the CMS collector, and allows users to specify desired pause targets.

As with CMS, G1 is designed for application that require shorter GC pauses.

G1 divides the heap into fixed-sized regions (the gray boxes) as in Figure 9-1, “Heap Division by G1”.

Figure 9-1 Heap Division by G1

The figure consists of a 10-by-10 grid. Most of the grid’s cells are gray. Nineteen cells are colored dark blue. These dark blue cells are randomly distributed in the upper six rows of the grid. Two of these dark blue cells contain a red box. A cell two cells wide and one cell high (which appears in the first row) and a cell three cells wide and one cell high (which appears in the sixth row) are colored dark blue and labeled “H”. Eight cells are colored light blue and contain a red box. Two of these cells are labeled “S”. These light blue cells with a red box are distributed randomly, most of them located in the upper half of the grid.

G1 is generational in a logical sense. A set of empty regions is designated as the logical young generation. In the figure, the young generation is light blue. Allocations are done out of that logical young generation, and when the young generation is full, that set of regions is garbage collected (a young collection). In some cases, regions out side the set of young regions (old regions in dark blue) can be garbage collected at the same time. This is referred to as a mixed collection. In the figure, the regions being collected are marked by red boxes. The figure illustrates a mixed collection because both young regions and old regions are being collected. The garbage collection is a compacting collection that copies live objects to selected, initially empty regions. Based on the age of a surviving object, the object can be copied to a survivor region (marked by “S”) or to an old region (not specifically shown). The regions marked by “H” contain humongous objects that are larger than half a region and are treated specially.

Allocation (Evacuation) Failure

As with CMS, the G1 collector runs parts of its collection while the application continues to run and there is a risk that the application will allocate objects faster than the garbage collector can recover free space. See the section Concurrent Mode Failure in Concurrent Mark Sweep (CMS) Collector for the analogous CMS behavior. In G1, the failure (exhaustion of the Java heap) occurs while G1 is copying live data out of one region (evacuating) into another region. The copying is done to compact the live data. If a free (empty) region cannot be found during the evacuation of a region being garbage collected, then an allocation failure occurs (because there is no space to allocate the live objects from the region being evacuated) and a stop-the-world (STW) full collection is done.

Floating Garbage

Objects can die during a G1 collection and not be collected. G1 uses a technique called snapshot-at-the-beginning (SATB) to guarantee that all live objects are found by the garbage collector. SATB states that any object that is live at the start of the concurrent marking (a marking over the entire heap) is considered live for the purpose of the collection. SATB allows floating garbage in a way analogous to that of a CMS incremental update.

Card Tables and Concurrent Phases

If a garbage collector does not collect the entire heap (an incremental collection), the garbage collector needs to know where there are pointers from the uncollected part of the heap into the part of the heap that is being collected. This is typically for a generational garbage collector in which the uncollected part of the heap is usually the old generation, and the collected part of the is the young generation. The data structure for keeping this information (old generation pointers to young generation objects), is a remembered set. A card table is a particular type of remembered set. Java HotSpot VM uses an array of bytes as a card table. Each byte is referred to as a card. A card corresponds to a range of addresses in the heap. Dirtying a card means changing the value of the byte to a dirty value; a dirty value might contain a new pointer from the old generation to the young generation in the address range covered by the card.

Processing a card means looking at the card to see if there is an old generation to young generation pointer and perhaps doing something with that information such as transferring it to another data structure.

G1 has concurrent marking phase which marks live objects found from the application. The concurrent marking extends from the end of a evacuation pause (where the initial marking work is done) to the remark. The concurrent cleanup phase adds regions emptied by the collection to the list of free regions and clears the remembered sets of those regions. In addition, a concurrent refinement thread runs as needed to process card table entries that have been dirtied by application writes and which may have cross region references.

Starting a Concurrent Collection Cycle

As mentioned previously, both young and old regions are garbage collected in a mixed collection. To collect old regions, G1 does a complete marking of the live objects in the heap. Such a marking is done by a concurrent marking phase. A concurrent marking phases is started when the occupancy of the entire Java heap reaches the value of the parameter

第九节、G1垃圾收集器(官方文档抄录)相关推荐

  1. word@tips官方文档和教程@软件界面介绍@功能区自定义@拼写检查@AI润色改进@ 图片顶部上方插入文字

    文章目录 word 文档和教程 word软件界面元素 字符和标记 格式标记 段落标记(paragraph marks) 自定义功能区(Ribbon) 自定义功能区要点@层次关系 添加自定义选项卡(ta ...

  2. OpenGL ES着色器语言之语句和结构体(官方文档第六章)内建变量(官方文档第七、八章)...

    OpenGL ES着色器语言之语句和结构体(官方文档第六章) OpenGL ES着色器语言的程序块基本构成如下: 语句和声明 函数定义 选择(if-else) 迭代(for, while, do-wh ...

  3. OpenGL ES着色器语言之变量和数据类型(二)(官方文档第四章)

    OpenGL ES着色器语言之变量和数据类型(二)(官方文档第四章) 4.5精度和精度修饰符 4.5.1范围和精度 用于存储和展示浮点数.整数变量的范围和精度依赖于数值的源(varying,unifo ...

  4. cassandra 3.x官方文档(4)---分区器

    写在前面 cassandra3.x官方文档的非官方翻译.翻译内容水平全依赖本人英文水平和对cassandra的理解.所以强烈建议阅读英文版cassandra 3.x 官方文档.此文档一半是翻译,一半是 ...

  5. Spine 骨骼动画查看器 Skeleton Viewer_官方文档中文版

    Spine 骨骼动画查看器 Skeleton Viewer_官方文档中文版 大家好,我是笨笨,笨笨的笨,笨笨的笨,谢谢! 欢迎加入专业Spine技术交流群 Spine2D骨骼动画 7708065 此文 ...

  6. Elasticsearch8.4.3安装最新ik分词器elasticsearch-analysis-ik【v8.4.3版本】(参考官方文档)

    一.前言   ik分词器官方源码版下载地址:   https://github.com/medcl/elasticsearch-analysis-ik     ik分词器官方发行版下载地址:   ht ...

  7. CDH6官方文档中文系列(8)----Cloudera升级指南

    Cloudera升级指南 最近在学习cdh6的官方文档,网上也比较难找到中文的文档. 其实官方英文文档的阅读难度其实并不是很高,所以在这里在学习官方文档的过程中,把它翻译成中文,在翻译的过程中加深学习 ...

  8. 文件标识符必须为双精度类型的整数值标量_【翻译】VTK官方文档 - vtk文件格式

    本文翻译自vtk官方文档:vtk_file_format 文末有链接 VTK提供了许多源对象和编写器对象,用于读取和写入流行的数据文件格式,此外,VTK也提供了自己的文件格式.创建一种数据文件格式的主 ...

  9. Python Turtle 海龟绘图详解官方文档中文版

    Python Turtle 海龟绘图详解 (官方文档中文版)-安徽省太湖中学陈晓中整理 概述 海龟绘图很适合用来引导孩子学习编程. 最初来自于 Wally Feurzeig, Seymour Pape ...

  10. Mybatis官方文档及使用简记

    Mybatis官方文档及使用简记 数据库建表 入门案例 无mapper类最传统的用法 使用mybatis generator 使用mybatis-generator mybatis-spring整合 ...

最新文章

  1. 麦克纳姆轮全向移动原理
  2. 如何获得阿里技术offer:从《阿里DBA面试题》体味阿里社会招聘
  3. OpenGL Draw TransformFeedback 绘制变换反馈的实例
  4. ABAP xml handling via SAX - 在ABAP里另一种处理xml的机制介绍
  5. jmeter测试客户端_如何在JMeter中执行客户端Web性能测试?
  6. STM32低功耗模式测试
  7. TCPMP源代码分析
  8. php 多版本 安装包下载,wamp 安装多版本php
  9. 联想拯救者笔记本加固态硬盘过程重点
  10. 网络安全策略和网络安全机制
  11. c语言编写坦克大战设计报告,c语言编写坦克大战源代码
  12. 仿网易云项目前端服务器部署+Nodejs部署
  13. 运维常说的 5个9、4个9、3个9 的可靠性,到底是什么鬼?
  14. latex 行内公式和行间公式高亮问题、多行高亮问题
  15. mysql经常断电_MySQL突然断电异常解决
  16. 准备搬家,送所有书籍!
  17. 面试官:如何在ASP.NET Core里给Action传递参数
  18. linux目录对应windows,linux目录和Windows目录对比
  19. 2k2实用球员_nba2kol2操作技巧大全,nba2kol2平民球星阵容搭配。
  20. jmeter并发测试教程_JMeter压力测试并发测试(入门篇)

热门文章

  1. 智慧能源管理设备和实现原理
  2. 路由器如何设置IP地址
  3. Qt6 QML Book/网络设置/本地文件
  4. win7无线热点_WIFI网络安全现状及家庭无线使用建议
  5. 能源企业如何构建网络安全体系?8月18日实战专家在线分享破局之道
  6. 红外 750 DBCO, IR 750 DBCO
  7. mysql数据库引擎转换_MySQL的MyISAM转换成InnoDB引擎的两种方法
  8. 关于计算机显示器,关于计算机显示器的指示灯?
  9. 多功能团队中的T型混合人才
  10. 大数据概况和Hadoop生态系统