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 | 7655f29 | 2013-07-29 11:07:13 -0700 | [diff] [blame] | 27 | #include "entrypoints/entrypoint_utils.h" |
Ian Rogers | 22d5e73 | 2014-07-15 22:23:51 -0700 | [diff] [blame] | 28 | #include "method_helper.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 29 | #include "object-inl.h" |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 30 | #include "object_array.h" |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 31 | #include "oat.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 32 | #include "quick/quick_method_frame_info.h" |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 33 | #include "read_barrier-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 34 | #include "runtime-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 35 | |
| 36 | namespace art { |
| 37 | namespace mirror { |
| 38 | |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 39 | inline uint32_t ArtMethod::ClassSize() { |
| 40 | uint32_t vtable_entries = Object::kVTableLength + 8; |
Fred Shih | 37f05ef | 2014-07-16 18:38:08 -0700 | [diff] [blame] | 41 | return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 42 | } |
| 43 | |
| 44 | template<ReadBarrierOption kReadBarrierOption> |
| 45 | inline Class* ArtMethod::GetJavaLangReflectArtMethod() { |
Hiroshi Yamauchi | 94f7b49 | 2014-07-22 18:08:23 -0700 | [diff] [blame] | 46 | DCHECK(!java_lang_reflect_ArtMethod_.IsNull()); |
| 47 | return java_lang_reflect_ArtMethod_.Read<kReadBarrierOption>(); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 48 | } |
| 49 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 50 | inline Class* ArtMethod::GetDeclaringClass() { |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 51 | Class* result = GetFieldObject<Class>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 52 | DCHECK(result != NULL) << this; |
| 53 | DCHECK(result->IsIdxLoaded() || result->IsErroneous()) << this; |
| 54 | return result; |
| 55 | } |
| 56 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 57 | inline void ArtMethod::SetDeclaringClass(Class *new_declaring_class) { |
Sebastien Hertz | d2fe10a | 2014-01-15 10:20:56 +0100 | [diff] [blame] | 58 | SetFieldObject<false>(OFFSET_OF_OBJECT_MEMBER(ArtMethod, declaring_class_), |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 59 | new_declaring_class); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 60 | } |
| 61 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 62 | inline uint32_t ArtMethod::GetAccessFlags() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 63 | DCHECK(GetDeclaringClass()->IsIdxLoaded() || GetDeclaringClass()->IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 64 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, access_flags_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 65 | } |
| 66 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 67 | inline uint16_t ArtMethod::GetMethodIndex() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 68 | DCHECK(GetDeclaringClass()->IsResolved() || GetDeclaringClass()->IsErroneous()); |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 69 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, method_index_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 70 | } |
| 71 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 72 | inline uint32_t ArtMethod::GetDexMethodIndex() { |
Dragos Sbirlea | 90af14d | 2013-08-15 17:50:16 -0700 | [diff] [blame] | 73 | #ifdef ART_SEA_IR_MODE |
| 74 | // TODO: Re-add this check for (PORTABLE + SMALL + ) SEA IR when PORTABLE IS fixed! |
| 75 | // DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
| 76 | #else |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 77 | DCHECK(GetDeclaringClass()->IsLoaded() || GetDeclaringClass()->IsErroneous()); |
Dragos Sbirlea | 90af14d | 2013-08-15 17:50:16 -0700 | [diff] [blame] | 78 | #endif |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 79 | return GetField32(OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_method_index_)); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 80 | } |
| 81 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 82 | inline ObjectArray<String>* ArtMethod::GetDexCacheStrings() { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 83 | return GetFieldObject<ObjectArray<String>>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 84 | OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_strings_)); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 85 | } |
| 86 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 87 | inline ObjectArray<ArtMethod>* ArtMethod::GetDexCacheResolvedMethods() { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 88 | return GetFieldObject<ObjectArray<ArtMethod>>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 89 | OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_methods_)); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 90 | } |
| 91 | |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 92 | inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index) { |
| 93 | ArtMethod* method = GetDexCacheResolvedMethods()->Get(method_index); |
| 94 | if (method != nullptr && !method->GetDeclaringClass()->IsErroneous()) { |
| 95 | return method; |
| 96 | } else { |
| 97 | return nullptr; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_idx, ArtMethod* new_method) { |
| 102 | GetDexCacheResolvedMethods()->Set<false>(method_idx, new_method); |
| 103 | } |
| 104 | |
| 105 | inline bool ArtMethod::HasDexCacheResolvedMethods() { |
| 106 | return GetDexCacheResolvedMethods() != nullptr; |
| 107 | } |
| 108 | |
| 109 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ObjectArray<ArtMethod>* other_cache) { |
| 110 | return GetDexCacheResolvedMethods() == other_cache; |
| 111 | } |
| 112 | |
| 113 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other) { |
| 114 | return GetDexCacheResolvedMethods() == other->GetDexCacheResolvedMethods(); |
| 115 | } |
| 116 | |
| 117 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 118 | inline ObjectArray<Class>* ArtMethod::GetDexCacheResolvedTypes() { |
Ian Rogers | 700a402 | 2014-05-19 16:49:03 -0700 | [diff] [blame] | 119 | return GetFieldObject<ObjectArray<Class>>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 120 | OFFSET_OF_OBJECT_MEMBER(ArtMethod, dex_cache_resolved_types_)); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 121 | } |
| 122 | |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 123 | template <bool kWithCheck> |
| 124 | inline Class* ArtMethod::GetDexCacheResolvedType(uint32_t type_index) { |
| 125 | Class* klass; |
| 126 | if (kWithCheck) { |
| 127 | klass = GetDexCacheResolvedTypes()->Get(type_index); |
| 128 | } else { |
| 129 | klass = GetDexCacheResolvedTypes()->GetWithoutChecks(type_index); |
| 130 | } |
| 131 | return (klass != nullptr && !klass->IsErroneous()) ? klass : nullptr; |
| 132 | } |
| 133 | |
| 134 | inline bool ArtMethod::HasDexCacheResolvedTypes() { |
| 135 | return GetDexCacheResolvedTypes() != nullptr; |
| 136 | } |
| 137 | |
| 138 | inline bool ArtMethod::HasSameDexCacheResolvedTypes(ObjectArray<Class>* other_cache) { |
| 139 | return GetDexCacheResolvedTypes() == other_cache; |
| 140 | } |
| 141 | |
| 142 | inline bool ArtMethod::HasSameDexCacheResolvedTypes(ArtMethod* other) { |
| 143 | return GetDexCacheResolvedTypes() == other->GetDexCacheResolvedTypes(); |
| 144 | } |
| 145 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 146 | inline uint32_t ArtMethod::GetCodeSize() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 147 | DCHECK(!IsRuntimeMethod() && !IsProxyMethod()) << PrettyMethod(this); |
Vladimir Marko | 8a63057 | 2014-04-09 18:45:35 +0100 | [diff] [blame] | 148 | const void* code = EntryPointToCodePointer(GetEntryPointFromQuickCompiledCode()); |
| 149 | if (code == nullptr) { |
| 150 | return 0u; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 151 | } |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 152 | return reinterpret_cast<const OatQuickMethodHeader*>(code)[-1].code_size_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 153 | } |
| 154 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 155 | inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 156 | switch (type) { |
| 157 | case kStatic: |
| 158 | return !IsStatic(); |
| 159 | case kDirect: |
| 160 | return !IsDirect() || IsStatic(); |
| 161 | case kVirtual: { |
| 162 | Class* methods_class = GetDeclaringClass(); |
| 163 | return IsDirect() || (methods_class->IsInterface() && !IsMiranda()); |
| 164 | } |
| 165 | case kSuper: |
Andreas Gampe | 8f252e6 | 2014-08-25 20:46:31 -0700 | [diff] [blame] | 166 | // Constructors and static methods are called with invoke-direct. |
| 167 | // Interface methods cannot be invoked with invoke-super. |
| 168 | return IsConstructor() || IsStatic() || GetDeclaringClass()->IsInterface(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 169 | case kInterface: { |
| 170 | Class* methods_class = GetDeclaringClass(); |
| 171 | return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass()); |
| 172 | } |
| 173 | default: |
| 174 | LOG(FATAL) << "Unreachable - invocation type: " << type; |
| 175 | return true; |
| 176 | } |
| 177 | } |
| 178 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 179 | inline void ArtMethod::AssertPcIsWithinQuickCode(uintptr_t pc) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 180 | if (!kIsDebugBuild) { |
| 181 | return; |
| 182 | } |
| 183 | if (IsNative() || IsRuntimeMethod() || IsProxyMethod()) { |
| 184 | return; |
| 185 | } |
Ian Rogers | 848871b | 2013-08-05 10:56:33 -0700 | [diff] [blame] | 186 | if (pc == GetQuickInstrumentationExitPc()) { |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 187 | return; |
| 188 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 189 | const void* code = GetEntryPointFromQuickCompiledCode(); |
| 190 | if (code == GetQuickToInterpreterBridge() || code == GetQuickInstrumentationEntryPoint()) { |
Ian Rogers | 62d6c77 | 2013-02-27 08:32:07 -0800 | [diff] [blame] | 191 | return; |
| 192 | } |
Jeff Hao | 0aba0ba | 2013-06-03 14:49:28 -0700 | [diff] [blame] | 193 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 194 | if (code == class_linker->GetQuickResolutionTrampoline() || |
| 195 | code == class_linker->GetQuickToInterpreterBridgeTrampoline()) { |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 196 | return; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 197 | } |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 198 | DCHECK(IsWithinQuickCode(pc)) |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 199 | << PrettyMethod(this) |
| 200 | << " pc=" << std::hex << pc |
Jeff Hao | 65d15d9 | 2013-07-16 16:39:33 -0700 | [diff] [blame] | 201 | << " code=" << code |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 202 | << " size=" << GetCodeSize(); |
| 203 | } |
| 204 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 205 | inline uint32_t ArtMethod::GetQuickOatCodeOffset() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 206 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 207 | return PointerToLowMemUInt32(GetEntryPointFromQuickCompiledCode()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 210 | inline uint32_t ArtMethod::GetPortableOatCodeOffset() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 211 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 212 | return PointerToLowMemUInt32(GetEntryPointFromPortableCompiledCode()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 213 | } |
| 214 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 215 | inline void ArtMethod::SetQuickOatCodeOffset(uint32_t code_offset) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 216 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 217 | SetEntryPointFromQuickCompiledCode(reinterpret_cast<void*>(code_offset)); |
| 218 | } |
| 219 | |
| 220 | inline void ArtMethod::SetPortableOatCodeOffset(uint32_t code_offset) { |
| 221 | DCHECK(!Runtime::Current()->IsStarted()); |
| 222 | SetEntryPointFromPortableCompiledCode(reinterpret_cast<void*>(code_offset)); |
| 223 | } |
| 224 | |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 225 | inline const void* ArtMethod::GetQuickOatEntryPoint() { |
| 226 | if (IsPortableCompiled() || IsAbstract() || IsRuntimeMethod() || IsProxyMethod()) { |
| 227 | return nullptr; |
| 228 | } |
| 229 | Runtime* runtime = Runtime::Current(); |
| 230 | const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this); |
| 231 | // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method |
| 232 | // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline) |
| 233 | // for non-native methods. |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 234 | DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline()); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 235 | if (UNLIKELY(entry_point == GetQuickToInterpreterBridge()) || |
| 236 | UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) { |
| 237 | return nullptr; |
| 238 | } |
| 239 | return entry_point; |
| 240 | } |
| 241 | |
| 242 | inline const void* ArtMethod::GetQuickOatCodePointer() { |
| 243 | return EntryPointToCodePointer(GetQuickOatEntryPoint()); |
| 244 | } |
| 245 | |
| 246 | inline const uint8_t* ArtMethod::GetMappingTable() { |
| 247 | const void* code_pointer = GetQuickOatCodePointer(); |
| 248 | if (code_pointer == nullptr) { |
| 249 | return nullptr; |
| 250 | } |
| 251 | return GetMappingTable(code_pointer); |
| 252 | } |
| 253 | |
| 254 | inline const uint8_t* ArtMethod::GetMappingTable(const void* code_pointer) { |
| 255 | DCHECK(code_pointer != nullptr); |
| 256 | DCHECK(code_pointer == GetQuickOatCodePointer()); |
| 257 | uint32_t offset = |
| 258 | reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].mapping_table_offset_; |
| 259 | if (UNLIKELY(offset == 0u)) { |
| 260 | return nullptr; |
| 261 | } |
| 262 | return reinterpret_cast<const uint8_t*>(code_pointer) - offset; |
| 263 | } |
| 264 | |
| 265 | inline const uint8_t* ArtMethod::GetVmapTable() { |
| 266 | const void* code_pointer = GetQuickOatCodePointer(); |
| 267 | if (code_pointer == nullptr) { |
| 268 | return nullptr; |
| 269 | } |
| 270 | return GetVmapTable(code_pointer); |
| 271 | } |
| 272 | |
| 273 | inline const uint8_t* ArtMethod::GetVmapTable(const void* code_pointer) { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 274 | if (IsOptimized()) { |
| 275 | LOG(FATAL) << "Unimplemented vmap table for optimized compiler"; |
| 276 | } |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 277 | DCHECK(code_pointer != nullptr); |
| 278 | DCHECK(code_pointer == GetQuickOatCodePointer()); |
| 279 | uint32_t offset = |
| 280 | reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_; |
| 281 | if (UNLIKELY(offset == 0u)) { |
| 282 | return nullptr; |
| 283 | } |
| 284 | return reinterpret_cast<const uint8_t*>(code_pointer) - offset; |
| 285 | } |
| 286 | |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 287 | inline StackMap ArtMethod::GetStackMap(uint32_t native_pc_offset) { |
Nicolas Geoffray | e982f0b | 2014-08-13 02:11:24 +0100 | [diff] [blame^] | 288 | return GetOptimizedCodeInfo().GetStackMapForNativePcOffset(native_pc_offset); |
| 289 | } |
| 290 | |
| 291 | inline CodeInfo ArtMethod::GetOptimizedCodeInfo() { |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 292 | DCHECK(IsOptimized()); |
| 293 | const void* code_pointer = GetQuickOatCodePointer(); |
| 294 | DCHECK(code_pointer != nullptr); |
| 295 | uint32_t offset = |
| 296 | reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].vmap_table_offset_; |
| 297 | 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^] | 298 | return CodeInfo(data); |
Nicolas Geoffray | 3946844 | 2014-09-02 15:17:15 +0100 | [diff] [blame] | 299 | } |
| 300 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 301 | inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 302 | DCHECK(!Runtime::Current()->IsStarted()); |
| 303 | SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset)); |
| 304 | } |
| 305 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 306 | inline uint32_t ArtMethod::GetOatNativeGcMapOffset() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 307 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 308 | return PointerToLowMemUInt32(GetNativeGcMap()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 309 | } |
| 310 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 311 | inline bool ArtMethod::IsRuntimeMethod() { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 312 | return GetDexMethodIndex() == DexFile::kDexNoIndex; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 313 | } |
| 314 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 315 | inline bool ArtMethod::IsCalleeSaveMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 316 | if (!IsRuntimeMethod()) { |
| 317 | return false; |
| 318 | } |
| 319 | Runtime* runtime = Runtime::Current(); |
| 320 | bool result = false; |
| 321 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 322 | if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) { |
| 323 | result = true; |
| 324 | break; |
| 325 | } |
| 326 | } |
| 327 | return result; |
| 328 | } |
| 329 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 330 | inline bool ArtMethod::IsResolutionMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 331 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 332 | // Check that if we do think it is phony it looks like the resolution method. |
| 333 | DCHECK(!result || IsRuntimeMethod()); |
| 334 | return result; |
| 335 | } |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 336 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 337 | inline bool ArtMethod::IsImtConflictMethod() { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 338 | bool result = this == Runtime::Current()->GetImtConflictMethod(); |
| 339 | // Check that if we do think it is phony it looks like the imt conflict method. |
| 340 | DCHECK(!result || IsRuntimeMethod()); |
| 341 | return result; |
| 342 | } |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 343 | |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 344 | inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc) { |
| 345 | const void* code = Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this); |
| 346 | return pc - reinterpret_cast<uintptr_t>(code); |
| 347 | } |
| 348 | |
| 349 | inline uintptr_t ArtMethod::NativePcOffset(const uintptr_t pc, const void* quick_entry_point) { |
| 350 | DCHECK(quick_entry_point != GetQuickToInterpreterBridge()); |
| 351 | DCHECK(quick_entry_point == Runtime::Current()->GetInstrumentation()->GetQuickCodeFor(this)); |
| 352 | return pc - reinterpret_cast<uintptr_t>(quick_entry_point); |
| 353 | } |
| 354 | |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 355 | template<VerifyObjectFlags kVerifyFlags> |
| 356 | inline void ArtMethod::SetNativeMethod(const void* native_method) { |
| 357 | SetFieldPtr<false, true, kVerifyFlags>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 358 | OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_), native_method); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 359 | } |
| 360 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 361 | inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() { |
| 362 | if (UNLIKELY(IsPortableCompiled())) { |
| 363 | // Portable compiled dex bytecode or jni stub. |
| 364 | return QuickMethodFrameInfo(kStackAlignment, 0u, 0u); |
| 365 | } |
| 366 | Runtime* runtime = Runtime::Current(); |
Serguei Katkov | 805bab1 | 2014-08-29 18:20:15 +0700 | [diff] [blame] | 367 | // For Proxy method we exclude direct method (there is only one direct method - constructor). |
| 368 | // Direct method is cloned from original java.lang.reflect.Proxy class together with code |
| 369 | // and as a result it is executed as usual quick compiled method without any stubs. |
| 370 | // So the frame info should be returned as it is a quick method not a stub. |
| 371 | if (UNLIKELY(IsAbstract()) || UNLIKELY(IsProxyMethod() && !IsDirect())) { |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 372 | return runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs); |
| 373 | } |
| 374 | if (UNLIKELY(IsRuntimeMethod())) { |
| 375 | return runtime->GetRuntimeMethodFrameInfo(this); |
| 376 | } |
| 377 | |
| 378 | const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this); |
| 379 | // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method |
| 380 | // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline) |
| 381 | // for non-native methods. And we really shouldn't see a failure for non-native methods here. |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 382 | DCHECK(entry_point != runtime->GetClassLinker()->GetQuickToInterpreterBridgeTrampoline()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 383 | CHECK(entry_point != GetQuickToInterpreterBridge()); |
| 384 | |
Dmitry Petrochenko | f0972a4 | 2014-05-16 17:43:39 +0700 | [diff] [blame] | 385 | if (UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) { |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 386 | // Generic JNI frame. |
| 387 | DCHECK(IsNative()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 388 | StackHandleScope<1> hs(Thread::Current()); |
| 389 | uint32_t handle_refs = |
| 390 | MethodHelper(hs.NewHandle(this)).GetNumberOfReferenceArgsWithoutReceiver() + 1; |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 391 | size_t scope_size = HandleScope::SizeOf(handle_refs); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 392 | QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs); |
Andreas Gampe | cf4035a | 2014-05-28 22:43:01 -0700 | [diff] [blame] | 393 | |
| 394 | // Callee saves + handle scope + method ref + alignment |
| 395 | size_t frame_size = RoundUp(callee_info.FrameSizeInBytes() + scope_size |
| 396 | - kPointerSize // callee-save frame stores a whole method pointer |
| 397 | + sizeof(StackReference<mirror::ArtMethod>), |
| 398 | kStackAlignment); |
| 399 | |
| 400 | return QuickMethodFrameInfo(frame_size, callee_info.CoreSpillMask(), callee_info.FpSpillMask()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 401 | } |
| 402 | |
| 403 | const void* code_pointer = EntryPointToCodePointer(entry_point); |
Vladimir Marko | 4c1c510 | 2014-05-14 16:51:16 +0100 | [diff] [blame] | 404 | return GetQuickFrameInfo(code_pointer); |
| 405 | } |
| 406 | |
| 407 | inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo(const void* code_pointer) { |
| 408 | DCHECK(code_pointer != nullptr); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 409 | DCHECK_EQ(code_pointer, GetQuickOatCodePointer()); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 410 | return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_; |
| 411 | } |
| 412 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 413 | inline const DexFile* ArtMethod::GetDexFile() { |
| 414 | return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache()->GetDexFile(); |
| 415 | } |
| 416 | |
| 417 | inline const char* ArtMethod::GetDeclaringClassDescriptor() { |
| 418 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 419 | uint32_t dex_method_idx = method->GetDexMethodIndex(); |
| 420 | if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) { |
| 421 | return "<runtime method>"; |
| 422 | } |
| 423 | const DexFile* dex_file = method->GetDexFile(); |
| 424 | return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); |
| 425 | } |
| 426 | |
| 427 | inline const char* ArtMethod::GetShorty(uint32_t* out_length) { |
| 428 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 429 | const DexFile* dex_file = method->GetDexFile(); |
| 430 | return dex_file->GetMethodShorty(dex_file->GetMethodId(method->GetDexMethodIndex()), out_length); |
| 431 | } |
| 432 | |
| 433 | inline const Signature ArtMethod::GetSignature() { |
| 434 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 435 | uint32_t dex_method_idx = method->GetDexMethodIndex(); |
| 436 | if (dex_method_idx != DexFile::kDexNoIndex) { |
| 437 | const DexFile* dex_file = method->GetDexFile(); |
| 438 | return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx)); |
| 439 | } |
| 440 | return Signature::NoSignature(); |
| 441 | } |
| 442 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 443 | inline const char* ArtMethod::GetName() { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 444 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 445 | uint32_t dex_method_idx = method->GetDexMethodIndex(); |
| 446 | if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) { |
| 447 | const DexFile* dex_file = method->GetDexFile(); |
| 448 | return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx)); |
| 449 | } |
| 450 | Runtime* runtime = Runtime::Current(); |
| 451 | if (method == runtime->GetResolutionMethod()) { |
| 452 | return "<runtime internal resolution method>"; |
| 453 | } else if (method == runtime->GetImtConflictMethod()) { |
| 454 | return "<runtime internal imt conflict method>"; |
| 455 | } else if (method == runtime->GetCalleeSaveMethod(Runtime::kSaveAll)) { |
| 456 | return "<runtime internal callee-save all registers method>"; |
| 457 | } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsOnly)) { |
| 458 | return "<runtime internal callee-save reference registers method>"; |
| 459 | } else if (method == runtime->GetCalleeSaveMethod(Runtime::kRefsAndArgs)) { |
| 460 | return "<runtime internal callee-save reference and argument registers method>"; |
| 461 | } else { |
| 462 | return "<unknown runtime internal method>"; |
| 463 | } |
| 464 | } |
| 465 | |
| 466 | inline const DexFile::CodeItem* ArtMethod::GetCodeItem() { |
| 467 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 468 | return method->GetDexFile()->GetCodeItem(method->GetCodeItemOffset()); |
| 469 | } |
| 470 | |
| 471 | inline bool ArtMethod::IsResolvedTypeIdx(uint16_t type_idx) { |
| 472 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 473 | return method->GetDexCacheResolvedType(type_idx) != nullptr; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 474 | } |
| 475 | |
| 476 | inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) { |
| 477 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 478 | if (dex_pc == DexFile::kDexNoIndex) { |
| 479 | return method->IsNative() ? -2 : -1; |
| 480 | } |
| 481 | return method->GetDexFile()->GetLineNumFromPC(method, dex_pc); |
| 482 | } |
| 483 | |
| 484 | inline const DexFile::ProtoId& ArtMethod::GetPrototype() { |
| 485 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 486 | const DexFile* dex_file = method->GetDexFile(); |
| 487 | return dex_file->GetMethodPrototype(dex_file->GetMethodId(method->GetDexMethodIndex())); |
| 488 | } |
| 489 | |
| 490 | inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() { |
| 491 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 492 | const DexFile* dex_file = method->GetDexFile(); |
| 493 | const DexFile::ProtoId& proto = dex_file->GetMethodPrototype( |
| 494 | dex_file->GetMethodId(method->GetDexMethodIndex())); |
| 495 | return dex_file->GetProtoParameters(proto); |
| 496 | } |
| 497 | |
| 498 | inline const char* ArtMethod::GetDeclaringClassSourceFile() { |
| 499 | return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetSourceFile(); |
| 500 | } |
| 501 | |
| 502 | inline uint16_t ArtMethod::GetClassDefIndex() { |
| 503 | return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexClassDefIndex(); |
| 504 | } |
| 505 | |
| 506 | inline const DexFile::ClassDef& ArtMethod::GetClassDef() { |
| 507 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 508 | return method->GetDexFile()->GetClassDef(GetClassDefIndex()); |
| 509 | } |
| 510 | |
| 511 | inline const char* ArtMethod::GetReturnTypeDescriptor() { |
| 512 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 513 | const DexFile* dex_file = method->GetDexFile(); |
| 514 | const DexFile::MethodId& method_id = dex_file->GetMethodId(method->GetDexMethodIndex()); |
| 515 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
| 516 | uint16_t return_type_idx = proto_id.return_type_idx_; |
| 517 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(return_type_idx)); |
| 518 | } |
| 519 | |
| 520 | inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(uint16_t type_idx) { |
| 521 | mirror::ArtMethod* method = GetInterfaceMethodIfProxy(); |
| 522 | const DexFile* dex_file = method->GetDexFile(); |
| 523 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx)); |
| 524 | } |
| 525 | |
| 526 | inline mirror::ClassLoader* ArtMethod::GetClassLoader() { |
| 527 | return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetClassLoader(); |
| 528 | } |
| 529 | |
| 530 | inline mirror::DexCache* ArtMethod::GetDexCache() { |
| 531 | return GetInterfaceMethodIfProxy()->GetDeclaringClass()->GetDexCache(); |
| 532 | } |
| 533 | |
| 534 | inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy() { |
| 535 | mirror::Class* klass = GetDeclaringClass(); |
| 536 | if (LIKELY(!klass->IsProxyClass())) { |
| 537 | return this; |
| 538 | } |
| 539 | mirror::ArtMethod* interface_method = GetDexCacheResolvedMethods()->Get(GetDexMethodIndex()); |
| 540 | DCHECK(interface_method != nullptr); |
| 541 | DCHECK_EQ(interface_method, |
| 542 | Runtime::Current()->GetClassLinker()->FindMethodForProxy(klass, this)); |
| 543 | return interface_method; |
| 544 | } |
| 545 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 546 | } // namespace mirror |
| 547 | } // namespace art |
| 548 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 549 | #endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_ |