继续基于上一次https://www.cnblogs.com/webor2006/p/11135005.html的官方G1文档进行解读,上一次分析到了这:

话不多说,继续往前读:

When performing garbage collections, G1 operates in a manner similar to the CMS collector. G1 performs a concurrent global marking phase to determine the liveness of objects throughout the heap. After the mark phase completes, G1 knows which regions are mostly empty. It collects in these regions first, which usually 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.

【解读:

“When performing garbage collections, G1 operates in a manner similar to the CMS collector.”

在执行垃圾收集的时候,G1的操作行为方式类似于CMS收集器很。

“G1 performs a concurrent global marking phase to determine the liveness of objects throughout the heap. After the mark phase completes, G1 knows which regions are mostly empty. ”

G1会执行一个并发的全局标记的阶段来去确定整个堆当中对象的存活情况。在标记阶段完成之后,G1就知道哪个区域几乎是空的【言外之后,也就是经过G1的标记之后就能清楚哪些区域存活的对象多,哪些存活的对象少了】。

“It collects in these regions first, which usually yields a large amount of free space. This is why this method of garbage collection is called Garbage-First. ”

它就会优先收集这些区域,这样就能产生大量的可用空间,这就是为什么这种垃圾收集器的方式称之为Garbage-Firt原因之所在。

“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会重点观注它的收集和压缩活动在这些堆的区域上,而这些区域是最有可能充满了可回收的对象,也就是说,垃圾。

“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使用了一个停顿可预测的模型来满足一个用户定义的暂停时间的目标,并且会选择一定数量的区域来进行回收,它是基于一个用户所指定的暂时间目标。

The regions identified by G1 as ripe for reclamation are garbage collected using evacuation. G1 copies objects from one or more regions of the heap to a single region on the heap, and in the process both compacts and frees up memory. This evacuation is performed in parallel on multi-processors, to decrease pause times and increase throughput. Thus, with each garbage collection, G1 continuously works to reduce fragmentation, working within the user defined pause times. This is beyond the capability of both the previous methods. CMS (Concurrent Mark Sweep ) garbage collector does not do compaction. ParallelOld garbage collection performs only whole-heap compaction, which results in considerable pause times.

【解读:

“The regions identified by G1 as ripe for reclamation are garbage collected using evacuation. ”

由G1标识出来的区域是完全可以做为垃圾来回收的。

“G1 copies objects from one or more regions of the heap to a single region on the heap, and in the process both compacts and frees up memory. ”

G1会从堆中的一个或者多个区域复制对象到堆中的另外一个单个区域,而且在复制这个过程当中还会进行压缩并且释放内存。【这里解释一下,比如图中这些区域存活的对象总大小只会占用一个区域的大小了:

这时就会将这三个存活的对象一起复制到另一个单个的区域中,比如Survivor中,如一下:

在存放到S时还会进行压缩,这时原来三个Eden Space中的空间就会得到释放可以用于其它对象的存放了。

“This evacuation is performed in parallel on multi-processors, to decrease pause times and increase throughput. Thus, with each garbage collection, G1 continuously works to reduce fragmentation, working within the user defined pause times. ”

这种回收在多处理器上是并行执行的,从而减少停顿的时间并且还能增加吞吐量。因此,对于每一个垃圾收集来说,G1会持续的工作来减少碎片的产生,而且是运行在用户所指定的停顿时间之内。

“This is beyond the capability of both the previous methods. CMS (Concurrent Mark Sweep ) garbage collector does not do compaction. ParallelOld garbage collection performs only whole-heap compaction, which results in considerable pause times.”

这完全超出了原来垃圾收集器的能力。CMS垃圾收集器并不会进行压缩。而ParallelOld垃圾收集器只会执行整个堆的压缩,这样就会耗费相当长的暂停时间。

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 does an estimate of how many regions can be collected within the user specified 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 while staying within the pause time target.

【解读:

“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. ”

值得关注的重点是G1并非是一个实时的收集器,它会尽最大的可能满足用户有所设定的停顿时间目标,但并非绝对精准。

“Based on data from previous collections, G1 does an estimate of how many regions can be collected within the user specified target time. ”

根据之前收集器的一些数据,G1会做一个近视的估量在用户所指定的目标时间内到底能收集多少个区域。

“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 while staying within the pause time target.”

