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