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() { |
| 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() { |
| 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() { |
| 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 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 156 | inline void ArtMethod::SetOatNativeGcMapOffset(uint32_t gc_map_offset) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 157 | DCHECK(!Runtime::Current()->IsStarted()); |
| 158 | SetNativeGcMap(reinterpret_cast<uint8_t*>(gc_map_offset)); |
| 159 | } |
| 160 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 161 | inline uint32_t ArtMethod::GetOatNativeGcMapOffset() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 162 | DCHECK(!Runtime::Current()->IsStarted()); |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 163 | return PointerToLowMemUInt32(GetNativeGcMap()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 164 | } |
| 165 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 166 | inline bool ArtMethod::IsRuntimeMethod() { |
Ian Rogers | 8b2c0b9 | 2013-09-19 02:56:49 -0700 | [diff] [blame] | 167 | return GetDexMethodIndex() == DexFile::kDexNoIndex; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 170 | inline bool ArtMethod::IsCalleeSaveMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 171 | if (!IsRuntimeMethod()) { |
| 172 | return false; |
| 173 | } |
| 174 | Runtime* runtime = Runtime::Current(); |
| 175 | bool result = false; |
| 176 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 177 | if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) { |
| 178 | result = true; |
| 179 | break; |
| 180 | } |
| 181 | } |
| 182 | return result; |
| 183 | } |
| 184 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 185 | inline bool ArtMethod::IsResolutionMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 186 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 187 | // Check that if we do think it is phony it looks like the resolution method. |
| 188 | DCHECK(!result || IsRuntimeMethod()); |
| 189 | return result; |
| 190 | } |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 191 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 192 | inline bool ArtMethod::IsImtConflictMethod() { |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 193 | bool result = this == Runtime::Current()->GetImtConflictMethod(); |
| 194 | // Check that if we do think it is phony it looks like the imt conflict method. |
| 195 | DCHECK(!result || IsRuntimeMethod()); |
| 196 | return result; |
| 197 | } |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 198 | |
| 199 | template<VerifyObjectFlags kVerifyFlags> |
| 200 | inline void ArtMethod::SetNativeMethod(const void* native_method) { |
| 201 | SetFieldPtr<false, true, kVerifyFlags>( |
Ian Rogers | b0fa5dc | 2014-04-28 16:47:08 -0700 | [diff] [blame] | 202 | OFFSET_OF_OBJECT_MEMBER(ArtMethod, entry_point_from_jni_), native_method); |
Mathieu Chartier | 4e30541 | 2014-02-19 10:54:44 -0800 | [diff] [blame] | 203 | } |
| 204 | |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 205 | inline QuickMethodFrameInfo ArtMethod::GetQuickFrameInfo() { |
| 206 | if (UNLIKELY(IsPortableCompiled())) { |
| 207 | // Portable compiled dex bytecode or jni stub. |
| 208 | return QuickMethodFrameInfo(kStackAlignment, 0u, 0u); |
| 209 | } |
| 210 | Runtime* runtime = Runtime::Current(); |
| 211 | if (UNLIKELY(IsAbstract()) || UNLIKELY(IsProxyMethod())) { |
| 212 | return runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs); |
| 213 | } |
| 214 | if (UNLIKELY(IsRuntimeMethod())) { |
| 215 | return runtime->GetRuntimeMethodFrameInfo(this); |
| 216 | } |
| 217 | |
| 218 | const void* entry_point = runtime->GetInstrumentation()->GetQuickCodeFor(this); |
| 219 | // On failure, instead of nullptr we get the quick-generic-jni-trampoline for native method |
| 220 | // indicating the generic JNI, or the quick-to-interpreter-bridge (but not the trampoline) |
| 221 | // for non-native methods. And we really shouldn't see a failure for non-native methods here. |
| 222 | DCHECK(entry_point != GetQuickToInterpreterBridgeTrampoline(runtime->GetClassLinker())); |
| 223 | CHECK(entry_point != GetQuickToInterpreterBridge()); |
| 224 | |
Dmitry Petrochenko | f0972a4 | 2014-05-16 17:43:39 +0700 | [diff] [blame] | 225 | if (UNLIKELY(entry_point == runtime->GetClassLinker()->GetQuickGenericJniTrampoline())) { |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 226 | // Generic JNI frame. |
| 227 | DCHECK(IsNative()); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 228 | uint32_t handle_refs = MethodHelper(this).GetNumberOfReferenceArgsWithoutReceiver() + 1; |
| 229 | size_t scope_size = HandleScope::GetAlignedHandleScopeSize(handle_refs); |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 230 | QuickMethodFrameInfo callee_info = runtime->GetCalleeSaveMethodFrameInfo(Runtime::kRefsAndArgs); |
Mathieu Chartier | eb8167a | 2014-05-07 15:43:14 -0700 | [diff] [blame] | 231 | return QuickMethodFrameInfo(callee_info.FrameSizeInBytes() + scope_size, |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 232 | callee_info.CoreSpillMask(), callee_info.FpSpillMask()); |
| 233 | } |
| 234 | |
| 235 | const void* code_pointer = EntryPointToCodePointer(entry_point); |
| 236 | return reinterpret_cast<const OatQuickMethodHeader*>(code_pointer)[-1].frame_info_; |
| 237 | } |
| 238 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 239 | } // namespace mirror |
| 240 | } // namespace art |
| 241 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 242 | #endif // ART_RUNTIME_MIRROR_ART_METHOD_INL_H_ |