Fix object verification.

Refactor VERIFY_OBJECT_ENABLED to become less brittle to change enum and global
constant.

Change-Id: Ie405106be81dce9a913730c7f46a5659582fa18b
diff --git a/src/mirror/dex_cache_test.cc b/src/mirror/dex_cache_test.cc
index 9817660..3d753e1 100644
--- a/src/mirror/dex_cache_test.cc
+++ b/src/mirror/dex_cache_test.cc
@@ -19,6 +19,7 @@
 #include "dex_cache.h"
 #include "heap.h"
 #include "mirror/object_array-inl.h"
+#include "mirror/object-inl.h"
 #include "sirt_ref.h"
 
 #include <stdio.h>
diff --git a/src/mirror/object-inl.h b/src/mirror/object-inl.h
index b6c8008..3913c81 100644
--- a/src/mirror/object-inl.h
+++ b/src/mirror/object-inl.h
@@ -263,6 +263,10 @@
   Runtime::Current()->GetHeap()->WriteBarrierField(dst, field_offset, new_value);
 }
 
+inline void Object::VerifyObject(const Object* obj) {
+  Runtime::Current()->GetHeap()->VerifyObject(obj);
+}
+
 }  // namespace mirror
 }  // namespace art
 
diff --git a/src/mirror/object.cc b/src/mirror/object.cc
index 5c65b83..4acb567 100644
--- a/src/mirror/object.cc
+++ b/src/mirror/object.cc
@@ -19,13 +19,15 @@
 #include "array-inl.h"
 #include "class.h"
 #include "class-inl.h"
+#include "class_linker-inl.h"
 #include "field.h"
 #include "field-inl.h"
 #include "gc/card_table-inl.h"
 #include "heap.h"
+#include "iftable-inl.h"
 #include "monitor.h"
 #include "object-inl.h"
-#include "object_array.h"
+#include "object_array-inl.h"
 #include "object_utils.h"
 #include "runtime.h"
 #include "sirt_ref.h"
@@ -80,8 +82,7 @@
   return copy.get();
 }
 
-#if VERIFY_OBJECT_ENABLED
-void Object::CheckFieldAssignment(MemberOffset field_offset, const Object* new_value) {
+void Object::CheckFieldAssignmentImpl(MemberOffset field_offset, const Object* new_value) {
   const Class* c = GetClass();
   if (Runtime::Current()->GetClassLinker() == NULL ||
       !Runtime::Current()->GetHeap()->IsObjectValidationEnabled() ||
@@ -123,7 +124,6 @@
   LOG(FATAL) << "Failed to find field for assignment to " << reinterpret_cast<void*>(this)
       << " of type " << PrettyDescriptor(c) << " at offset " << field_offset;
 }
-#endif
 
 }  // namespace mirror
 }  // namespace art
diff --git a/src/mirror/object.h b/src/mirror/object.h
index c404b61..0cce8d8 100644
--- a/src/mirror/object.h
+++ b/src/mirror/object.h
@@ -58,6 +58,8 @@
 #define OFFSET_OF_OBJECT_MEMBER(type, field) \
     MemberOffset(OFFSETOF_MEMBER(type, field))
 
+const bool kCheckFieldAssignments = false;
+
 // C++ mirror of java.lang.Object
 class MANAGED Object {
  public:
@@ -231,15 +233,17 @@
   }
 
  private:
-#if VERIFY_OBJECT_ENABLED
   static void VerifyObject(const Object* obj);
-  void CheckFieldAssignment(MemberOffset field_offset, const Object* new_value)
+
+  // Verify the type correctness of stores to fields.
+  void CheckFieldAssignmentImpl(MemberOffset field_offset, const Object* new_value)
       SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-#else
-  static void VerifyObject(const Object*) {}
-  void CheckFieldAssignment(MemberOffset, const Object*)
-      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {}
-#endif
+  void CheckFieldAssignment(MemberOffset field_offset, const Object* new_value)
+      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+    if (kCheckFieldAssignments) {
+      CheckFieldAssignmentImpl(field_offset, new_value);
+    }
+  }
 
   // Write barrier called post update to a reference bearing field.
   static void WriteBarrierField(const Object* dst, MemberOffset offset, const Object* new_value);