Remove ArtMethod's declaring class state checks.

This check was not very useful because the Class is already
in a state to pass the check when we're constructing the
ArtMethod and it can never revert to an earlier state, so
the check is essentially a weak protection against GC bugs.
Besides not being very useful, the check had the ability to
invalidate ObjPtr<> cookies (when called in non-runnable
state), making it difficult to fully ObjPtr<>-ify the code.

Also remove a lot of kReadBarrierOption template parameters
which were needed specifically for this check. This removes
unnecessary maintence burden as shown by past bugs dealing
with carefully adding those parameters where necessary.

Test: m test-art-host-gtest
Test: testrunner.py --host --optimizing
Bug: 74373650
Bug: 31113334
Change-Id: I87f2999fc4e7c27b5c2307139269b4b5f6649d16
diff --git a/runtime/art_method-inl.h b/runtime/art_method-inl.h
index 9da4a39..ac22f07 100644
--- a/runtime/art_method-inl.h
+++ b/runtime/art_method-inl.h
@@ -60,12 +60,6 @@
   if (kIsDebugBuild) {
     if (!IsRuntimeMethod()) {
       CHECK(result != nullptr) << this;
-      if (kCheckDeclaringClassState) {
-        if (!(result->IsIdxLoaded() || result->IsErroneous())) {
-          LOG(FATAL_WITHOUT_ABORT) << "Class status: " << result->GetStatus();
-          LOG(FATAL) << result->PrettyClass();
-        }
-      }
     } else {
       CHECK(result == nullptr) << this;
     }
@@ -94,16 +88,6 @@
   return method_index_;
 }
 
-template <ReadBarrierOption kReadBarrierOption>
-inline uint32_t ArtMethod::GetDexMethodIndex() {
-  if (kCheckDeclaringClassState) {
-    CHECK(IsRuntimeMethod() ||
-          GetDeclaringClass<kReadBarrierOption>()->IsIdxLoaded() ||
-          GetDeclaringClass<kReadBarrierOption>()->IsErroneous());
-  }
-  return GetDexMethodIndexUnchecked();
-}
-
 inline ObjPtr<mirror::Class> ArtMethod::LookupResolvedClassFromTypeIndex(dex::TypeIndex type_idx) {
   ScopedAssertNoThreadSuspension ants(__FUNCTION__);
   ObjPtr<mirror::Class> type =
@@ -196,14 +180,7 @@
 inline const char* ArtMethod::GetShorty(uint32_t* out_length) {
   DCHECK(!IsProxyMethod());
   const DexFile* dex_file = GetDexFile();
-  // Don't do a read barrier in the DCHECK() inside GetDexMethodIndex() as GetShorty()
-  // can be called when the declaring class is about to be unloaded and cannot be added
-  // to the mark stack (subsequent GC assertion would fail).
-  // It is safe to avoid the read barrier as the ArtMethod is constructed with a declaring
-  // Class already satisfying the DCHECK() inside GetDexMethodIndex(), so even if that copy
-  // of declaring class becomes a from-space object, it shall satisfy the DCHECK().
-  return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex<kWithoutReadBarrier>()),
-                                   out_length);
+  return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length);
 }
 
 inline const Signature ArtMethod::GetSignature() {
@@ -329,7 +306,7 @@
 
 template <ReadBarrierOption kReadBarrierOption>
 inline mirror::DexCache* ArtMethod::GetDexCache() {
-  if (LIKELY(!IsObsolete<kReadBarrierOption>())) {
+  if (LIKELY(!IsObsolete())) {
     ObjPtr<mirror::Class> klass = GetDeclaringClass<kReadBarrierOption>();
     return klass->GetDexCache<kDefaultVerifyFlags, kReadBarrierOption>();
   } else {
@@ -382,12 +359,12 @@
 
 template <ReadBarrierOption kReadBarrierOption>
 inline bool ArtMethod::HasSingleImplementation() {
-  if (IsFinal<kReadBarrierOption>() || GetDeclaringClass<kReadBarrierOption>()->IsFinal()) {
+  if (IsFinal() || GetDeclaringClass<kReadBarrierOption>()->IsFinal()) {
     // We don't set kAccSingleImplementation for these cases since intrinsic
     // can use the flag also.
     return true;
   }
-  return (GetAccessFlags<kReadBarrierOption>() & kAccSingleImplementation) != 0;
+  return (GetAccessFlags() & kAccSingleImplementation) != 0;
 }
 
 inline HiddenApiAccessFlags::ApiList ArtMethod::GetHiddenApiAccessFlags()
@@ -529,9 +506,9 @@
   }
 }
 
-template <ReadBarrierOption kReadBarrierOption, typename Visitor>
+template <typename Visitor>
 inline void ArtMethod::UpdateEntrypoints(const Visitor& visitor, PointerSize pointer_size) {
-  if (IsNative<kReadBarrierOption>()) {
+  if (IsNative()) {
     const void* old_native_code = GetEntryPointFromJniPtrSize(pointer_size);
     const void* new_native_code = visitor(old_native_code);
     if (old_native_code != new_native_code) {