ART: Add flag for ArtMethod class state checks

The checks, especially in GetAccessFlags, is expensive. To help
with running a debug build on devices, add a flag to be able to
turn the checks off.

Bug: 35644369
Test: m
Change-Id: I2a3db1a56986df8f4a8b2dc5bcb26e1bcaea0a24
diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h
index 473d9cf..685e26c 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -55,8 +55,10 @@
   if (kIsDebugBuild) {
     if (!IsRuntimeMethod()) {
       CHECK(result != nullptr) << this;
-      CHECK(result->IsIdxLoaded() || result->IsErroneous())
-          << result->GetStatus() << " " << result->PrettyClass();
+      if (kCheckDeclaringClassState) {
+        CHECK(result->IsIdxLoaded() || result->IsErroneous())
+            << result->GetStatus() << " " << result->PrettyClass();
+      }
     } else {
       CHECK(result == nullptr) << this;
     }
@@ -89,7 +91,7 @@
 
 template <ReadBarrierOption kReadBarrierOption>
 inline uint32_t ArtMethod::GetAccessFlags() {
-  if (kIsDebugBuild) {
+  if (kCheckDeclaringClassState) {
     Thread* self = Thread::Current();
     if (!Locks::mutator_lock_->IsSharedHeld(self)) {
       if (self->IsThreadSuspensionAllowable()) {
@@ -118,8 +120,10 @@
 }
 
 inline uint32_t ArtMethod::GetDexMethodIndex() {
-  DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
-         GetDeclaringClass()->IsErroneous());
+  if (kCheckDeclaringClassState) {
+    CHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() ||
+          GetDeclaringClass()->IsErroneous());
+  }
   return GetDexMethodIndexUnchecked();
 }