Clean up mod union table
Fixed some formatting and removed unused forward declarations.
Bug: 19534862
Change-Id: Icfd5143e5bb7be0570248fd0f4bbf97125a9a35b
diff --git a/runtime/gc/accounting/mod_union_table-inl.h b/runtime/gc/accounting/mod_union_table-inl.h
index c756127..3a09634 100644
--- a/runtime/gc/accounting/mod_union_table-inl.h
+++ b/runtime/gc/accounting/mod_union_table-inl.h
@@ -28,7 +28,8 @@
// A mod-union table to record image references to the Zygote and alloc space.
class ModUnionTableToZygoteAllocspace : public ModUnionTableReferenceCache {
public:
- explicit ModUnionTableToZygoteAllocspace(const std::string& name, Heap* heap,
+ explicit ModUnionTableToZygoteAllocspace(const std::string& name,
+ Heap* heap,
space::ContinuousSpace* space)
: ModUnionTableReferenceCache(name, heap, space) {}
diff --git a/runtime/gc/accounting/mod_union_table.cc b/runtime/gc/accounting/mod_union_table.cc
index 5151819..1361f7b 100644
--- a/runtime/gc/accounting/mod_union_table.cc
+++ b/runtime/gc/accounting/mod_union_table.cc
@@ -27,9 +27,7 @@
#include "gc/space/space.h"
#include "mirror/object-inl.h"
#include "space_bitmap-inl.h"
-#include "thread.h"
-
-using ::art::mirror::Object;
+#include "thread-inl.h"
namespace art {
namespace gc {
@@ -38,10 +36,10 @@
class ModUnionAddToCardSetVisitor {
public:
explicit ModUnionAddToCardSetVisitor(ModUnionTable::CardSet* const cleared_cards)
- : cleared_cards_(cleared_cards) {
- }
+ : cleared_cards_(cleared_cards) {}
- inline void operator()(uint8_t* card, uint8_t expected_value,
+ inline void operator()(uint8_t* card,
+ uint8_t expected_value,
uint8_t new_value ATTRIBUTE_UNUSED) const {
if (expected_value == CardTable::kCardDirty) {
cleared_cards_->insert(card);
@@ -55,10 +53,10 @@
class ModUnionAddToCardBitmapVisitor {
public:
ModUnionAddToCardBitmapVisitor(ModUnionTable::CardBitmap* bitmap, CardTable* card_table)
- : bitmap_(bitmap), card_table_(card_table) {
- }
+ : bitmap_(bitmap), card_table_(card_table) {}
- inline void operator()(uint8_t* card, uint8_t expected_value,
+ inline void operator()(uint8_t* card,
+ uint8_t expected_value,
uint8_t new_value ATTRIBUTE_UNUSED) const {
if (expected_value == CardTable::kCardDirty) {
// We want the address the card represents, not the address of the card.
@@ -93,12 +91,13 @@
space::ContinuousSpace* from_space,
space::ContinuousSpace* immune_space,
bool* contains_reference_to_other_space)
- : visitor_(visitor), from_space_(from_space), immune_space_(immune_space),
- contains_reference_to_other_space_(contains_reference_to_other_space) {
- }
+ : visitor_(visitor),
+ from_space_(from_space),
+ immune_space_(immune_space),
+ contains_reference_to_other_space_(contains_reference_to_other_space) {}
// Extra parameters are required since we use this same visitor signature for checking objects.
- void operator()(Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const
+ void operator()(mirror::Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const
SHARED_REQUIRES(Locks::mutator_lock_) {
MarkReference(obj->GetFieldObjectReferenceAddr(offset));
}
@@ -144,14 +143,18 @@
space::ContinuousSpace* from_space,
space::ContinuousSpace* immune_space,
bool* contains_reference_to_other_space)
- : visitor_(visitor), from_space_(from_space), immune_space_(immune_space),
+ : visitor_(visitor),
+ from_space_(from_space),
+ immune_space_(immune_space),
contains_reference_to_other_space_(contains_reference_to_other_space) {}
- void operator()(Object* root) const
+ void operator()(mirror::Object* root) const
REQUIRES(Locks::heap_bitmap_lock_)
SHARED_REQUIRES(Locks::mutator_lock_) {
DCHECK(root != nullptr);
- ModUnionUpdateObjectReferencesVisitor ref_visitor(visitor_, from_space_, immune_space_,
+ ModUnionUpdateObjectReferencesVisitor ref_visitor(visitor_,
+ from_space_,
+ immune_space_,
contains_reference_to_other_space_);
root->VisitReferences(ref_visitor, VoidFunctor());
}
@@ -176,7 +179,7 @@
public:
AddToReferenceArrayVisitor(ModUnionTableReferenceCache* mod_union_table,
MarkObjectVisitor* visitor,
- std::vector<mirror::HeapReference<Object>*>* references,
+ std::vector<mirror::HeapReference<mirror::Object>*>* references,
bool* has_target_reference)
: mod_union_table_(mod_union_table),
visitor_(visitor),
@@ -184,9 +187,9 @@
has_target_reference_(has_target_reference) {}
// Extra parameters are required since we use this same visitor signature for checking objects.
- void operator()(Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const
+ void operator()(mirror::Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const
SHARED_REQUIRES(Locks::mutator_lock_) {
- mirror::HeapReference<Object>* ref_ptr = obj->GetFieldObjectReferenceAddr(offset);
+ mirror::HeapReference<mirror::Object>* ref_ptr = obj->GetFieldObjectReferenceAddr(offset);
mirror::Object* ref = ref_ptr->AsMirrorPtr();
// Only add the reference if it is non null and fits our criteria.
if (ref != nullptr && mod_union_table_->ShouldAddReference(ref)) {
@@ -214,7 +217,7 @@
private:
ModUnionTableReferenceCache* const mod_union_table_;
MarkObjectVisitor* const visitor_;
- std::vector<mirror::HeapReference<Object>*>* const references_;
+ std::vector<mirror::HeapReference<mirror::Object>*>* const references_;
bool* const has_target_reference_;
};
@@ -222,14 +225,14 @@
public:
ModUnionReferenceVisitor(ModUnionTableReferenceCache* const mod_union_table,
MarkObjectVisitor* visitor,
- std::vector<mirror::HeapReference<Object>*>* references,
+ std::vector<mirror::HeapReference<mirror::Object>*>* references,
bool* has_target_reference)
: mod_union_table_(mod_union_table),
visitor_(visitor),
references_(references),
has_target_reference_(has_target_reference) {}
- void operator()(Object* obj) const
+ void operator()(mirror::Object* obj) const
SHARED_REQUIRES(Locks::heap_bitmap_lock_, Locks::mutator_lock_) {
// We don't have an early exit since we use the visitor pattern, an early
// exit should significantly speed this up.
@@ -243,23 +246,23 @@
private:
ModUnionTableReferenceCache* const mod_union_table_;
MarkObjectVisitor* const visitor_;
- std::vector<mirror::HeapReference<Object>*>* const references_;
+ std::vector<mirror::HeapReference<mirror::Object>*>* const references_;
bool* const has_target_reference_;
};
class CheckReferenceVisitor {
public:
CheckReferenceVisitor(ModUnionTableReferenceCache* mod_union_table,
- const std::set<const Object*>& references)
+ const std::set<mirror::Object*>& references)
: mod_union_table_(mod_union_table),
- references_(references) {
- }
+ references_(references) {}
// Extra parameters are required since we use this same visitor signature for checking objects.
- void operator()(Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const
+ void operator()(mirror::Object* obj, MemberOffset offset, bool is_static ATTRIBUTE_UNUSED) const
SHARED_REQUIRES(Locks::heap_bitmap_lock_, Locks::mutator_lock_) {
mirror::Object* ref = obj->GetFieldObject<mirror::Object>(offset);
- if (ref != nullptr && mod_union_table_->ShouldAddReference(ref) &&
+ if (ref != nullptr &&
+ mod_union_table_->ShouldAddReference(ref) &&
references_.find(ref) == references_.end()) {
Heap* heap = mod_union_table_->GetHeap();
space::ContinuousSpace* from_space = heap->FindContinuousSpaceFromObject(obj, false);
@@ -290,18 +293,17 @@
private:
ModUnionTableReferenceCache* const mod_union_table_;
- const std::set<const Object*>& references_;
+ const std::set<mirror::Object*>& references_;
};
class ModUnionCheckReferences {
public:
ModUnionCheckReferences(ModUnionTableReferenceCache* mod_union_table,
- const std::set<const Object*>& references)
+ const std::set<mirror::Object*>& references)
REQUIRES(Locks::heap_bitmap_lock_)
- : mod_union_table_(mod_union_table), references_(references) {
- }
+ : mod_union_table_(mod_union_table), references_(references) {}
- void operator()(Object* obj) const NO_THREAD_SAFETY_ANALYSIS {
+ void operator()(mirror::Object* obj) const NO_THREAD_SAFETY_ANALYSIS {
Locks::heap_bitmap_lock_->AssertSharedHeld(Thread::Current());
CheckReferenceVisitor visitor(mod_union_table_, references_);
obj->VisitReferences(visitor, VoidFunctor());
@@ -309,13 +311,13 @@
private:
ModUnionTableReferenceCache* const mod_union_table_;
- const std::set<const Object*>& references_;
+ const std::set<mirror::Object*>& references_;
};
void ModUnionTableReferenceCache::Verify() {
// Start by checking that everything in the mod union table is marked.
for (const auto& ref_pair : references_) {
- for (mirror::HeapReference<Object>* ref : ref_pair.second) {
+ for (mirror::HeapReference<mirror::Object>* ref : ref_pair.second) {
CHECK(heap_->IsLiveObjectLocked(ref->AsMirrorPtr()));
}
}
@@ -326,8 +328,8 @@
for (const auto& ref_pair : references_) {
const uint8_t* card = ref_pair.first;
if (*card == CardTable::kCardClean) {
- std::set<const Object*> reference_set;
- for (mirror::HeapReference<Object>* obj_ptr : ref_pair.second) {
+ std::set<mirror::Object*> reference_set;
+ for (mirror::HeapReference<mirror::Object>* obj_ptr : ref_pair.second) {
reference_set.insert(obj_ptr->AsMirrorPtr());
}
ModUnionCheckReferences visitor(this, reference_set);
@@ -351,7 +353,7 @@
uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card_addr));
uintptr_t end = start + CardTable::kCardSize;
os << reinterpret_cast<void*>(start) << "-" << reinterpret_cast<void*>(end) << "->{";
- for (mirror::HeapReference<Object>* ref : ref_pair.second) {
+ for (mirror::HeapReference<mirror::Object>* ref : ref_pair.second) {
os << reinterpret_cast<const void*>(ref->AsMirrorPtr()) << ",";
}
os << "},";
@@ -360,7 +362,7 @@
void ModUnionTableReferenceCache::UpdateAndMarkReferences(MarkObjectVisitor* visitor) {
CardTable* const card_table = heap_->GetCardTable();
- std::vector<mirror::HeapReference<Object>*> cards_references;
+ std::vector<mirror::HeapReference<mirror::Object>*> cards_references;
// If has_target_reference is true then there was a GcRoot compressed reference which wasn't
// added. In this case we need to keep the card dirty.
// We don't know if the GcRoot addresses will remain constant, for example, classloaders have a
@@ -375,7 +377,7 @@
uintptr_t start = reinterpret_cast<uintptr_t>(card_table->AddrFromCard(card));
uintptr_t end = start + CardTable::kCardSize;
space::ContinuousSpace* space =
- heap_->FindContinuousSpaceFromObject(reinterpret_cast<Object*>(start), false);
+ heap_->FindContinuousSpaceFromObject(reinterpret_cast<mirror::Object*>(start), false);
DCHECK(space != nullptr);
ContinuousSpaceBitmap* live_bitmap = space->GetLiveBitmap();
live_bitmap->VisitMarkedRange(start, end, add_visitor);
@@ -402,12 +404,12 @@
cleared_cards_ = std::move(new_cleared_cards);
size_t count = 0;
for (auto it = references_.begin(); it != references_.end();) {
- std::vector<mirror::HeapReference<Object>*>& references = it->second;
+ std::vector<mirror::HeapReference<mirror::Object>*>& references = it->second;
// Since there is no card mark for setting a reference to null, we check each reference.
// If all of the references of a card are null then we can remove that card. This is racy
// with the mutators, but handled by rescanning dirty cards.
bool all_null = true;
- for (mirror::HeapReference<Object>* obj_ptr : references) {
+ for (mirror::HeapReference<mirror::Object>* obj_ptr : references) {
if (obj_ptr->AsMirrorPtr() != nullptr) {
all_null = false;
visitor->MarkHeapReference(obj_ptr);
@@ -426,7 +428,8 @@
}
}
-ModUnionTableCardCache::ModUnionTableCardCache(const std::string& name, Heap* heap,
+ModUnionTableCardCache::ModUnionTableCardCache(const std::string& name,
+ Heap* heap,
space::ContinuousSpace* space)
: ModUnionTable(name, heap, space) {
// Normally here we could use End() instead of Limit(), but for testing we may want to have a
@@ -441,10 +444,15 @@
class CardBitVisitor {
public:
- CardBitVisitor(MarkObjectVisitor* visitor, space::ContinuousSpace* space,
- space::ContinuousSpace* immune_space, ModUnionTable::CardBitmap* card_bitmap)
- : visitor_(visitor), space_(space), immune_space_(immune_space),
- bitmap_(space->GetLiveBitmap()), card_bitmap_(card_bitmap) {
+ CardBitVisitor(MarkObjectVisitor* visitor,
+ space::ContinuousSpace* space,
+ space::ContinuousSpace* immune_space,
+ ModUnionTable::CardBitmap* card_bitmap)
+ : visitor_(visitor),
+ space_(space),
+ immune_space_(immune_space),
+ bitmap_(space->GetLiveBitmap()),
+ card_bitmap_(card_bitmap) {
DCHECK(immune_space_ != nullptr);
}
diff --git a/runtime/gc/accounting/mod_union_table.h b/runtime/gc/accounting/mod_union_table.h
index 5888193..a7a4246 100644
--- a/runtime/gc/accounting/mod_union_table.h
+++ b/runtime/gc/accounting/mod_union_table.h
@@ -29,26 +29,17 @@
namespace art {
namespace mirror {
- class Object;
+class Object;
} // namespace mirror
namespace gc {
-
-namespace collector {
- class MarkSweep;
-} // namespace collector
namespace space {
class ContinuousSpace;
- class Space;
} // namespace space
-
class Heap;
namespace accounting {
-class Bitmap;
-class HeapBitmap;
-
// The mod-union table is the union of modified cards. It is used to allow the card table to be
// cleared between GC phases, reducing the number of dirty cards that need to be scanned.
class ModUnionTable {
@@ -60,8 +51,7 @@
explicit ModUnionTable(const std::string& name, Heap* heap, space::ContinuousSpace* space)
: name_(name),
heap_(heap),
- space_(space) {
- }
+ space_(space) {}
virtual ~ModUnionTable() {}
@@ -89,12 +79,15 @@
virtual bool ContainsCardFor(uintptr_t addr) = 0;
virtual void Dump(std::ostream& os) = 0;
+
space::ContinuousSpace* GetSpace() {
return space_;
}
+
Heap* GetHeap() const {
return heap_;
}
+
const std::string& GetName() const {
return name_;
}
@@ -111,6 +104,7 @@
explicit ModUnionTableReferenceCache(const std::string& name, Heap* heap,
space::ContinuousSpace* space)
: ModUnionTable(name, heap, space) {}
+
virtual ~ModUnionTableReferenceCache() {}
// Clear and store cards for a space.
@@ -151,6 +145,7 @@
// Note: There is assumption that the space End() doesn't change.
explicit ModUnionTableCardCache(const std::string& name, Heap* heap,
space::ContinuousSpace* space);
+
virtual ~ModUnionTableCardCache() {}
// Clear and store cards for a space.