Additional heap verification for the Gc
There are now two verification booleans which can be enabled. When these get enabled, it verifies that each live object only references other live objects.
Changed SetClass to use SetFieldPtr to avoid having an extra card mark. This is safe since all classes are held live by the class linker.
Change-Id: I005bb59e5cc8153a79d3ccb3d7b5cabd29fb4051
diff --git a/src/mark_sweep.h b/src/mark_sweep.h
index db845b7..2333bdb 100644
--- a/src/mark_sweep.h
+++ b/src/mark_sweep.h
@@ -142,6 +142,21 @@
void SweepSystemWeaks(bool swap_bitmaps)
SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_);
+ template <typename Visitor>
+ static void VisitObjectReferences(const Object* obj, const Visitor& visitor)
+ SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
+ GlobalSynchronization::mutator_lock_) {
+ DCHECK(obj != NULL);
+ DCHECK(obj->GetClass() != NULL);
+ if (obj->IsClass()) {
+ VisitClassReferences(obj, visitor);
+ } else if (obj->IsArrayInstance()) {
+ VisitArrayReferences(obj, visitor);
+ } else {
+ VisitOtherReferences(obj, visitor);
+ }
+ }
+
private:
// Returns true if the object has its bit set in the mark bitmap.
bool IsMarked(const Object* object) const
@@ -200,28 +215,13 @@
SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
GlobalSynchronization::mutator_lock_);
- template <typename Visitor>
- void VisitObjectReferences(const Object* obj, const Visitor& visitor)
- SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
- GlobalSynchronization::mutator_lock_) {
- DCHECK(obj != NULL);
- DCHECK(obj->GetClass() != NULL);
- if (obj->IsClass()) {
- VisitClassReferences(obj, visitor);
- } else if (obj->IsArrayInstance()) {
- VisitArrayReferences(obj, visitor);
- } else {
- VisitOtherReferences(obj, visitor);
- }
- }
-
// Grays references in instance fields.
void ScanInstanceFields(const Object* obj)
EXCLUSIVE_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
template <typename Visitor>
- void VisitInstanceFieldsReferences(const Object* obj, const Visitor& visitor)
+ static void VisitInstanceFieldsReferences(const Object* obj, const Visitor& visitor)
SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_)
SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_) {
DCHECK(obj != NULL);
@@ -237,7 +237,7 @@
template <typename Visitor>
- void VisitClassReferences(const Object* obj, const Visitor& visitor)
+ static void VisitClassReferences(const Object* obj, const Visitor& visitor)
SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
GlobalSynchronization::mutator_lock_) {
VisitInstanceFieldsReferences(obj, visitor);
@@ -250,9 +250,9 @@
SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
template <typename Visitor>
- void VisitStaticFieldsReferences(const Class* klass, const Visitor& visitor)
+ static void VisitStaticFieldsReferences(const Class* klass, const Visitor& visitor)
SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
- GlobalSynchronization::mutator_lock_) {\
+ GlobalSynchronization::mutator_lock_) {
DCHECK(klass != NULL);
VisitFieldsReferences(klass, klass->GetReferenceStaticOffsets(), true, visitor);
}
@@ -263,7 +263,7 @@
SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
template <typename Visitor>
- void VisitFieldsReferences(const Object* obj, uint32_t ref_offsets, bool is_static,
+ static void VisitFieldsReferences(const Object* obj, uint32_t ref_offsets, bool is_static,
const Visitor& visitor)
SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
GlobalSynchronization::mutator_lock_) {
@@ -305,7 +305,7 @@
SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
template <typename Visitor>
- void VisitArrayReferences(const Object* obj, const Visitor& visitor)
+ static void VisitArrayReferences(const Object* obj, const Visitor& visitor)
SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
GlobalSynchronization::mutator_lock_) {
visitor(obj, obj->GetClass(), Object::ClassOffset(), false);
@@ -324,7 +324,7 @@
SHARED_LOCKS_REQUIRED(GlobalSynchronization::mutator_lock_);
template <typename Visitor>
- void VisitOtherReferences(const Object* obj, const Visitor& visitor)
+ static void VisitOtherReferences(const Object* obj, const Visitor& visitor)
SHARED_LOCKS_REQUIRED(GlobalSynchronization::heap_bitmap_lock_,
GlobalSynchronization::mutator_lock_) {
return VisitInstanceFieldsReferences(obj, visitor);