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