这样的话,收集器就会有一个相对精确的收集区域成本的模型,并且用这个模型来确定哪些以及多少区域要被收集才能满足停顿时间的目标。

Note: G1 has both concurrent (runs along with application threads, e.g., refinement, marking, cleanup) and parallel (multi-threaded, e.g., stop the world) phases. Full garbage collections are still single threaded, but if tuned properly your applications should avoid full GCs.

【解读:

Note: G1 has both concurrent (runs along with application threads, e.g., refinement, marking, cleanup) and parallel (multi-threaded, e.g., stop the world) phases. ”

说明:G1既拥有并发(同应用线程同时运行,如标记、清除等),又有并行(多个线程,比如说STW)阶段。

“Full garbage collections are still single threaded, but if tuned properly your applications should avoid full GCs.”

Full GC依然是单线程的,但是如果调优得比较好的话你就应用应该尽量Full GC的情况发生。

接着来看一下“G1 Footprint”,也就是G1物理占用的空间,如下:

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.

如果你从ParallelOldGC或者CMS收集器往G1来迁移的话,你会看到一个更大的JVM处理的大小。这是因为跟“RSet”和“CSet”的数据结构相关。【这个在之前的理论中也学习过了,如:

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%.

已记忆集合或者也称之为RSet,它会追踪到一个指定区域的对象引用。在堆中的每一个区域都有一个RSet。这个RSet使得并行和独立区域的收集成为可能。整体RSets的大小应该是小于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.

收集集合又称为CSet,它会设置在GC当中会被收集的区域,在CSets当中所有存活的数据在GC当中都会被拷贝或复制。区域的集合可能是Eden、survivor或者是Old generation,CSets在整个JVM的的大小会少于1%。

继续,“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.

G1的第一关注点是为用户提供一种解决方案,其用户群体是他们运行的应用需要大的堆空间并且是有限的GC的延迟。这个意味着堆空间大小大于是在6G左右或者更大,并且稳定可预测的间隔时间应该是在0.5s之内。

Applications running today with either the CMS or the ParallelOldGC garbage collector would benefit switching to G1 if the application has one or more of the following traits.

在现在应用使用从CMS或者ParallelOldGC垃圾收集器都会从切换至G1受益,如果应用拥有如下几个特点:

      • Full GC durations are too long or too frequent.
        Full GC的持续时间太长或太频繁了。
      • The rate of object allocation rate or promotion varies significantly.
        对象分派或晋升率比较大。
      • Undesired long garbage collection or compaction pauses (longer than 0.5 to 1 second)
        不需要长时间的垃圾收集或者停顿的间隔(通常是长于0.5或1秒)

Note: If you are using CMS or ParallelOldGC and your application is not experiencing long garbage collection pauses, it is fine to stay with your current collector. Changing to the G1 collector is not a requirement for using the latest JDK.
说明:如果你使用了CMS或者ParallelOldGC,并且你的应用并没有经历过长时间的垃圾收集停顿时间,还是可以继续保持你现有的收集器的,切换成G1收集器对于使用了最新版的JDK来说并不是一个需求。

至此咱们就把这三部分的东东给解读完了,如下:

