G1 RSet 管理

注意:jdk14中G1代码有极大不同

 

RSet中遍历分区

bool ScanRSClosure::doHeapRegion(HeapRegion* r) {
	
	HeapRegionRemSet* hrrs = r->rem_set();
	if (hrrs->iter_is_complete()) return false;
	if (!_try_claimed && hrrs->claim_iter()) return false;

	_g1h->push_dirty_cards_region(r);//更新RSet

	HeapRegionRemSetIterator iter(hrrs);
	size_t card_index;
	//一次扫描分区数,默认64
	size_t jump_to_card = hrrs->iter_claimed_next(_block_size);
	for (size_t current_card = 0; iter.has_next(card_index); current_card++) {
		if (current_card >= jump_to_card + _block_size) {
			jump_to_card = hrrs->iter_claimed_next(_block_size);
		}
		if (curent_card < jump_to_card) continue;
		HeapWord* card_start = _g1h->bot_shared()->address_for_index(card_index);

		HeapRegion* card_region = _g1h->heap_region_containing(card_start);//引用者分区
		_cards++;		

		//不在CSet才需要更新,在CSet会被回收
		if (!card_region->in_collection_set() && !_ct_bs->is_card_dirty(card_index)) {
			scanCard(card_index, card_region);
		}
	}
	//..
}

对每一个分区查找对应引用了此分区的对象

void HeapRegionDCTOC::walk_mem_region(...) {
	G1CollectedHeap* _g1;
	size_t oop_size;
	HeapWord* cur = bottom;//pointer to the first object

	if (!g1h->is_obj_dead(oop(cur), _hr)) {
		oop_size = oop(cur)->oop_iterate(_rs_scan, mr);
	} else {
		oop_size = _hr->block_size(cur);
	}

	cur += oop_size;

	if (cur < top) {
		oop cur_oop = oop(cur);
		oop_size = _hr->block_size(cur);
		HeapWord* next_obj = cur + oop_size;
		while(next_obj < top) {
			if (!g1h->is_obj_dead(oop(cur), _hr)) {
				cur_oop->oop_iterate(_rs_scan);
			}
			cur = next_obj;
			//..
			//主要有dummy填充,while起来挺快的
		}
	}
	//最后一个对象可能跨区域
	if (!g1h->is_obj_dead(oop(cur), _hr)) {
		oop_size = oop(cur)->oop_iterate(_rs_scan, mr);
	}
}

对对象的字段查找

template <class T> inline void G1ParPushHeapRSClosure::do_oop_nv(T* p) {
	T heap_oop = oopDesc::load_heap_oop(p);
	if (!oopDesc::is_null(heap_oop)) {
		oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
		if (_g1->is_in_cset_or_humongous(obj)) {
			_par_scan_state->push_on_queue(p);
		}
	}
}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值