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