Fix and optimize verify object.
VerifyObject no longer resides in heap. You can now enable
VerifyObject for non-debug builds. VerifyStack is still slow, so it
is now guarded by its own flag.
Fixed the image writer to not use verification at places where
verification fails due to invalid reads.
Fixed RosAlloc to use SizeOf which doesn't call verify object.
Added a flag paremeter to some of the mirror getters / setters to
be able to selectively disable VerifyObject on certain calls.
Optimized the GC to not verify each object multiple times during
object scanning if verify object is enabled.
Added 3 verification options: verify reads, verify this, and verify
writes so that you can select how much verification you want for
mirror getters and setters.
Removed some useless DCHECKs which would slow debug builds without
providing any benefits.
TODO: RosAlloc verification doesn't currently work with verify
objects.
Bug: 12934910
Bug: 12879358
Change-Id: Ic61033104dfc334543f89b0fc0ad8cd4f4015d69
diff --git a/runtime/gc/heap.h b/runtime/gc/heap.h
index 21a2365..83202a5 100644
--- a/runtime/gc/heap.h
+++ b/runtime/gc/heap.h
@@ -37,6 +37,7 @@
#include "reference_queue.h"
#include "safe_map.h"
#include "thread_pool.h"
+#include "verify_object.h"
namespace art {
@@ -99,15 +100,6 @@
kAllocatorTypeLOS, // Large object space, also doesn't have entrypoints.
};
-// How we want to sanity check the heap's correctness.
-enum HeapVerificationMode {
- kHeapVerificationNotPermitted, // Too early in runtime start-up for heap to be verified.
- kNoHeapVerification, // Production default.
- kVerifyAllFast, // Sanity check all heap accesses with quick(er) tests.
- kVerifyAll // Sanity check all heap accesses.
-};
-static constexpr HeapVerificationMode kDesiredHeapVerification = kNoHeapVerification;
-
// If true, use rosalloc/RosAllocSpace instead of dlmalloc/DlMallocSpace
static constexpr bool kUseRosAlloc = true;
@@ -208,14 +200,9 @@
void ChangeCollector(CollectorType collector_type);
// The given reference is believed to be to an object in the Java heap, check the soundness of it.
- void VerifyObjectImpl(mirror::Object* o);
- void VerifyObject(mirror::Object* o) {
- if (o != nullptr && this != nullptr && verify_object_mode_ > kNoHeapVerification) {
- VerifyObjectImpl(o);
- }
- }
- // Check that c.getClass() == c.getClass().getClass().
- bool VerifyClassClass(const mirror::Class* c) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
+ // TODO: NO_THREAD_SAFETY_ANALYSIS since we call this everywhere and it is impossible to find a
+ // proper lock ordering for it.
+ void VerifyObjectBody(mirror::Object* o) NO_THREAD_SAFETY_ANALYSIS;
// Check sanity of all live references.
void VerifyHeap() LOCKS_EXCLUDED(Locks::heap_bitmap_lock_);
@@ -347,21 +334,20 @@
// Enable verification of object references when the runtime is sufficiently initialized.
void EnableObjectValidation() {
- verify_object_mode_ = kDesiredHeapVerification;
- if (verify_object_mode_ > kNoHeapVerification) {
+ verify_object_mode_ = kVerifyObjectSupport;
+ if (verify_object_mode_ > kVerifyObjectModeDisabled) {
VerifyHeap();
}
}
// Disable object reference verification for image writing.
void DisableObjectValidation() {
- verify_object_mode_ = kHeapVerificationNotPermitted;
+ verify_object_mode_ = kVerifyObjectModeDisabled;
}
// Other checks may be performed if we know the heap should be in a sane state.
bool IsObjectValidationEnabled() const {
- return kDesiredHeapVerification > kNoHeapVerification &&
- verify_object_mode_ > kHeapVerificationNotPermitted;
+ return verify_object_mode_ > kVerifyObjectModeDisabled;
}
// Returns true if low memory mode is enabled.
@@ -665,10 +651,6 @@
LOCKS_EXCLUDED(Locks::heap_bitmap_lock_);
void RemoveSpace(space::Space* space) LOCKS_EXCLUDED(Locks::heap_bitmap_lock_);
- // No thread saftey analysis since we call this everywhere and it is impossible to find a proper
- // lock ordering for it.
- void VerifyObjectBody(mirror::Object *obj) NO_THREAD_SAFETY_ANALYSIS;
-
static void VerificationCallback(mirror::Object* obj, void* arg)
SHARED_LOCKS_REQUIRED(GlobalSychronization::heap_bitmap_lock_);
@@ -916,7 +898,7 @@
AtomicInteger total_allocation_time_;
// The current state of heap verification, may be enabled or disabled.
- HeapVerificationMode verify_object_mode_;
+ VerifyObjectMode verify_object_mode_;
// Compacting GC disable count, prevents compacting GC from running iff > 0.
size_t disable_moving_gc_count_ GUARDED_BY(gc_complete_lock_);