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