G1垃圾收集器原理剖析【官方解读】的更多相关文章

  1. G1 垃圾收集器深入剖析(图文超详解)

    G1(Garbage First)垃圾收集器是目前垃圾回收技术最前沿的成果之一. G1 同 CMS 垃圾回收器一样,关注最小时延的垃圾回收器,适合大尺寸堆内存的垃圾收集.但是,G1 最大的特点是引入分 ...

  2. G1垃圾收集器系统化说明【官方解读】

    还是继续G1官网解读,上一次已经将这三节的东东读完了,如下: 所以接一来则继续往下读: Reviewing Generational GC and CMS[回顾一下CMS收集器] The Concur ...

  3. G1垃圾收集器官方文档透彻解读【官方解读】

    在前几次中已经对G1的理论进行了一个比较详细的了解了,对于G1垃圾收集器最权威的解读肯定得上官网,当咱们将官网的理解透了,那基本上网上对于G1的说明其实最终都是来自于官网,所以接下来会详细来解读Ora ...

  4. G1垃圾收集器的实现原理

    (G1垃圾收集器的实现原理.G1和CMS经常被单独拎出来问) https://tech.meituan.com/g1.html G1太复杂,说下CMS吧

  5. 深入理解 Java G1 垃圾收集器--转

    原文地址:http://blog.jobbole.com/109170/?utm_source=hao.jobbole.com&utm_medium=relatedArticle 本文首先简单 ...

  6. 【JVM】7、深入理解Java G1垃圾收集器

    本文首先简单介绍了垃圾收集的常见方式,然后再分析了G1收集器的收集原理,相比其他垃圾收集器的优势,最后给出了一些调优实践. 一,什么是垃圾回收 首先,在了解G1之前,我们需要清楚的知道,垃圾回收是什么 ...

  7. 转:深入理解Java G1垃圾收集器

    本文首先简单介绍了垃圾收集的常见方式,然后再分析了G1收集器的收集原理,相比其他垃圾收集器的优势,最后给出了一些调优实践. 一,什么是垃圾回收 首先,在了解G1之前,我们需要清楚的知道,垃圾回收是什么 ...

  8. [转] 深入理解Java G1垃圾收集器

    [From] https://www.cnblogs.com/ASPNET2008/p/6496481.html 深入理解Java G1垃圾收集器 本文首先简单介绍了垃圾收集的常见方式,然后再分析了G ...

  9. 深入理解Java G1垃圾收集器

    本文首先简单介绍了垃圾收集的常见方式,然后再分析了G1收集器的收集原理,相比其他垃圾收集器的优势,最后给出了一些调优实践. 一,什么是垃圾回收 首先,在了解G1之前,我们需要清楚的知道,垃圾回收是什么 ...

随机推荐

  1. iOS 多线程的简单理解(4) 线程锁的简单使用

    要用到多线程 ,就不得不考虑,线程之间的交互,线程是否安全 推荐一个原文链接 是关于 线程锁的基本使用的  http://blog.csdn.net/qq_30513483/article/detai ...

  2. 微服务Consul系列之服务注册与服务发现

    在进行服务注册之前先确认集群是否建立,关于服务注册可以看上篇微服务Consul系列之集群搭建的介绍,两种注册方式:一种是注册HTTP API.另一种是通过配置文件定义,下面讲解的是基于后者配置文件定义 ...

  3. Configuring and Running Django + Celery in Docker Containers

    Configuring and Running Django + Celery in Docker Containers  Justyna Ilczuk  Oct 25, 2016  0 Commen ...

  4. 常见问题:MySQL/索引

    普通索引 最常用,没有任何限制. 唯一索引 必须唯一,但允许空值,如果是组合索引,列值的组合必须唯一. 组合索引 由于MySQL查询时,只能使用一个索引,因此建立组合索引在组合查询的场景下更加有效.组 ...

  5. Deep Learning Recommendation Model for Personalization and Recommendation Systems

    这篇文章出自facebook,主要探索了如何利用类别型特征(categorical features)并且构建一个深度推荐系统.值得注意的是,文章还特别强调了工业实现上如何实现并行,也很良心地给出了基 ...

  6. Object 方法的 hashCode,equals方法源码

    文章目录 hashCode方法注释 equals 方法注释 equals 方法 hashCode方法注释 Object 的 hashCode 方法,是本地方法: Returns a hash code ...

  7. C++中数组占用的内存计算

    在C++中int类型每个空间是4个字节,long long int 是8个字节,而bool类型是1个字节 所以一般能用bool就别用int,节约空间 数组占用内存的计算 a[1001][1001]的空 ...

  8. Spyder中报错: Check failed: PyBfloat16_Type.tp_base != nullptr

    报错问题: 问题1:tensorflow/python/lib/core/bfloat16.cc:675] Check failed: PyBfloat16_Type.tp_base != nullp ...

  9. 计算机网络--TCP协议深入理解

    在近期学习计算机网络的过程中,由于知识点过于零散,琐碎,从而学习起来痛苦不堪,此贴只是总结了基于传输层的TCP协议相关的知识细节,并加入一点自己的理解,并无创新,若有理解不当之处,敬请提出,感谢! 首 ...

  10. Composer简介

    Composer 是 PHP 的一个依赖管理工具.它允许你申明项目所依赖的代码库,它会在你的项目中为你安装他们. 依赖管理 Composer 不是一个包管理器.是的,它涉及 "package ...