diff options
| author | 2014-12-03 01:32:33 +0000 | |
|---|---|---|
| committer | 2014-12-03 01:32:34 +0000 | |
| commit | a4b47a196c5630d2be6ab5ee8b321e17bcc5a4a7 (patch) | |
| tree | b52d3c8ef3d7dab404a4d7ccc1dd7922046031d8 | |
| parent | 539f93847d78525b30666658643a8e21e41f16d8 (diff) | |
| parent | b5fb207ed5e3570ec14e18811b3fa066168fe493 (diff) | |
Merge "Remove MethodHelper::HasSameSignatureWithDifferentClassLoaders."
| -rw-r--r-- | runtime/Android.mk | 1 | ||||
| -rw-r--r-- | runtime/class_linker.cc | 60 | ||||
| -rw-r--r-- | runtime/method_helper.cc | 79 | ||||
| -rw-r--r-- | runtime/method_helper.h | 43 | ||||
| -rw-r--r-- | runtime/mirror/object_test.cc | 1 |
5 files changed, 52 insertions, 132 deletions
diff --git a/runtime/Android.mk b/runtime/Android.mk index d4548a2bc7..7dfdb75529 100644 --- a/runtime/Android.mk +++ b/runtime/Android.mk @@ -90,7 +90,6 @@ LIBART_COMMON_SRC_FILES := \ 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 04e2992375..6aab632dd7 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 @@ bool ClassLinker::WaitForInitializeClass(Handle<mirror::Class> klass, Thread* se 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 @@ bool ClassLinker::ValidateSuperClassDescriptors(Handle<mirror::Class> klass) { // 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 @@ bool ClassLinker::ValidateSuperClassDescriptors(Handle<mirror::Class> klass) { 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 4e634c8a55..0000000000 --- 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 44c69135a5..d21bf5cb36 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 @@ class MethodHelperT { 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 25b3144840..9d789cd0cc 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" |