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