Revert "Walk up the super chain to find an IMT to share."

This reverts commit fa26b96f2f56ea2380d96922f3c859a2c3b417e8.

Bug: 266937358

Reason for revert: Breaks libcore tests

Change-Id: I4a889029203ffbc6ecdd09c4d5e4dea163da0ffc
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index c265c0e..d5efb68 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -5973,6 +5973,17 @@
   return class_loader == nullptr ? boot_class_table_.get() : class_loader->GetClassTable();
 }
 
+static ImTable* FindSuperImt(ObjPtr<mirror::Class> klass, PointerSize pointer_size)
+    REQUIRES_SHARED(Locks::mutator_lock_) {
+  while (klass->HasSuperClass()) {
+    klass = klass->GetSuperClass();
+    if (klass->ShouldHaveImt()) {
+      return klass->GetImt(pointer_size);
+    }
+  }
+  return nullptr;
+}
+
 bool ClassLinker::LinkClass(Thread* self,
                             const char* descriptor,
                             Handle<mirror::Class> klass,
@@ -6008,7 +6019,7 @@
     // will possibly create a table that is incorrect for either of the classes.
     // Same IMT with new_conflict does not happen very often.
     if (!new_conflict) {
-      ImTable* super_imt = klass->FindSuperImt(image_pointer_size_);
+      ImTable* super_imt = FindSuperImt(klass.Get(), image_pointer_size_);
       if (super_imt != nullptr) {
         bool imt_equals = true;
         for (size_t i = 0; i < ImTable::kSize && imt_equals; ++i) {
@@ -6382,8 +6393,9 @@
   // Compare the IMT with the super class including the conflict methods. If they are equivalent,
   // we can just use the same pointer.
   ImTable* imt = nullptr;
-  ImTable* super_imt = klass->FindSuperImt(image_pointer_size_);
-  if (super_imt != nullptr) {
+  ObjPtr<mirror::Class> super_class = klass->GetSuperClass();
+  if (super_class != nullptr && super_class->ShouldHaveImt()) {
+    ImTable* super_imt = super_class->GetImt(image_pointer_size_);
     bool same = true;
     for (size_t i = 0; same && i < ImTable::kSize; ++i) {
       ArtMethod* method = imt_data[i];
@@ -6412,7 +6424,6 @@
   if (imt == nullptr) {
     imt = klass->GetImt(image_pointer_size_);
     DCHECK(imt != nullptr);
-    DCHECK_NE(imt, super_imt);
     imt->Populate(imt_data, image_pointer_size_);
   } else {
     klass->SetImt(imt, image_pointer_size_);
diff --git a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
index f08b005..f0c5953 100644
--- a/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
+++ b/runtime/entrypoints/quick/quick_trampoline_entrypoints.cc
@@ -2293,7 +2293,6 @@
       interface_method,
       method);
   if (new_conflict_method != conflict_method) {
-    DCHECK_NE(imt, cls->FindSuperImt(kRuntimePointerSize));
     // Update the IMT if we create a new conflict method. No fence needed here, as the
     // data is consistent.
     imt->Set(imt_index,
diff --git a/runtime/mirror/class-inl.h b/runtime/mirror/class-inl.h
index e2fd82f..b6b1415 100644
--- a/runtime/mirror/class-inl.h
+++ b/runtime/mirror/class-inl.h
@@ -1195,17 +1195,6 @@
   SetAccessFlagsDuringLinking(flags | kAccHasDefaultMethod);
 }
 
-inline ImTable* Class::FindSuperImt(PointerSize pointer_size) {
-  ObjPtr<mirror::Class> klass = this;
-  while (klass->HasSuperClass()) {
-    klass = klass->GetSuperClass();
-    if (klass->ShouldHaveImt()) {
-      return klass->GetImt(pointer_size);
-    }
-  }
-  return nullptr;
-}
-
 }  // namespace mirror
 }  // namespace art
 
diff --git a/runtime/mirror/class.h b/runtime/mirror/class.h
index fa2352d..bd37534 100644
--- a/runtime/mirror/class.h
+++ b/runtime/mirror/class.h
@@ -866,8 +866,6 @@
 
   void SetImt(ImTable* imt, PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_);
 
-  ImTable* FindSuperImt(PointerSize pointer_size) REQUIRES_SHARED(Locks::mutator_lock_);
-
   ArtMethod* GetEmbeddedVTableEntry(uint32_t i, PointerSize pointer_size)
       REQUIRES_SHARED(Locks::mutator_lock_);