#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 {
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);
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.
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));
}
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());
}
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),
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)) {
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_;
};
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.
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);
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());
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()));
}
}
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);
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 << "},";
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
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);
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);
}
}
-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
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);
}