Skip to content

Commit

Permalink
g1 ygc root scan add image
Browse files Browse the repository at this point in the history
  • Loading branch information
yoa1226 committed Oct 21, 2024
1 parent 50b314b commit c181349
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions _posts/2024-08-25-g1-gc-young-gc-root-scan.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ virtual void work(uint worker_id) {
}
```
<image src="/assets/gc-young-gc-root-scan/g1-gc-ygc-rset-scan.png" width = "80%"/>
这里主要逻辑都在 `G1MergeCardSetClosure` 里面,它主要做了三件事情。
1. 遍历记忆集,将记忆集中的 region 的 card 对应的 card table 位置标记为 dirty,即将记忆集存储的转换成 card table 存储。
2. 将记忆集中的 region 统一添加到 ` _scan_state._next_dirty_regions` 中。
后续 heap root scan 阶段需要依赖上面两类的信息。
3. 将会收集中的 reigon 统一添加到 ` _scan_state._all_dirty_regions`,由于这部分 region 被回收了,那么其对应的 card table 位置需要被清理。
3. 将回收集中的 reigon 统一添加到 ` _scan_state._all_dirty_regions`,由于这部分 region 被回收了,那么其对应的 card table 位置需要被清理。
### G1MergeCardSetClosure
Expand Down Expand Up @@ -159,6 +161,7 @@ class G1MergeCardSetClosure : public G1HeapRegionClosure {

对每个 dirty card 进行处理,`_merge_card_set_cache` 用于优化性能,`mark_clean_as_dirty` 将存在跨 region 引用的 card 标记为 dirty card。


```cpp
//->ptr.iterate(cl, _config->inline_ptr_bits_per_card());
//->found(value & card_mask);
Expand All @@ -175,11 +178,17 @@ class G1MergeCardSetClosure : public G1HeapRegionClosure {
}

void mark_card(G1CardTable::CardValue* value) {
if (_ct->mark_clean_as_dirty(value)) { }
if (_ct->mark_clean_as_dirty(value)) {
_scan_state->set_chunk_dirty(_ct->index_for_cardvalue(value));
}
}
}
```

`scan_state->set_chunk_dirty`对 card index 进行压缩,64 个 card组成一个 chunk。相当于对 dirty card 分层,添加了一层索引,后续可以看到对

<image src="/assets/gc-young-gc-root-scan/g1-gc-young-gc-root-scan-chunk.png" width="80%"/>

## scan root

scan root 的代码如下,核心逻辑封装在 `scan_roots` 中:
Expand Down Expand Up @@ -632,7 +641,9 @@ class G1CardTableChunkClaimer {
}
```
`_region_scan_chunks` 在遍历记忆集的时候初始化, 用于加快查找。
<image src="/assets/gc-young-gc-root-scan/g1-gc-young-gc-root-scan-chunk.png" width="80%"/>
`_region_scan_chunks` 在遍历记忆集的时候初始化后, 用于加快查找。
```cpp
void set_chunk_range_dirty(size_t const region_card_idx, size_t const card_length) {
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c181349

Please sign in to comment.