// If it is not a DexCache, visit all references.
mirror::Class* klass = object->GetClass();
if (klass != dex_cache_class_) {
- object->VisitReferences<false /* visit class */>(*this, *this);
+ object->VisitReferences(*this, *this);
}
}
}
}
FixupClassVisitor visitor(this, copy);
- static_cast<mirror::Object*>(orig)->VisitReferences<true /*visit class*/>(visitor, visitor);
+ static_cast<mirror::Object*>(orig)->VisitReferences(visitor, visitor);
}
void ImageWriter::FixupObject(Object* orig, Object* copy) {
down_cast<mirror::ClassLoader*>(copy)->SetClassTable(nullptr);
}
FixupVisitor visitor(this, copy);
- orig->VisitReferences<true /*visit class*/>(visitor, visitor);
+ orig->VisitReferences(visitor, visitor);
}
}
}
}
PatchOat::PatchVisitor visitor(this, copy);
- object->VisitReferences<true, kVerifyNone>(visitor, visitor);
+ object->VisitReferences<kVerifyNone>(visitor, visitor);
if (object->IsClass<kVerifyNone>()) {
auto* klass = object->AsClass();
auto* copy_klass = down_cast<mirror::Class*>(copy);
DCHECK(root != nullptr);
ModUnionUpdateObjectReferencesVisitor ref_visitor(visitor_, from_space_, immune_space_,
contains_reference_to_other_space_);
- root->VisitReferences<kMovingClasses>(ref_visitor, VoidFunctor());
+ root->VisitReferences(ref_visitor, VoidFunctor());
}
private:
visitor_,
references_,
has_target_reference_);
- obj->VisitReferences<kMovingClasses>(visitor, VoidFunctor());
+ obj->VisitReferences(visitor, VoidFunctor());
}
private:
void operator()(Object* obj) const NO_THREAD_SAFETY_ANALYSIS {
Locks::heap_bitmap_lock_->AssertSharedHeld(Thread::Current());
CheckReferenceVisitor visitor(mod_union_table_, references_);
- obj->VisitReferences<kMovingClasses>(visitor, VoidFunctor());
+ obj->VisitReferences(visitor, VoidFunctor());
}
private:
SHARED_REQUIRES(Locks::mutator_lock_) {
RememberedSetReferenceVisitor visitor(target_space_, contains_reference_to_target_space_,
collector_);
- obj->VisitReferences<kMovingClasses>(visitor, visitor);
+ obj->VisitReferences(visitor, visitor);
}
private:
space::RegionSpace* region_space = collector->RegionSpace();
CHECK(!region_space->IsInFromSpace(obj)) << "Scanning object " << obj << " in from space";
ConcurrentCopyingVerifyNoFromSpaceRefsFieldVisitor visitor(collector);
- obj->VisitReferences<true>(visitor, visitor);
+ obj->VisitReferences(visitor, visitor);
if (kUseBakerReadBarrier) {
if (collector->RegionSpace()->IsInToSpace(obj)) {
CHECK(obj->GetReadBarrierPointer() == nullptr)
CHECK(!region_space->IsInFromSpace(obj)) << "Scanning object " << obj << " in from space";
collector->AssertToSpaceInvariant(nullptr, MemberOffset(0), obj);
ConcurrentCopyingAssertToSpaceInvariantFieldVisitor visitor(collector);
- obj->VisitReferences<true>(visitor, visitor);
+ obj->VisitReferences(visitor, visitor);
}
private:
void ConcurrentCopying::Scan(mirror::Object* to_ref) {
DCHECK(!region_space_->IsInFromSpace(to_ref));
ConcurrentCopyingRefFieldsVisitor visitor(this);
- to_ref->VisitReferences<true>(visitor, visitor);
+ to_ref->VisitReferences(visitor, visitor);
}
// Process a field.
void MarkCompact::UpdateObjectReferences(mirror::Object* obj) {
UpdateReferenceVisitor visitor(this);
- obj->VisitReferences<kMovingClasses>(visitor, visitor);
+ obj->VisitReferences(visitor, visitor);
}
inline mirror::Object* MarkCompact::GetMarkedForwardAddress(mirror::Object* obj) {
// Visit all of the references of an object and update.
void MarkCompact::ScanObject(mirror::Object* obj) {
MarkCompactMarkObjectVisitor visitor(this);
- obj->VisitReferences<kMovingClasses>(visitor, visitor);
+ obj->VisitReferences(visitor, visitor);
}
// Scan anything that's on the mark stack.
inline void MarkSweep::ScanObjectVisit(mirror::Object* obj, const MarkVisitor& visitor,
const ReferenceVisitor& ref_visitor) {
DCHECK(IsMarked(obj)) << "Scanning unmarked object " << obj << "\n" << heap_->DumpSpaces();
- obj->VisitReferences<false>(visitor, ref_visitor);
+ obj->VisitReferences(visitor, ref_visitor);
if (kCountScannedTypes) {
mirror::Class* klass = obj->GetClass<kVerifyNone>();
if (UNLIKELY(klass == mirror::Class::GetJavaLangClass())) {
void SemiSpace::VerifyNoFromSpaceReferences(Object* obj) {
DCHECK(!from_space_->HasAddress(obj)) << "Scanning object " << obj << " in from space";
SemiSpaceVerifyNoFromSpaceReferencesVisitor visitor(from_space_);
- obj->VisitReferences<kMovingClasses>(visitor, VoidFunctor());
+ obj->VisitReferences(visitor, VoidFunctor());
}
class SemiSpaceVerifyNoFromSpaceReferencesObjectVisitor {
void SemiSpace::ScanObject(Object* obj) {
DCHECK(!from_space_->HasAddress(obj)) << "Scanning object " << obj << " in from space";
SemiSpaceMarkObjectVisitor visitor(this);
- obj->VisitReferences<kMovingClasses>(visitor, visitor);
+ obj->VisitReferences(visitor, visitor);
}
// Scan anything that's on the mark stack.
// TODO: Fix lock analysis to not use NO_THREAD_SAFETY_ANALYSIS, requires support for
// annotalysis on visitors.
void operator()(mirror::Object* o) const NO_THREAD_SAFETY_ANALYSIS {
- o->VisitReferences<true>(*this, VoidFunctor());
+ o->VisitReferences(*this, VoidFunctor());
}
// For Object::VisitReferences.
// be live or else how did we find it in the live bitmap?
VerifyReferenceVisitor visitor(heap_, fail_count_, verify_referent_);
// The class doesn't count as a reference but we should verify it anyways.
- obj->VisitReferences<true>(visitor, visitor);
+ obj->VisitReferences(visitor, visitor);
}
static void VisitCallback(mirror::Object* obj, void* arg)
void operator()(mirror::Object* obj) const
SHARED_REQUIRES(Locks::mutator_lock_, Locks::heap_bitmap_lock_) {
VerifyReferenceCardVisitor visitor(heap_, const_cast<bool*>(&failed_));
- obj->VisitReferences<true>(visitor, VoidFunctor());
+ obj->VisitReferences(visitor, VoidFunctor());
}
bool Failed() const {
}
GcRootVisitor visitor(this);
- obj->VisitReferences<true>(visitor, VoidFunctor());
+ obj->VisitReferences(visitor, VoidFunctor());
gc::Heap* const heap = Runtime::Current()->GetHeap();
const gc::space::ContinuousSpace* const space = heap->FindContinuousSpaceFromObject(obj, true);
return size;
}
-template <bool kVisitClass, typename Visitor>
+template <typename Visitor>
inline void Class::VisitReferences(mirror::Class* klass, const Visitor& visitor) {
- VisitInstanceFieldsReferences<kVisitClass>(klass, visitor);
+ VisitInstanceFieldsReferences(klass, visitor);
// Right after a class is allocated, but not yet loaded
// (kStatusNotReady, see ClassLinker::LoadClass()), GC may find it
// and scan it. IsTemp() may call Class::GetAccessFlags() but may
// Temp classes don't ever populate imt/vtable or static fields and they are not even
// allocated with the right size for those. Also, unresolved classes don't have fields
// linked yet.
- VisitStaticFieldsReferences<kVisitClass>(this, visitor);
+ VisitStaticFieldsReferences(this, visitor);
}
// Since this class is reachable, we must also visit the associated roots when we scan it.
VisitNativeRoots(visitor, Runtime::Current()->GetClassLinker()->GetImagePointerSize());
h_new_class_obj->SetClassSize(new_length_);
// Visit all of the references to make sure there is no from space references in the native
// roots.
- h_new_class_obj->VisitReferences<true>(h_new_class_obj->GetClass(),
- ReadBarrierOnNativeRootsVisitor());
+ static_cast<mirror::Object*>(h_new_class_obj.Get())->VisitReferences(
+ ReadBarrierOnNativeRootsVisitor(), VoidFunctor());
}
private:
void SetPreverifiedFlagOnAllMethods(size_t pointer_size)
SHARED_REQUIRES(Locks::mutator_lock_);
- template <bool kVisitClass, typename Visitor>
- void VisitReferences(mirror::Class* klass, const Visitor& visitor)
- SHARED_REQUIRES(Locks::mutator_lock_);
-
// Get the descriptor of the class. In a few cases a std::string is required, rather than
// always create one the storage argument is populated and its internal c_str() returned. We do
// this to avoid memory allocation in the common case.
static MemberOffset EmbeddedImTableOffset(size_t pointer_size);
static MemberOffset EmbeddedVTableOffset(size_t pointer_size);
+ template <typename Visitor>
+ void VisitReferences(mirror::Class* klass, const Visitor& visitor)
+ SHARED_REQUIRES(Locks::mutator_lock_);
+
// Defining class loader, or null for the "bootstrap" system loader.
HeapReference<ClassLoader> class_loader_;
static GcRoot<Class> java_lang_Class_;
friend struct art::ClassOffsets; // for verifying offset information
+ friend class Object; // For VisitReferences
DISALLOW_IMPLICIT_CONSTRUCTORS(Class);
};
namespace art {
namespace mirror {
-template <const bool kVisitClass, VerifyObjectFlags kVerifyFlags, typename Visitor>
+template <VerifyObjectFlags kVerifyFlags, typename Visitor>
inline void ClassLoader::VisitReferences(mirror::Class* klass, const Visitor& visitor) {
// Visit instance fields first.
- VisitInstanceFieldsReferences<kVisitClass>(klass, visitor);
+ VisitInstanceFieldsReferences(klass, visitor);
// Visit classes loaded after.
ReaderMutexLock mu(Thread::Current(), *Locks::classlinker_classes_lock_);
ClassTable* const class_table = GetClassTable();
SetField64<false>(OFFSET_OF_OBJECT_MEMBER(ClassLoader, class_table_),
reinterpret_cast<uint64_t>(class_table));
}
+
+ private:
// Visit instance fields of the class loader as well as its associated classes.
// Null class loader is handled by ClassLinker::VisitClassRoots.
- template <const bool kVisitClass, VerifyObjectFlags kVerifyFlags, typename Visitor>
+ template <VerifyObjectFlags kVerifyFlags, typename Visitor>
void VisitReferences(mirror::Class* klass, const Visitor& visitor)
SHARED_REQUIRES(Locks::mutator_lock_)
REQUIRES(!Locks::classlinker_classes_lock_);
- private:
// Field order required by test "ValidateFieldOrderOfJavaCppUnionClasses".
HeapReference<Object> packages_;
HeapReference<ClassLoader> parent_;
uint64_t class_table_;
friend struct art::ClassLoaderOffsets; // for verifying offset information
+ friend class Object; // For VisitReferences
DISALLOW_IMPLICIT_CONSTRUCTORS(ClassLoader);
};
return success;
}
-template<bool kVisitClass, bool kIsStatic, typename Visitor>
+template<bool kIsStatic, typename Visitor>
inline void Object::VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) {
if (!kIsStatic && (ref_offsets != mirror::Class::kClassWalkSuper)) {
// Instance fields and not the slow-path.
- if (kVisitClass) {
- visitor(this, ClassOffset(), kIsStatic);
- }
uint32_t field_offset = mirror::kObjectHeaderSize;
while (ref_offsets != 0) {
if ((ref_offsets & 1) != 0) {
? klass->GetFirstReferenceStaticFieldOffset(
Runtime::Current()->GetClassLinker()->GetImagePointerSize())
: klass->GetFirstReferenceInstanceFieldOffset();
- for (size_t i = 0; i < num_reference_fields; ++i) {
+ for (size_t i = 0u; i < num_reference_fields; ++i) {
// TODO: Do a simpler check?
- if (kVisitClass || field_offset.Uint32Value() != ClassOffset().Uint32Value()) {
+ if (field_offset.Uint32Value() != ClassOffset().Uint32Value()) {
visitor(this, field_offset, kIsStatic);
}
field_offset = MemberOffset(field_offset.Uint32Value() +
}
}
-template<bool kVisitClass, typename Visitor>
+template<typename Visitor>
inline void Object::VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) {
- VisitFieldsReferences<kVisitClass, false>(
- klass->GetReferenceInstanceOffsets<kVerifyNone>(), visitor);
+ VisitFieldsReferences<false>(klass->GetReferenceInstanceOffsets<kVerifyNone>(), visitor);
}
-template<bool kVisitClass, typename Visitor>
+template<typename Visitor>
inline void Object::VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) {
DCHECK(!klass->IsTemp());
- klass->VisitFieldsReferences<kVisitClass, true>(0, visitor);
+ klass->VisitFieldsReferences<true>(0, visitor);
}
-
template<VerifyObjectFlags kVerifyFlags>
inline bool Object::IsClassLoader() {
return GetClass<kVerifyFlags>()->IsClassLoaderClass();
return down_cast<mirror::ClassLoader*>(this);
}
-template <const bool kVisitClass, VerifyObjectFlags kVerifyFlags, typename Visitor,
- typename JavaLangRefVisitor>
+template <VerifyObjectFlags kVerifyFlags, typename Visitor, typename JavaLangRefVisitor>
inline void Object::VisitReferences(const Visitor& visitor,
const JavaLangRefVisitor& ref_visitor) {
mirror::Class* klass = GetClass<kVerifyFlags>();
+ visitor(this, ClassOffset(), false);
if (klass == Class::GetJavaLangClass()) {
- AsClass<kVerifyNone>()->VisitReferences<kVisitClass>(klass, visitor);
+ AsClass<kVerifyNone>()->VisitReferences(klass, visitor);
} else if (klass->IsArrayClass() || klass->IsStringClass()) {
if (klass->IsObjectArrayClass<kVerifyNone>()) {
- AsObjectArray<mirror::Object, kVerifyNone>()->VisitReferences<kVisitClass>(visitor);
- } else if (kVisitClass) {
- visitor(this, ClassOffset(), false);
+ AsObjectArray<mirror::Object, kVerifyNone>()->VisitReferences(visitor);
}
} else if (klass->IsClassLoaderClass()) {
mirror::ClassLoader* class_loader = AsClassLoader<kVerifyFlags>();
- class_loader->VisitReferences<kVisitClass, kVerifyFlags>(klass, visitor);
+ class_loader->VisitReferences<kVerifyFlags>(klass, visitor);
} else {
DCHECK(!klass->IsVariableSize());
- VisitInstanceFieldsReferences<kVisitClass>(klass, visitor);
+ VisitInstanceFieldsReferences(klass, visitor);
if (UNLIKELY(klass->IsTypeOfReferenceClass<kVerifyNone>())) {
ref_visitor(klass, AsReference());
}
// object above, copy references fields one by one again with a
// RB. TODO: Optimize this later?
CopyReferenceFieldsWithReadBarrierVisitor visitor(dest);
- src->VisitReferences<true>(visitor, visitor);
+ src->VisitReferences(visitor, visitor);
}
gc::Heap* heap = Runtime::Current()->GetHeap();
// Perform write barriers on copied object references.
}
// TODO fix thread safety analysis broken by the use of template. This should be
// SHARED_REQUIRES(Locks::mutator_lock_).
- template <const bool kVisitClass, VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
- typename Visitor, typename JavaLangRefVisitor = VoidFunctor>
+ template <VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags,
+ typename Visitor,
+ typename JavaLangRefVisitor = VoidFunctor>
void VisitReferences(const Visitor& visitor, const JavaLangRefVisitor& ref_visitor)
NO_THREAD_SAFETY_ANALYSIS;
}
// TODO: Fixme when anotatalysis works with visitors.
- template<bool kVisitClass, bool kIsStatic, typename Visitor>
+ template<bool kIsStatic, typename Visitor>
void VisitFieldsReferences(uint32_t ref_offsets, const Visitor& visitor) HOT_ATTR
NO_THREAD_SAFETY_ANALYSIS;
- template<bool kVisitClass, typename Visitor>
+ template<typename Visitor>
void VisitInstanceFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
SHARED_REQUIRES(Locks::mutator_lock_);
- template<bool kVisitClass, typename Visitor>
+ template<typename Visitor>
void VisitStaticFieldsReferences(mirror::Class* klass, const Visitor& visitor) HOT_ATTR
SHARED_REQUIRES(Locks::mutator_lock_);
(i * sizeof(HeapReference<Object>)));
}
-template<class T> template<const bool kVisitClass, typename Visitor>
+template<class T> template<typename Visitor>
void ObjectArray<T>::VisitReferences(const Visitor& visitor) {
- if (kVisitClass) {
- visitor(this, ClassOffset(), false);
- }
const size_t length = static_cast<size_t>(GetLength());
for (size_t i = 0; i < length; ++i) {
visitor(this, OffsetOfElement(i), false);
ObjectArray<T>* CopyOf(Thread* self, int32_t new_length)
SHARED_REQUIRES(Locks::mutator_lock_) REQUIRES(!Roles::uninterruptible_);
+ static MemberOffset OffsetOfElement(int32_t i);
+
+ private:
// TODO fix thread safety analysis broken by the use of template. This should be
// SHARED_REQUIRES(Locks::mutator_lock_).
- template<const bool kVisitClass, typename Visitor>
+ template<typename Visitor>
void VisitReferences(const Visitor& visitor) NO_THREAD_SAFETY_ANALYSIS;
- static MemberOffset OffsetOfElement(int32_t i);
-
- private:
+ friend class Object; // For VisitReferences
DISALLOW_IMPLICIT_CONSTRUCTORS(ObjectArray);
};