From 4e30541a92381fb280cd0be9a1763b713ee4d64c Mon Sep 17 00:00:00 2001 From: Mathieu Chartier Date: Wed, 19 Feb 2014 10:54:44 -0800 Subject: 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 --- runtime/stack.h | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) (limited to 'runtime/stack.h') diff --git a/runtime/stack.h b/runtime/stack.h index 7e9889e..6a62922 100644 --- a/runtime/stack.h +++ b/runtime/stack.h @@ -22,7 +22,9 @@ #include "base/casts.h" #include "base/macros.h" #include "arch/context.h" +#include "mirror/object.h" #include "mirror/object_reference.h" +#include "verify_object.h" #include #include @@ -213,26 +215,20 @@ class ShadowFrame { return *reinterpret_cast(vreg); } - template + template mirror::Object* GetVRegReference(size_t i) const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { DCHECK_LT(i, NumberOfVRegs()); + mirror::Object* ref; if (HasReferenceArray()) { - mirror::Object* ref = References()[i].AsMirrorPtr(); - if (kChecked) { - CHECK(VerifyReference(ref)) << "VReg " << i << "(" << ref - << ") is in protected space, reference array " << true; - } - return ref; + ref = References()[i].AsMirrorPtr(); } else { const uint32_t* vreg_ptr = &vregs_[i]; - mirror::Object* ref = - reinterpret_cast*>(vreg_ptr)->AsMirrorPtr(); - if (kChecked) { - CHECK(VerifyReference(ref)) << "VReg " << i - << "(" << ref << ") is in protected space, reference array " << false; - } - return ref; + ref = reinterpret_cast*>(vreg_ptr)->AsMirrorPtr(); } + if (kVerifyFlags & kVerifyReads) { + VerifyObject(ref); + } + return ref; } // Get view of vregs as range of consecutive arguments starting at i. @@ -290,10 +286,12 @@ class ShadowFrame { } } + template void SetVRegReference(size_t i, mirror::Object* val) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { DCHECK_LT(i, NumberOfVRegs()); - DCHECK(!kMovingCollector || VerifyReference(val)) - << "VReg " << i << "(" << val << ") is in protected space"; + if (kVerifyFlags & kVerifyWrites) { + VerifyObject(val); + } uint32_t* vreg = &vregs_[i]; reinterpret_cast*>(vreg)->Assign(val); if (HasReferenceArray()) { @@ -374,8 +372,6 @@ class ShadowFrame { return reinterpret_cast*>(vreg_end); } - bool VerifyReference(const mirror::Object* val) const; - StackReference* References() { return const_cast*>(const_cast(this)->References()); } -- cgit v1.1