区域内的 G1GC 压缩

G1GC compaction within regions

据我了解,G1 GC 执行疏散以从年轻区域和旧区域回收堆,这样做会间接压缩堆(将活动对象从待收集区域复制到空区域)。 G1 GC 是否会遇到这样一种情况,即没有完全空的区域可供复制对象,但在半满区域中有足够的碎片堆?我想问一下,G1是否跟踪区域内的空闲space,是否在区域内进行压缩?

when will be G1 ( Garbage Collector) starts running and in which memory area it collect first?

堆被分成很多等价的预估堆区,每区一个感触范围的虚拟内存。某些地区集被分配了类似的工作(伊甸园、幸存者、旧)

G1 执行全球同步冲压阶段,以确定整堆物品的活性。印记阶段完成后,G1 知道哪些区域大部分未填充。它首先聚集在这些地区,通常会产生很多免费space。这就是这种垃圾分类策略被称为垃圾优先的原因。顾名思义,G1 将其分类和压实运动集中在可能会装载可回收物品(即垃圾)的堆栈区域。 G1 使用中断预测模型来满足客户特征化的停止时间目标,并根据预定的暂停时间目标选择要收集的站点数量。

G1 区分为准备好恢复的区域是使用清理收集的垃圾。 G1 将对象从存储的至少一个区域复制到堆栈上的一个单独区域,并且在这个过程中两者压缩并打开内存。这种偏离在多处理器上并行执行,以减少停止时间并增加吞吐量。通过这种方式,对于每个垃圾分类,G1 始终试图减少断裂,在客户特征延迟时间内工作。这是过去两种技术的能力。

Basically, The amount of live data in each region is tracked, and when a collection is triggered the G1GC will clear the ones with the most ‘garbage’ first.

这意味着它也可以从半满区域收集垃圾。

HotSpot VM Garbage Collection Tuning Guide says in the Allocation (Evacuation) Failure 部分:

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.

这意味着,尽管没有明确说明,STW 完整集合能够执行压缩,否则,它不能解决碎片问题。我只在有关 Humongous Objects and Humongous Allocations:

的部分中找到了有关压缩功能的间接提示

To reduce copying overhead, the humongous objects are not included in any evacuation pause. A full garbage collection cycle compacts humongous objects in place.

这并不意味着“G1跟踪区域内的免费space”,因为这会违背默认执行复制的目的,而是,这些必要的信息可能会在完整收集,作为过程的一部分。