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