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 | |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 19 | #include <memory> |
| 20 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 21 | #include "base/stl_util.h" |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 22 | #include "bitmap-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 23 | #include "card_table-inl.h" |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 24 | #include "gc/accounting/space_bitmap-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 25 | #include "gc/heap.h" |
Lei Li | 3befba4 | 2015-01-23 16:37:59 +0800 | [diff] [blame] | 26 | #include "gc/space/image_space.h" |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 27 | #include "gc/space/space.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 28 | #include "mirror/object-inl.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 29 | #include "space_bitmap-inl.h" |
| 30 | #include "thread.h" |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 31 | |
Brian Carlstrom | 3e3d591 | 2013-07-18 00:19:45 -0700 | [diff] [blame] | 32 | using ::art::mirror::Object; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 33 | |
| 34 | namespace art { |
| 35 | namespace gc { |
| 36 | namespace accounting { |
| 37 | |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 38 | class ModUnionAddToCardSetVisitor { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 39 | public: |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 40 | explicit ModUnionAddToCardSetVisitor(ModUnionTable::CardSet* const cleared_cards) |
| 41 | : cleared_cards_(cleared_cards) { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 42 | } |
| 43 | |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 44 | inline void operator()(uint8_t* card, uint8_t expected_value, |
| 45 | uint8_t new_value ATTRIBUTE_UNUSED) const { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 46 | if (expected_value == CardTable::kCardDirty) { |
| 47 | cleared_cards_->insert(card); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | private: |
Mathieu Chartier | 0a9dc05 | 2013-07-25 11:01:28 -0700 | [diff] [blame] | 52 | ModUnionTable::CardSet* const cleared_cards_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 55 | class ModUnionAddToCardBitmapVisitor { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 56 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 57 | ModUnionAddToCardBitmapVisitor(ModUnionTable::CardBitmap* bitmap, CardTable* card_table) |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 58 | : bitmap_(bitmap), card_table_(card_table) { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 59 | } |
| 60 | |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 61 | inline void operator()(uint8_t* card, uint8_t expected_value, |
| 62 | uint8_t new_value ATTRIBUTE_UNUSED) const { |
| 63 | if (expected_value == CardTable::kCardDirty) { |
| 64 | // We want the address the card represents, not the address of the card. |
| 65 | bitmap_->Set(reinterpret_cast<uintptr_t>(card_table_->AddrFromCard(card))); |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | private: |
| 70 | ModUnionTable::CardBitmap* const bitmap_; |
| 71 | CardTable* const card_table_; |
| 72 | }; |
| 73 | |
| 74 | class ModUnionAddToCardVectorVisitor { |
| 75 | public: |
| 76 | explicit ModUnionAddToCardVectorVisitor(std::vector<uint8_t*>* cleared_cards) |
| 77 | : cleared_cards_(cleared_cards) { |
| 78 | } |
| 79 | |
| 80 | void operator()(uint8_t* card, uint8_t expected_card, uint8_t new_card ATTRIBUTE_UNUSED) const { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 81 | if (expected_card == CardTable::kCardDirty) { |
| 82 | cleared_cards_->push_back(card); |
| 83 | } |
| 84 | } |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 85 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 86 | private: |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 87 | std::vector<uint8_t*>* const cleared_cards_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 88 | }; |
| 89 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 90 | class ModUnionUpdateObjectReferencesVisitor { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 91 | public: |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 92 | ModUnionUpdateObjectReferencesVisitor(MarkObjectVisitor* visitor, |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 93 | space::ContinuousSpace* from_space, |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 94 | space::ContinuousSpace* immune_space, |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 95 | bool* contains_reference_to_other_space) |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 96 | : visitor_(visitor), from_space_(from_space), immune_space_(immune_space), |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 97 | contains_reference_to_other_space_(contains_reference_to_other_space) { |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 98 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 99 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 100 | // Extra parameters are required since we use this same visitor signature for checking objects. |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 101 | void operator()(Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 102 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | d82e89e | 2015-08-05 10:10:07 -0700 | [diff] [blame] | 103 | MarkReference(obj->GetFieldObjectReferenceAddr(offset)); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 106 | void VisitRootIfNonNull(mirror::CompressedReference<mirror::Object>* root) const |
| 107 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | d82e89e | 2015-08-05 10:10:07 -0700 | [diff] [blame] | 108 | VisitRoot(root); |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | void VisitRoot(mirror::CompressedReference<mirror::Object>* root) const |
| 112 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | d82e89e | 2015-08-05 10:10:07 -0700 | [diff] [blame] | 113 | MarkReference(root); |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 116 | private: |
Mathieu Chartier | d82e89e | 2015-08-05 10:10:07 -0700 | [diff] [blame] | 117 | template<bool kPoisonReferences> |
| 118 | void MarkReference(mirror::ObjectReference<kPoisonReferences, mirror::Object>* obj_ptr) const |
| 119 | SHARED_REQUIRES(Locks::mutator_lock_) { |
| 120 | // Only add the reference if it is non null and fits our criteria. |
| 121 | mirror::Object* ref = obj_ptr->AsMirrorPtr(); |
| 122 | if (ref != nullptr && !from_space_->HasAddress(ref) && !immune_space_->HasAddress(ref)) { |
| 123 | *contains_reference_to_other_space_ = true; |
| 124 | mirror::Object* new_object = visitor_->MarkObject(ref); |
| 125 | if (ref != new_object) { |
| 126 | obj_ptr->Assign(new_object); |
| 127 | } |
| 128 | } |
| 129 | } |
| 130 | |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 131 | MarkObjectVisitor* const visitor_; |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 132 | // Space which we are scanning |
| 133 | space::ContinuousSpace* const from_space_; |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 134 | space::ContinuousSpace* const immune_space_; |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 135 | // Set if we have any references to another space. |
| 136 | bool* const contains_reference_to_other_space_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 139 | class ModUnionScanImageRootVisitor { |
| 140 | public: |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 141 | // Immune space is any other space which we don't care about references to. Currently this is |
| 142 | // the image space in the case of the zygote mod union table. |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 143 | ModUnionScanImageRootVisitor(MarkObjectVisitor* visitor, |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 144 | space::ContinuousSpace* from_space, |
| 145 | space::ContinuousSpace* immune_space, |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 146 | bool* contains_reference_to_other_space) |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 147 | : visitor_(visitor), from_space_(from_space), immune_space_(immune_space), |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 148 | contains_reference_to_other_space_(contains_reference_to_other_space) {} |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 149 | |
| 150 | void operator()(Object* root) const |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 151 | REQUIRES(Locks::heap_bitmap_lock_) |
| 152 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 153 | DCHECK(root != nullptr); |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 154 | ModUnionUpdateObjectReferencesVisitor ref_visitor(visitor_, from_space_, immune_space_, |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 155 | contains_reference_to_other_space_); |
Mathieu Chartier | 059ef3d | 2015-08-18 13:54:21 -0700 | [diff] [blame^] | 156 | root->VisitReferences(ref_visitor, VoidFunctor()); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 157 | } |
| 158 | |
| 159 | private: |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 160 | MarkObjectVisitor* const visitor_; |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 161 | // Space which we are scanning |
| 162 | space::ContinuousSpace* const from_space_; |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 163 | space::ContinuousSpace* const immune_space_; |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 164 | // Set if we have any references to another space. |
| 165 | bool* const contains_reference_to_other_space_; |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 166 | }; |
| 167 | |
| 168 | void ModUnionTableReferenceCache::ClearCards() { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 169 | CardTable* card_table = GetHeap()->GetCardTable(); |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 170 | ModUnionAddToCardSetVisitor visitor(&cleared_cards_); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 171 | // 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] | 172 | card_table->ModifyCardsAtomic(space_->Begin(), space_->End(), AgeCardVisitor(), visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | class AddToReferenceArrayVisitor { |
| 176 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 177 | AddToReferenceArrayVisitor(ModUnionTableReferenceCache* mod_union_table, |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 178 | MarkObjectVisitor* visitor, |
| 179 | std::vector<mirror::HeapReference<Object>*>* references, |
| 180 | bool* has_target_reference) |
| 181 | : mod_union_table_(mod_union_table), |
| 182 | visitor_(visitor), |
| 183 | references_(references), |
| 184 | has_target_reference_(has_target_reference) {} |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 185 | |
| 186 | // Extra parameters are required since we use this same visitor signature for checking objects. |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 187 | void operator()(Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 188 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 189 | mirror::HeapReference<Object>* ref_ptr = obj->GetFieldObjectReferenceAddr(offset); |
| 190 | mirror::Object* ref = ref_ptr->AsMirrorPtr(); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 191 | // Only add the reference if it is non null and fits our criteria. |
Mathieu Chartier | 4aeec17 | 2014-03-27 16:09:46 -0700 | [diff] [blame] | 192 | if (ref != nullptr && mod_union_table_->ShouldAddReference(ref)) { |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 193 | // Push the adddress of the reference. |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 194 | references_->push_back(ref_ptr); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 195 | } |
| 196 | } |
| 197 | |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 198 | void VisitRootIfNonNull(mirror::CompressedReference<mirror::Object>* root) const |
| 199 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 200 | if (!root->IsNull()) { |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 201 | VisitRoot(root); |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | void VisitRoot(mirror::CompressedReference<mirror::Object>* root) const |
| 206 | SHARED_REQUIRES(Locks::mutator_lock_) { |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 207 | if (mod_union_table_->ShouldAddReference(root->AsMirrorPtr())) { |
| 208 | *has_target_reference_ = true; |
| 209 | // TODO: Add MarkCompressedReference callback here. |
| 210 | root->Assign(visitor_->MarkObject(root->AsMirrorPtr())); |
| 211 | } |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 212 | } |
| 213 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 214 | private: |
| 215 | ModUnionTableReferenceCache* const mod_union_table_; |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 216 | MarkObjectVisitor* const visitor_; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 217 | std::vector<mirror::HeapReference<Object>*>* const references_; |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 218 | bool* const has_target_reference_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 219 | }; |
| 220 | |
| 221 | class ModUnionReferenceVisitor { |
| 222 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 223 | ModUnionReferenceVisitor(ModUnionTableReferenceCache* const mod_union_table, |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 224 | MarkObjectVisitor* visitor, |
| 225 | std::vector<mirror::HeapReference<Object>*>* references, |
| 226 | bool* has_target_reference) |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 227 | : mod_union_table_(mod_union_table), |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 228 | visitor_(visitor), |
| 229 | references_(references), |
| 230 | has_target_reference_(has_target_reference) {} |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 231 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 232 | void operator()(Object* obj) const |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 233 | SHARED_REQUIRES(Locks::heap_bitmap_lock_, Locks::mutator_lock_) { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 234 | // We don't have an early exit since we use the visitor pattern, an early |
| 235 | // exit should significantly speed this up. |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 236 | AddToReferenceArrayVisitor visitor(mod_union_table_, |
| 237 | visitor_, |
| 238 | references_, |
| 239 | has_target_reference_); |
Mathieu Chartier | 059ef3d | 2015-08-18 13:54:21 -0700 | [diff] [blame^] | 240 | obj->VisitReferences(visitor, VoidFunctor()); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 241 | } |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 242 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 243 | private: |
| 244 | ModUnionTableReferenceCache* const mod_union_table_; |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 245 | MarkObjectVisitor* const visitor_; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 246 | std::vector<mirror::HeapReference<Object>*>* const references_; |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 247 | bool* const has_target_reference_; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 248 | }; |
| 249 | |
| 250 | class CheckReferenceVisitor { |
| 251 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 252 | CheckReferenceVisitor(ModUnionTableReferenceCache* mod_union_table, |
| 253 | const std::set<const Object*>& references) |
| 254 | : mod_union_table_(mod_union_table), |
| 255 | references_(references) { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 256 | } |
| 257 | |
| 258 | // Extra parameters are required since we use this same visitor signature for checking objects. |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 259 | void operator()(Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 260 | SHARED_REQUIRES(Locks::heap_bitmap_lock_, Locks::mutator_lock_) { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 261 | mirror::Object* ref = obj->GetFieldObject<mirror::Object>(offset); |
Mathieu Chartier | 4aeec17 | 2014-03-27 16:09:46 -0700 | [diff] [blame] | 262 | if (ref != nullptr && mod_union_table_->ShouldAddReference(ref) && |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 263 | references_.find(ref) == references_.end()) { |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 264 | Heap* heap = mod_union_table_->GetHeap(); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 265 | space::ContinuousSpace* from_space = heap->FindContinuousSpaceFromObject(obj, false); |
| 266 | space::ContinuousSpace* to_space = heap->FindContinuousSpaceFromObject(ref, false); |
Mathieu Chartier | 407f702 | 2014-02-18 14:37:05 -0800 | [diff] [blame] | 267 | LOG(INFO) << "Object " << reinterpret_cast<const void*>(obj) << "(" << PrettyTypeOf(obj) |
| 268 | << ")" << "References " << reinterpret_cast<const void*>(ref) << "(" << PrettyTypeOf(ref) |
| 269 | << ") without being in mod-union table"; |
| 270 | LOG(INFO) << "FromSpace " << from_space->GetName() << " type " |
| 271 | << from_space->GetGcRetentionPolicy(); |
| 272 | LOG(INFO) << "ToSpace " << to_space->GetName() << " type " |
| 273 | << to_space->GetGcRetentionPolicy(); |
Mathieu Chartier | 4c13a3f | 2014-07-14 14:57:16 -0700 | [diff] [blame] | 274 | heap->DumpSpaces(LOG(INFO)); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 275 | LOG(FATAL) << "FATAL ERROR"; |
| 276 | } |
| 277 | } |
| 278 | |
Mathieu Chartier | da7c650 | 2015-07-23 16:01:26 -0700 | [diff] [blame] | 279 | void VisitRootIfNonNull(mirror::CompressedReference<mirror::Object>* root) const |
| 280 | SHARED_REQUIRES(Locks::mutator_lock_) { |
| 281 | if (kIsDebugBuild && !root->IsNull()) { |
| 282 | VisitRoot(root); |
| 283 | } |
| 284 | } |
| 285 | |
| 286 | void VisitRoot(mirror::CompressedReference<mirror::Object>* root) const |
| 287 | SHARED_REQUIRES(Locks::mutator_lock_) { |
| 288 | DCHECK(!mod_union_table_->ShouldAddReference(root->AsMirrorPtr())); |
| 289 | } |
| 290 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 291 | private: |
| 292 | ModUnionTableReferenceCache* const mod_union_table_; |
| 293 | const std::set<const Object*>& references_; |
| 294 | }; |
| 295 | |
| 296 | class ModUnionCheckReferences { |
| 297 | public: |
Roland Levillain | 3887c46 | 2015-08-12 18:15:42 +0100 | [diff] [blame] | 298 | ModUnionCheckReferences(ModUnionTableReferenceCache* mod_union_table, |
| 299 | const std::set<const Object*>& references) |
Mathieu Chartier | 9044347 | 2015-07-16 20:32:27 -0700 | [diff] [blame] | 300 | REQUIRES(Locks::heap_bitmap_lock_) |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 301 | : mod_union_table_(mod_union_table), references_(references) { |
| 302 | } |
| 303 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 304 | void operator()(Object* obj) const NO_THREAD_SAFETY_ANALYSIS { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 305 | Locks::heap_bitmap_lock_->AssertSharedHeld(Thread::Current()); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 306 | CheckReferenceVisitor visitor(mod_union_table_, references_); |
Mathieu Chartier | 059ef3d | 2015-08-18 13:54:21 -0700 | [diff] [blame^] | 307 | obj->VisitReferences(visitor, VoidFunctor()); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | private: |
| 311 | ModUnionTableReferenceCache* const mod_union_table_; |
| 312 | const std::set<const Object*>& references_; |
| 313 | }; |
| 314 | |
| 315 | void ModUnionTableReferenceCache::Verify() { |
| 316 | // Start by checking that everything in the mod union table is marked. |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 317 | for (const auto& ref_pair : references_) { |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 318 | for (mirror::HeapReference<Object>* ref : ref_pair.second) { |
| 319 | CHECK(heap_->IsLiveObjectLocked(ref->AsMirrorPtr())); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 320 | } |
| 321 | } |
| 322 | |
| 323 | // 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] | 324 | CardTable* card_table = heap_->GetCardTable(); |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 325 | ContinuousSpaceBitmap* live_bitmap = space_->GetLiveBitmap(); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 326 | for (const auto& ref_pair : references_) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 327 | const uint8_t* card = ref_pair.first; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 328 | if (*card == CardTable::kCardClean) { |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 329 | std::set<const Object*> reference_set; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 330 | for (mirror::HeapReference<Object>* obj_ptr : ref_pair.second) { |
| 331 | reference_set.insert(obj_ptr->AsMirrorPtr()); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 332 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 333 | ModUnionCheckReferences visitor(this, reference_set); |
| 334 | uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card)); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 335 | live_bitmap->VisitMarkedRange(start, start + CardTable::kCardSize, visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 336 | } |
| 337 | } |
| 338 | } |
| 339 | |
| 340 | void ModUnionTableReferenceCache::Dump(std::ostream& os) { |
| 341 | CardTable* card_table = heap_->GetCardTable(); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 342 | os << "ModUnionTable cleared cards: ["; |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 343 | for (uint8_t* card_addr : cleared_cards_) { |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 344 | uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr)); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 345 | uintptr_t end = start + CardTable::kCardSize; |
| 346 | os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << ","; |
| 347 | } |
| 348 | os << "]\nModUnionTable references: ["; |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 349 | for (const auto& ref_pair : references_) { |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 350 | const uint8_t* card_addr = ref_pair.first; |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 351 | uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr)); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 352 | uintptr_t end = start + CardTable::kCardSize; |
| 353 | os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << "->{"; |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 354 | for (mirror::HeapReference<Object>* ref : ref_pair.second) { |
| 355 | os << reinterpret_cast<const void*>(ref->AsMirrorPtr()) << ","; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 356 | } |
| 357 | os << "},"; |
| 358 | } |
| 359 | } |
| 360 | |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 361 | void ModUnionTableReferenceCache::UpdateAndMarkReferences(MarkObjectVisitor* visitor) { |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 362 | CardTable* const card_table = heap_->GetCardTable(); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 363 | std::vector<mirror::HeapReference<Object>*> cards_references; |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 364 | // If has_target_reference is true then there was a GcRoot compressed reference which wasn't |
| 365 | // added. In this case we need to keep the card dirty. |
| 366 | // We don't know if the GcRoot addresses will remain constant, for example, classloaders have a |
| 367 | // hash set of GcRoot which may be resized or modified. |
| 368 | bool has_target_reference; |
| 369 | ModUnionReferenceVisitor add_visitor(this, visitor, &cards_references, &has_target_reference); |
| 370 | CardSet new_cleared_cards; |
| 371 | for (uint8_t* card : cleared_cards_) { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 372 | // Clear and re-compute alloc space references associated with this card. |
| 373 | cards_references.clear(); |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 374 | has_target_reference = false; |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 375 | uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card)); |
| 376 | uintptr_t end = start + CardTable::kCardSize; |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 377 | space::ContinuousSpace* space = |
| 378 | heap_->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false); |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 379 | DCHECK(space != nullptr); |
Mathieu Chartier | a8e8f9c | 2014-04-09 14:51:05 -0700 | [diff] [blame] | 380 | ContinuousSpaceBitmap* live_bitmap = space->GetLiveBitmap(); |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 381 | live_bitmap->VisitMarkedRange(start, end, add_visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 382 | // Update the corresponding references for the card. |
Mathieu Chartier | 02e2511 | 2013-08-14 16:14:24 -0700 | [diff] [blame] | 383 | auto found = references_.find(card); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 384 | if (found == references_.end()) { |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 385 | // Don't add card for an empty reference array. |
| 386 | if (!cards_references.empty()) { |
| 387 | references_.Put(card, cards_references); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 388 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 389 | } else { |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 390 | if (cards_references.empty()) { |
| 391 | references_.erase(found); |
| 392 | } else { |
| 393 | found->second = cards_references; |
| 394 | } |
| 395 | } |
| 396 | if (has_target_reference) { |
| 397 | // Keep this card for next time since it contains a GcRoot which matches the |
| 398 | // ShouldAddReference criteria. This usually occurs for class loaders. |
| 399 | new_cleared_cards.insert(card); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 400 | } |
| 401 | } |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 402 | cleared_cards_ = std::move(new_cleared_cards); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 403 | size_t count = 0; |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 404 | for (auto it = references_.begin(); it != references_.end();) { |
| 405 | std::vector<mirror::HeapReference<Object>*>& references = it->second; |
| 406 | // Since there is no card mark for setting a reference to null, we check each reference. |
| 407 | // If all of the references of a card are null then we can remove that card. This is racy |
| 408 | // with the mutators, but handled by rescanning dirty cards. |
| 409 | bool all_null = true; |
| 410 | for (mirror::HeapReference<Object>* obj_ptr : references) { |
| 411 | if (obj_ptr->AsMirrorPtr() != nullptr) { |
| 412 | all_null = false; |
| 413 | visitor->MarkHeapReference(obj_ptr); |
| 414 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 415 | } |
Mathieu Chartier | a52f2f9 | 2015-08-16 14:37:04 -0700 | [diff] [blame] | 416 | count += references.size(); |
| 417 | if (!all_null) { |
| 418 | ++it; |
| 419 | } else { |
| 420 | // All null references, erase the array from the set. |
| 421 | it = references_.erase(it); |
| 422 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 423 | } |
| 424 | if (VLOG_IS_ON(heap)) { |
| 425 | VLOG(gc) << "Marked " << count << " references in mod union table"; |
| 426 | } |
| 427 | } |
| 428 | |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 429 | ModUnionTableCardCache::ModUnionTableCardCache(const std::string& name, Heap* heap, |
| 430 | space::ContinuousSpace* space) |
| 431 | : ModUnionTable(name, heap, space) { |
| 432 | // Normally here we could use End() instead of Limit(), but for testing we may want to have a |
| 433 | // mod-union table for a space which can still grow. |
| 434 | if (!space->IsImageSpace()) { |
| 435 | CHECK_ALIGNED(reinterpret_cast<uintptr_t>(space->Limit()), CardTable::kCardSize); |
| 436 | } |
| 437 | card_bitmap_.reset(CardBitmap::Create( |
| 438 | "mod union bitmap", reinterpret_cast<uintptr_t>(space->Begin()), |
| 439 | RoundUp(reinterpret_cast<uintptr_t>(space->Limit()), CardTable::kCardSize))); |
| 440 | } |
| 441 | |
| 442 | class CardBitVisitor { |
| 443 | public: |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 444 | CardBitVisitor(MarkObjectVisitor* visitor, space::ContinuousSpace* space, |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 445 | space::ContinuousSpace* immune_space, ModUnionTable::CardBitmap* card_bitmap) |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 446 | : visitor_(visitor), space_(space), immune_space_(immune_space), |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 447 | bitmap_(space->GetLiveBitmap()), card_bitmap_(card_bitmap) { |
| 448 | DCHECK(immune_space_ != nullptr); |
| 449 | } |
| 450 | |
| 451 | void operator()(size_t bit_index) const { |
| 452 | const uintptr_t start = card_bitmap_->AddrFromBitIndex(bit_index); |
| 453 | DCHECK(space_->HasAddress(reinterpret_cast<mirror::Object*>(start))) |
| 454 | << start << " " << *space_; |
| 455 | bool reference_to_other_space = false; |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 456 | ModUnionScanImageRootVisitor scan_visitor(visitor_, space_, immune_space_, |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 457 | &reference_to_other_space); |
| 458 | bitmap_->VisitMarkedRange(start, start + CardTable::kCardSize, scan_visitor); |
| 459 | if (!reference_to_other_space) { |
| 460 | // No non null reference to another space, clear the bit. |
| 461 | card_bitmap_->ClearBit(bit_index); |
| 462 | } |
| 463 | } |
| 464 | |
| 465 | private: |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 466 | MarkObjectVisitor* const visitor_; |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 467 | space::ContinuousSpace* const space_; |
| 468 | space::ContinuousSpace* const immune_space_; |
| 469 | ContinuousSpaceBitmap* const bitmap_; |
| 470 | ModUnionTable::CardBitmap* const card_bitmap_; |
| 471 | }; |
| 472 | |
Mathieu Chartier | 11409ae | 2013-09-23 11:49:36 -0700 | [diff] [blame] | 473 | void ModUnionTableCardCache::ClearCards() { |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 474 | CardTable* const card_table = GetHeap()->GetCardTable(); |
| 475 | ModUnionAddToCardBitmapVisitor visitor(card_bitmap_.get(), card_table); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 476 | // 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] | 477 | card_table->ModifyCardsAtomic(space_->Begin(), space_->End(), AgeCardVisitor(), visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 478 | } |
| 479 | |
| 480 | // Mark all references to the alloc space(s). |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 481 | void ModUnionTableCardCache::UpdateAndMarkReferences(MarkObjectVisitor* visitor) { |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 482 | auto* image_space = heap_->GetImageSpace(); |
| 483 | // If we don't have an image space, just pass in space_ as the immune space. Pass in the same |
| 484 | // space_ instead of image_space to avoid a null check in ModUnionUpdateObjectReferencesVisitor. |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 485 | CardBitVisitor bit_visitor(visitor, space_, image_space != nullptr ? image_space : space_, |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 486 | card_bitmap_.get()); |
| 487 | card_bitmap_->VisitSetBits( |
Mathieu Chartier | 9750995 | 2015-07-13 14:35:43 -0700 | [diff] [blame] | 488 | 0, RoundUp(space_->Size(), CardTable::kCardSize) / CardTable::kCardSize, bit_visitor); |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | void ModUnionTableCardCache::Dump(std::ostream& os) { |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 492 | os << "ModUnionTable dirty cards: ["; |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 493 | // TODO: Find cleaner way of doing this. |
| 494 | for (uint8_t* addr = space_->Begin(); addr < AlignUp(space_->End(), CardTable::kCardSize); |
| 495 | addr += CardTable::kCardSize) { |
| 496 | if (card_bitmap_->Test(reinterpret_cast<uintptr_t>(addr))) { |
| 497 | os << reinterpret_cast<void*>(addr) << "-" |
| 498 | << reinterpret_cast<void*>(addr + CardTable::kCardSize) << "\n"; |
| 499 | } |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 500 | } |
| 501 | os << "]"; |
| 502 | } |
| 503 | |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 504 | void ModUnionTableCardCache::SetCards() { |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 505 | // Only clean up to the end since there cannot be any objects past the End() of the space. |
Ian Rogers | 1373595 | 2014-10-08 12:43:28 -0700 | [diff] [blame] | 506 | for (uint8_t* addr = space_->Begin(); addr < AlignUp(space_->End(), CardTable::kCardSize); |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 507 | addr += CardTable::kCardSize) { |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 508 | card_bitmap_->Set(reinterpret_cast<uintptr_t>(addr)); |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 509 | } |
| 510 | } |
| 511 | |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 512 | bool ModUnionTableCardCache::ContainsCardFor(uintptr_t addr) { |
| 513 | return card_bitmap_->Test(addr); |
| 514 | } |
| 515 | |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 516 | void ModUnionTableReferenceCache::SetCards() { |
Mathieu Chartier | 4858a93 | 2015-01-23 13:18:53 -0800 | [diff] [blame] | 517 | for (uint8_t* addr = space_->Begin(); addr < AlignUp(space_->End(), CardTable::kCardSize); |
| 518 | addr += CardTable::kCardSize) { |
| 519 | cleared_cards_.insert(heap_->GetCardTable()->CardFromAddr(reinterpret_cast<void*>(addr))); |
| 520 | } |
| 521 | } |
| 522 | |
| 523 | bool ModUnionTableReferenceCache::ContainsCardFor(uintptr_t addr) { |
| 524 | auto* card_ptr = heap_->GetCardTable()->CardFromAddr(reinterpret_cast<void*>(addr)); |
| 525 | return cleared_cards_.find(card_ptr) != cleared_cards_.end() || |
| 526 | references_.find(card_ptr) != references_.end(); |
Mathieu Chartier | e4cab17 | 2014-08-19 18:24:04 -0700 | [diff] [blame] | 527 | } |
| 528 | |
Ian Rogers | 1d54e73 | 2013-05-02 21:10:01 -0700 | [diff] [blame] | 529 | } // namespace accounting |
| 530 | } // namespace gc |
| 531 | } // namespace art |