ART: clear dirty cards of alloc space for MS/CMS partial and full GCs
For MS/CMS partial and full GCs, we could clear the dirty cards of alloc
space when we process cards as we care about the dirty cards after GC
starts.
Change-Id: I1f9b32b20d75979387bc5d26b0cf9a256dcf20b6
Signed-off-by: Lei Li <lei.l.li@intel.com>
diff --git a/runtime/gc/accounting/card_table.cc b/runtime/gc/accounting/card_table.cc
index b7b6099..ca1e7c1 100644
--- a/runtime/gc/accounting/card_table.cc
+++ b/runtime/gc/accounting/card_table.cc
@@ -102,6 +102,26 @@
mem_map_->MadviseDontNeedAndZero();
}
+void CardTable::ClearCardRange(uint8_t* start, uint8_t* end) {
+ if (!kMadviseZeroes) {
+ memset(start, 0, end - start);
+ return;
+ }
+ CHECK_ALIGNED(reinterpret_cast<uintptr_t>(start), kCardSize);
+ CHECK_ALIGNED(reinterpret_cast<uintptr_t>(end), kCardSize);
+ static_assert(kCardClean == 0, "kCardClean must be 0");
+ uint8_t* start_card = CardFromAddr(start);
+ uint8_t* end_card = CardFromAddr(end);
+ uint8_t* round_start = AlignUp(start_card, kPageSize);
+ uint8_t* round_end = AlignDown(end_card, kPageSize);
+ if (round_start < round_end) {
+ madvise(round_start, round_end - round_start, MADV_DONTNEED);
+ }
+ // Handle unaligned regions at start / end.
+ memset(start_card, 0, std::min(round_start, end_card) - start_card);
+ memset(std::max(round_end, start_card), 0, end_card - std::max(round_end, start_card));
+}
+
bool CardTable::AddrIsInCardTable(const void* addr) const {
return IsValidCard(biased_begin_ + ((uintptr_t)addr >> kCardShift));
}