diff options
author | Mathieu Chartier <mathieuc@google.com> | 2014-02-19 10:54:44 -0800 |
---|---|---|
committer | Mathieu Chartier <mathieuc@google.com> | 2014-02-21 15:24:04 -0800 |
commit | 4e30541a92381fb280cd0be9a1763b713ee4d64c (patch) | |
tree | 84093651bbf0ad95b66b846c4f4cf4101994037b /runtime/stack.h | |
parent | e266ba9935bd12d685d83f73cd8d759e46c3014d (diff) | |
download | art-4e30541a92381fb280cd0be9a1763b713ee4d64c.zip art-4e30541a92381fb280cd0be9a1763b713ee4d64c.tar.gz art-4e30541a92381fb280cd0be9a1763b713ee4d64c.tar.bz2 |
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
Diffstat (limited to 'runtime/stack.h')
-rw-r--r-- | runtime/stack.h | 32 |
1 files changed, 14 insertions, 18 deletions
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 <stdint.h> #include <string> @@ -213,26 +215,20 @@ class ShadowFrame { return *reinterpret_cast<unaligned_double*>(vreg); } - template <bool kChecked = false> + template<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> 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<const StackReference<mirror::Object>*>(vreg_ptr)->AsMirrorPtr(); - if (kChecked) { - CHECK(VerifyReference(ref)) << "VReg " << i - << "(" << ref << ") is in protected space, reference array " << false; - } - return ref; + ref = reinterpret_cast<const StackReference<mirror::Object>*>(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<VerifyObjectFlags kVerifyFlags = kDefaultVerifyFlags> 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<StackReference<mirror::Object>*>(vreg)->Assign(val); if (HasReferenceArray()) { @@ -374,8 +372,6 @@ class ShadowFrame { return reinterpret_cast<const StackReference<mirror::Object>*>(vreg_end); } - bool VerifyReference(const mirror::Object* val) const; - StackReference<mirror::Object>* References() { return const_cast<StackReference<mirror::Object>*>(const_cast<const ShadowFrame*>(this)->References()); } |