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 | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 44 | inline mirror::Class* ArtMethod::GetDeclaringClassUnchecked() { |
Hiroshi Yamauchi | 3f64f25 | 2015-06-12 18:35:06 -0700 | [diff] [blame] | 45 | GcRootSource gc_root_source(this); |
| 46 | return declaring_class_.Read(&gc_root_source); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 47 | } |
| 48 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 49 | inline mirror::Class* ArtMethod::GetDeclaringClassNoBarrier() { |
| 50 | return declaring_class_.Read<kWithoutReadBarrier>(); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 51 | } |
| 52 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 53 | inline mirror::Class* ArtMethod::GetDeclaringClass() { |
| 54 | mirror::Class* result = GetDeclaringClassUnchecked(); |
| 55 | if (kIsDebugBuild) { |
| 56 | if (!IsRuntimeMethod()) { |
| 57 | CHECK(result != nullptr) << this; |
| 58 | CHECK(result->IsIdxLoaded() || result->IsErroneous()) |
| 59 | << result->GetStatus() << " " << PrettyClass(result); |
| 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 | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 67 | inline void ArtMethod::SetDeclaringClass(mirror::Class* new_declaring_class) { |
| 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. |
| 82 | ALWAYS_INLINE |
| 83 | static inline void DoGetAccessFlagsHelper(ArtMethod* method) NO_THREAD_SAFETY_ANALYSIS { |
| 84 | CHECK(method->IsRuntimeMethod() || method->GetDeclaringClass()->IsIdxLoaded() || |
| 85 | method->GetDeclaringClass()->IsErroneous()); |
| 86 | } |
| 87 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 88 | inline uint32_t ArtMethod::GetAccessFlags() { |
Andreas Gampe | cbc96b8 | 2015-09-30 20:05:24 +0000 | [diff] [blame] | 89 | if (kIsDebugBuild) { |
| 90 | Thread* self = Thread::Current(); |
| 91 | if (!Locks::mutator_lock_->IsSharedHeld(self)) { |
| 92 | ScopedObjectAccess soa(self); |
| 93 | CHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() || |
| 94 | GetDeclaringClass()->IsErroneous()); |
| 95 | } else { |
| 96 | // We cannot use SOA in this case. We might be holding the lock, but may not be in the |
| 97 | // runnable state (e.g., during GC). |
| 98 | Locks::mutator_lock_->AssertSharedHeld(self); |
| 99 | DoGetAccessFlagsHelper(this); |
| 100 | } |
| 101 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 102 | return access_flags_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 103 | } |
| 104 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 105 | inline uint16_t ArtMethod::GetMethodIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 106 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved() || |
| 107 | GetDeclaringClass()->IsErroneous()); |
| 108 | return method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 109 | } |
| 110 | |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 111 | inline uint16_t ArtMethod::GetMethodIndexDuringLinking() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 112 | return method_index_; |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 113 | } |
| 114 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 115 | inline uint32_t ArtMethod::GetDexMethodIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 116 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() || |
| 117 | GetDeclaringClass()->IsErroneous()); |
| 118 | return dex_method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 121 | inline ArtMethod** ArtMethod::GetDexCacheResolvedMethods(size_t pointer_size) { |
| 122 | return GetNativePointer<ArtMethod**>(DexCacheResolvedMethodsOffset(pointer_size), |
| 123 | pointer_size); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 124 | } |
| 125 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 126 | inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 127 | // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here |
| 128 | // without accessing the DexCache and we don't want to do that in release build. |
| 129 | DCHECK_LT(method_index, |
| 130 | GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass() |
| 131 | ->GetDexCache()->NumResolvedMethods()); |
| 132 | ArtMethod* method = mirror::DexCache::GetElementPtrSize(GetDexCacheResolvedMethods(ptr_size), |
| 133 | method_index, |
| 134 | ptr_size); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 135 | if (LIKELY(method != nullptr)) { |
| 136 | auto* declaring_class = method->GetDeclaringClass(); |
| 137 | if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) { |
| 138 | return method; |
| 139 | } |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 140 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 141 | return nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 142 | } |
| 143 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 144 | inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_index, ArtMethod* new_method, |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 145 | size_t ptr_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 146 | // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here |
| 147 | // without accessing the DexCache and we don't want to do that in release build. |
| 148 | DCHECK_LT(method_index, |
| 149 | GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass() |
| 150 | ->GetDexCache()->NumResolvedMethods()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 151 | DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 152 | mirror::DexCache::SetElementPtrSize(GetDexCacheResolvedMethods(ptr_size), |
| 153 | method_index, |
| 154 | new_method, |
| 155 | ptr_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 156 | } |
| 157 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 158 | inline bool ArtMethod::HasDexCacheResolvedMethods(size_t pointer_size) { |
| 159 | return GetDexCacheResolvedMethods(pointer_size) != nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 162 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod** other_cache, |
| 163 | size_t pointer_size) { |
| 164 | return GetDexCacheResolvedMethods(pointer_size) == other_cache; |
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, size_t pointer_size) { |
| 168 | return GetDexCacheResolvedMethods(pointer_size) == |
| 169 | other->GetDexCacheResolvedMethods(pointer_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 170 | } |
| 171 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 172 | inline GcRoot<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes(size_t pointer_size) { |
| 173 | return GetNativePointer<GcRoot<mirror::Class>*>(DexCacheResolvedTypesOffset(pointer_size), |
| 174 | pointer_size); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 175 | } |
| 176 | |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 177 | template <bool kWithCheck> |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 178 | inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index, size_t ptr_size) { |
| 179 | if (kWithCheck) { |
| 180 | mirror::DexCache* dex_cache = |
| 181 | GetInterfaceMethodIfProxy(ptr_size)->GetDeclaringClass()->GetDexCache(); |
| 182 | if (UNLIKELY(type_index >= dex_cache->NumResolvedTypes())) { |
| 183 | ThrowArrayIndexOutOfBoundsException(type_index, dex_cache->NumResolvedTypes()); |
| 184 | return nullptr; |
| 185 | } |
| 186 | } |
| 187 | mirror::Class* klass = GetDexCacheResolvedTypes(ptr_size)[type_index].Read(); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 188 | return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr; |
| 189 | } |
| 190 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 191 | inline bool ArtMethod::HasDexCacheResolvedTypes(size_t pointer_size) { |
| 192 | return GetDexCacheResolvedTypes(pointer_size) != nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 193 | } |
| 194 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 195 | inline bool ArtMethod::HasSameDexCacheResolvedTypes(GcRoot<mirror::Class>* other_cache, |
| 196 | size_t pointer_size) { |
| 197 | return GetDexCacheResolvedTypes(pointer_size) == other_cache; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 200 | inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other, size_t pointer_size) { |
| 201 | return GetDexCacheResolvedTypes(pointer_size) == other->GetDexCacheResolvedTypes(pointer_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 202 | } |
| 203 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 204 | inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, |
| 205 | bool resolve, |
| 206 | size_t ptr_size) { |
| 207 | mirror::Class* type = GetDexCacheResolvedType(type_idx, ptr_size); |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 208 | if (type == nullptr && resolve) { |
| 209 | type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this); |
| 210 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 211 | } |
| 212 | return type; |
| 213 | } |
| 214 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 215 | inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 216 | switch (type) { |
| 217 | case kStatic: |
| 218 | return !IsStatic(); |
| 219 | case kDirect: |
| 220 | return !IsDirect() || IsStatic(); |
| 221 | case kVirtual: { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 222 | mirror::Class* methods_class = GetDeclaringClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 223 | return IsDirect() || (methods_class->IsInterface() && !IsMiranda()); |
| 224 | } |
| 225 | case kSuper: |
Andreas Gampe | 8f252e6 | 2014-08-25 20:46:31 -0700 | [diff] [blame] | 226 | // Constructors and static methods are called with invoke-direct. |
| 227 | // Interface methods cannot be invoked with invoke-super. |
| 228 | return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 229 | case kInterface: { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 230 | mirror::Class* methods_class = GetDeclaringClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 231 | return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass()); |
| 232 | } |
| 233 | default: |
| 234 | LOG(FATAL) << "Unreachable - invocation type: " << type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 235 | UNREACHABLE(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 236 | } |
| 237 | } |
| 238 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 239 | inline bool ArtMethod::IsRuntimeMethod() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 240 | return dex_method_index_ == DexFile::kDexNoIndex; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 241 | } |
| 242 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 243 | inline bool ArtMethod::IsCalleeSaveMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 244 | if (!IsRuntimeMethod()) { |
| 245 | return false; |
| 246 | } |
| 247 | Runtime* runtime = Runtime::Current(); |
| 248 | bool result = false; |
| 249 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 250 | if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) { |
| 251 | result = true; |
| 252 | break; |
| 253 | } |
| 254 | } |
| 255 | return result; |
| 256 | } |
| 257 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 258 | inline bool ArtMethod::IsResolutionMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 259 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 260 | // Check that if we do think it is phony it looks like the resolution method. |
| 261 | DCHECK(!result || IsRuntimeMethod()); |
| 262 | return result; |
| 263 | } |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 264 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 265 | inline bool ArtMethod::IsImtConflictMethod() { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 266 | bool result = this == Runtime::Current()->GetImtConflictMethod(); |
| 267 | // Check that if we do think it is phony it looks like the imt conflict method. |
| 268 | DCHECK(!result || IsRuntimeMethod()); |
| 269 | return result; |
| 270 | } |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 271 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 272 | inline bool ArtMethod::IsImtUnimplementedMethod() { |
| 273 | bool result = this == Runtime::Current()->GetImtUnimplementedMethod(); |
| 274 | // Check that if we do think it is phony it looks like the imt unimplemented method. |
| 275 | DCHECK(!result || IsRuntimeMethod()); |
| 276 | return result; |
| 277 | } |
| 278 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 279 | inline const DexFile* ArtMethod::GetDexFile() { |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 280 | return GetDexCache()->GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 281 | } |
| 282 | |
| 283 | inline const char* ArtMethod::GetDeclaringClassDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 284 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 285 | if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) { |
| 286 | return "<runtime method>"; |
| 287 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 288 | DCHECK(!IsProxyMethod()); |
| 289 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 290 | return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); |
| 291 | } |
| 292 | |
| 293 | inline const char* ArtMethod::GetShorty(uint32_t* out_length) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 294 | DCHECK(!IsProxyMethod()); |
| 295 | const DexFile* dex_file = GetDexFile(); |
| 296 | return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 297 | } |
| 298 | |
| 299 | inline const Signature ArtMethod::GetSignature() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 300 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 301 | if (dex_method_idx != DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 302 | DCHECK(!IsProxyMethod()); |
| 303 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 304 | return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx)); |
| 305 | } |
| 306 | return Signature::NoSignature(); |
| 307 | } |
| 308 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 309 | inline const char* ArtMethod::GetName() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 310 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 311 | if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 312 | DCHECK(!IsProxyMethod()); |
| 313 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 314 | return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx)); |
| 315 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 316 | Runtime* const runtime = Runtime::Current(); |
| 317 | if (this == runtime->GetResolutionMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 318 | return "<runtime internal resolution method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 319 | } else if (this == runtime->GetImtConflictMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 320 | return "<runtime internal imt conflict method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 321 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 322 | return "<runtime internal callee-save all registers method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 323 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 324 | return "<runtime internal callee-save reference registers method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 325 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 326 | return "<runtime internal callee-save reference and argument registers method>"; |
| 327 | } else { |
| 328 | return "<unknown runtime internal method>"; |
| 329 | } |
| 330 | } |
| 331 | |
| 332 | inline const DexFile::CodeItem* ArtMethod::GetCodeItem() { |
Mathieu Chartier | 12b3dd7 | 2014-12-11 13:25:33 -0800 | [diff] [blame] | 333 | return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 334 | } |
| 335 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 336 | inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx, size_t ptr_size) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 337 | DCHECK(!IsProxyMethod()); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 338 | return GetDexCacheResolvedType(type_idx, ptr_size) != nullptr; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 342 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 343 | if (dex_pc == DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 344 | return IsNative() ? -2 : -1; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 345 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 346 | return GetDexFile()->GetLineNumFromPC(this, dex_pc); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | inline const DexFile::ProtoId& ArtMethod::GetPrototype() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 350 | DCHECK(!IsProxyMethod()); |
| 351 | const DexFile* dex_file = GetDexFile(); |
| 352 | return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 353 | } |
| 354 | |
| 355 | inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() { |
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 | const DexFile::ProtoId& proto = dex_file->GetMethodPrototype( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 359 | dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 360 | return dex_file->GetProtoParameters(proto); |
| 361 | } |
| 362 | |
| 363 | inline const char* ArtMethod::GetDeclaringClassSourceFile() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 364 | DCHECK(!IsProxyMethod()); |
| 365 | return GetDeclaringClass()->GetSourceFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 366 | } |
| 367 | |
| 368 | inline uint16_t ArtMethod::GetClassDefIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 369 | DCHECK(!IsProxyMethod()); |
| 370 | return GetDeclaringClass()->GetDexClassDefIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | inline const DexFile::ClassDef& ArtMethod::GetClassDef() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 374 | DCHECK(!IsProxyMethod()); |
| 375 | return GetDexFile()->GetClassDef(GetClassDefIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | inline const char* ArtMethod::GetReturnTypeDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 379 | DCHECK(!IsProxyMethod()); |
| 380 | const DexFile* dex_file = GetDexFile(); |
| 381 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 382 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
| 383 | uint16_t return_type_idx = proto_id.return_type_idx_; |
| 384 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx)); |
| 385 | } |
| 386 | |
| 387 | inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 388 | DCHECK(!IsProxyMethod()); |
| 389 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 390 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx)); |
| 391 | } |
| 392 | |
| 393 | inline mirror::ClassLoader* ArtMethod::GetClassLoader() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 394 | DCHECK(!IsProxyMethod()); |
| 395 | return GetDeclaringClass()->GetClassLoader(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | inline mirror::DexCache* ArtMethod::GetDexCache() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 399 | DCHECK(!IsProxyMethod()); |
| 400 | return GetDeclaringClass()->GetDexCache(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 401 | } |
| 402 | |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 403 | inline bool ArtMethod::IsProxyMethod() { |
| 404 | return GetDeclaringClass()->IsProxyClass(); |
| 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 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 446 | template<typename RootVisitorType> |
Mathieu Chartier | 1147b9b | 2015-09-14 18:50:08 -0700 | [diff] [blame] | 447 | void ArtMethod::VisitRoots(RootVisitorType& visitor, size_t pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 448 | ArtMethod* interface_method = nullptr; |
| 449 | mirror::Class* klass = declaring_class_.Read(); |
| 450 | if (UNLIKELY(klass != nullptr && klass->IsProxyClass())) { |
| 451 | // For normal methods, dex cache shortcuts will be visited through the declaring class. |
| 452 | // However, for proxies we need to keep the interface method alive, so we visit its roots. |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 453 | interface_method = mirror::DexCache::GetElementPtrSize( |
| 454 | GetDexCacheResolvedMethods(pointer_size), |
| 455 | GetDexMethodIndex(), |
| 456 | pointer_size); |
| 457 | DCHECK(interface_method != nullptr); |
| 458 | DCHECK_EQ(interface_method, |
| 459 | Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this)); |
Mathieu Chartier | 1147b9b | 2015-09-14 18:50:08 -0700 | [diff] [blame] | 460 | interface_method->VisitRoots(visitor, pointer_size); |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 461 | } |
| 462 | |
Mathieu Chartier | e3b034a | 2015-05-31 14:29:23 -0700 | [diff] [blame] | 463 | visitor.VisitRootIfNonNull(declaring_class_.AddressWithoutBarrier()); |
Mathieu Chartier | 1147b9b | 2015-09-14 18:50:08 -0700 | [diff] [blame] | 464 | ProfilingInfo* profiling_info = GetProfilingInfo(pointer_size); |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 465 | if (hotness_count_ != 0 && !IsNative() && profiling_info != nullptr) { |
| 466 | profiling_info->VisitRoots(visitor); |
| 467 | } |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 468 | } |
| 469 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 470 | inline void ArtMethod::CopyFrom(const ArtMethod* src, size_t image_pointer_size) { |
| 471 | memcpy(reinterpret_cast<void*>(this), reinterpret_cast<const void*>(src), |
Vladimir Marko | 1463285 | 2015-08-17 12:07:23 +0100 | [diff] [blame] | 472 | Size(image_pointer_size)); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 473 | declaring_class_ = GcRoot<mirror::Class>(const_cast<ArtMethod*>(src)->GetDeclaringClass()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 474 | } |
| 475 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 476 | } // namespace art |
| 477 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 478 | #endif // ART_RUNTIME_ART_METHOD_INL_H_ |