blob: 9ca29ce07c9f11843816d9eb16a6b1a597bd44da [file] [log] [blame]
Ian Rogers22d5e732014-07-15 22:23:51 -07001/*
2 * Copyright (C) 2011 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Ian Rogerse5877a12014-07-16 12:06:35 -070017#include "method_helper-inl.h"
Ian Rogers22d5e732014-07-15 22:23:51 -070018
19#include "class_linker.h"
20#include "dex_file-inl.h"
21#include "handle_scope-inl.h"
22#include "mirror/art_method-inl.h"
23#include "mirror/dex_cache.h"
24#include "runtime.h"
25
26namespace art {
27
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070028template <template <class T> class HandleKind>
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070029template <template <class T2> class HandleKind2>
Ian Rogersded66a02014-10-28 18:12:55 -070030bool MethodHelperT<HandleKind>::HasSameSignatureWithDifferentClassLoaders(Thread* self,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070031 MethodHelperT<HandleKind2>* other) {
Ian Rogersded66a02014-10-28 18:12:55 -070032 {
33 StackHandleScope<1> hs(self);
34 Handle<mirror::Class> return_type(hs.NewHandle(GetMethod()->GetReturnType()));
35 if (UNLIKELY(other->GetMethod()->GetReturnType() != return_type.Get())) {
36 return false;
37 }
Ian Rogerse5877a12014-07-16 12:06:35 -070038 }
39 const DexFile::TypeList* types = method_->GetParameterTypeList();
40 const DexFile::TypeList* other_types = other->method_->GetParameterTypeList();
41 if (types == nullptr) {
42 return (other_types == nullptr) || (other_types->Size() == 0);
43 } else if (UNLIKELY(other_types == nullptr)) {
44 return types->Size() == 0;
45 }
46 uint32_t num_types = types->Size();
47 if (UNLIKELY(num_types != other_types->Size())) {
48 return false;
49 }
50 for (uint32_t i = 0; i < num_types; ++i) {
Ian Rogersa0485602014-12-02 15:48:04 -080051 mirror::Class* param_type =
52 method_->GetClassFromTypeIndex(types->GetTypeItem(i).type_idx_, true);
Ian Rogerse5877a12014-07-16 12:06:35 -070053 mirror::Class* other_param_type =
Ian Rogersa0485602014-12-02 15:48:04 -080054 other->method_->GetClassFromTypeIndex(other_types->GetTypeItem(i).type_idx_, true);
Ian Rogerse5877a12014-07-16 12:06:35 -070055 if (UNLIKELY(param_type != other_param_type)) {
56 return false;
57 }
58 }
59 return true;
60}
61
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070062// Instantiate methods.
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070063template
Ian Rogersded66a02014-10-28 18:12:55 -070064bool MethodHelperT<Handle>::HasSameSignatureWithDifferentClassLoaders<Handle>(Thread* self,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070065 MethodHelperT<Handle>* other);
66
67template
Ian Rogersded66a02014-10-28 18:12:55 -070068bool MethodHelperT<Handle>::HasSameSignatureWithDifferentClassLoaders<MutableHandle>(Thread* self,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070069 MethodHelperT<MutableHandle>* other);
70
71template
Ian Rogersded66a02014-10-28 18:12:55 -070072bool MethodHelperT<MutableHandle>::HasSameSignatureWithDifferentClassLoaders<Handle>(Thread* self,
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070073 MethodHelperT<Handle>* other);
74
75template
76bool MethodHelperT<MutableHandle>::HasSameSignatureWithDifferentClassLoaders<MutableHandle>(
Ian Rogersded66a02014-10-28 18:12:55 -070077 Thread* self, MethodHelperT<MutableHandle>* other);
Andreas Gampe5a4b8a22014-09-11 08:30:08 -070078
Ian Rogers22d5e732014-07-15 22:23:51 -070079} // namespace art