Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 19 | #include "base/stl_util.h" |
| 20 | #include "card_table-inl.h" |
| 21 | #include "heap_bitmap.h" |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 22 | #include "gc/collector/mark_sweep.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 23 | #include "gc/collector/mark_sweep-inl.h" |
| 24 | #include "gc/heap.h" |
| 25 | #include "gc/space/space.h" |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 26 | #include "mirror/art_field-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 27 | #include "mirror/object-inl.h" |
| 28 | #include "mirror/class-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 29 | #include "mirror/object_array-inl.h" |
| 30 | #include "space_bitmap-inl.h" |
| 31 | #include "thread.h" |
| 32 | #include "UniquePtr.h" |
| 33 | |
Brian Carlstrom | 3e3d591 | 2013-07-18 00:19:45 -0700 | [diff] [blame] | 34 | using ::art::mirror::Object; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 35 | |
| 36 | namespace art { |
| 37 | namespace gc { |
| 38 | namespace accounting { |
| 39 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 40 | class ModUnionClearCardSetVisitor { |
| 41 | public: |
Mathieu Chartier | 0a9dc05 | 2013-07-25 11:01:28 -0700 | [diff] [blame] | 42 | explicit ModUnionClearCardSetVisitor(ModUnionTable::CardSet* const cleared_cards) |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 43 | : cleared_cards_(cleared_cards) { |
| 44 | } |
| 45 | |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 46 | inline void operator()(byte* card, byte expected_value, byte new_value) const { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 47 | if (expected_value == CardTable::kCardDirty) { |
| 48 | cleared_cards_->insert(card); |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | private: |
Mathieu Chartier | 0a9dc05 | 2013-07-25 11:01:28 -0700 | [diff] [blame] | 53 | ModUnionTable::CardSet* const cleared_cards_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 54 | }; |
| 55 | |
| 56 | class ModUnionClearCardVisitor { |
| 57 | public: |
| 58 | explicit ModUnionClearCardVisitor(std::vector<byte*>* cleared_cards) |
| 59 | : cleared_cards_(cleared_cards) { |
| 60 | } |
| 61 | |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 62 | void operator()(byte* card, byte expected_card, byte new_card) const { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 63 | if (expected_card == CardTable::kCardDirty) { |
| 64 | cleared_cards_->push_back(card); |
| 65 | } |
| 66 | } |
| 67 | private: |
| 68 | std::vector<byte*>* const cleared_cards_; |
| 69 | }; |
| 70 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 71 | class ModUnionUpdateObjectReferencesVisitor { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 72 | public: |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 73 | ModUnionUpdateObjectReferencesVisitor(RootVisitor visitor, void* arg) |
| 74 | : visitor_(visitor), |
| 75 | arg_(arg) { |
| 76 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 77 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 78 | // Extra parameters are required since we use this same visitor signature for checking objects. |
| 79 | void operator()(Object* obj, Object* ref, const MemberOffset& offset, |
| 80 | bool /* is_static */) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 81 | // Only add the reference if it is non null and fits our criteria. |
| 82 | if (ref != nullptr) { |
| 83 | Object* new_ref = visitor_(ref, arg_); |
| 84 | if (new_ref != ref) { |
| 85 | obj->SetFieldObject(offset, ref, false, true); |
| 86 | } |
| 87 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | private: |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 91 | RootVisitor* visitor_; |
| 92 | void* arg_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 93 | }; |
| 94 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 95 | class ModUnionScanImageRootVisitor { |
| 96 | public: |
| 97 | ModUnionScanImageRootVisitor(RootVisitor visitor, void* arg) |
| 98 | : visitor_(visitor), arg_(arg) {} |
| 99 | |
| 100 | void operator()(Object* root) const |
| 101 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) |
| 102 | SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { |
| 103 | DCHECK(root != NULL); |
| 104 | ModUnionUpdateObjectReferencesVisitor ref_visitor(visitor_, arg_); |
| 105 | collector::MarkSweep::VisitObjectReferences(root, ref_visitor, true); |
| 106 | } |
| 107 | |
| 108 | private: |
| 109 | RootVisitor* visitor_; |
| 110 | void* arg_; |
| 111 | }; |
| 112 | |
| 113 | void ModUnionTableReferenceCache::ClearCards() { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 114 | CardTable* card_table = GetHeap()->GetCardTable(); |
| 115 | ModUnionClearCardSetVisitor visitor(&cleared_cards_); |
| 116 | // Clear dirty cards in the this space and update the corresponding mod-union bits. |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 117 | card_table->ModifyCardsAtomic(space_->Begin(), space_->End(), AgeCardVisitor(), visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 118 | } |
| 119 | |
| 120 | class AddToReferenceArrayVisitor { |
| 121 | public: |
| 122 | explicit AddToReferenceArrayVisitor(ModUnionTableReferenceCache* mod_union_table, |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 123 | std::vector<Object**>* references) |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 124 | : mod_union_table_(mod_union_table), |
| 125 | references_(references) { |
| 126 | } |
| 127 | |
| 128 | // Extra parameters are required since we use this same visitor signature for checking objects. |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 129 | void operator()(Object* obj, Object* ref, const MemberOffset& offset, |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 130 | bool /* is_static */) const { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 131 | // Only add the reference if it is non null and fits our criteria. |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 132 | if (ref != nullptr && mod_union_table_->AddReference(obj, ref)) { |
| 133 | // Push the adddress of the reference. |
| 134 | references_->push_back(obj->GetFieldObjectAddr(offset)); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 135 | } |
| 136 | } |
| 137 | |
| 138 | private: |
| 139 | ModUnionTableReferenceCache* const mod_union_table_; |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 140 | std::vector<Object**>* const references_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 141 | }; |
| 142 | |
| 143 | class ModUnionReferenceVisitor { |
| 144 | public: |
| 145 | explicit ModUnionReferenceVisitor(ModUnionTableReferenceCache* const mod_union_table, |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 146 | std::vector<Object**>* references) |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 147 | : mod_union_table_(mod_union_table), |
| 148 | references_(references) { |
| 149 | } |
| 150 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 151 | void operator()(Object* obj) const |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 152 | SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_) { |
| 153 | DCHECK(obj != NULL); |
| 154 | // We don't have an early exit since we use the visitor pattern, an early |
| 155 | // exit should significantly speed this up. |
| 156 | AddToReferenceArrayVisitor visitor(mod_union_table_, references_); |
| 157 | collector::MarkSweep::VisitObjectReferences(obj, visitor); |
| 158 | } |
| 159 | private: |
| 160 | ModUnionTableReferenceCache* const mod_union_table_; |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 161 | std::vector<Object**>* const references_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
| 164 | class CheckReferenceVisitor { |
| 165 | public: |
| 166 | explicit CheckReferenceVisitor(ModUnionTableReferenceCache* mod_union_table, |
| 167 | const std::set<const Object*>& references) |
| 168 | : mod_union_table_(mod_union_table), |
| 169 | references_(references) { |
| 170 | } |
| 171 | |
| 172 | // Extra parameters are required since we use this same visitor signature for checking objects. |
| 173 | // TODO: Fixme when anotatalysis works with visitors. |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 174 | void operator()(const Object* obj, const Object* ref, |
| 175 | const MemberOffset& /* offset */, bool /* is_static */) const |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 176 | SHARED_LOCKS_REQUIRED(Locks::heap_bitmap_lock_, Locks::mutator_lock_) { |
| 177 | Heap* heap = mod_union_table_->GetHeap(); |
| 178 | if (ref != NULL && mod_union_table_->AddReference(obj, ref) && |
| 179 | references_.find(ref) == references_.end()) { |
| 180 | space::ContinuousSpace* from_space = heap->FindContinuousSpaceFromObject(obj, false); |
| 181 | space::ContinuousSpace* to_space = heap->FindContinuousSpaceFromObject(ref, false); |
| 182 | LOG(INFO) << "Object " << reinterpret_cast<const void*>(obj) << "(" << PrettyTypeOf(obj) << ")" |
| 183 | << "References " << reinterpret_cast<const void*>(ref) |
| 184 | << "(" << PrettyTypeOf(ref) << ") without being in mod-union table"; |
| 185 | LOG(INFO) << "FromSpace " << from_space->GetName() << " type " << from_space->GetGcRetentionPolicy(); |
| 186 | LOG(INFO) << "ToSpace " << to_space->GetName() << " type " << to_space->GetGcRetentionPolicy(); |
| 187 | mod_union_table_->GetHeap()->DumpSpaces(); |
| 188 | LOG(FATAL) << "FATAL ERROR"; |
| 189 | } |
| 190 | } |
| 191 | |
| 192 | private: |
| 193 | ModUnionTableReferenceCache* const mod_union_table_; |
| 194 | const std::set<const Object*>& references_; |
| 195 | }; |
| 196 | |
| 197 | class ModUnionCheckReferences { |
| 198 | public: |
Brian Carlstrom | df62950 | 2013-07-17 22:39:56 -0700 | [diff] [blame] | 199 | explicit ModUnionCheckReferences(ModUnionTableReferenceCache* mod_union_table, |
| 200 | const std::set<const Object*>& references) |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 201 | EXCLUSIVE_LOCKS_REQUIRED(Locks::heap_bitmap_lock_) |
| 202 | : mod_union_table_(mod_union_table), references_(references) { |
| 203 | } |
| 204 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 205 | void operator()(Object* obj) const NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 206 | Locks::heap_bitmap_lock_->AssertSharedHeld(Thread::Current()); |
| 207 | DCHECK(obj != NULL); |
| 208 | CheckReferenceVisitor visitor(mod_union_table_, references_); |
| 209 | collector::MarkSweep::VisitObjectReferences(obj, visitor); |
| 210 | } |
| 211 | |
| 212 | private: |
| 213 | ModUnionTableReferenceCache* const mod_union_table_; |
| 214 | const std::set<const Object*>& references_; |
| 215 | }; |
| 216 | |
| 217 | void ModUnionTableReferenceCache::Verify() { |
| 218 | // Start by checking that everything in the mod union table is marked. |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 219 | for (const auto& ref_pair : references_) { |
| 220 | for (Object** ref : ref_pair.second) { |
| 221 | CHECK(heap_->IsLiveObjectLocked(*ref)); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 222 | } |
| 223 | } |
| 224 | |
| 225 | // Check the references of each clean card which is also in the mod union table. |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 226 | CardTable* card_table = heap_->GetCardTable(); |
| 227 | SpaceBitmap* live_bitmap = space_->GetLiveBitmap(); |
| 228 | for (const auto& ref_pair : references_) { |
| 229 | const byte* card = ref_pair.first; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 230 | if (*card == CardTable::kCardClean) { |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 231 | std::set<const Object*> reference_set; |
| 232 | for (Object** obj_ptr : ref_pair.second) { |
| 233 | reference_set.insert(*obj_ptr); |
| 234 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 235 | ModUnionCheckReferences visitor(this, reference_set); |
| 236 | uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card)); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 237 | live_bitmap->VisitMarkedRange(start, start + CardTable::kCardSize, visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 238 | } |
| 239 | } |
| 240 | } |
| 241 | |
| 242 | void ModUnionTableReferenceCache::Dump(std::ostream& os) { |
| 243 | CardTable* card_table = heap_->GetCardTable(); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 244 | os << "ModUnionTable cleared cards: ["; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 245 | for (byte* card_addr : cleared_cards_) { |
| 246 | uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr)); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 247 | uintptr_t end = start + CardTable::kCardSize; |
| 248 | os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << ","; |
| 249 | } |
| 250 | os << "]\nModUnionTable references: ["; |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 251 | for (const auto& ref_pair : references_) { |
| 252 | const byte* card_addr = ref_pair.first; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 253 | uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr)); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 254 | uintptr_t end = start + CardTable::kCardSize; |
| 255 | os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << "->{"; |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 256 | for (Object** ref : ref_pair.second) { |
| 257 | os << reinterpret_cast<const void*>(*ref) << ","; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 258 | } |
| 259 | os << "},"; |
| 260 | } |
| 261 | } |
| 262 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 263 | void ModUnionTableReferenceCache::UpdateAndMarkReferences(RootVisitor visitor, void* arg) { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 264 | Heap* heap = GetHeap(); |
| 265 | CardTable* card_table = heap->GetCardTable(); |
| 266 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 267 | std::vector<Object**> cards_references; |
| 268 | ModUnionReferenceVisitor add_visitor(this, &cards_references); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 269 | |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 270 | for (const auto& card : cleared_cards_) { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 271 | // Clear and re-compute alloc space references associated with this card. |
| 272 | cards_references.clear(); |
| 273 | uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card)); |
| 274 | uintptr_t end = start + CardTable::kCardSize; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 275 | auto* space = heap->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false); |
| 276 | DCHECK(space != nullptr); |
| 277 | SpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 278 | live_bitmap->VisitMarkedRange(start, end, add_visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 279 | |
| 280 | // Update the corresponding references for the card. |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 281 | auto found = references_.find(card); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 282 | if (found == references_.end()) { |
| 283 | if (cards_references.empty()) { |
| 284 | // No reason to add empty array. |
| 285 | continue; |
| 286 | } |
| 287 | references_.Put(card, cards_references); |
| 288 | } else { |
| 289 | found->second = cards_references; |
| 290 | } |
| 291 | } |
| 292 | cleared_cards_.clear(); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 293 | size_t count = 0; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 294 | for (const auto& ref : references_) { |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 295 | for (const auto& obj_ptr : ref.second) { |
| 296 | Object* obj = *obj_ptr; |
| 297 | if (obj != nullptr) { |
| 298 | Object* new_obj = visitor(obj, arg); |
| 299 | // Avoid dirtying pages in the image unless necessary. |
| 300 | if (new_obj != obj) { |
| 301 | *obj_ptr = new_obj; |
| 302 | } |
| 303 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 304 | } |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 305 | count += ref.second.size(); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 306 | } |
| 307 | if (VLOG_IS_ON(heap)) { |
| 308 | VLOG(gc) << "Marked " << count << " references in mod union table"; |
| 309 | } |
| 310 | } |
| 311 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 312 | void ModUnionTableCardCache::ClearCards() { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 313 | CardTable* card_table = GetHeap()->GetCardTable(); |
| 314 | ModUnionClearCardSetVisitor visitor(&cleared_cards_); |
| 315 | // Clear dirty cards in the this space and update the corresponding mod-union bits. |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 316 | card_table->ModifyCardsAtomic(space_->Begin(), space_->End(), AgeCardVisitor(), visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 317 | } |
| 318 | |
| 319 | // Mark all references to the alloc space(s). |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 320 | void ModUnionTableCardCache::UpdateAndMarkReferences(RootVisitor visitor, void* arg) { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 321 | CardTable* card_table = heap_->GetCardTable(); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 322 | ModUnionScanImageRootVisitor scan_visitor(visitor, arg); |
| 323 | SpaceBitmap* bitmap = space_->GetLiveBitmap(); |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 324 | for (const byte* card_addr : cleared_cards_) { |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame^] | 325 | uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr)); |
| 326 | DCHECK(space_->HasAddress(reinterpret_cast<Object*>(start))); |
| 327 | bitmap->VisitMarkedRange(start, start + CardTable::kCardSize, scan_visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
| 331 | void ModUnionTableCardCache::Dump(std::ostream& os) { |
| 332 | CardTable* card_table = heap_->GetCardTable(); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 333 | os << "ModUnionTable dirty cards: ["; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 334 | for (const byte* card_addr : cleared_cards_) { |
| 335 | auto start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr)); |
| 336 | auto end = start + CardTable::kCardSize; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 337 | os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << ","; |
| 338 | } |
| 339 | os << "]"; |
| 340 | } |
| 341 | |
| 342 | } // namespace accounting |
| 343 | } // namespace gc |
| 344 | } // namespace art |