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" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 23 | #include "dex_file.h" |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 24 | #include "dex_file-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 25 | #include "gc_root-inl.h" |
| 26 | #include "mirror/class-inl.h" |
| 27 | #include "mirror/dex_cache.h" |
| 28 | #include "mirror/object-inl.h" |
| 29 | #include "mirror/object_array.h" |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 30 | #include "oat.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 31 | #include "quick/quick_method_frame_info.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 32 | #include "read_barrier-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 33 | #include "runtime-inl.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 34 | #include "utils.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | |
| 36 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 37 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 38 | inline mirror::Class* ArtMethod::GetDeclaringClassUnchecked() { |
| 39 | return declaring_class_.Read(); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 40 | } |
| 41 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 42 | inline mirror::Class* ArtMethod::GetDeclaringClassNoBarrier() { |
| 43 | return declaring_class_.Read<kWithoutReadBarrier>(); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 44 | } |
| 45 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 46 | inline mirror::Class* ArtMethod::GetDeclaringClass() { |
| 47 | mirror::Class* result = GetDeclaringClassUnchecked(); |
| 48 | if (kIsDebugBuild) { |
| 49 | if (!IsRuntimeMethod()) { |
| 50 | CHECK(result != nullptr) << this; |
| 51 | CHECK(result->IsIdxLoaded() || result->IsErroneous()) |
| 52 | << result->GetStatus() << " " << PrettyClass(result); |
| 53 | } else { |
| 54 | CHECK(result == nullptr) << this; |
| 55 | } |
| 56 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 57 | return result; |
| 58 | } |
| 59 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 60 | inline void ArtMethod::SetDeclaringClass(mirror::Class* new_declaring_class) { |
| 61 | declaring_class_ = GcRoot<mirror::Class>(new_declaring_class); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 64 | inline uint32_t ArtMethod::GetAccessFlags() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 65 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() || |
| 66 | GetDeclaringClass()->IsErroneous()); |
| 67 | return access_flags_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 68 | } |
| 69 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 70 | inline uint16_t ArtMethod::GetMethodIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 71 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved() || |
| 72 | GetDeclaringClass()->IsErroneous()); |
| 73 | return method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 74 | } |
| 75 | |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 76 | inline uint16_t ArtMethod::GetMethodIndexDuringLinking() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 77 | return method_index_; |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 80 | inline uint32_t ArtMethod::GetDexMethodIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 81 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() || |
| 82 | GetDeclaringClass()->IsErroneous()); |
| 83 | return dex_method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 84 | } |
| 85 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 86 | inline mirror::PointerArray* ArtMethod::GetDexCacheResolvedMethods() { |
| 87 | return dex_cache_resolved_methods_.Read(); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 90 | inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, size_t ptr_size) { |
| 91 | auto* method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>( |
| 92 | method_index, ptr_size); |
| 93 | if (LIKELY(method != nullptr)) { |
| 94 | auto* declaring_class = method->GetDeclaringClass(); |
| 95 | if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) { |
| 96 | return method; |
| 97 | } |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 98 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 99 | return nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 102 | inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method, |
| 103 | size_t ptr_size) { |
| 104 | DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr); |
| 105 | GetDexCacheResolvedMethods()->SetElementPtrSize(method_idx, new_method, ptr_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| 108 | inline bool ArtMethod::HasDexCacheResolvedMethods() { |
| 109 | return GetDexCacheResolvedMethods() != nullptr; |
| 110 | } |
| 111 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 112 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(mirror::PointerArray* other_cache) { |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 113 | return GetDexCacheResolvedMethods() == other_cache; |
| 114 | } |
| 115 | |
| 116 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) { |
| 117 | return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods(); |
| 118 | } |
| 119 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 120 | inline mirror::ObjectArray<mirror::Class>* ArtMethod::GetDexCacheResolvedTypes() { |
| 121 | return dex_cache_resolved_types_.Read(); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 124 | template <bool kWithCheck> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 125 | inline mirror::Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) { |
| 126 | mirror::Class* klass = kWithCheck ? |
| 127 | GetDexCacheResolvedTypes()->Get(type_index) : |
| 128 | GetDexCacheResolvedTypes()->GetWithoutChecks(type_index); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 129 | return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr; |
| 130 | } |
| 131 | |
| 132 | inline bool ArtMethod::HasDexCacheResolvedTypes() { |
| 133 | return GetDexCacheResolvedTypes() != nullptr; |
| 134 | } |
| 135 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 136 | inline bool ArtMethod::HasSameDexCacheResolvedTypes( |
| 137 | mirror::ObjectArray<mirror::Class>* other_cache) { |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 138 | return GetDexCacheResolvedTypes() == other_cache; |
| 139 | } |
| 140 | |
| 141 | inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) { |
| 142 | return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes(); |
| 143 | } |
| 144 | |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 145 | inline mirror::Class* ArtMethod::GetClassFromTypeIndex(uint16_t type_idx, bool resolve) { |
| 146 | mirror::Class* type = GetDexCacheResolvedType(type_idx); |
| 147 | if (type == nullptr && resolve) { |
| 148 | type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this); |
| 149 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 150 | } |
| 151 | return type; |
| 152 | } |
| 153 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 154 | inline uint32_t ArtMethod::GetCodeSize() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 155 | DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this); |
Mathieu Chartier | e5f13e5 | 2015-02-24 09:37:21 -0800 | [diff] [blame] | 156 | return GetCodeSize(EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode())); |
| 157 | } |
| 158 | |
| 159 | inline uint32_t ArtMethod::GetCodeSize(const void* code) { |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 160 | if (code == nullptr) { |
| 161 | return 0u; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 162 | } |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 163 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 166 | inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 167 | switch (type) { |
| 168 | case kStatic: |
| 169 | return !IsStatic(); |
| 170 | case kDirect: |
| 171 | return !IsDirect() || IsStatic(); |
| 172 | case kVirtual: { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 173 | mirror::Class* methods_class = GetDeclaringClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 174 | return IsDirect() || (methods_class->IsInterface() && !IsMiranda()); |
| 175 | } |
| 176 | case kSuper: |
Andreas Gampe | 8f252e6 | 2014-08-25 20:46:31 -0700 | [diff] [blame] | 177 | // Constructors and static methods are called with invoke-direct. |
| 178 | // Interface methods cannot be invoked with invoke-super. |
| 179 | return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 180 | case kInterface: { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 181 | mirror::Class* methods_class = GetDeclaringClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 182 | return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass()); |
| 183 | } |
| 184 | default: |
| 185 | LOG(FATAL) << "Unreachable - invocation type: " << type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 186 | UNREACHABLE(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 187 | } |
| 188 | } |
| 189 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 190 | inline uint32_t ArtMethod::GetQuickOatCodeOffset() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 191 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 192 | return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 193 | } |
| 194 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 195 | inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 196 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 197 | SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset)); |
| 198 | } |
| 199 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 200 | inline const uint8_t* ArtMethod::GetMappingTable(size_t pointer_size) { |
| 201 | const void* code_pointer = GetQuickOatCodePointer(pointer_size); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 202 | if (code_pointer == nullptr) { |
| 203 | return nullptr; |
| 204 | } |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 205 | return GetMappingTable(code_pointer, pointer_size); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 206 | } |
| 207 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 208 | inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer, size_t pointer_size) { |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 209 | DCHECK(code_pointer != nullptr); |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 210 | DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size)); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 211 | uint32_t offset = |
| 212 | reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_; |
| 213 | if (UNLIKELY(offset == 0u)) { |
| 214 | return nullptr; |
| 215 | } |
| 216 | return reinterpret_cast<const uint8_t*>(code_pointer) - offset; |
| 217 | } |
| 218 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 219 | inline const uint8_t* ArtMethod::GetVmapTable(size_t pointer_size) { |
| 220 | const void* code_pointer = GetQuickOatCodePointer(pointer_size); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 221 | if (code_pointer == nullptr) { |
| 222 | return nullptr; |
| 223 | } |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 224 | return GetVmapTable(code_pointer, pointer_size); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 225 | } |
| 226 | |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 227 | inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer, size_t pointer_size) { |
| 228 | CHECK(!IsOptimized(pointer_size)) << "Unimplemented vmap table for optimized compiler"; |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 229 | DCHECK(code_pointer != nullptr); |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 230 | DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size)); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 231 | uint32_t offset = |
| 232 | reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_; |
| 233 | if (UNLIKELY(offset == 0u)) { |
| 234 | return nullptr; |
| 235 | } |
| 236 | return reinterpret_cast<const uint8_t*>(code_pointer) - offset; |
| 237 | } |
| 238 | |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 239 | inline CodeInfo ArtMethod::GetOptimizedCodeInfo() { |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 240 | DCHECK(IsOptimized(sizeof(void*))); |
| 241 | const void* code_pointer = GetQuickOatCodePointer(sizeof(void*)); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 242 | DCHECK(code_pointer != nullptr); |
| 243 | uint32_t offset = |
| 244 | reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 245 | const void* data = |
| 246 | reinterpret_cast<const void*>(reinterpret_cast<const uint8_t*>(code_pointer) - offset); |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame] | 247 | return CodeInfo(data); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 248 | } |
| 249 | |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 250 | inline const uint8_t* ArtMethod::GetNativeGcMap(size_t pointer_size) { |
| 251 | const void* code_pointer = GetQuickOatCodePointer(pointer_size); |
| 252 | if (code_pointer == nullptr) { |
| 253 | return nullptr; |
| 254 | } |
| 255 | return GetNativeGcMap(code_pointer, pointer_size); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 256 | } |
| 257 | |
Mathieu Chartier | 957ca1c | 2014-11-21 16:51:29 -0800 | [diff] [blame] | 258 | inline const uint8_t* ArtMethod::GetNativeGcMap(const void* code_pointer, size_t pointer_size) { |
| 259 | DCHECK(code_pointer != nullptr); |
| 260 | DCHECK_EQ(code_pointer, GetQuickOatCodePointer(pointer_size)); |
| 261 | uint32_t offset = |
| 262 | reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].gc_map_offset_; |
| 263 | if (UNLIKELY(offset == 0u)) { |
| 264 | return nullptr; |
| 265 | } |
| 266 | return reinterpret_cast<const uint8_t*>(code_pointer) - offset; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 267 | } |
| 268 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 269 | inline bool ArtMethod::IsRuntimeMethod() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 270 | return dex_method_index_ == DexFile::kDexNoIndex; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 271 | } |
| 272 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 273 | inline bool ArtMethod::IsCalleeSaveMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 274 | if (!IsRuntimeMethod()) { |
| 275 | return false; |
| 276 | } |
| 277 | Runtime* runtime = Runtime::Current(); |
| 278 | bool result = false; |
| 279 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 280 | if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) { |
| 281 | result = true; |
| 282 | break; |
| 283 | } |
| 284 | } |
| 285 | return result; |
| 286 | } |
| 287 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 288 | inline bool ArtMethod::IsResolutionMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 289 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 290 | // Check that if we do think it is phony it looks like the resolution method. |
| 291 | DCHECK(!result || IsRuntimeMethod()); |
| 292 | return result; |
| 293 | } |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 294 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 295 | inline bool ArtMethod::IsImtConflictMethod() { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 296 | bool result = this == Runtime::Current()->GetImtConflictMethod(); |
| 297 | // Check that if we do think it is phony it looks like the imt conflict method. |
| 298 | DCHECK(!result || IsRuntimeMethod()); |
| 299 | return result; |
| 300 | } |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 301 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 302 | inline bool ArtMethod::IsImtUnimplementedMethod() { |
| 303 | bool result = this == Runtime::Current()->GetImtUnimplementedMethod(); |
| 304 | // Check that if we do think it is phony it looks like the imt unimplemented method. |
| 305 | DCHECK(!result || IsRuntimeMethod()); |
| 306 | return result; |
| 307 | } |
| 308 | |
Ian Rogers | 6f3dbba | 2014-10-14 17:41:57 -0700 | [diff] [blame] | 309 | inline uintptr_t ArtMethod::NativeQuickPcOffset(const uintptr_t pc) { |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 310 | const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor( |
| 311 | this, sizeof(void*)); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 312 | return pc - reinterpret_cast<uintptr_t>(code); |
| 313 | } |
| 314 | |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 315 | inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) { |
| 316 | DCHECK(code_pointer != nullptr); |
Mathieu Chartier | a7dd038 | 2014-11-20 17:08:58 -0800 | [diff] [blame] | 317 | DCHECK_EQ(code_pointer, GetQuickOatCodePointer(sizeof(void*))); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 318 | return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_; |
| 319 | } |
| 320 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 321 | inline const DexFile* ArtMethod::GetDexFile() { |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 322 | return GetDexCache()->GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | inline const char* ArtMethod::GetDeclaringClassDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 326 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 327 | if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) { |
| 328 | return "<runtime method>"; |
| 329 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 330 | DCHECK(!IsProxyMethod()); |
| 331 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 332 | return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); |
| 333 | } |
| 334 | |
| 335 | inline const char* ArtMethod::GetShorty(uint32_t* out_length) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 336 | DCHECK(!IsProxyMethod()); |
| 337 | const DexFile* dex_file = GetDexFile(); |
| 338 | return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 339 | } |
| 340 | |
| 341 | inline const Signature ArtMethod::GetSignature() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 342 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 343 | if (dex_method_idx != DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 344 | DCHECK(!IsProxyMethod()); |
| 345 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 346 | return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx)); |
| 347 | } |
| 348 | return Signature::NoSignature(); |
| 349 | } |
| 350 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 351 | inline const char* ArtMethod::GetName() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 352 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 353 | if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 354 | DCHECK(!IsProxyMethod()); |
| 355 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 356 | return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx)); |
| 357 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 358 | Runtime* const runtime = Runtime::Current(); |
| 359 | if (this == runtime->GetResolutionMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 360 | return "<runtime internal resolution method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 361 | } else if (this == runtime->GetImtConflictMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 362 | return "<runtime internal imt conflict method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 363 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 364 | return "<runtime internal callee-save all registers method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 365 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 366 | return "<runtime internal callee-save reference registers method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 367 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 368 | return "<runtime internal callee-save reference and argument registers method>"; |
| 369 | } else { |
| 370 | return "<unknown runtime internal method>"; |
| 371 | } |
| 372 | } |
| 373 | |
| 374 | inline const DexFile::CodeItem* ArtMethod::GetCodeItem() { |
Mathieu Chartier | 12b3dd7 | 2014-12-11 13:25:33 -0800 | [diff] [blame] | 375 | return GetDeclaringClass()->GetDexFile().GetCodeItem(GetCodeItemOffset()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 376 | } |
| 377 | |
| 378 | inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 379 | DCHECK(!IsProxyMethod()); |
| 380 | return GetDexCacheResolvedType(type_idx) != nullptr; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 381 | } |
| 382 | |
| 383 | inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 384 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 385 | if (dex_pc == DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 386 | return IsNative() ? -2 : -1; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 387 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 388 | return GetDexFile()->GetLineNumFromPC(this, dex_pc); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 389 | } |
| 390 | |
| 391 | inline const DexFile::ProtoId& ArtMethod::GetPrototype() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 392 | DCHECK(!IsProxyMethod()); |
| 393 | const DexFile* dex_file = GetDexFile(); |
| 394 | return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 395 | } |
| 396 | |
| 397 | inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 398 | DCHECK(!IsProxyMethod()); |
| 399 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 400 | const DexFile::ProtoId& proto = dex_file->GetMethodPrototype( |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 401 | dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 402 | return dex_file->GetProtoParameters(proto); |
| 403 | } |
| 404 | |
| 405 | inline const char* ArtMethod::GetDeclaringClassSourceFile() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 406 | DCHECK(!IsProxyMethod()); |
| 407 | return GetDeclaringClass()->GetSourceFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 408 | } |
| 409 | |
| 410 | inline uint16_t ArtMethod::GetClassDefIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 411 | DCHECK(!IsProxyMethod()); |
| 412 | return GetDeclaringClass()->GetDexClassDefIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 413 | } |
| 414 | |
| 415 | inline const DexFile::ClassDef& ArtMethod::GetClassDef() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 416 | DCHECK(!IsProxyMethod()); |
| 417 | return GetDexFile()->GetClassDef(GetClassDefIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 418 | } |
| 419 | |
| 420 | inline const char* ArtMethod::GetReturnTypeDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 421 | DCHECK(!IsProxyMethod()); |
| 422 | const DexFile* dex_file = GetDexFile(); |
| 423 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 424 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
| 425 | uint16_t return_type_idx = proto_id.return_type_idx_; |
| 426 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx)); |
| 427 | } |
| 428 | |
| 429 | inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 430 | DCHECK(!IsProxyMethod()); |
| 431 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 432 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx)); |
| 433 | } |
| 434 | |
| 435 | inline mirror::ClassLoader* ArtMethod::GetClassLoader() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 436 | DCHECK(!IsProxyMethod()); |
| 437 | return GetDeclaringClass()->GetClassLoader(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 438 | } |
| 439 | |
| 440 | inline mirror::DexCache* ArtMethod::GetDexCache() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 441 | DCHECK(!IsProxyMethod()); |
| 442 | return GetDeclaringClass()->GetDexCache(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 443 | } |
| 444 | |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 445 | inline bool ArtMethod::IsProxyMethod() { |
| 446 | return GetDeclaringClass()->IsProxyClass(); |
| 447 | } |
| 448 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 449 | inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(size_t pointer_size) { |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 450 | if (LIKELY(!IsProxyMethod())) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 451 | return this; |
| 452 | } |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 453 | mirror::Class* klass = GetDeclaringClass(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 454 | auto interface_method = GetDexCacheResolvedMethods()->GetElementPtrSize<ArtMethod*>( |
| 455 | GetDexMethodIndex(), pointer_size); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 456 | DCHECK(interface_method != nullptr); |
| 457 | DCHECK_EQ(interface_method, |
| 458 | Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this)); |
| 459 | return interface_method; |
| 460 | } |
| 461 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 462 | inline void ArtMethod::SetDexCacheResolvedMethods(mirror::PointerArray* new_dex_cache_methods) { |
| 463 | dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>(new_dex_cache_methods); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 464 | } |
| 465 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 466 | inline void ArtMethod::SetDexCacheResolvedTypes( |
| 467 | mirror::ObjectArray<mirror::Class>* new_dex_cache_types) { |
| 468 | dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>(new_dex_cache_types); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 471 | inline mirror::Class* ArtMethod::GetReturnType(bool resolve) { |
| 472 | DCHECK(!IsProxyMethod()); |
| 473 | const DexFile* dex_file = GetDexFile(); |
| 474 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
| 475 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
| 476 | uint16_t return_type_idx = proto_id.return_type_idx_; |
| 477 | mirror::Class* type = GetDexCacheResolvedType(return_type_idx); |
| 478 | if (type == nullptr && resolve) { |
| 479 | type = Runtime::Current()->GetClassLinker()->ResolveType(return_type_idx, this); |
| 480 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 481 | } |
| 482 | return type; |
| 483 | } |
| 484 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 485 | template<typename RootVisitorType> |
| 486 | void ArtMethod::VisitRoots(RootVisitorType& visitor) { |
| 487 | visitor.VisitRoot(declaring_class_.AddressWithoutBarrier()); |
| 488 | visitor.VisitRoot(dex_cache_resolved_methods_.AddressWithoutBarrier()); |
| 489 | visitor.VisitRoot(dex_cache_resolved_types_.AddressWithoutBarrier()); |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 490 | } |
| 491 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 492 | inline void ArtMethod::CopyFrom(const ArtMethod* src, size_t image_pointer_size) { |
| 493 | memcpy(reinterpret_cast<void*>(this), reinterpret_cast<const void*>(src), |
| 494 | ObjectSize(image_pointer_size)); |
| 495 | declaring_class_ = GcRoot<mirror::Class>(const_cast<ArtMethod*>(src)->GetDeclaringClass()); |
| 496 | dex_cache_resolved_methods_ = GcRoot<mirror::PointerArray>( |
| 497 | const_cast<ArtMethod*>(src)->GetDexCacheResolvedMethods()); |
| 498 | dex_cache_resolved_types_ = GcRoot<mirror::ObjectArray<mirror::Class>>( |
| 499 | const_cast<ArtMethod*>(src)->GetDexCacheResolvedTypes()); |
| 500 | } |
| 501 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 502 | } // namespace art |
| 503 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame^] | 504 | #endif // ART_RUNTIME_ART_METHOD_INL_H_ |