Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [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 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_ART_METHOD_INL_H_ |
| 18 | #define ART_RUNTIME_ART_METHOD_INL_H_ |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 19 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 20 | #include "art_method.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 21 | |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 22 | #include "art_field.h" |
Mathieu Chartier | 7c0fe5e | 2015-07-17 19:53:47 -0700 | [diff] [blame] | 23 | #include "base/logging.h" |
Hiroshi Yamauchi | 0037082 | 2015-08-18 14:47:25 -0700 | [diff] [blame] | 24 | #include "class_linker-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 25 | #include "common_throws.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 26 | #include "dex_file.h" |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 27 | #include "dex_file_annotations.h" |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 28 | #include "dex_file-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "gc_root-inl.h" |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 30 | #include "jit/profiling_info.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 32 | #include "mirror/dex_cache-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "mirror/object-inl.h" |
| 34 | #include "mirror/object_array.h" |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 35 | #include "oat.h" |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 36 | #include "obj_ptr-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 37 | #include "quick/quick_method_frame_info.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 38 | #include "read_barrier-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 39 | #include "runtime-inl.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 40 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | cbc96b8 | 2015-09-30 20:05:24 +0000 | [diff] [blame] | 41 | #include "thread-inl.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 42 | #include "utils.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 43 | |
| 44 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 45 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 46 | template <ReadBarrierOption kReadBarrierOption> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 47 | inline mirror::Class* ArtMethod::GetDeclaringClassUnchecked() { |
Hiroshi Yamauchi | 3f64f25 | 2015-06-12 18:35:06 -0700 | [diff] [blame] | 48 | GcRootSource gc_root_source(this); |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 49 | return declaring_class_.Read<kReadBarrierOption>(&gc_root_source); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 52 | template <ReadBarrierOption kReadBarrierOption> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 53 | inline mirror::Class* ArtMethod::GetDeclaringClass() { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 54 | mirror::Class* result = GetDeclaringClassUnchecked<kReadBarrierOption>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 55 | if (kIsDebugBuild) { |
| 56 | if (!IsRuntimeMethod()) { |
| 57 | CHECK(result != nullptr) << this; |
| 58 | CHECK(result->IsIdxLoaded() || result->IsErroneous()) |
David Sehr | 709b070 | 2016-10-13 09:12:37 -0700 | [diff] [blame] | 59 | << result->GetStatus() << " " << result->PrettyClass(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 60 | } else { |
| 61 | CHECK(result == nullptr) << this; |
| 62 | } |
| 63 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 64 | return result; |
| 65 | } |
| 66 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 67 | inline void ArtMethod::SetDeclaringClass(ObjPtr<mirror::Class> new_declaring_class) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 68 | declaring_class_ = GcRoot<mirror::Class>(new_declaring_class); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 69 | } |
| 70 | |
Mathieu Chartier | 10e5ea9 | 2015-08-13 12:56:31 -0700 | [diff] [blame] | 71 | inline bool ArtMethod::CASDeclaringClass(mirror::Class* expected_class, |
| 72 | mirror::Class* desired_class) { |
| 73 | GcRoot<mirror::Class> expected_root(expected_class); |
| 74 | GcRoot<mirror::Class> desired_root(desired_class); |
| 75 | return reinterpret_cast<Atomic<GcRoot<mirror::Class>>*>(&declaring_class_)-> |
| 76 | CompareExchangeStrongSequentiallyConsistent( |
| 77 | expected_root, desired_root); |
| 78 | } |
| 79 | |
Andreas Gampe | cbc96b8 | 2015-09-30 20:05:24 +0000 | [diff] [blame] | 80 | // AssertSharedHeld doesn't work in GetAccessFlags, so use a NO_THREAD_SAFETY_ANALYSIS helper. |
| 81 | // TODO: Figure out why ASSERT_SHARED_CAPABILITY doesn't work. |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 82 | template <ReadBarrierOption kReadBarrierOption> |
| 83 | ALWAYS_INLINE static inline void DoGetAccessFlagsHelper(ArtMethod* method) |
| 84 | NO_THREAD_SAFETY_ANALYSIS { |
| 85 | CHECK(method->IsRuntimeMethod() || |
| 86 | method->GetDeclaringClass<kReadBarrierOption>()->IsIdxLoaded() || |
| 87 | method->GetDeclaringClass<kReadBarrierOption>()->IsErroneous()); |
Andreas Gampe | cbc96b8 | 2015-09-30 20:05:24 +0000 | [diff] [blame] | 88 | } |
| 89 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 90 | template <ReadBarrierOption kReadBarrierOption> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 91 | inline uint32_t ArtMethod::GetAccessFlags() { |
Andreas Gampe | cbc96b8 | 2015-09-30 20:05:24 +0000 | [diff] [blame] | 92 | if (kIsDebugBuild) { |
| 93 | Thread* self = Thread::Current(); |
| 94 | if (!Locks::mutator_lock_->IsSharedHeld(self)) { |
Mathieu Chartier | 10b218d | 2016-07-25 17:48:52 -0700 | [diff] [blame] | 95 | if (self->IsThreadSuspensionAllowable()) { |
| 96 | ScopedObjectAccess soa(self); |
| 97 | CHECK(IsRuntimeMethod() || |
| 98 | GetDeclaringClass<kReadBarrierOption>()->IsIdxLoaded() || |
| 99 | GetDeclaringClass<kReadBarrierOption>()->IsErroneous()); |
| 100 | } |
Andreas Gampe | cbc96b8 | 2015-09-30 20:05:24 +0000 | [diff] [blame] | 101 | } else { |
| 102 | // We cannot use SOA in this case. We might be holding the lock, but may not be in the |
| 103 | // runnable state (e.g., during GC). |
| 104 | Locks::mutator_lock_->AssertSharedHeld(self); |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 105 | DoGetAccessFlagsHelper<kReadBarrierOption>(this); |
Andreas Gampe | cbc96b8 | 2015-09-30 20:05:24 +0000 | [diff] [blame] | 106 | } |
| 107 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 108 | return access_flags_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 111 | inline uint16_t ArtMethod::GetMethodIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 112 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved() || |
| 113 | GetDeclaringClass()->IsErroneous()); |
| 114 | return method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 115 | } |
| 116 | |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 117 | inline uint16_t ArtMethod::GetMethodIndexDuringLinking() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 118 | return method_index_; |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 119 | } |
| 120 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 121 | inline uint32_t ArtMethod::GetDexMethodIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 122 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() || |
| 123 | GetDeclaringClass()->IsErroneous()); |
| 124 | return dex_method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 125 | } |
| 126 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 127 | inline ArtMethod** ArtMethod::GetDexCacheResolvedMethods(PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 128 | return GetNativePointer<ArtMethod**>(DexCacheResolvedMethodsOffset(pointer_size), |
| 129 | pointer_size); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 130 | } |
| 131 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 132 | inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, |
| 133 | PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 134 | // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here |
| 135 | // without accessing the DexCache and we don't want to do that in release build. |
| 136 | DCHECK_LT(method_index, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 137 | GetInterfaceMethodIfProxy(pointer_size)->GetDeclaringClass() |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 138 | ->GetDexCache()->NumResolvedMethods()); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 139 | ArtMethod* method = mirror::DexCache::GetElementPtrSize(GetDexCacheResolvedMethods(pointer_size), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 140 | method_index, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 141 | pointer_size); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 142 | if (LIKELY(method != nullptr)) { |
| 143 | auto* declaring_class = method->GetDeclaringClass(); |
| 144 | if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) { |
| 145 | return method; |
| 146 | } |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 147 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 148 | return nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 149 | } |
| 150 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 151 | inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_index, |
| 152 | ArtMethod* new_method, |
| 153 | PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 154 | // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here |
| 155 | // without accessing the DexCache and we don't want to do that in release build. |
| 156 | DCHECK_LT(method_index, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 157 | GetInterfaceMethodIfProxy(pointer_size)->GetDeclaringClass() |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 158 | ->GetDexCache()->NumResolvedMethods()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 159 | DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 160 | mirror::DexCache::SetElementPtrSize(GetDexCacheResolvedMethods(pointer_size), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 161 | method_index, |
| 162 | new_method, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 163 | pointer_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 164 | } |
| 165 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 166 | inline bool ArtMethod::HasDexCacheResolvedMethods(PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 167 | return GetDexCacheResolvedMethods(pointer_size) != nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 168 | } |
| 169 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 170 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod** other_cache, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 171 | PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 172 | return GetDexCacheResolvedMethods(pointer_size) == other_cache; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 173 | } |
| 174 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 175 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other, PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 176 | return GetDexCacheResolvedMethods(pointer_size) == |
| 177 | other->GetDexCacheResolvedMethods(pointer_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 180 | inline GcRoot<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes(PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 181 | return GetNativePointer<GcRoot<mirror::Class>*>(DexCacheResolvedTypesOffset(pointer_size), |
| 182 | pointer_size); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 183 | } |
| 184 | |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 185 | template <bool kWithCheck> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 186 | inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index, |
| 187 | PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 188 | if (kWithCheck) { |
| 189 | mirror::DexCache* dex_cache = |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 190 | GetInterfaceMethodIfProxy(pointer_size)->GetDeclaringClass()->GetDexCache(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 191 | if (UNLIKELY(type_index >= dex_cache->NumResolvedTypes())) { |
| 192 | ThrowArrayIndexOutOfBoundsException(type_index, dex_cache->NumResolvedTypes()); |
| 193 | return nullptr; |
| 194 | } |
| 195 | } |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 196 | mirror::Class* klass = GetDexCacheResolvedTypes(pointer_size)[type_index].Read(); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 197 | return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr; |
| 198 | } |
| 199 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 200 | inline bool ArtMethod::HasDexCacheResolvedTypes(PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 201 | return GetDexCacheResolvedTypes(pointer_size) != nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 204 | inline bool ArtMethod::HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 205 | PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 206 | return GetDexCacheResolvedTypes(pointer_size) == other_cache; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 209 | inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other, PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 210 | return GetDexCacheResolvedTypes(pointer_size) == other->GetDexCacheResolvedTypes(pointer_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 211 | } |
| 212 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 213 | inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, |
| 214 | bool resolve, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 215 | PointerSize pointer_size) { |
| 216 | mirror::Class* type = GetDexCacheResolvedType(type_idx, pointer_size); |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 217 | if (type == nullptr && resolve) { |
| 218 | type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this); |
| 219 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 220 | } |
| 221 | return type; |
| 222 | } |
| 223 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 224 | inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 225 | switch (type) { |
| 226 | case kStatic: |
| 227 | return !IsStatic(); |
| 228 | case kDirect: |
| 229 | return !IsDirect() || IsStatic(); |
| 230 | case kVirtual: { |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 231 | // We have an error if we are direct or a non-copied (i.e. not part of a real class) interface |
| 232 | // method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 233 | mirror::Class* methods_class = GetDeclaringClass(); |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 234 | return IsDirect() || (methods_class->IsInterface() && !IsCopied()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 235 | } |
| 236 | case kSuper: |
Andreas Gampe | 8f252e6 | 2014-08-25 20:46:31 -0700 | [diff] [blame] | 237 | // Constructors and static methods are called with invoke-direct. |
Alex Light | 705ad49 | 2015-09-21 11:36:30 -0700 | [diff] [blame] | 238 | return IsConstructor() || IsStatic(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 239 | case kInterface: { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 240 | mirror::Class* methods_class = GetDeclaringClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 241 | return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass()); |
| 242 | } |
| 243 | default: |
| 244 | LOG(FATAL) << "Unreachable - invocation type: " << type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 245 | UNREACHABLE(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 246 | } |
| 247 | } |
| 248 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 249 | inline bool ArtMethod::IsRuntimeMethod() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 250 | return dex_method_index_ == DexFile::kDexNoIndex; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 251 | } |
| 252 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 253 | inline bool ArtMethod::IsCalleeSaveMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 254 | if (!IsRuntimeMethod()) { |
| 255 | return false; |
| 256 | } |
| 257 | Runtime* runtime = Runtime::Current(); |
| 258 | bool result = false; |
| 259 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 260 | if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) { |
| 261 | result = true; |
| 262 | break; |
| 263 | } |
| 264 | } |
| 265 | return result; |
| 266 | } |
| 267 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 268 | inline bool ArtMethod::IsResolutionMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 269 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 270 | // Check that if we do think it is phony it looks like the resolution method. |
| 271 | DCHECK(!result || IsRuntimeMethod()); |
| 272 | return result; |
| 273 | } |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 274 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 275 | inline bool ArtMethod::IsImtUnimplementedMethod() { |
| 276 | bool result = this == Runtime::Current()->GetImtUnimplementedMethod(); |
| 277 | // Check that if we do think it is phony it looks like the imt unimplemented method. |
| 278 | DCHECK(!result || IsRuntimeMethod()); |
| 279 | return result; |
| 280 | } |
| 281 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 282 | inline const DexFile* ArtMethod::GetDexFile() { |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 283 | return GetDexCache()->GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 284 | } |
| 285 | |
| 286 | inline const char* ArtMethod::GetDeclaringClassDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 287 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 288 | if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) { |
| 289 | return "<runtime method>"; |
| 290 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 291 | DCHECK(!IsProxyMethod()); |
| 292 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 293 | return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); |
| 294 | } |
| 295 | |
| 296 | inline const char* ArtMethod::GetShorty(uint32_t* out_length) { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 297 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 298 | const DexFile* dex_file = GetDexFile(); |
| 299 | return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | inline const Signature ArtMethod::GetSignature() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 303 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 304 | if (dex_method_idx != DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 305 | DCHECK(!IsProxyMethod()); |
| 306 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 307 | return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx)); |
| 308 | } |
| 309 | return Signature::NoSignature(); |
| 310 | } |
| 311 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 312 | inline const char* ArtMethod::GetName() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 313 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 314 | if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 315 | DCHECK(!IsProxyMethod()); |
| 316 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 317 | return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx)); |
| 318 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 319 | Runtime* const runtime = Runtime::Current(); |
| 320 | if (this == runtime->GetResolutionMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 321 | return "<runtime internal resolution method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 322 | } else if (this == runtime->GetImtConflictMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 323 | return "<runtime internal imt conflict method>"; |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 324 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAllCalleeSaves)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 325 | return "<runtime internal callee-save all registers method>"; |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 326 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveRefsOnly)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 327 | return "<runtime internal callee-save reference registers method>"; |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 328 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveRefsAndArgs)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 329 | return "<runtime internal callee-save reference and argument registers method>"; |
| 330 | } else { |
| 331 | return "<unknown runtime internal method>"; |
| 332 | } |
| 333 | } |
| 334 | |
| 335 | inline const DexFile::CodeItem* ArtMethod::GetCodeItem() { |
Mathieu Chartier | 12b3dd7 | 2014-12-11 13:25:33 -0800 | [diff] [blame] | 336 | return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 337 | } |
| 338 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 339 | inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx, PointerSize pointer_size) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 340 | DCHECK(!IsProxyMethod()); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 341 | return GetDexCacheResolvedType(type_idx, pointer_size) != nullptr; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 345 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 346 | if (dex_pc == DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 347 | return IsNative() ? -2 : -1; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 348 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 349 | return annotations::GetLineNumFromPC(GetDexFile(), this, dex_pc); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 350 | } |
| 351 | |
| 352 | inline const DexFile::ProtoId& ArtMethod::GetPrototype() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 353 | DCHECK(!IsProxyMethod()); |
| 354 | const DexFile* dex_file = GetDexFile(); |
| 355 | return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 356 | } |
| 357 | |
| 358 | inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 359 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 360 | const DexFile* dex_file = GetDexFile(); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 361 | const DexFile::ProtoId& proto = dex_file->GetMethodPrototype( |
| 362 | dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 363 | return dex_file->GetProtoParameters(proto); |
| 364 | } |
| 365 | |
| 366 | inline const char* ArtMethod::GetDeclaringClassSourceFile() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 367 | DCHECK(!IsProxyMethod()); |
| 368 | return GetDeclaringClass()->GetSourceFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 369 | } |
| 370 | |
| 371 | inline uint16_t ArtMethod::GetClassDefIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 372 | DCHECK(!IsProxyMethod()); |
| 373 | return GetDeclaringClass()->GetDexClassDefIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 374 | } |
| 375 | |
| 376 | inline const DexFile::ClassDef& ArtMethod::GetClassDef() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 377 | DCHECK(!IsProxyMethod()); |
| 378 | return GetDexFile()->GetClassDef(GetClassDefIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 379 | } |
| 380 | |
| 381 | inline const char* ArtMethod::GetReturnTypeDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 382 | DCHECK(!IsProxyMethod()); |
| 383 | const DexFile* dex_file = GetDexFile(); |
| 384 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 385 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
| 386 | uint16_t return_type_idx = proto_id.return_type_idx_; |
| 387 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx)); |
| 388 | } |
| 389 | |
| 390 | inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 391 | DCHECK(!IsProxyMethod()); |
| 392 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 393 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx)); |
| 394 | } |
| 395 | |
| 396 | inline mirror::ClassLoader* ArtMethod::GetClassLoader() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 397 | DCHECK(!IsProxyMethod()); |
| 398 | return GetDeclaringClass()->GetClassLoader(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 399 | } |
| 400 | |
| 401 | inline mirror::DexCache* ArtMethod::GetDexCache() { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 402 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 403 | return GetDeclaringClass()->GetDexCache(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 404 | } |
| 405 | |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 406 | template<ReadBarrierOption kReadBarrierOption> |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 407 | inline bool ArtMethod::IsProxyMethod() { |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 408 | return GetDeclaringClass<kReadBarrierOption>()->IsProxyClass(); |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 409 | } |
| 410 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 411 | inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(PointerSize pointer_size) { |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 412 | if (LIKELY(!IsProxyMethod())) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 413 | return this; |
| 414 | } |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 415 | mirror::Class* klass = GetDeclaringClass(); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 416 | ArtMethod* interface_method = mirror::DexCache::GetElementPtrSize( |
| 417 | GetDexCacheResolvedMethods(pointer_size), |
| 418 | GetDexMethodIndex(), |
| 419 | pointer_size); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 420 | DCHECK(interface_method != nullptr); |
| 421 | DCHECK_EQ(interface_method, |
| 422 | Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this)); |
| 423 | return interface_method; |
| 424 | } |
| 425 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 426 | inline void ArtMethod::SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 427 | PointerSize pointer_size) { |
| 428 | SetNativePointer(DexCacheResolvedMethodsOffset(pointer_size), |
| 429 | new_dex_cache_methods, |
| 430 | pointer_size); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 431 | } |
| 432 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 433 | inline void ArtMethod::SetDexCacheResolvedTypes(GcRoot<mirror::Class>* new_dex_cache_types, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 434 | PointerSize pointer_size) { |
| 435 | SetNativePointer(DexCacheResolvedTypesOffset(pointer_size), new_dex_cache_types, pointer_size); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 436 | } |
| 437 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 438 | inline mirror::Class* ArtMethod::GetReturnType(bool resolve, PointerSize pointer_size) { |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 439 | DCHECK(!IsProxyMethod()); |
| 440 | const DexFile* dex_file = GetDexFile(); |
| 441 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
| 442 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
| 443 | uint16_t return_type_idx = proto_id.return_type_idx_; |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 444 | mirror::Class* type = GetDexCacheResolvedType(return_type_idx, pointer_size); |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 445 | if (type == nullptr && resolve) { |
| 446 | type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this); |
| 447 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 448 | } |
| 449 | return type; |
| 450 | } |
| 451 | |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 452 | template<ReadBarrierOption kReadBarrierOption, typename RootVisitorType> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 453 | void ArtMethod::VisitRoots(RootVisitorType& visitor, PointerSize pointer_size) { |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 454 | if (LIKELY(!declaring_class_.IsNull())) { |
| 455 | visitor.VisitRoot(declaring_class_.AddressWithoutBarrier()); |
| 456 | mirror::Class* klass = declaring_class_.Read<kReadBarrierOption>(); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 457 | if (UNLIKELY(klass->IsProxyClass())) { |
| 458 | // For normal methods, dex cache shortcuts will be visited through the declaring class. |
| 459 | // However, for proxies we need to keep the interface method alive, so we visit its roots. |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 460 | ArtMethod* interface_method = mirror::DexCache::GetElementPtrSize( |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 461 | GetDexCacheResolvedMethods(pointer_size), |
| 462 | GetDexMethodIndex(), |
| 463 | pointer_size); |
| 464 | DCHECK(interface_method != nullptr); |
| 465 | DCHECK_EQ(interface_method, |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 466 | Runtime::Current()->GetClassLinker()->FindMethodForProxy<kReadBarrierOption>( |
| 467 | klass, this)); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 468 | interface_method->VisitRoots(visitor, pointer_size); |
| 469 | } |
Nicolas Geoffray | 022dd86 | 2016-05-04 09:51:24 +0100 | [diff] [blame] | 470 | // We know we don't have profiling information if the class hasn't been verified. Note |
| 471 | // that this check also ensures the IsNative call can be made, as IsNative expects a fully |
| 472 | // created class (and not a retired one). |
| 473 | if (klass->IsVerified()) { |
| 474 | // Runtime methods and native methods use the same field as the profiling info for |
| 475 | // storing their own data (jni entrypoint for native methods, and ImtConflictTable for |
| 476 | // some runtime methods). |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 477 | if (!IsNative<kReadBarrierOption>() && !IsRuntimeMethod()) { |
Nicolas Geoffray | 022dd86 | 2016-05-04 09:51:24 +0100 | [diff] [blame] | 478 | ProfilingInfo* profiling_info = GetProfilingInfo(pointer_size); |
| 479 | if (profiling_info != nullptr) { |
| 480 | profiling_info->VisitRoots(visitor); |
| 481 | } |
Hiroshi Yamauchi | b79eb75 | 2016-03-07 13:56:33 -0800 | [diff] [blame] | 482 | } |
| 483 | } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 484 | } |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 485 | } |
| 486 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 487 | template <typename Visitor> |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 488 | inline void ArtMethod::UpdateObjectsForImageRelocation(const Visitor& visitor, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 489 | PointerSize pointer_size) { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 490 | mirror::Class* old_class = GetDeclaringClassUnchecked<kWithoutReadBarrier>(); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 491 | mirror::Class* new_class = visitor(old_class); |
| 492 | if (old_class != new_class) { |
| 493 | SetDeclaringClass(new_class); |
| 494 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 495 | ArtMethod** old_methods = GetDexCacheResolvedMethods(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 496 | ArtMethod** new_methods = visitor(old_methods); |
| 497 | if (old_methods != new_methods) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 498 | SetDexCacheResolvedMethods(new_methods, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 499 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 500 | GcRoot<mirror::Class>* old_types = GetDexCacheResolvedTypes(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 501 | GcRoot<mirror::Class>* new_types = visitor(old_types); |
| 502 | if (old_types != new_types) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 503 | SetDexCacheResolvedTypes(new_types, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 507 | template <ReadBarrierOption kReadBarrierOption, typename Visitor> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 508 | inline void ArtMethod::UpdateEntrypoints(const Visitor& visitor, PointerSize pointer_size) { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 509 | if (IsNative<kReadBarrierOption>()) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 510 | const void* old_native_code = GetEntryPointFromJniPtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 511 | const void* new_native_code = visitor(old_native_code); |
| 512 | if (old_native_code != new_native_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 513 | SetEntryPointFromJniPtrSize(new_native_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 514 | } |
| 515 | } else { |
Andreas Gampe | 75f0885 | 2016-07-19 08:06:07 -0700 | [diff] [blame] | 516 | DCHECK(GetDataPtrSize(pointer_size) == nullptr); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 517 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 518 | const void* old_code = GetEntryPointFromQuickCompiledCodePtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 519 | const void* new_code = visitor(old_code); |
| 520 | if (old_code != new_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 521 | SetEntryPointFromQuickCompiledCodePtrSize(new_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 522 | } |
| 523 | } |
| 524 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 525 | } // namespace art |
| 526 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 527 | #endif // ART_RUNTIME_ART_METHOD_INL_H_ |