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 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 17 | #ifndef ART_RUNTIME_ART_METHOD_INL_H_ |
| 18 | #define ART_RUNTIME_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" |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 23 | #include "base/callee_save_type.h" |
Hiroshi Yamauchi | 0037082 | 2015-08-18 14:47:25 -0700 | [diff] [blame] | 24 | #include "class_linker-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 25 | #include "common_throws.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 26 | #include "dex/code_item_accessors-inl.h" |
| 27 | #include "dex/dex_file-inl.h" |
| 28 | #include "dex/dex_file_annotations.h" |
| 29 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 30 | #include "dex/invoke_type.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 31 | #include "dex/primitive.h" |
Andreas Gampe | b79674c | 2019-05-14 16:16:46 -0700 | [diff] [blame] | 32 | #include "dex/signature.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "gc_root-inl.h" |
David Srbecky | e36e7f2 | 2018-11-14 14:21:23 +0000 | [diff] [blame] | 34 | #include "imtable-inl.h" |
David Brazdil | 8714435 | 2018-01-24 12:50:01 +0000 | [diff] [blame] | 35 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 36 | #include "jit/profiling_info.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 37 | #include "mirror/class-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 38 | #include "mirror/dex_cache-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 39 | #include "mirror/object-inl.h" |
| 40 | #include "mirror/object_array.h" |
Nicolas Geoffray | 4c0b4bc | 2017-03-17 13:08:26 +0000 | [diff] [blame] | 41 | #include "mirror/string.h" |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 42 | #include "oat.h" |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 43 | #include "obj_ptr-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 44 | #include "quick/quick_method_frame_info.h" |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 45 | #include "read_barrier-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 46 | #include "runtime-inl.h" |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame] | 47 | #include "thread-current-inl.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 48 | |
| 49 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 50 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 51 | template <ReadBarrierOption kReadBarrierOption> |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 52 | inline ObjPtr<mirror::Class> ArtMethod::GetDeclaringClassUnchecked() { |
Hiroshi Yamauchi | 3f64f25 | 2015-06-12 18:35:06 -0700 | [diff] [blame] | 53 | GcRootSource gc_root_source(this); |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 54 | return declaring_class_.Read<kReadBarrierOption>(&gc_root_source); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 57 | template <ReadBarrierOption kReadBarrierOption> |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 58 | inline ObjPtr<mirror::Class> ArtMethod::GetDeclaringClass() { |
| 59 | ObjPtr<mirror::Class> result = GetDeclaringClassUnchecked<kReadBarrierOption>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 60 | if (kIsDebugBuild) { |
| 61 | if (!IsRuntimeMethod()) { |
| 62 | CHECK(result != nullptr) << this; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 63 | } else { |
| 64 | CHECK(result == nullptr) << this; |
| 65 | } |
| 66 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 67 | return result; |
| 68 | } |
| 69 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 70 | inline void ArtMethod::SetDeclaringClass(ObjPtr<mirror::Class> new_declaring_class) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 71 | declaring_class_ = GcRoot<mirror::Class>(new_declaring_class); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 72 | } |
| 73 | |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 74 | inline bool ArtMethod::CASDeclaringClass(ObjPtr<mirror::Class> expected_class, |
| 75 | ObjPtr<mirror::Class> desired_class) { |
Mathieu Chartier | 10e5ea9 | 2015-08-13 12:56:31 -0700 | [diff] [blame] | 76 | GcRoot<mirror::Class> expected_root(expected_class); |
| 77 | GcRoot<mirror::Class> desired_root(desired_class); |
Orion Hodson | 4557b38 | 2018-01-03 11:47:54 +0000 | [diff] [blame] | 78 | auto atomic_root_class = reinterpret_cast<Atomic<GcRoot<mirror::Class>>*>(&declaring_class_); |
| 79 | return atomic_root_class->CompareAndSetStrongSequentiallyConsistent(expected_root, desired_root); |
Mathieu Chartier | 10e5ea9 | 2015-08-13 12:56:31 -0700 | [diff] [blame] | 80 | } |
| 81 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 82 | inline uint16_t ArtMethod::GetMethodIndex() { |
Vladimir Marko | 72ab684 | 2017-01-20 19:32:50 +0000 | [diff] [blame] | 83 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 84 | return method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 85 | } |
| 86 | |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 87 | inline uint16_t ArtMethod::GetMethodIndexDuringLinking() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 88 | return method_index_; |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 89 | } |
| 90 | |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 91 | inline ObjPtr<mirror::Class> ArtMethod::LookupResolvedClassFromTypeIndex(dex::TypeIndex type_idx) { |
Vladimir Marko | 4098a7a | 2017-11-06 16:00:51 +0000 | [diff] [blame] | 92 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 93 | ObjPtr<mirror::Class> type = |
| 94 | Runtime::Current()->GetClassLinker()->LookupResolvedType(type_idx, this); |
| 95 | DCHECK(!Thread::Current()->IsExceptionPending()); |
| 96 | return type; |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | inline ObjPtr<mirror::Class> ArtMethod::ResolveClassFromTypeIndex(dex::TypeIndex type_idx) { |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 100 | ObjPtr<mirror::Class> type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this); |
| 101 | DCHECK_EQ(type == nullptr, Thread::Current()->IsExceptionPending()); |
| 102 | return type; |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -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: { |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 112 | // We have an error if we are direct or a non-copied (i.e. not part of a real class) interface |
| 113 | // method. |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 114 | ObjPtr<mirror::Class> methods_class = GetDeclaringClass(); |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 115 | return IsDirect() || (methods_class->IsInterface() && !IsCopied()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 116 | } |
| 117 | case kSuper: |
Andreas Gampe | 8f252e6 | 2014-08-25 20:46:31 -0700 | [diff] [blame] | 118 | // Constructors and static methods are called with invoke-direct. |
Alex Light | 705ad49 | 2015-09-21 11:36:30 -0700 | [diff] [blame] | 119 | return IsConstructor() || IsStatic(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 120 | case kInterface: { |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 121 | ObjPtr<mirror::Class> methods_class = GetDeclaringClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 122 | return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass()); |
| 123 | } |
| 124 | default: |
| 125 | LOG(FATAL) << "Unreachable - invocation type: " << type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 126 | UNREACHABLE(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 127 | } |
| 128 | } |
| 129 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 130 | inline bool ArtMethod::IsCalleeSaveMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 131 | if (!IsRuntimeMethod()) { |
| 132 | return false; |
| 133 | } |
| 134 | Runtime* runtime = Runtime::Current(); |
| 135 | bool result = false; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 136 | for (uint32_t i = 0; i < static_cast<uint32_t>(CalleeSaveType::kLastCalleeSaveType); i++) { |
| 137 | if (this == runtime->GetCalleeSaveMethod(CalleeSaveType(i))) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 138 | result = true; |
| 139 | break; |
| 140 | } |
| 141 | } |
| 142 | return result; |
| 143 | } |
| 144 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 145 | inline bool ArtMethod::IsResolutionMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 146 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 147 | // Check that if we do think it is phony it looks like the resolution method. |
| 148 | DCHECK(!result || IsRuntimeMethod()); |
| 149 | return result; |
| 150 | } |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 151 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 152 | inline bool ArtMethod::IsImtUnimplementedMethod() { |
| 153 | bool result = this == Runtime::Current()->GetImtUnimplementedMethod(); |
| 154 | // Check that if we do think it is phony it looks like the imt unimplemented method. |
| 155 | DCHECK(!result || IsRuntimeMethod()); |
| 156 | return result; |
| 157 | } |
| 158 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 159 | inline const DexFile* ArtMethod::GetDexFile() { |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 160 | // It is safe to avoid the read barrier here since the dex file is constant, so if we read the |
| 161 | // from-space dex file pointer it will be equal to the to-space copy. |
| 162 | return GetDexCache<kWithoutReadBarrier>()->GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 163 | } |
| 164 | |
| 165 | inline const char* ArtMethod::GetDeclaringClassDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 166 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 167 | if (UNLIKELY(dex_method_idx == dex::kDexNoIndex)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 168 | return "<runtime method>"; |
| 169 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 170 | DCHECK(!IsProxyMethod()); |
| 171 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 172 | return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); |
| 173 | } |
| 174 | |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 175 | inline const char* ArtMethod::GetShorty() { |
| 176 | uint32_t unused_length; |
| 177 | return GetShorty(&unused_length); |
| 178 | } |
| 179 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 180 | inline const char* ArtMethod::GetShorty(uint32_t* out_length) { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 181 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 182 | const DexFile* dex_file = GetDexFile(); |
Vladimir Marko | c945e0d | 2018-07-18 17:26:45 +0100 | [diff] [blame] | 183 | return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | inline const Signature ArtMethod::GetSignature() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 187 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 188 | if (dex_method_idx != dex::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 189 | DCHECK(!IsProxyMethod()); |
| 190 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 191 | return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx)); |
| 192 | } |
| 193 | return Signature::NoSignature(); |
| 194 | } |
| 195 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 196 | inline const char* ArtMethod::GetName() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 197 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 198 | if (LIKELY(dex_method_idx != dex::kDexNoIndex)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 199 | DCHECK(!IsProxyMethod()); |
| 200 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 201 | return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx)); |
| 202 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 203 | Runtime* const runtime = Runtime::Current(); |
| 204 | if (this == runtime->GetResolutionMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 205 | return "<runtime internal resolution method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 206 | } else if (this == runtime->GetImtConflictMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 207 | return "<runtime internal imt conflict method>"; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 208 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveAllCalleeSaves)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 209 | return "<runtime internal callee-save all registers method>"; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 210 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsOnly)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 211 | return "<runtime internal callee-save reference registers method>"; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 212 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 213 | return "<runtime internal callee-save reference and argument registers method>"; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 214 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverything)) { |
| 215 | return "<runtime internal save-every-register method>"; |
Mingyao Yang | 0a87a65 | 2017-04-12 13:43:15 -0700 | [diff] [blame] | 216 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverythingForClinit)) { |
| 217 | return "<runtime internal save-every-register method for clinit>"; |
| 218 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverythingForSuspendCheck)) { |
| 219 | return "<runtime internal save-every-register method for suspend check>"; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 220 | } else { |
| 221 | return "<unknown runtime internal method>"; |
| 222 | } |
| 223 | } |
| 224 | |
Vladimir Marko | 18090d1 | 2018-06-01 16:53:12 +0100 | [diff] [blame] | 225 | inline ObjPtr<mirror::String> ArtMethod::ResolveNameString() { |
| 226 | DCHECK(!IsProxyMethod()); |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 227 | const dex::MethodId& method_id = GetDexFile()->GetMethodId(GetDexMethodIndex()); |
Vladimir Marko | 18090d1 | 2018-06-01 16:53:12 +0100 | [diff] [blame] | 228 | return Runtime::Current()->GetClassLinker()->ResolveString(method_id.name_idx_, this); |
| 229 | } |
| 230 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 231 | inline const dex::CodeItem* ArtMethod::GetCodeItem() { |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 232 | return GetDexFile()->GetCodeItem(GetCodeItemOffset()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 233 | } |
| 234 | |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 235 | inline bool ArtMethod::IsResolvedTypeIdx(dex::TypeIndex type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 236 | DCHECK(!IsProxyMethod()); |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 237 | return LookupResolvedClassFromTypeIndex(type_idx) != nullptr; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 238 | } |
| 239 | |
| 240 | inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 241 | DCHECK(!IsProxyMethod()); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 242 | if (dex_pc == dex::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 243 | return IsNative() ? -2 : -1; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 244 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 245 | return annotations::GetLineNumFromPC(GetDexFile(), this, dex_pc); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 246 | } |
| 247 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 248 | inline const dex::ProtoId& ArtMethod::GetPrototype() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 249 | DCHECK(!IsProxyMethod()); |
| 250 | const DexFile* dex_file = GetDexFile(); |
| 251 | return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 252 | } |
| 253 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 254 | inline const dex::TypeList* ArtMethod::GetParameterTypeList() { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 255 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 256 | const DexFile* dex_file = GetDexFile(); |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 257 | const dex::ProtoId& proto = dex_file->GetMethodPrototype( |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 258 | dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 259 | return dex_file->GetProtoParameters(proto); |
| 260 | } |
| 261 | |
| 262 | inline const char* ArtMethod::GetDeclaringClassSourceFile() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 263 | DCHECK(!IsProxyMethod()); |
| 264 | return GetDeclaringClass()->GetSourceFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | inline uint16_t ArtMethod::GetClassDefIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 268 | DCHECK(!IsProxyMethod()); |
Alex Light | f2f1c9d | 2017-03-15 15:35:46 +0000 | [diff] [blame] | 269 | if (LIKELY(!IsObsolete())) { |
| 270 | return GetDeclaringClass()->GetDexClassDefIndex(); |
| 271 | } else { |
| 272 | return FindObsoleteDexClassDefIndex(); |
| 273 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 276 | inline const dex::ClassDef& ArtMethod::GetClassDef() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 277 | DCHECK(!IsProxyMethod()); |
| 278 | return GetDexFile()->GetClassDef(GetClassDefIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 279 | } |
| 280 | |
Orion Hodson | 58143d2 | 2018-02-20 08:44:20 +0000 | [diff] [blame] | 281 | inline size_t ArtMethod::GetNumberOfParameters() { |
| 282 | constexpr size_t return_type_count = 1u; |
| 283 | return strlen(GetShorty()) - return_type_count; |
| 284 | } |
| 285 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 286 | inline const char* ArtMethod::GetReturnTypeDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 287 | DCHECK(!IsProxyMethod()); |
| 288 | const DexFile* dex_file = GetDexFile(); |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 289 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(GetReturnTypeIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 290 | } |
| 291 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 292 | inline Primitive::Type ArtMethod::GetReturnTypePrimitive() { |
| 293 | return Primitive::GetType(GetReturnTypeDescriptor()[0]); |
| 294 | } |
| 295 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 296 | inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(dex::TypeIndex type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 297 | DCHECK(!IsProxyMethod()); |
| 298 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 299 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx)); |
| 300 | } |
| 301 | |
Vladimir Marko | c524e9e | 2019-03-26 10:54:50 +0000 | [diff] [blame] | 302 | inline ObjPtr<mirror::ClassLoader> ArtMethod::GetClassLoader() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 303 | DCHECK(!IsProxyMethod()); |
| 304 | return GetDeclaringClass()->GetClassLoader(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 305 | } |
| 306 | |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 307 | template <ReadBarrierOption kReadBarrierOption> |
Vladimir Marko | c524e9e | 2019-03-26 10:54:50 +0000 | [diff] [blame] | 308 | inline ObjPtr<mirror::DexCache> ArtMethod::GetDexCache() { |
Vladimir Marko | c945e0d | 2018-07-18 17:26:45 +0100 | [diff] [blame] | 309 | if (LIKELY(!IsObsolete())) { |
Vladimir Marko | 09c5ca4 | 2018-05-31 15:15:31 +0100 | [diff] [blame] | 310 | ObjPtr<mirror::Class> klass = GetDeclaringClass<kReadBarrierOption>(); |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 311 | return klass->GetDexCache<kDefaultVerifyFlags, kReadBarrierOption>(); |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 312 | } else { |
| 313 | DCHECK(!IsProxyMethod()); |
| 314 | return GetObsoleteDexCache(); |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 315 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 316 | } |
| 317 | |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 318 | inline bool ArtMethod::IsProxyMethod() { |
Roland Levillain | fa854e4 | 2018-02-07 13:09:55 +0000 | [diff] [blame] | 319 | DCHECK(!IsRuntimeMethod()) << "ArtMethod::IsProxyMethod called on a runtime method"; |
Vladimir Marko | 415ac85 | 2019-03-21 12:49:10 +0000 | [diff] [blame] | 320 | // No read barrier needed, we're reading the constant declaring class only to read |
| 321 | // the constant proxy flag. See ReadBarrierOption. |
Mathieu Chartier | 90c5a9b | 2017-02-01 13:10:06 -0800 | [diff] [blame] | 322 | return GetDeclaringClass<kWithoutReadBarrier>()->IsProxyClass(); |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 323 | } |
| 324 | |
Vladimir Marko | d1ee20f | 2017-08-17 09:21:16 +0000 | [diff] [blame] | 325 | inline ArtMethod* ArtMethod::GetInterfaceMethodForProxyUnchecked(PointerSize pointer_size) { |
| 326 | DCHECK(IsProxyMethod()); |
| 327 | // Do not check IsAssignableFrom() here as it relies on raw reference comparison |
| 328 | // which may give false negatives while visiting references for a non-CC moving GC. |
| 329 | return reinterpret_cast<ArtMethod*>(GetDataPtrSize(pointer_size)); |
| 330 | } |
| 331 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 332 | inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(PointerSize pointer_size) { |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 333 | if (LIKELY(!IsProxyMethod())) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 334 | return this; |
| 335 | } |
Vladimir Marko | d1ee20f | 2017-08-17 09:21:16 +0000 | [diff] [blame] | 336 | ArtMethod* interface_method = GetInterfaceMethodForProxyUnchecked(pointer_size); |
| 337 | // We can check that the proxy class implements the interface only if the proxy class |
| 338 | // is resolved, otherwise the interface table is not yet initialized. |
| 339 | DCHECK(!GetDeclaringClass()->IsResolved() || |
| 340 | interface_method->GetDeclaringClass()->IsAssignableFrom(GetDeclaringClass())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 341 | return interface_method; |
| 342 | } |
| 343 | |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 344 | inline dex::TypeIndex ArtMethod::GetReturnTypeIndex() { |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 345 | DCHECK(!IsProxyMethod()); |
| 346 | const DexFile* dex_file = GetDexFile(); |
Andreas Gampe | 3f1dcd3 | 2018-12-28 09:39:56 -0800 | [diff] [blame] | 347 | const dex::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
| 348 | const dex::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 349 | return proto_id.return_type_idx_; |
| 350 | } |
| 351 | |
| 352 | inline ObjPtr<mirror::Class> ArtMethod::LookupResolvedReturnType() { |
| 353 | return LookupResolvedClassFromTypeIndex(GetReturnTypeIndex()); |
| 354 | } |
| 355 | |
| 356 | inline ObjPtr<mirror::Class> ArtMethod::ResolveReturnType() { |
| 357 | return ResolveClassFromTypeIndex(GetReturnTypeIndex()); |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 358 | } |
| 359 | |
Alexey Grebenkin | be4c2bd | 2018-02-01 19:09:59 +0300 | [diff] [blame] | 360 | template <ReadBarrierOption kReadBarrierOption> |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 361 | inline bool ArtMethod::HasSingleImplementation() { |
Vladimir Marko | c945e0d | 2018-07-18 17:26:45 +0100 | [diff] [blame] | 362 | if (IsFinal() || GetDeclaringClass<kReadBarrierOption>()->IsFinal()) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 363 | // We don't set kAccSingleImplementation for these cases since intrinsic |
| 364 | // can use the flag also. |
| 365 | return true; |
| 366 | } |
Vladimir Marko | c945e0d | 2018-07-18 17:26:45 +0100 | [diff] [blame] | 367 | return (GetAccessFlags() & kAccSingleImplementation) != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 370 | template<ReadBarrierOption kReadBarrierOption, typename RootVisitorType> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 371 | void ArtMethod::VisitRoots(RootVisitorType& visitor, PointerSize pointer_size) { |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 372 | if (LIKELY(!declaring_class_.IsNull())) { |
| 373 | visitor.VisitRoot(declaring_class_.AddressWithoutBarrier()); |
Vladimir Marko | d93e374 | 2018-07-18 10:58:13 +0100 | [diff] [blame] | 374 | ObjPtr<mirror::Class> klass = declaring_class_.Read<kReadBarrierOption>(); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 375 | if (UNLIKELY(klass->IsProxyClass())) { |
| 376 | // For normal methods, dex cache shortcuts will be visited through the declaring class. |
| 377 | // However, for proxies we need to keep the interface method alive, so we visit its roots. |
Vladimir Marko | d1ee20f | 2017-08-17 09:21:16 +0000 | [diff] [blame] | 378 | ArtMethod* interface_method = GetInterfaceMethodForProxyUnchecked(pointer_size); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 379 | DCHECK(interface_method != nullptr); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 380 | interface_method->VisitRoots(visitor, pointer_size); |
| 381 | } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 382 | } |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 383 | } |
| 384 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 385 | template <typename Visitor> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 386 | inline void ArtMethod::UpdateEntrypoints(const Visitor& visitor, PointerSize pointer_size) { |
Vladimir Marko | c945e0d | 2018-07-18 17:26:45 +0100 | [diff] [blame] | 387 | if (IsNative()) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 388 | const void* old_native_code = GetEntryPointFromJniPtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 389 | const void* new_native_code = visitor(old_native_code); |
| 390 | if (old_native_code != new_native_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 391 | SetEntryPointFromJniPtrSize(new_native_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 392 | } |
| 393 | } else { |
Andreas Gampe | 75f0885 | 2016-07-19 08:06:07 -0700 | [diff] [blame] | 394 | DCHECK(GetDataPtrSize(pointer_size) == nullptr); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 395 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 396 | const void* old_code = GetEntryPointFromQuickCompiledCodePtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 397 | const void* new_code = visitor(old_code); |
| 398 | if (old_code != new_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 399 | SetEntryPointFromQuickCompiledCodePtrSize(new_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 403 | inline CodeItemInstructionAccessor ArtMethod::DexInstructions() { |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 404 | return CodeItemInstructionAccessor(*GetDexFile(), GetCodeItem()); |
| 405 | } |
| 406 | |
| 407 | inline CodeItemDataAccessor ArtMethod::DexInstructionData() { |
| 408 | return CodeItemDataAccessor(*GetDexFile(), GetCodeItem()); |
| 409 | } |
| 410 | |
| 411 | inline CodeItemDebugInfoAccessor ArtMethod::DexInstructionDebugInfo() { |
| 412 | return CodeItemDebugInfoAccessor(*GetDexFile(), GetCodeItem(), GetDexMethodIndex()); |
Mathieu Chartier | 69147f1 | 2017-11-06 20:02:24 -0800 | [diff] [blame] | 413 | } |
| 414 | |
David Srbecky | e36e7f2 | 2018-11-14 14:21:23 +0000 | [diff] [blame] | 415 | inline void ArtMethod::SetCounter(int16_t hotness_count) { |
| 416 | DCHECK(!IsAbstract()) << PrettyMethod(); |
| 417 | hotness_count_ = hotness_count; |
| 418 | } |
| 419 | |
| 420 | inline uint16_t ArtMethod::GetCounter() { |
| 421 | DCHECK(!IsAbstract()) << PrettyMethod(); |
| 422 | return hotness_count_; |
| 423 | } |
| 424 | |
| 425 | inline uint32_t ArtMethod::GetImtIndex() { |
| 426 | if (LIKELY(IsAbstract() && imt_index_ != 0)) { |
| 427 | uint16_t imt_index = ~imt_index_; |
| 428 | DCHECK_EQ(imt_index, ImTable::GetImtIndex(this)) << PrettyMethod(); |
| 429 | return imt_index; |
| 430 | } else { |
| 431 | return ImTable::GetImtIndex(this); |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | inline void ArtMethod::CalculateAndSetImtIndex() { |
| 436 | DCHECK(IsAbstract()) << PrettyMethod(); |
| 437 | imt_index_ = ~ImTable::GetImtIndex(this); |
| 438 | } |
| 439 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 440 | } // namespace art |
| 441 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 442 | #endif // ART_RUNTIME_ART_METHOD_INL_H_ |