Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 1 | /* |
| 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 | |
| 17 | #ifndef ART_RUNTIME_METHOD_HELPER_INL_H_ |
| 18 | #define ART_RUNTIME_METHOD_HELPER_INL_H_ |
| 19 | |
| 20 | #include "method_helper.h" |
| 21 | |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 22 | #include "class_linker.h" |
| 23 | #include "mirror/object_array.h" |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 24 | #include "runtime.h" |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 25 | #include "thread-inl.h" |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 26 | |
| 27 | namespace art { |
| 28 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 29 | template <template <class T> class HandleKind> |
| 30 | template <template <class T2> class HandleKind2> |
| 31 | inline bool MethodHelperT<HandleKind>::HasSameNameAndSignature(MethodHelperT<HandleKind2>* other) { |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 32 | const DexFile* dex_file = method_->GetDexFile(); |
| 33 | const DexFile::MethodId& mid = dex_file->GetMethodId(GetMethod()->GetDexMethodIndex()); |
| 34 | if (method_->GetDexCache() == other->method_->GetDexCache()) { |
| 35 | const DexFile::MethodId& other_mid = |
| 36 | dex_file->GetMethodId(other->GetMethod()->GetDexMethodIndex()); |
| 37 | return mid.name_idx_ == other_mid.name_idx_ && mid.proto_idx_ == other_mid.proto_idx_; |
| 38 | } |
| 39 | const DexFile* other_dex_file = other->method_->GetDexFile(); |
| 40 | const DexFile::MethodId& other_mid = |
| 41 | other_dex_file->GetMethodId(other->GetMethod()->GetDexMethodIndex()); |
| 42 | if (!DexFileStringEquals(dex_file, mid.name_idx_, other_dex_file, other_mid.name_idx_)) { |
| 43 | return false; // Name mismatch. |
| 44 | } |
| 45 | return dex_file->GetMethodSignature(mid) == other_dex_file->GetMethodSignature(other_mid); |
| 46 | } |
| 47 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 48 | template <template <class T> class HandleKind> |
| 49 | inline mirror::Class* MethodHelperT<HandleKind>::GetClassFromTypeIdx(uint16_t type_idx, |
| 50 | bool resolve) { |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 51 | mirror::ArtMethod* method = GetMethod(); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 52 | mirror::Class* type = method->GetDexCacheResolvedType(type_idx); |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 53 | if (type == nullptr && resolve) { |
| 54 | type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, method); |
| 55 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 56 | } |
| 57 | return type; |
| 58 | } |
| 59 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 60 | template <template <class T> class HandleKind> |
| 61 | inline mirror::Class* MethodHelperT<HandleKind>::GetReturnType(bool resolve) { |
Ian Rogers | e5877a1 | 2014-07-16 12:06:35 -0700 | [diff] [blame] | 62 | mirror::ArtMethod* method = GetMethod(); |
| 63 | const DexFile* dex_file = method->GetDexFile(); |
| 64 | const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex()); |
| 65 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
| 66 | uint16_t return_type_idx = proto_id.return_type_idx_; |
| 67 | return GetClassFromTypeIdx(return_type_idx, resolve); |
| 68 | } |
| 69 | |
Andreas Gampe | 5a4b8a2 | 2014-09-11 08:30:08 -0700 | [diff] [blame] | 70 | template <template <class T> class HandleKind> |
| 71 | inline mirror::String* MethodHelperT<HandleKind>::ResolveString(uint32_t string_idx) { |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 72 | mirror::ArtMethod* method = GetMethod(); |
| 73 | mirror::String* s = method->GetDexCacheStrings()->Get(string_idx); |
| 74 | if (UNLIKELY(s == nullptr)) { |
| 75 | StackHandleScope<1> hs(Thread::Current()); |
| 76 | Handle<mirror::DexCache> dex_cache(hs.NewHandle(method->GetDexCache())); |
| 77 | s = Runtime::Current()->GetClassLinker()->ResolveString(*method->GetDexFile(), string_idx, |
| 78 | dex_cache); |
| 79 | } |
| 80 | return s; |
| 81 | } |
| 82 | |
| 83 | } // namespace art |
| 84 | |
| 85 | #endif // ART_RUNTIME_METHOD_HELPER_INL_H_ |