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 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 108 | return access_flags_.load(std::memory_order_relaxed); |
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() { |
Vladimir Marko | 72ab684 | 2017-01-20 19:32:50 +0000 | [diff] [blame] | 112 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 113 | return method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 114 | } |
| 115 | |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 116 | inline uint16_t ArtMethod::GetMethodIndexDuringLinking() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 117 | return method_index_; |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 118 | } |
| 119 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 120 | inline uint32_t ArtMethod::GetDexMethodIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 121 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() || |
| 122 | GetDeclaringClass()->IsErroneous()); |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 123 | return GetDexMethodIndexUnchecked(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 124 | } |
| 125 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 126 | inline ArtMethod** ArtMethod::GetDexCacheResolvedMethods(PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 127 | return GetNativePointer<ArtMethod**>(DexCacheResolvedMethodsOffset(pointer_size), |
| 128 | pointer_size); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 129 | } |
| 130 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 131 | inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, |
| 132 | PointerSize pointer_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, |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 136 | GetInterfaceMethodIfProxy(pointer_size)->GetDexCache()->NumResolvedMethods()); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 137 | ArtMethod* method = mirror::DexCache::GetElementPtrSize(GetDexCacheResolvedMethods(pointer_size), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 138 | method_index, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 139 | pointer_size); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 140 | if (LIKELY(method != nullptr)) { |
| 141 | auto* declaring_class = method->GetDeclaringClass(); |
| 142 | if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) { |
| 143 | return method; |
| 144 | } |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 145 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 146 | return nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 147 | } |
| 148 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 149 | inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_index, |
| 150 | ArtMethod* new_method, |
| 151 | PointerSize pointer_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, |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 155 | GetInterfaceMethodIfProxy(pointer_size)->GetDexCache()->NumResolvedMethods()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 156 | DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 157 | mirror::DexCache::SetElementPtrSize(GetDexCacheResolvedMethods(pointer_size), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 158 | method_index, |
| 159 | new_method, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 160 | pointer_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 161 | } |
| 162 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 163 | inline bool ArtMethod::HasDexCacheResolvedMethods(PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 164 | return GetDexCacheResolvedMethods(pointer_size) != nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 165 | } |
| 166 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 167 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod** other_cache, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 168 | PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 169 | return GetDexCacheResolvedMethods(pointer_size) == other_cache; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 172 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other, PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 173 | return GetDexCacheResolvedMethods(pointer_size) == |
| 174 | other->GetDexCacheResolvedMethods(pointer_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 177 | inline mirror::Class* ArtMethod::GetClassFromTypeIndex(dex::TypeIndex type_idx, bool resolve) { |
| 178 | ObjPtr<mirror::DexCache> dex_cache = GetDexCache(); |
| 179 | ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx); |
| 180 | if (UNLIKELY(type == nullptr) && resolve) { |
| 181 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
| 182 | type = class_linker->ResolveType(type_idx, this); |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 183 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 184 | } |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 185 | return type.Ptr(); |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 186 | } |
| 187 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 188 | inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 189 | switch (type) { |
| 190 | case kStatic: |
| 191 | return !IsStatic(); |
| 192 | case kDirect: |
| 193 | return !IsDirect() || IsStatic(); |
| 194 | case kVirtual: { |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 195 | // We have an error if we are direct or a non-copied (i.e. not part of a real class) interface |
| 196 | // method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 197 | mirror::Class* methods_class = GetDeclaringClass(); |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 198 | return IsDirect() || (methods_class->IsInterface() && !IsCopied()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 199 | } |
| 200 | case kSuper: |
Andreas Gampe | 8f252e6 | 2014-08-25 20:46:31 -0700 | [diff] [blame] | 201 | // Constructors and static methods are called with invoke-direct. |
Alex Light | 705ad49 | 2015-09-21 11:36:30 -0700 | [diff] [blame] | 202 | return IsConstructor() || IsStatic(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 203 | case kInterface: { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 204 | mirror::Class* methods_class = GetDeclaringClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 205 | return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass()); |
| 206 | } |
| 207 | default: |
| 208 | LOG(FATAL) << "Unreachable - invocation type: " << type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 209 | UNREACHABLE(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 210 | } |
| 211 | } |
| 212 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 213 | inline bool ArtMethod::IsRuntimeMethod() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 214 | return dex_method_index_ == DexFile::kDexNoIndex; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 215 | } |
| 216 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 217 | inline bool ArtMethod::IsCalleeSaveMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 218 | if (!IsRuntimeMethod()) { |
| 219 | return false; |
| 220 | } |
| 221 | Runtime* runtime = Runtime::Current(); |
| 222 | bool result = false; |
| 223 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 224 | if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) { |
| 225 | result = true; |
| 226 | break; |
| 227 | } |
| 228 | } |
| 229 | return result; |
| 230 | } |
| 231 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 232 | inline bool ArtMethod::IsResolutionMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 233 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 234 | // Check that if we do think it is phony it looks like the resolution method. |
| 235 | DCHECK(!result || IsRuntimeMethod()); |
| 236 | return result; |
| 237 | } |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 238 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 239 | inline bool ArtMethod::IsImtUnimplementedMethod() { |
| 240 | bool result = this == Runtime::Current()->GetImtUnimplementedMethod(); |
| 241 | // Check that if we do think it is phony it looks like the imt unimplemented method. |
| 242 | DCHECK(!result || IsRuntimeMethod()); |
| 243 | return result; |
| 244 | } |
| 245 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 246 | inline const DexFile* ArtMethod::GetDexFile() { |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame^] | 247 | // It is safe to avoid the read barrier here since the dex file is constant, so if we read the |
| 248 | // from-space dex file pointer it will be equal to the to-space copy. |
| 249 | return GetDexCache<kWithoutReadBarrier>()->GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 250 | } |
| 251 | |
| 252 | inline const char* ArtMethod::GetDeclaringClassDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 253 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 254 | if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) { |
| 255 | return "<runtime method>"; |
| 256 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 257 | DCHECK(!IsProxyMethod()); |
| 258 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 259 | return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); |
| 260 | } |
| 261 | |
| 262 | inline const char* ArtMethod::GetShorty(uint32_t* out_length) { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 263 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 264 | const DexFile* dex_file = GetDexFile(); |
| 265 | return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 266 | } |
| 267 | |
| 268 | inline const Signature ArtMethod::GetSignature() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 269 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 270 | if (dex_method_idx != DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 271 | DCHECK(!IsProxyMethod()); |
| 272 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 273 | return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx)); |
| 274 | } |
| 275 | return Signature::NoSignature(); |
| 276 | } |
| 277 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 278 | inline const char* ArtMethod::GetName() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 279 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 280 | if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 281 | DCHECK(!IsProxyMethod()); |
| 282 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 283 | return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx)); |
| 284 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 285 | Runtime* const runtime = Runtime::Current(); |
| 286 | if (this == runtime->GetResolutionMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 287 | return "<runtime internal resolution method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 288 | } else if (this == runtime->GetImtConflictMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 289 | return "<runtime internal imt conflict method>"; |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 290 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAllCalleeSaves)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 291 | return "<runtime internal callee-save all registers method>"; |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 292 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveRefsOnly)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 293 | return "<runtime internal callee-save reference registers method>"; |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 294 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveRefsAndArgs)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 295 | return "<runtime internal callee-save reference and argument registers method>"; |
| 296 | } else { |
| 297 | return "<unknown runtime internal method>"; |
| 298 | } |
| 299 | } |
| 300 | |
| 301 | inline const DexFile::CodeItem* ArtMethod::GetCodeItem() { |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 302 | return GetDexFile()->GetCodeItem(GetCodeItemOffset()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 303 | } |
| 304 | |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 305 | inline bool ArtMethod::IsResolvedTypeIdx(dex::TypeIndex type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 306 | DCHECK(!IsProxyMethod()); |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 307 | return GetClassFromTypeIndex(type_idx, /* resolve */ false) != nullptr; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 311 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 312 | if (dex_pc == DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 313 | return IsNative() ? -2 : -1; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 314 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 315 | return annotations::GetLineNumFromPC(GetDexFile(), this, dex_pc); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 316 | } |
| 317 | |
| 318 | inline const DexFile::ProtoId& ArtMethod::GetPrototype() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 319 | DCHECK(!IsProxyMethod()); |
| 320 | const DexFile* dex_file = GetDexFile(); |
| 321 | return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 325 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 326 | const DexFile* dex_file = GetDexFile(); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 327 | const DexFile::ProtoId& proto = dex_file->GetMethodPrototype( |
| 328 | dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 329 | return dex_file->GetProtoParameters(proto); |
| 330 | } |
| 331 | |
| 332 | inline const char* ArtMethod::GetDeclaringClassSourceFile() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 333 | DCHECK(!IsProxyMethod()); |
| 334 | return GetDeclaringClass()->GetSourceFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 335 | } |
| 336 | |
| 337 | inline uint16_t ArtMethod::GetClassDefIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 338 | DCHECK(!IsProxyMethod()); |
| 339 | return GetDeclaringClass()->GetDexClassDefIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 340 | } |
| 341 | |
| 342 | inline const DexFile::ClassDef& ArtMethod::GetClassDef() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 343 | DCHECK(!IsProxyMethod()); |
| 344 | return GetDexFile()->GetClassDef(GetClassDefIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 345 | } |
| 346 | |
| 347 | inline const char* ArtMethod::GetReturnTypeDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 348 | DCHECK(!IsProxyMethod()); |
| 349 | const DexFile* dex_file = GetDexFile(); |
| 350 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 351 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 352 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(proto_id.return_type_idx_)); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 353 | } |
| 354 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 355 | inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(dex::TypeIndex type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 356 | DCHECK(!IsProxyMethod()); |
| 357 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 358 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx)); |
| 359 | } |
| 360 | |
| 361 | inline mirror::ClassLoader* ArtMethod::GetClassLoader() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 362 | DCHECK(!IsProxyMethod()); |
| 363 | return GetDeclaringClass()->GetClassLoader(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 364 | } |
| 365 | |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame^] | 366 | template <ReadBarrierOption kReadBarrierOption> |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 367 | inline mirror::DexCache* ArtMethod::GetDexCache() { |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 368 | if (LIKELY(!IsObsolete())) { |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame^] | 369 | mirror::Class* klass = GetDeclaringClass<kReadBarrierOption>(); |
| 370 | return klass->GetDexCache<kDefaultVerifyFlags, kReadBarrierOption>(); |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 371 | } else { |
| 372 | DCHECK(!IsProxyMethod()); |
| 373 | return GetObsoleteDexCache(); |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 374 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 377 | template<ReadBarrierOption kReadBarrierOption> |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 378 | inline bool ArtMethod::IsProxyMethod() { |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 379 | return GetDeclaringClass<kReadBarrierOption>()->IsProxyClass(); |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 380 | } |
| 381 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 382 | inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(PointerSize pointer_size) { |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 383 | if (LIKELY(!IsProxyMethod())) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 384 | return this; |
| 385 | } |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 386 | ArtMethod* interface_method = mirror::DexCache::GetElementPtrSize( |
| 387 | GetDexCacheResolvedMethods(pointer_size), |
| 388 | GetDexMethodIndex(), |
| 389 | pointer_size); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 390 | DCHECK(interface_method != nullptr); |
| 391 | DCHECK_EQ(interface_method, |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame^] | 392 | Runtime::Current()->GetClassLinker()->FindMethodForProxy(GetDeclaringClass(), this)); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 393 | return interface_method; |
| 394 | } |
| 395 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 396 | inline void ArtMethod::SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 397 | PointerSize pointer_size) { |
| 398 | SetNativePointer(DexCacheResolvedMethodsOffset(pointer_size), |
| 399 | new_dex_cache_methods, |
| 400 | pointer_size); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 403 | inline mirror::Class* ArtMethod::GetReturnType(bool resolve) { |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 404 | DCHECK(!IsProxyMethod()); |
| 405 | const DexFile* dex_file = GetDexFile(); |
| 406 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
| 407 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 408 | dex::TypeIndex return_type_idx = proto_id.return_type_idx_; |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 409 | return GetClassFromTypeIndex(return_type_idx, resolve); |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 410 | } |
| 411 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 412 | inline bool ArtMethod::HasSingleImplementation() { |
| 413 | if (IsFinal() || GetDeclaringClass()->IsFinal()) { |
| 414 | // We don't set kAccSingleImplementation for these cases since intrinsic |
| 415 | // can use the flag also. |
| 416 | return true; |
| 417 | } |
| 418 | return (GetAccessFlags() & kAccSingleImplementation) != 0; |
| 419 | } |
| 420 | |
| 421 | inline void ArtMethod::SetIntrinsic(uint32_t intrinsic) { |
| 422 | DCHECK(IsUint<8>(intrinsic)); |
| 423 | // Currently we only do intrinsics for static/final methods or methods of final |
| 424 | // classes. We don't set kHasSingleImplementation for those methods. |
| 425 | DCHECK(IsStatic() || IsFinal() || GetDeclaringClass()->IsFinal()) << |
| 426 | "Potential conflict with kAccSingleImplementation"; |
| 427 | uint32_t new_value = (GetAccessFlags() & kAccFlagsNotUsedByIntrinsic) | |
| 428 | kAccIntrinsic | |
| 429 | (intrinsic << POPCOUNT(kAccFlagsNotUsedByIntrinsic)); |
| 430 | if (kIsDebugBuild) { |
| 431 | uint32_t java_flags = (GetAccessFlags() & kAccJavaFlagsMask); |
| 432 | bool is_constructor = IsConstructor(); |
| 433 | bool is_synchronized = IsSynchronized(); |
| 434 | bool skip_access_checks = SkipAccessChecks(); |
| 435 | bool is_fast_native = IsFastNative(); |
| 436 | bool is_copied = IsCopied(); |
| 437 | bool is_miranda = IsMiranda(); |
| 438 | bool is_default = IsDefault(); |
| 439 | bool is_default_conflict = IsDefaultConflicting(); |
| 440 | bool is_compilable = IsCompilable(); |
| 441 | bool must_count_locks = MustCountLocks(); |
| 442 | SetAccessFlags(new_value); |
| 443 | DCHECK_EQ(java_flags, (GetAccessFlags() & kAccJavaFlagsMask)); |
| 444 | DCHECK_EQ(is_constructor, IsConstructor()); |
| 445 | DCHECK_EQ(is_synchronized, IsSynchronized()); |
| 446 | DCHECK_EQ(skip_access_checks, SkipAccessChecks()); |
| 447 | DCHECK_EQ(is_fast_native, IsFastNative()); |
| 448 | DCHECK_EQ(is_copied, IsCopied()); |
| 449 | DCHECK_EQ(is_miranda, IsMiranda()); |
| 450 | DCHECK_EQ(is_default, IsDefault()); |
| 451 | DCHECK_EQ(is_default_conflict, IsDefaultConflicting()); |
| 452 | DCHECK_EQ(is_compilable, IsCompilable()); |
| 453 | DCHECK_EQ(must_count_locks, MustCountLocks()); |
| 454 | } else { |
| 455 | SetAccessFlags(new_value); |
| 456 | } |
| 457 | } |
| 458 | |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 459 | template<ReadBarrierOption kReadBarrierOption, typename RootVisitorType> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 460 | void ArtMethod::VisitRoots(RootVisitorType& visitor, PointerSize pointer_size) { |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 461 | if (LIKELY(!declaring_class_.IsNull())) { |
| 462 | visitor.VisitRoot(declaring_class_.AddressWithoutBarrier()); |
| 463 | mirror::Class* klass = declaring_class_.Read<kReadBarrierOption>(); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 464 | if (UNLIKELY(klass->IsProxyClass())) { |
| 465 | // For normal methods, dex cache shortcuts will be visited through the declaring class. |
| 466 | // 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] | 467 | ArtMethod* interface_method = mirror::DexCache::GetElementPtrSize( |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 468 | GetDexCacheResolvedMethods(pointer_size), |
| 469 | GetDexMethodIndex(), |
| 470 | pointer_size); |
| 471 | DCHECK(interface_method != nullptr); |
| 472 | DCHECK_EQ(interface_method, |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 473 | Runtime::Current()->GetClassLinker()->FindMethodForProxy<kReadBarrierOption>( |
| 474 | klass, this)); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 475 | interface_method->VisitRoots(visitor, pointer_size); |
| 476 | } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 477 | } |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 478 | } |
| 479 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 480 | template <typename Visitor> |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 481 | inline void ArtMethod::UpdateObjectsForImageRelocation(const Visitor& visitor, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 482 | PointerSize pointer_size) { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 483 | mirror::Class* old_class = GetDeclaringClassUnchecked<kWithoutReadBarrier>(); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 484 | mirror::Class* new_class = visitor(old_class); |
| 485 | if (old_class != new_class) { |
| 486 | SetDeclaringClass(new_class); |
| 487 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 488 | ArtMethod** old_methods = GetDexCacheResolvedMethods(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 489 | ArtMethod** new_methods = visitor(old_methods); |
| 490 | if (old_methods != new_methods) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 491 | SetDexCacheResolvedMethods(new_methods, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 492 | } |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 493 | } |
| 494 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 495 | template <ReadBarrierOption kReadBarrierOption, typename Visitor> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 496 | inline void ArtMethod::UpdateEntrypoints(const Visitor& visitor, PointerSize pointer_size) { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 497 | if (IsNative<kReadBarrierOption>()) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 498 | const void* old_native_code = GetEntryPointFromJniPtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 499 | const void* new_native_code = visitor(old_native_code); |
| 500 | if (old_native_code != new_native_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 501 | SetEntryPointFromJniPtrSize(new_native_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 502 | } |
| 503 | } else { |
Andreas Gampe | 75f0885 | 2016-07-19 08:06:07 -0700 | [diff] [blame] | 504 | DCHECK(GetDataPtrSize(pointer_size) == nullptr); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 505 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 506 | const void* old_code = GetEntryPointFromQuickCompiledCodePtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 507 | const void* new_code = visitor(old_code); |
| 508 | if (old_code != new_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 509 | SetEntryPointFromQuickCompiledCodePtrSize(new_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 510 | } |
| 511 | } |
| 512 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 513 | } // namespace art |
| 514 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 515 | #endif // ART_RUNTIME_ART_METHOD_INL_H_ |