After completing marking, G1 collects liveness information on a per-card basis for various purposes.
G1 iterates over the mark bitmap and sets the appropriate bits. It does so by pretty elaborate code that special cases short sequences of bits to set in G1CardLiveDataHelper::set_card_bitmap_range():
if ((end_idx - start_idx) <= 8) {
for (BitMap::idx_t i = start_idx; i < end_idx; i += 1) {
_card_bm.set_bit(i);
}
} else {
_card_bm.set_range(start_idx, end_idx);
}
The question is whether the special casing for very small ranges (why <= 8?) is necessary, and the entire method could be replaced by a _card_bm.set_range(start_idx, end_idx, BitMap::small_range) call.
Investigate the performance impact and implement a more optimal solution.
Most likely the difference will not be noticeable unless on a really large heap, and if so, special-casing setting the first two bits should be sufficient.