Remove MethodHelper::HasSameSignatureWithDifferentClassLoaders.

Move sole use to a static function within class_linker.cc.
Remove unused MutableMethodHelper and empty method_helper.cc.

Change-Id: Ia26bc76674ed2ee7c9c546de820cc181005fed77
diff --git a/runtime/Android.mk b/runtime/Android.mk
index d4548a2..7dfdb75 100644
--- a/runtime/Android.mk
+++ b/runtime/Android.mk
@@ -90,7 +90,6 @@
   jobject_comparator.cc \
   mem_map.cc \
   memory_region.cc \
-  method_helper.cc \
   mirror/art_field.cc \
   mirror/art_method.cc \
   mirror/array.cc \
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 04e2992..6aab632 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -43,7 +43,6 @@
 #include "intern_table.h"
 #include "interpreter/interpreter.h"
 #include "leb128.h"
-#include "method_helper.h"
 #include "oat.h"
 #include "oat_file.h"
 #include "object_lock.h"
@@ -4346,6 +4345,41 @@
   UNREACHABLE();
 }
 
+static bool HasSameSignatureWithDifferentClassLoaders(Thread* self,
+                                                      Handle<mirror::ArtMethod> method1,
+                                                      Handle<mirror::ArtMethod> method2)
+    SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
+  {
+    StackHandleScope<1> hs(self);
+    Handle<mirror::Class> return_type(hs.NewHandle(method1->GetReturnType()));
+    if (UNLIKELY(method2->GetReturnType() != return_type.Get())) {
+      return false;
+    }
+  }
+  const DexFile::TypeList* types1 = method1->GetParameterTypeList();
+  const DexFile::TypeList* types2 = method2->GetParameterTypeList();
+  if (types1 == nullptr) {
+    return (types2 == nullptr) || (types2->Size() == 0);
+  } else if (UNLIKELY(types2 == nullptr)) {
+    return types1->Size() == 0;
+  }
+  uint32_t num_types = types1->Size();
+  if (UNLIKELY(num_types != types2->Size())) {
+    return false;
+  }
+  for (uint32_t i = 0; i < num_types; ++i) {
+    mirror::Class* param_type =
+        method1->GetClassFromTypeIndex(types1->GetTypeItem(i).type_idx_, true);
+    mirror::Class* other_param_type =
+        method2->GetClassFromTypeIndex(types2->GetTypeItem(i).type_idx_, true);
+    if (UNLIKELY(param_type != other_param_type)) {
+      return false;
+    }
+  }
+  return true;
+}
+
+
 bool ClassLinker::ValidateSuperClassDescriptors(Handle<mirror::Class> klass) {
   if (klass->IsInterface()) {
     return true;
@@ -4353,19 +4387,19 @@
   // Begin with the methods local to the superclass.
   Thread* self = Thread::Current();
   StackHandleScope<2> hs(self);
-  MutableMethodHelper mh(hs.NewHandle<mirror::ArtMethod>(nullptr));
-  MutableMethodHelper super_mh(hs.NewHandle<mirror::ArtMethod>(nullptr));
+  MutableHandle<mirror::ArtMethod> h_m(hs.NewHandle<mirror::ArtMethod>(nullptr));
+  MutableHandle<mirror::ArtMethod> super_h_m(hs.NewHandle<mirror::ArtMethod>(nullptr));
   if (klass->HasSuperClass() &&
       klass->GetClassLoader() != klass->GetSuperClass()->GetClassLoader()) {
     for (int i = klass->GetSuperClass()->GetVTableLength() - 1; i >= 0; --i) {
-      mh.ChangeMethod(klass->GetVTableEntry(i));
-      super_mh.ChangeMethod(klass->GetSuperClass()->GetVTableEntry(i));
-      if (mh.GetMethod() != super_mh.GetMethod() &&
-          !mh.HasSameSignatureWithDifferentClassLoaders(self, &super_mh)) {
+      h_m.Assign(klass->GetVTableEntry(i));
+      super_h_m.Assign(klass->GetSuperClass()->GetVTableEntry(i));
+      if (h_m.Get() != super_h_m.Get() &&
+          !HasSameSignatureWithDifferentClassLoaders(self, h_m, super_h_m)) {
         ThrowLinkageError(klass.Get(),
                           "Class %s method %s resolves differently in superclass %s",
                           PrettyDescriptor(klass.Get()).c_str(),
-                          PrettyMethod(mh.GetMethod()).c_str(),
+                          PrettyMethod(h_m.Get()).c_str(),
                           PrettyDescriptor(klass->GetSuperClass()).c_str());
         return false;
       }
@@ -4375,14 +4409,14 @@
     if (klass->GetClassLoader() != klass->GetIfTable()->GetInterface(i)->GetClassLoader()) {
       uint32_t num_methods = klass->GetIfTable()->GetInterface(i)->NumVirtualMethods();
       for (uint32_t j = 0; j < num_methods; ++j) {
-        mh.ChangeMethod(klass->GetIfTable()->GetMethodArray(i)->GetWithoutChecks(j));
-        super_mh.ChangeMethod(klass->GetIfTable()->GetInterface(i)->GetVirtualMethod(j));
-        if (mh.GetMethod() != super_mh.GetMethod() &&
-            !mh.HasSameSignatureWithDifferentClassLoaders(self, &super_mh)) {
+        h_m.Assign(klass->GetIfTable()->GetMethodArray(i)->GetWithoutChecks(j));
+        super_h_m.Assign(klass->GetIfTable()->GetInterface(i)->GetVirtualMethod(j));
+        if (h_m.Get() != super_h_m.Get() &&
+            !HasSameSignatureWithDifferentClassLoaders(self, h_m, super_h_m)) {
           ThrowLinkageError(klass.Get(),
                             "Class %s method %s resolves differently in interface %s",
                             PrettyDescriptor(klass.Get()).c_str(),
-                            PrettyMethod(mh.GetMethod()).c_str(),
+                            PrettyMethod(h_m.Get()).c_str(),
                             PrettyDescriptor(klass->GetIfTable()->GetInterface(i)).c_str());
           return false;
         }
diff --git a/runtime/method_helper.cc b/runtime/method_helper.cc
deleted file mode 100644
index 4e634c8..0000000
--- a/runtime/method_helper.cc
+++ /dev/null
@@ -1,79 +0,0 @@
-/*
- * Copyright (C) 2011 The Android Open Source Project
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- *      http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-#include "method_helper.h"
-
-#include "class_linker.h"
-#include "dex_file-inl.h"
-#include "handle_scope-inl.h"
-#include "mirror/art_method-inl.h"
-#include "mirror/dex_cache.h"
-#include "runtime.h"
-
-namespace art {
-
-template <template <class T> class HandleKind>
-template <template <class T2> class HandleKind2>
-bool MethodHelperT<HandleKind>::HasSameSignatureWithDifferentClassLoaders(Thread* self,
-    MethodHelperT<HandleKind2>* other) {
-  {
-    StackHandleScope<1> hs(self);
-    Handle<mirror::Class> return_type(hs.NewHandle(GetMethod()->GetReturnType()));
-    if (UNLIKELY(other->GetMethod()->GetReturnType() != return_type.Get())) {
-      return false;
-    }
-  }
-  const DexFile::TypeList* types = method_->GetParameterTypeList();
-  const DexFile::TypeList* other_types = other->method_->GetParameterTypeList();
-  if (types == nullptr) {
-    return (other_types == nullptr) || (other_types->Size() == 0);
-  } else if (UNLIKELY(other_types == nullptr)) {
-    return types->Size() == 0;
-  }
-  uint32_t num_types = types->Size();
-  if (UNLIKELY(num_types != other_types->Size())) {
-    return false;
-  }
-  for (uint32_t i = 0; i < num_types; ++i) {
-    mirror::Class* param_type =
-        method_->GetClassFromTypeIndex(types->GetTypeItem(i).type_idx_, true);
-    mirror::Class* other_param_type =
-        other->method_->GetClassFromTypeIndex(other_types->GetTypeItem(i).type_idx_, true);
-    if (UNLIKELY(param_type != other_param_type)) {
-      return false;
-    }
-  }
-  return true;
-}
-
-// Instantiate methods.
-template
-bool MethodHelperT<Handle>::HasSameSignatureWithDifferentClassLoaders<Handle>(Thread* self,
-    MethodHelperT<Handle>* other);
-
-template
-bool MethodHelperT<Handle>::HasSameSignatureWithDifferentClassLoaders<MutableHandle>(Thread* self,
-    MethodHelperT<MutableHandle>* other);
-
-template
-bool MethodHelperT<MutableHandle>::HasSameSignatureWithDifferentClassLoaders<Handle>(Thread* self,
-    MethodHelperT<Handle>* other);
-
-template
-bool MethodHelperT<MutableHandle>::HasSameSignatureWithDifferentClassLoaders<MutableHandle>(
-    Thread* self, MethodHelperT<MutableHandle>* other);
-
-}  // namespace art
diff --git a/runtime/method_helper.h b/runtime/method_helper.h
index 44c6913..d21bf5c 100644
--- a/runtime/method_helper.h
+++ b/runtime/method_helper.h
@@ -24,11 +24,10 @@
 
 namespace art {
 
-template <template <class T> class HandleKind>
-class MethodHelperT {
+class MethodHelper {
  public:
-  explicit MethodHelperT(HandleKind<mirror::ArtMethod> m)
-      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) : method_(m), shorty_(nullptr), shorty_len_(0) {
+  explicit MethodHelper(Handle<mirror::ArtMethod> m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_)
+      : method_(m), shorty_(nullptr), shorty_len_(0) {
   }
 
   mirror::ArtMethod* GetMethod() const SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
@@ -98,47 +97,15 @@
     return GetParamPrimitiveType(param) == Primitive::kPrimNot;
   }
 
-  template <template <class T> class HandleKind2>
-  bool HasSameSignatureWithDifferentClassLoaders(Thread* self, MethodHelperT<HandleKind2>* other)
-      SHARED_LOCKS_REQUIRED(Locks::mutator_lock_);
-
- protected:
-  HandleKind<mirror::ArtMethod> method_;
+ private:
+  Handle<mirror::ArtMethod> method_;
 
   const char* shorty_;
   uint32_t shorty_len_;
 
- private:
-  template <template <class T2> class HandleKind2> friend class MethodHelperT;
-
-  DISALLOW_COPY_AND_ASSIGN(MethodHelperT);
-};
-
-class MethodHelper : public MethodHelperT<Handle> {
-  using MethodHelperT<Handle>::MethodHelperT;
- private:
   DISALLOW_COPY_AND_ASSIGN(MethodHelper);
 };
 
-class MutableMethodHelper : public MethodHelperT<MutableHandle> {
-  using MethodHelperT<MutableHandle>::MethodHelperT;
- public:
-  void ChangeMethod(mirror::ArtMethod* new_m) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-    DCHECK(new_m != nullptr);
-    SetMethod(new_m);
-    shorty_ = nullptr;
-  }
-
- private:
-  // Set the method_ field, for proxy methods looking up the interface method via the resolved
-  // methods table.
-  void SetMethod(mirror::ArtMethod* method) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) {
-    method_.Assign(method);
-  }
-
-  DISALLOW_COPY_AND_ASSIGN(MutableMethodHelper);
-};
-
 }  // namespace art
 
 #endif  // ART_RUNTIME_METHOD_HELPER_H_
diff --git a/runtime/mirror/object_test.cc b/runtime/mirror/object_test.cc
index 25b3144..9d789cd 100644
--- a/runtime/mirror/object_test.cc
+++ b/runtime/mirror/object_test.cc
@@ -34,7 +34,6 @@
 #include "gc/heap.h"
 #include "handle_scope-inl.h"
 #include "iftable-inl.h"
-#include "method_helper.h"
 #include "object-inl.h"
 #include "object_array-inl.h"
 #include "scoped_thread_state_change.h"