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