OpenJDK16 ZGC 源码分析(七)GC阶段之转移集

1. 简介

在并发处理完强引用和非强引用后,ZGC就进入了转移阶段。
本文将介绍转移阶段开始的两个小步骤,重置转移集和选择转移集。

2. 源码分析

2.1 重置转移集

在标记阶段介绍后,所有的引用都已经指向对象迁移后的新地址,ZForwardingTable中的数据已经全部失效。此时需要重置转移集,为下一轮GC做准备。
hotspot/share/gc/z/zHeap.cpp

void ZHeap::reset_relocation_set() {
   
  // 重置forwarding table
  ZRelocationSetIterator iter(&_relocation_set);
  for (ZForwarding* forwarding; iter.next(&forwarding);) {
   
    _forwarding_table.remove(forwarding);
  }

  // 重置转移集
  _relocation_set.reset();
}

重置forwarding table逻辑如下:
hotspot/share/gc/z/zForwardingTable.inline.hpp

inline void ZForwardingTable::remove(ZForwarding* forwarding) {
   
  const uintptr_t offset = forwarding->start();
  const size_t size = forwarding->size();

  assert(_map.get(offset) == forwarding, "Invalid entry");
  // 将offset后size个元素置为null
  _map.put(offset, size, NULL);
}

转移集的reset逻辑也比较简单,就是迭代器调用forwarding的析构函数:
hotspot/share/gc/z/zRelocationSet.cpp

void ZRelocationSet::reset() {
   
  // 析构forwardings
  ZRelocationSetIterator iter
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值