blob: 753b42deb52785bd6503c82cc1780efa11ed9c9a [file] [log] [blame]
Ian Rogers1d54e732013-05-02 21:10:01 -07001/*
2 * Copyright (C) 2012 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "mod_union_table.h"
18
Ian Rogers700a4022014-05-19 16:49:03 -070019#include <memory>
20
Ian Rogers1d54e732013-05-02 21:10:01 -070021#include "base/stl_util.h"
22#include "card_table-inl.h"
23#include "heap_bitmap.h"
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -070024#include "gc/accounting/space_bitmap-inl.h"
Mathieu Chartier11409ae2013-09-23 11:49:36 -070025#include "gc/collector/mark_sweep.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070026#include "gc/collector/mark_sweep-inl.h"
27#include "gc/heap.h"
28#include "gc/space/space.h"
Brian Carlstromea46f952013-07-30 01:26:50 -070029#include "mirror/art_field-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070030#include "mirror/object-inl.h"
31#include "mirror/class-inl.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070032#include "mirror/object_array-inl.h"
33#include "space_bitmap-inl.h"
34#include "thread.h"
Ian Rogers1d54e732013-05-02 21:10:01 -070035
Brian Carlstrom3e3d5912013-07-18 00:19:45 -070036using ::art::mirror::Object;
Ian Rogers1d54e732013-05-02 21:10:01 -070037
38namespace art {
39namespace gc {
40namespace accounting {
41
Ian Rogers1d54e732013-05-02 21:10:01 -070042class ModUnionClearCardSetVisitor {
43 public:
Mathieu Chartier0a9dc052013-07-25 11:01:28 -070044 explicit ModUnionClearCardSetVisitor(ModUnionTable::CardSet* const cleared_cards)
Ian Rogers1d54e732013-05-02 21:10:01 -070045 : cleared_cards_(cleared_cards) {
46 }
47
Ian Rogers13735952014-10-08 12:43:28 -070048 inline void operator()(uint8_t* card, uint8_t expected_value, uint8_t new_value) const {
Ian Rogers1d54e732013-05-02 21:10:01 -070049 if (expected_value == CardTable::kCardDirty) {
50 cleared_cards_->insert(card);
51 }
52 }
53
54 private:
Mathieu Chartier0a9dc052013-07-25 11:01:28 -070055 ModUnionTable::CardSet* const cleared_cards_;
Ian Rogers1d54e732013-05-02 21:10:01 -070056};
57
58class ModUnionClearCardVisitor {
59 public:
Ian Rogers13735952014-10-08 12:43:28 -070060 explicit ModUnionClearCardVisitor(std::vector<uint8_t*>* cleared_cards)
Ian Rogers1d54e732013-05-02 21:10:01 -070061 : cleared_cards_(cleared_cards) {
62 }
63
Ian Rogers13735952014-10-08 12:43:28 -070064 void operator()(uint8_t* card, uint8_t expected_card, uint8_t new_card) const {
Ian Rogers1d54e732013-05-02 21:10:01 -070065 if (expected_card == CardTable::kCardDirty) {
66 cleared_cards_->push_back(card);
67 }
68 }
69 private:
Ian Rogers13735952014-10-08 12:43:28 -070070 std::vector<uint8_t*>* const cleared_cards_;
Ian Rogers1d54e732013-05-02 21:10:01 -070071};
72
Mathieu Chartier11409ae2013-09-23 11:49:36 -070073class ModUnionUpdateObjectReferencesVisitor {
Ian Rogers1d54e732013-05-02 21:10:01 -070074 public:
Mathieu Chartiere4cab172014-08-19 18:24:04 -070075 ModUnionUpdateObjectReferencesVisitor(MarkHeapReferenceCallback* callback, void* arg,
76 space::ContinuousSpace* from_space,
77 bool* contains_reference_to_other_space)
78 : callback_(callback), arg_(arg), from_space_(from_space),
79 contains_reference_to_other_space_(contains_reference_to_other_space) {
Mathieu Chartier11409ae2013-09-23 11:49:36 -070080 }
Ian Rogers1d54e732013-05-02 21:10:01 -070081
Mathieu Chartier11409ae2013-09-23 11:49:36 -070082 // Extra parameters are required since we use this same visitor signature for checking objects.
Mathieu Chartier4aeec172014-03-27 16:09:46 -070083 void operator()(Object* obj, MemberOffset offset, bool /*is_static*/) const
Mathieu Chartier407f7022014-02-18 14:37:05 -080084 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
Mathieu Chartier11409ae2013-09-23 11:49:36 -070085 // Only add the reference if it is non null and fits our criteria.
Mathieu Chartier407f7022014-02-18 14:37:05 -080086 mirror::HeapReference<Object>* obj_ptr = obj->GetFieldObjectReferenceAddr(offset);
Mathieu Chartiere4cab172014-08-19 18:24:04 -070087 mirror::Object* ref = obj_ptr->AsMirrorPtr();
88 if (ref != nullptr && !from_space_->HasAddress(ref)) {
89 *contains_reference_to_other_space_ = true;
Mathieu Chartier407f7022014-02-18 14:37:05 -080090 callback_(obj_ptr, arg_);
Mathieu Chartier11409ae2013-09-23 11:49:36 -070091 }
Ian Rogers1d54e732013-05-02 21:10:01 -070092 }
93
94 private:
Mathieu Chartier407f7022014-02-18 14:37:05 -080095 MarkHeapReferenceCallback* const callback_;
Mathieu Chartier11409ae2013-09-23 11:49:36 -070096 void* arg_;
Mathieu Chartiere4cab172014-08-19 18:24:04 -070097 // Space which we are scanning
98 space::ContinuousSpace* const from_space_;
99 // Set if we have any references to another space.
100 bool* const contains_reference_to_other_space_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700101};
102
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700103class ModUnionScanImageRootVisitor {
104 public:
Mathieu Chartiere4cab172014-08-19 18:24:04 -0700105 ModUnionScanImageRootVisitor(MarkHeapReferenceCallback* callback, void* arg,
106 space::ContinuousSpace* from_space,
107 bool* contains_reference_to_other_space)
108 : callback_(callback), arg_(arg), from_space_(from_space),
109 contains_reference_to_other_space_(contains_reference_to_other_space) {}
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700110
111 void operator()(Object* root) const
112 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
113 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
114 DCHECK(root != NULL);
Mathieu Chartiere4cab172014-08-19 18:24:04 -0700115 ModUnionUpdateObjectReferencesVisitor ref_visitor(callback_, arg_, from_space_,
116 contains_reference_to_other_space_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700117 root->VisitReferences<kMovingClasses>(ref_visitor, VoidFunctor());
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700118 }
119
120 private:
Mathieu Chartier407f7022014-02-18 14:37:05 -0800121 MarkHeapReferenceCallback* const callback_;
Mathieu Chartier83c8ee02014-01-28 14:50:23 -0800122 void* const arg_;
Mathieu Chartiere4cab172014-08-19 18:24:04 -0700123 // Space which we are scanning
124 space::ContinuousSpace* const from_space_;
125 // Set if we have any references to another space.
126 bool* const contains_reference_to_other_space_;
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700127};
128
129void ModUnionTableReferenceCache::ClearCards() {
Ian Rogers1d54e732013-05-02 21:10:01 -0700130 CardTable* card_table = GetHeap()->GetCardTable();
131 ModUnionClearCardSetVisitor visitor(&cleared_cards_);
132 // Clear dirty cards in the this space and update the corresponding mod-union bits.
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700133 card_table->ModifyCardsAtomic(space_->Begin(), space_->End(), AgeCardVisitor(), visitor);
Ian Rogers1d54e732013-05-02 21:10:01 -0700134}
135
136class AddToReferenceArrayVisitor {
137 public:
138 explicit AddToReferenceArrayVisitor(ModUnionTableReferenceCache* mod_union_table,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800139 std::vector<mirror::HeapReference<Object>*>* references)
140 : mod_union_table_(mod_union_table), references_(references) {
Ian Rogers1d54e732013-05-02 21:10:01 -0700141 }
142
143 // Extra parameters are required since we use this same visitor signature for checking objects.
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700144 void operator()(Object* obj, MemberOffset offset, bool /*is_static*/) const
Mathieu Chartier407f7022014-02-18 14:37:05 -0800145 SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
146 mirror::HeapReference<Object>* ref_ptr = obj->GetFieldObjectReferenceAddr(offset);
147 mirror::Object* ref = ref_ptr->AsMirrorPtr();
Ian Rogers1d54e732013-05-02 21:10:01 -0700148 // Only add the reference if it is non null and fits our criteria.
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700149 if (ref != nullptr && mod_union_table_->ShouldAddReference(ref)) {
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700150 // Push the adddress of the reference.
Mathieu Chartier407f7022014-02-18 14:37:05 -0800151 references_->push_back(ref_ptr);
Ian Rogers1d54e732013-05-02 21:10:01 -0700152 }
153 }
154
155 private:
156 ModUnionTableReferenceCache* const mod_union_table_;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800157 std::vector<mirror::HeapReference<Object>*>* const references_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700158};
159
160class ModUnionReferenceVisitor {
161 public:
162 explicit ModUnionReferenceVisitor(ModUnionTableReferenceCache* const mod_union_table,
Ian Rogersef7d42f2014-01-06 12:55:46 -0800163 std::vector<mirror::HeapReference<Object>*>* references)
Ian Rogers1d54e732013-05-02 21:10:01 -0700164 : mod_union_table_(mod_union_table),
165 references_(references) {
166 }
167
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700168 void operator()(Object* obj) const
Ian Rogers1d54e732013-05-02 21:10:01 -0700169 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_) {
Ian Rogers1d54e732013-05-02 21:10:01 -0700170 // We don't have an early exit since we use the visitor pattern, an early
171 // exit should significantly speed this up.
172 AddToReferenceArrayVisitor visitor(mod_union_table_, references_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700173 obj->VisitReferences<kMovingClasses>(visitor, VoidFunctor());
Ian Rogers1d54e732013-05-02 21:10:01 -0700174 }
175 private:
176 ModUnionTableReferenceCache* const mod_union_table_;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800177 std::vector<mirror::HeapReference<Object>*>* const references_;
Ian Rogers1d54e732013-05-02 21:10:01 -0700178};
179
180class CheckReferenceVisitor {
181 public:
182 explicit CheckReferenceVisitor(ModUnionTableReferenceCache* mod_union_table,
183 const std::set<const Object*>& references)
184 : mod_union_table_(mod_union_table),
185 references_(references) {
186 }
187
188 // Extra parameters are required since we use this same visitor signature for checking objects.
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700189 void operator()(Object* obj, MemberOffset offset, bool /*is_static*/) const
Ian Rogers1d54e732013-05-02 21:10:01 -0700190 SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_) {
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700191 mirror::Object* ref = obj->GetFieldObject<mirror::Object>(offset);
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700192 if (ref != nullptr && mod_union_table_->ShouldAddReference(ref) &&
Ian Rogers1d54e732013-05-02 21:10:01 -0700193 references_.find(ref) == references_.end()) {
Mathieu Chartier407f7022014-02-18 14:37:05 -0800194 Heap* heap = mod_union_table_->GetHeap();
Ian Rogers1d54e732013-05-02 21:10:01 -0700195 space::ContinuousSpace* from_space = heap->FindContinuousSpaceFromObject(obj, false);
196 space::ContinuousSpace* to_space = heap->FindContinuousSpaceFromObject(ref, false);
Mathieu Chartier407f7022014-02-18 14:37:05 -0800197 LOG(INFO) << "Object " << reinterpret_cast<const void*>(obj) << "(" << PrettyTypeOf(obj)
198 << ")" << "References " << reinterpret_cast<const void*>(ref) << "(" << PrettyTypeOf(ref)
199 << ") without being in mod-union table";
200 LOG(INFO) << "FromSpace " << from_space->GetName() << " type "
201 << from_space->GetGcRetentionPolicy();
202 LOG(INFO) << "ToSpace " << to_space->GetName() << " type "
203 << to_space->GetGcRetentionPolicy();
Mathieu Chartier4c13a3f2014-07-14 14:57:16 -0700204 heap->DumpSpaces(LOG(INFO));
Ian Rogers1d54e732013-05-02 21:10:01 -0700205 LOG(FATAL) << "FATAL ERROR";
206 }
207 }
208
209 private:
210 ModUnionTableReferenceCache* const mod_union_table_;
211 const std::set<const Object*>& references_;
212};
213
214class ModUnionCheckReferences {
215 public:
Brian Carlstromdf629502013-07-17 22:39:56 -0700216 explicit ModUnionCheckReferences(ModUnionTableReferenceCache* mod_union_table,
217 const std::set<const Object*>& references)
Ian Rogers1d54e732013-05-02 21:10:01 -0700218 EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_)
219 : mod_union_table_(mod_union_table), references_(references) {
220 }
221
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700222 void operator()(Object* obj) const NO_THREAD_SAFETY_ANALYSIS {
Ian Rogers1d54e732013-05-02 21:10:01 -0700223 Locks::heap_bitmap_lock_->AssertSharedHeld(Thread::Current());
Ian Rogers1d54e732013-05-02 21:10:01 -0700224 CheckReferenceVisitor visitor(mod_union_table_, references_);
Ian Rogersb0fa5dc2014-04-28 16:47:08 -0700225 obj->VisitReferences<kMovingClasses>(visitor, VoidFunctor());
Ian Rogers1d54e732013-05-02 21:10:01 -0700226 }
227
228 private:
229 ModUnionTableReferenceCache* const mod_union_table_;
230 const std::set<const Object*>& references_;
231};
232
233void ModUnionTableReferenceCache::Verify() {
234 // Start by checking that everything in the mod union table is marked.
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700235 for (const auto& ref_pair : references_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800236 for (mirror::HeapReference<Object>* ref : ref_pair.second) {
237 CHECK(heap_->IsLiveObjectLocked(ref->AsMirrorPtr()));
Ian Rogers1d54e732013-05-02 21:10:01 -0700238 }
239 }
240
241 // Check the references of each clean card which is also in the mod union table.
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700242 CardTable* card_table = heap_->GetCardTable();
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -0700243 ContinuousSpaceBitmap* live_bitmap = space_->GetLiveBitmap();
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700244 for (const auto& ref_pair : references_) {
Ian Rogers13735952014-10-08 12:43:28 -0700245 const uint8_t* card = ref_pair.first;
Ian Rogers1d54e732013-05-02 21:10:01 -0700246 if (*card == CardTable::kCardClean) {
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700247 std::set<const Object*> reference_set;
Ian Rogersef7d42f2014-01-06 12:55:46 -0800248 for (mirror::HeapReference<Object>* obj_ptr : ref_pair.second) {
249 reference_set.insert(obj_ptr->AsMirrorPtr());
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700250 }
Ian Rogers1d54e732013-05-02 21:10:01 -0700251 ModUnionCheckReferences visitor(this, reference_set);
252 uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700253 live_bitmap->VisitMarkedRange(start, start + CardTable::kCardSize, visitor);
Ian Rogers1d54e732013-05-02 21:10:01 -0700254 }
255 }
256}
257
258void ModUnionTableReferenceCache::Dump(std::ostream& os) {
259 CardTable* card_table = heap_->GetCardTable();
Ian Rogers1d54e732013-05-02 21:10:01 -0700260 os << "ModUnionTable cleared cards: [";
Ian Rogers13735952014-10-08 12:43:28 -0700261 for (uint8_t* card_addr : cleared_cards_) {
Mathieu Chartier02e25112013-08-14 16:14:24 -0700262 uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
Ian Rogers1d54e732013-05-02 21:10:01 -0700263 uintptr_t end = start + CardTable::kCardSize;
264 os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << ",";
265 }
266 os << "]\nModUnionTable references: [";
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700267 for (const auto& ref_pair : references_) {
Ian Rogers13735952014-10-08 12:43:28 -0700268 const uint8_t* card_addr = ref_pair.first;
Mathieu Chartier02e25112013-08-14 16:14:24 -0700269 uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
Ian Rogers1d54e732013-05-02 21:10:01 -0700270 uintptr_t end = start + CardTable::kCardSize;
271 os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << "->{";
Ian Rogersef7d42f2014-01-06 12:55:46 -0800272 for (mirror::HeapReference<Object>* ref : ref_pair.second) {
273 os << reinterpret_cast<const void*>(ref->AsMirrorPtr()) << ",";
Ian Rogers1d54e732013-05-02 21:10:01 -0700274 }
275 os << "},";
276 }
277}
278
Mathieu Chartier407f7022014-02-18 14:37:05 -0800279void ModUnionTableReferenceCache::UpdateAndMarkReferences(MarkHeapReferenceCallback* callback,
Mathieu Chartier815873e2014-02-13 18:02:13 -0800280 void* arg) {
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700281 CardTable* card_table = heap_->GetCardTable();
Ian Rogers1d54e732013-05-02 21:10:01 -0700282
Ian Rogersef7d42f2014-01-06 12:55:46 -0800283 std::vector<mirror::HeapReference<Object>*> cards_references;
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700284 ModUnionReferenceVisitor add_visitor(this, &cards_references);
Ian Rogers1d54e732013-05-02 21:10:01 -0700285
Mathieu Chartier02e25112013-08-14 16:14:24 -0700286 for (const auto& card : cleared_cards_) {
Ian Rogers1d54e732013-05-02 21:10:01 -0700287 // Clear and re-compute alloc space references associated with this card.
288 cards_references.clear();
289 uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
290 uintptr_t end = start + CardTable::kCardSize;
Mathieu Chartier4aeec172014-03-27 16:09:46 -0700291 auto* space = heap_->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
Mathieu Chartier02e25112013-08-14 16:14:24 -0700292 DCHECK(space != nullptr);
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -0700293 ContinuousSpaceBitmap* live_bitmap = space->GetLiveBitmap();
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700294 live_bitmap->VisitMarkedRange(start, end, add_visitor);
Ian Rogers1d54e732013-05-02 21:10:01 -0700295
296 // Update the corresponding references for the card.
Mathieu Chartier02e25112013-08-14 16:14:24 -0700297 auto found = references_.find(card);
Ian Rogers1d54e732013-05-02 21:10:01 -0700298 if (found == references_.end()) {
299 if (cards_references.empty()) {
300 // No reason to add empty array.
301 continue;
302 }
303 references_.Put(card, cards_references);
304 } else {
305 found->second = cards_references;
306 }
307 }
308 cleared_cards_.clear();
Ian Rogers1d54e732013-05-02 21:10:01 -0700309 size_t count = 0;
Mathieu Chartier02e25112013-08-14 16:14:24 -0700310 for (const auto& ref : references_) {
Ian Rogersef7d42f2014-01-06 12:55:46 -0800311 for (mirror::HeapReference<Object>* obj_ptr : ref.second) {
Mathieu Chartier407f7022014-02-18 14:37:05 -0800312 callback(obj_ptr, arg);
Ian Rogers1d54e732013-05-02 21:10:01 -0700313 }
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700314 count += ref.second.size();
Ian Rogers1d54e732013-05-02 21:10:01 -0700315 }
316 if (VLOG_IS_ON(heap)) {
317 VLOG(gc) << "Marked " << count << " references in mod union table";
318 }
319}
320
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700321void ModUnionTableCardCache::ClearCards() {
Ian Rogers1d54e732013-05-02 21:10:01 -0700322 CardTable* card_table = GetHeap()->GetCardTable();
323 ModUnionClearCardSetVisitor visitor(&cleared_cards_);
324 // Clear dirty cards in the this space and update the corresponding mod-union bits.
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700325 card_table->ModifyCardsAtomic(space_->Begin(), space_->End(), AgeCardVisitor(), visitor);
Ian Rogers1d54e732013-05-02 21:10:01 -0700326}
327
328// Mark all references to the alloc space(s).
Mathieu Chartier407f7022014-02-18 14:37:05 -0800329void ModUnionTableCardCache::UpdateAndMarkReferences(MarkHeapReferenceCallback* callback,
330 void* arg) {
Ian Rogers1d54e732013-05-02 21:10:01 -0700331 CardTable* card_table = heap_->GetCardTable();
Mathieu Chartiera8e8f9c2014-04-09 14:51:05 -0700332 ContinuousSpaceBitmap* bitmap = space_->GetLiveBitmap();
Mathieu Chartiere4cab172014-08-19 18:24:04 -0700333 bool reference_to_other_space = false;
334 ModUnionScanImageRootVisitor scan_visitor(callback, arg, space_, &reference_to_other_space);
335 for (auto it = cleared_cards_.begin(), end = cleared_cards_.end(); it != end; ) {
336 uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(*it));
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700337 DCHECK(space_->HasAddress(reinterpret_cast<Object*>(start)));
Mathieu Chartiere4cab172014-08-19 18:24:04 -0700338 reference_to_other_space = false;
Mathieu Chartier11409ae2013-09-23 11:49:36 -0700339 bitmap->VisitMarkedRange(start, start + CardTable::kCardSize, scan_visitor);
Mathieu Chartiere4cab172014-08-19 18:24:04 -0700340 if (!reference_to_other_space) {
341 // No non null reference to another space, remove the card.
342 it = cleared_cards_.erase(it);
343 } else {
344 ++it;
345 }
Ian Rogers1d54e732013-05-02 21:10:01 -0700346 }
347}
348
349void ModUnionTableCardCache::Dump(std::ostream& os) {
350 CardTable* card_table = heap_->GetCardTable();
Ian Rogers1d54e732013-05-02 21:10:01 -0700351 os << "ModUnionTable dirty cards: [";
Ian Rogers13735952014-10-08 12:43:28 -0700352 for (const uint8_t* card_addr : cleared_cards_) {
Mathieu Chartier02e25112013-08-14 16:14:24 -0700353 auto start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
354 auto end = start + CardTable::kCardSize;
Mathieu Chartier590fee92013-09-13 13:46:47 -0700355 os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << "\n";
Ian Rogers1d54e732013-05-02 21:10:01 -0700356 }
357 os << "]";
358}
359
Mathieu Chartiere4cab172014-08-19 18:24:04 -0700360void ModUnionTableCardCache::SetCards() {
361 CardTable* card_table = heap_->GetCardTable();
Ian Rogers13735952014-10-08 12:43:28 -0700362 for (uint8_t* addr = space_->Begin(); addr < AlignUp(space_->End(), CardTable::kCardSize);
Mathieu Chartiere4cab172014-08-19 18:24:04 -0700363 addr += CardTable::kCardSize) {
364 cleared_cards_.insert(card_table->CardFromAddr(addr));
365 }
366}
367
368void ModUnionTableReferenceCache::SetCards() {
369}
370
Ian Rogers1d54e732013-05-02 21:10:01 -0700371} // namespace accounting
372} // namespace gc
373} // namespace art