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" |
David Sehr | 8f4b056 | 2018-03-02 12:01:51 -0800 | [diff] [blame] | 24 | #include "base/utils.h" |
Hiroshi Yamauchi | 0037082 | 2015-08-18 14:47:25 -0700 | [diff] [blame] | 25 | #include "class_linker-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 26 | #include "common_throws.h" |
David Sehr | 9e734c7 | 2018-01-04 17:56:19 -0800 | [diff] [blame] | 27 | #include "dex/code_item_accessors-inl.h" |
| 28 | #include "dex/dex_file-inl.h" |
| 29 | #include "dex/dex_file_annotations.h" |
| 30 | #include "dex/dex_file_types.h" |
David Sehr | 8c0961f | 2018-01-23 16:11:38 -0800 | [diff] [blame] | 31 | #include "dex/invoke_type.h" |
David Sehr | 67bf42e | 2018-02-26 16:43:04 -0800 | [diff] [blame] | 32 | #include "dex/primitive.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "gc_root-inl.h" |
David Brazdil | 8714435 | 2018-01-24 12:50:01 +0000 | [diff] [blame] | 34 | #include "intrinsics_enum.h" |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 35 | #include "jit/profiling_info.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 36 | #include "mirror/class-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 37 | #include "mirror/dex_cache-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 38 | #include "mirror/object-inl.h" |
| 39 | #include "mirror/object_array.h" |
Nicolas Geoffray | 4c0b4bc | 2017-03-17 13:08:26 +0000 | [diff] [blame] | 40 | #include "mirror/string.h" |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 41 | #include "oat.h" |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 42 | #include "obj_ptr-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 43 | #include "quick/quick_method_frame_info.h" |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 44 | #include "read_barrier-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 45 | #include "runtime-inl.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 46 | #include "scoped_thread_state_change-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> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 52 | inline 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> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 58 | inline mirror::Class* ArtMethod::GetDeclaringClass() { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 59 | 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; |
Andreas Gampe | b1106e2 | 2017-02-23 11:34:48 -0800 | [diff] [blame] | 63 | if (kCheckDeclaringClassState) { |
Nicolas Geoffray | 4c0b4bc | 2017-03-17 13:08:26 +0000 | [diff] [blame] | 64 | if (!(result->IsIdxLoaded() || result->IsErroneous())) { |
| 65 | LOG(FATAL_WITHOUT_ABORT) << "Class status: " << result->GetStatus(); |
| 66 | LOG(FATAL) << result->PrettyClass(); |
| 67 | } |
Andreas Gampe | b1106e2 | 2017-02-23 11:34:48 -0800 | [diff] [blame] | 68 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 69 | } else { |
| 70 | CHECK(result == nullptr) << this; |
| 71 | } |
| 72 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 73 | return result; |
| 74 | } |
| 75 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 76 | inline void ArtMethod::SetDeclaringClass(ObjPtr<mirror::Class> new_declaring_class) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 77 | declaring_class_ = GcRoot<mirror::Class>(new_declaring_class); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 78 | } |
| 79 | |
Mathieu Chartier | 10e5ea9 | 2015-08-13 12:56:31 -0700 | [diff] [blame] | 80 | inline bool ArtMethod::CASDeclaringClass(mirror::Class* expected_class, |
| 81 | mirror::Class* desired_class) { |
| 82 | GcRoot<mirror::Class> expected_root(expected_class); |
| 83 | GcRoot<mirror::Class> desired_root(desired_class); |
Orion Hodson | 4557b38 | 2018-01-03 11:47:54 +0000 | [diff] [blame] | 84 | auto atomic_root_class = reinterpret_cast<Atomic<GcRoot<mirror::Class>>*>(&declaring_class_); |
| 85 | return atomic_root_class->CompareAndSetStrongSequentiallyConsistent(expected_root, desired_root); |
Mathieu Chartier | 10e5ea9 | 2015-08-13 12:56:31 -0700 | [diff] [blame] | 86 | } |
| 87 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 88 | inline uint16_t ArtMethod::GetMethodIndex() { |
Vladimir Marko | 72ab684 | 2017-01-20 19:32:50 +0000 | [diff] [blame] | 89 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 90 | return method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 91 | } |
| 92 | |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 93 | inline uint16_t ArtMethod::GetMethodIndexDuringLinking() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 94 | return method_index_; |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 95 | } |
| 96 | |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 97 | template <ReadBarrierOption kReadBarrierOption> |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 98 | inline uint32_t ArtMethod::GetDexMethodIndex() { |
Andreas Gampe | b1106e2 | 2017-02-23 11:34:48 -0800 | [diff] [blame] | 99 | if (kCheckDeclaringClassState) { |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 100 | CHECK(IsRuntimeMethod() || |
| 101 | GetDeclaringClass<kReadBarrierOption>()->IsIdxLoaded() || |
| 102 | GetDeclaringClass<kReadBarrierOption>()->IsErroneous()); |
Andreas Gampe | b1106e2 | 2017-02-23 11:34:48 -0800 | [diff] [blame] | 103 | } |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 104 | return GetDexMethodIndexUnchecked(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 105 | } |
| 106 | |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 107 | inline ObjPtr<mirror::Class> ArtMethod::LookupResolvedClassFromTypeIndex(dex::TypeIndex type_idx) { |
Vladimir Marko | 4098a7a | 2017-11-06 16:00:51 +0000 | [diff] [blame] | 108 | ScopedAssertNoThreadSuspension ants(__FUNCTION__); |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 109 | ObjPtr<mirror::Class> type = |
| 110 | Runtime::Current()->GetClassLinker()->LookupResolvedType(type_idx, this); |
| 111 | DCHECK(!Thread::Current()->IsExceptionPending()); |
| 112 | return type; |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | inline ObjPtr<mirror::Class> ArtMethod::ResolveClassFromTypeIndex(dex::TypeIndex type_idx) { |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 116 | ObjPtr<mirror::Class> type = Runtime::Current()->GetClassLinker()->ResolveType(type_idx, this); |
| 117 | DCHECK_EQ(type == nullptr, Thread::Current()->IsExceptionPending()); |
| 118 | return type; |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 119 | } |
| 120 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 121 | inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 122 | switch (type) { |
| 123 | case kStatic: |
| 124 | return !IsStatic(); |
| 125 | case kDirect: |
| 126 | return !IsDirect() || IsStatic(); |
| 127 | case kVirtual: { |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 128 | // We have an error if we are direct or a non-copied (i.e. not part of a real class) interface |
| 129 | // method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 130 | mirror::Class* methods_class = GetDeclaringClass(); |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 131 | return IsDirect() || (methods_class->IsInterface() && !IsCopied()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 132 | } |
| 133 | case kSuper: |
Andreas Gampe | 8f252e6 | 2014-08-25 20:46:31 -0700 | [diff] [blame] | 134 | // Constructors and static methods are called with invoke-direct. |
Alex Light | 705ad49 | 2015-09-21 11:36:30 -0700 | [diff] [blame] | 135 | return IsConstructor() || IsStatic(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 136 | case kInterface: { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 137 | mirror::Class* methods_class = GetDeclaringClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 138 | return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass()); |
| 139 | } |
| 140 | default: |
| 141 | LOG(FATAL) << "Unreachable - invocation type: " << type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 142 | UNREACHABLE(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 143 | } |
| 144 | } |
| 145 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 146 | inline bool ArtMethod::IsCalleeSaveMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 147 | if (!IsRuntimeMethod()) { |
| 148 | return false; |
| 149 | } |
| 150 | Runtime* runtime = Runtime::Current(); |
| 151 | bool result = false; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 152 | for (uint32_t i = 0; i < static_cast<uint32_t>(CalleeSaveType::kLastCalleeSaveType); i++) { |
| 153 | if (this == runtime->GetCalleeSaveMethod(CalleeSaveType(i))) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 154 | result = true; |
| 155 | break; |
| 156 | } |
| 157 | } |
| 158 | return result; |
| 159 | } |
| 160 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 161 | inline bool ArtMethod::IsResolutionMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 162 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 163 | // Check that if we do think it is phony it looks like the resolution method. |
| 164 | DCHECK(!result || IsRuntimeMethod()); |
| 165 | return result; |
| 166 | } |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 167 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 168 | inline bool ArtMethod::IsImtUnimplementedMethod() { |
| 169 | bool result = this == Runtime::Current()->GetImtUnimplementedMethod(); |
| 170 | // Check that if we do think it is phony it looks like the imt unimplemented method. |
| 171 | DCHECK(!result || IsRuntimeMethod()); |
| 172 | return result; |
| 173 | } |
| 174 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 175 | inline const DexFile* ArtMethod::GetDexFile() { |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 176 | // It is safe to avoid the read barrier here since the dex file is constant, so if we read the |
| 177 | // from-space dex file pointer it will be equal to the to-space copy. |
| 178 | return GetDexCache<kWithoutReadBarrier>()->GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 179 | } |
| 180 | |
| 181 | inline const char* ArtMethod::GetDeclaringClassDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 182 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 183 | if (UNLIKELY(dex_method_idx == dex::kDexNoIndex)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 184 | return "<runtime method>"; |
| 185 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 186 | DCHECK(!IsProxyMethod()); |
| 187 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 188 | return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); |
| 189 | } |
| 190 | |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 191 | inline const char* ArtMethod::GetShorty() { |
| 192 | uint32_t unused_length; |
| 193 | return GetShorty(&unused_length); |
| 194 | } |
| 195 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 196 | inline const char* ArtMethod::GetShorty(uint32_t* out_length) { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 197 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 198 | const DexFile* dex_file = GetDexFile(); |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 199 | // Don't do a read barrier in the DCHECK() inside GetDexMethodIndex() as GetShorty() |
| 200 | // can be called when the declaring class is about to be unloaded and cannot be added |
| 201 | // to the mark stack (subsequent GC assertion would fail). |
| 202 | // It is safe to avoid the read barrier as the ArtMethod is constructed with a declaring |
| 203 | // Class already satisfying the DCHECK() inside GetDexMethodIndex(), so even if that copy |
| 204 | // of declaring class becomes a from-space object, it shall satisfy the DCHECK(). |
| 205 | return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex<kWithoutReadBarrier>()), |
| 206 | out_length); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 207 | } |
| 208 | |
| 209 | inline const Signature ArtMethod::GetSignature() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 210 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 211 | if (dex_method_idx != dex::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 212 | DCHECK(!IsProxyMethod()); |
| 213 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 214 | return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx)); |
| 215 | } |
| 216 | return Signature::NoSignature(); |
| 217 | } |
| 218 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 219 | inline const char* ArtMethod::GetName() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 220 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 221 | if (LIKELY(dex_method_idx != dex::kDexNoIndex)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 222 | DCHECK(!IsProxyMethod()); |
| 223 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 224 | return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx)); |
| 225 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 226 | Runtime* const runtime = Runtime::Current(); |
| 227 | if (this == runtime->GetResolutionMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 228 | return "<runtime internal resolution method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 229 | } else if (this == runtime->GetImtConflictMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 230 | return "<runtime internal imt conflict method>"; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 231 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveAllCalleeSaves)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 232 | return "<runtime internal callee-save all registers method>"; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 233 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsOnly)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 234 | return "<runtime internal callee-save reference registers method>"; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 235 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveRefsAndArgs)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 236 | return "<runtime internal callee-save reference and argument registers method>"; |
Andreas Gampe | 8228cdf | 2017-05-30 15:03:54 -0700 | [diff] [blame] | 237 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverything)) { |
| 238 | return "<runtime internal save-every-register method>"; |
Mingyao Yang | 0a87a65 | 2017-04-12 13:43:15 -0700 | [diff] [blame] | 239 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverythingForClinit)) { |
| 240 | return "<runtime internal save-every-register method for clinit>"; |
| 241 | } else if (this == runtime->GetCalleeSaveMethod(CalleeSaveType::kSaveEverythingForSuspendCheck)) { |
| 242 | return "<runtime internal save-every-register method for suspend check>"; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 243 | } else { |
| 244 | return "<unknown runtime internal method>"; |
| 245 | } |
| 246 | } |
| 247 | |
| 248 | inline const DexFile::CodeItem* ArtMethod::GetCodeItem() { |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 249 | return GetDexFile()->GetCodeItem(GetCodeItemOffset()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 250 | } |
| 251 | |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 252 | inline bool ArtMethod::IsResolvedTypeIdx(dex::TypeIndex type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 253 | DCHECK(!IsProxyMethod()); |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 254 | return LookupResolvedClassFromTypeIndex(type_idx) != nullptr; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 258 | DCHECK(!IsProxyMethod()); |
Andreas Gampe | e2abbc6 | 2017-09-15 11:59:26 -0700 | [diff] [blame] | 259 | if (dex_pc == dex::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 260 | return IsNative() ? -2 : -1; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 261 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 262 | return annotations::GetLineNumFromPC(GetDexFile(), this, dex_pc); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | inline const DexFile::ProtoId& ArtMethod::GetPrototype() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 266 | DCHECK(!IsProxyMethod()); |
| 267 | const DexFile* dex_file = GetDexFile(); |
| 268 | return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 272 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 273 | const DexFile* dex_file = GetDexFile(); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 274 | const DexFile::ProtoId& proto = dex_file->GetMethodPrototype( |
| 275 | dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 276 | return dex_file->GetProtoParameters(proto); |
| 277 | } |
| 278 | |
| 279 | inline const char* ArtMethod::GetDeclaringClassSourceFile() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 280 | DCHECK(!IsProxyMethod()); |
| 281 | return GetDeclaringClass()->GetSourceFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 282 | } |
| 283 | |
| 284 | inline uint16_t ArtMethod::GetClassDefIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 285 | DCHECK(!IsProxyMethod()); |
Alex Light | f2f1c9d | 2017-03-15 15:35:46 +0000 | [diff] [blame] | 286 | if (LIKELY(!IsObsolete())) { |
| 287 | return GetDeclaringClass()->GetDexClassDefIndex(); |
| 288 | } else { |
| 289 | return FindObsoleteDexClassDefIndex(); |
| 290 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | inline const DexFile::ClassDef& ArtMethod::GetClassDef() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 294 | DCHECK(!IsProxyMethod()); |
| 295 | return GetDexFile()->GetClassDef(GetClassDefIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 296 | } |
| 297 | |
Orion Hodson | a2649fc | 2018-02-20 08:44:20 +0000 | [diff] [blame] | 298 | inline size_t ArtMethod::GetNumberOfParameters() { |
| 299 | constexpr size_t return_type_count = 1u; |
| 300 | return strlen(GetShorty()) - return_type_count; |
| 301 | } |
| 302 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 303 | inline const char* ArtMethod::GetReturnTypeDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 304 | DCHECK(!IsProxyMethod()); |
| 305 | const DexFile* dex_file = GetDexFile(); |
Vladimir Marko | 666ee3d | 2017-12-11 18:37:36 +0000 | [diff] [blame] | 306 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(GetReturnTypeIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Alex Light | d766158 | 2017-05-01 13:48:16 -0700 | [diff] [blame] | 309 | inline Primitive::Type ArtMethod::GetReturnTypePrimitive() { |
| 310 | return Primitive::GetType(GetReturnTypeDescriptor()[0]); |
| 311 | } |
| 312 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 313 | inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(dex::TypeIndex type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 314 | DCHECK(!IsProxyMethod()); |
| 315 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 316 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx)); |
| 317 | } |
| 318 | |
| 319 | inline mirror::ClassLoader* ArtMethod::GetClassLoader() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 320 | DCHECK(!IsProxyMethod()); |
| 321 | return GetDeclaringClass()->GetClassLoader(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 322 | } |
| 323 | |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 324 | template <ReadBarrierOption kReadBarrierOption> |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 325 | inline mirror::DexCache* ArtMethod::GetDexCache() { |
Vladimir Marko | 2196c65 | 2017-11-30 16:16:07 +0000 | [diff] [blame] | 326 | if (LIKELY(!IsObsolete<kReadBarrierOption>())) { |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 327 | mirror::Class* klass = GetDeclaringClass<kReadBarrierOption>(); |
| 328 | return klass->GetDexCache<kDefaultVerifyFlags, kReadBarrierOption>(); |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 329 | } else { |
| 330 | DCHECK(!IsProxyMethod()); |
| 331 | return GetObsoleteDexCache(); |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 332 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 333 | } |
| 334 | |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 335 | inline bool ArtMethod::IsProxyMethod() { |
Roland Levillain | fa854e4 | 2018-02-07 13:09:55 +0000 | [diff] [blame] | 336 | DCHECK(!IsRuntimeMethod()) << "ArtMethod::IsProxyMethod called on a runtime method"; |
Mathieu Chartier | 90c5a9b | 2017-02-01 13:10:06 -0800 | [diff] [blame] | 337 | // Avoid read barrier since the from-space version of the class will have the correct proxy class |
| 338 | // flags since they are constant for the lifetime of the class. |
| 339 | return GetDeclaringClass<kWithoutReadBarrier>()->IsProxyClass(); |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Vladimir Marko | d1ee20f | 2017-08-17 09:21:16 +0000 | [diff] [blame] | 342 | inline ArtMethod* ArtMethod::GetInterfaceMethodForProxyUnchecked(PointerSize pointer_size) { |
| 343 | DCHECK(IsProxyMethod()); |
| 344 | // Do not check IsAssignableFrom() here as it relies on raw reference comparison |
| 345 | // which may give false negatives while visiting references for a non-CC moving GC. |
| 346 | return reinterpret_cast<ArtMethod*>(GetDataPtrSize(pointer_size)); |
| 347 | } |
| 348 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 349 | inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(PointerSize pointer_size) { |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 350 | if (LIKELY(!IsProxyMethod())) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 351 | return this; |
| 352 | } |
Vladimir Marko | d1ee20f | 2017-08-17 09:21:16 +0000 | [diff] [blame] | 353 | ArtMethod* interface_method = GetInterfaceMethodForProxyUnchecked(pointer_size); |
| 354 | // We can check that the proxy class implements the interface only if the proxy class |
| 355 | // is resolved, otherwise the interface table is not yet initialized. |
| 356 | DCHECK(!GetDeclaringClass()->IsResolved() || |
| 357 | interface_method->GetDeclaringClass()->IsAssignableFrom(GetDeclaringClass())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 358 | return interface_method; |
| 359 | } |
| 360 | |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 361 | inline dex::TypeIndex ArtMethod::GetReturnTypeIndex() { |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 362 | DCHECK(!IsProxyMethod()); |
| 363 | const DexFile* dex_file = GetDexFile(); |
| 364 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
| 365 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
Vladimir Marko | b45528c | 2017-07-27 14:14:28 +0100 | [diff] [blame] | 366 | return proto_id.return_type_idx_; |
| 367 | } |
| 368 | |
| 369 | inline ObjPtr<mirror::Class> ArtMethod::LookupResolvedReturnType() { |
| 370 | return LookupResolvedClassFromTypeIndex(GetReturnTypeIndex()); |
| 371 | } |
| 372 | |
| 373 | inline ObjPtr<mirror::Class> ArtMethod::ResolveReturnType() { |
| 374 | return ResolveClassFromTypeIndex(GetReturnTypeIndex()); |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 375 | } |
| 376 | |
Alexey Grebenkin | ab2ce84 | 2018-02-01 19:09:59 +0300 | [diff] [blame] | 377 | template <ReadBarrierOption kReadBarrierOption> |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 378 | inline bool ArtMethod::HasSingleImplementation() { |
Alexey Grebenkin | ab2ce84 | 2018-02-01 19:09:59 +0300 | [diff] [blame] | 379 | if (IsFinal<kReadBarrierOption>() || GetDeclaringClass<kReadBarrierOption>()->IsFinal()) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 380 | // We don't set kAccSingleImplementation for these cases since intrinsic |
| 381 | // can use the flag also. |
| 382 | return true; |
| 383 | } |
Alexey Grebenkin | ab2ce84 | 2018-02-01 19:09:59 +0300 | [diff] [blame] | 384 | return (GetAccessFlags<kReadBarrierOption>() & kAccSingleImplementation) != 0; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 385 | } |
| 386 | |
David Brazdil | 14c212a | 2018-04-23 13:50:38 +0100 | [diff] [blame] | 387 | inline HiddenApiAccessFlags::ApiList ArtMethod::GetHiddenApiAccessFlags() |
| 388 | REQUIRES_SHARED(Locks::mutator_lock_) { |
David Brazdil | 49dded0 | 2018-04-19 12:41:04 +0100 | [diff] [blame] | 389 | if (UNLIKELY(IsIntrinsic())) { |
| 390 | switch (static_cast<Intrinsics>(GetIntrinsic())) { |
| 391 | case Intrinsics::kSystemArrayCopyChar: |
| 392 | case Intrinsics::kStringGetCharsNoCheck: |
| 393 | case Intrinsics::kReferenceGetReferent: |
| 394 | // These intrinsics are on the light greylist and will fail a DCHECK in |
| 395 | // SetIntrinsic() if their flags change on the respective dex methods. |
| 396 | // Note that the DCHECK currently won't fail if the dex methods are |
| 397 | // whitelisted, e.g. in the core image (b/77733081). As a result, we |
| 398 | // might print warnings but we won't change the semantics. |
| 399 | return HiddenApiAccessFlags::kLightGreylist; |
| 400 | case Intrinsics::kVarHandleFullFence: |
| 401 | case Intrinsics::kVarHandleAcquireFence: |
| 402 | case Intrinsics::kVarHandleReleaseFence: |
| 403 | case Intrinsics::kVarHandleLoadLoadFence: |
| 404 | case Intrinsics::kVarHandleStoreStoreFence: |
| 405 | case Intrinsics::kVarHandleCompareAndExchange: |
| 406 | case Intrinsics::kVarHandleCompareAndExchangeAcquire: |
| 407 | case Intrinsics::kVarHandleCompareAndExchangeRelease: |
| 408 | case Intrinsics::kVarHandleCompareAndSet: |
| 409 | case Intrinsics::kVarHandleGet: |
| 410 | case Intrinsics::kVarHandleGetAcquire: |
| 411 | case Intrinsics::kVarHandleGetAndAdd: |
| 412 | case Intrinsics::kVarHandleGetAndAddAcquire: |
| 413 | case Intrinsics::kVarHandleGetAndAddRelease: |
| 414 | case Intrinsics::kVarHandleGetAndBitwiseAnd: |
| 415 | case Intrinsics::kVarHandleGetAndBitwiseAndAcquire: |
| 416 | case Intrinsics::kVarHandleGetAndBitwiseAndRelease: |
| 417 | case Intrinsics::kVarHandleGetAndBitwiseOr: |
| 418 | case Intrinsics::kVarHandleGetAndBitwiseOrAcquire: |
| 419 | case Intrinsics::kVarHandleGetAndBitwiseOrRelease: |
| 420 | case Intrinsics::kVarHandleGetAndBitwiseXor: |
| 421 | case Intrinsics::kVarHandleGetAndBitwiseXorAcquire: |
| 422 | case Intrinsics::kVarHandleGetAndBitwiseXorRelease: |
| 423 | case Intrinsics::kVarHandleGetAndSet: |
| 424 | case Intrinsics::kVarHandleGetAndSetAcquire: |
| 425 | case Intrinsics::kVarHandleGetAndSetRelease: |
| 426 | case Intrinsics::kVarHandleGetOpaque: |
| 427 | case Intrinsics::kVarHandleGetVolatile: |
| 428 | case Intrinsics::kVarHandleSet: |
| 429 | case Intrinsics::kVarHandleSetOpaque: |
| 430 | case Intrinsics::kVarHandleSetRelease: |
| 431 | case Intrinsics::kVarHandleSetVolatile: |
| 432 | case Intrinsics::kVarHandleWeakCompareAndSet: |
| 433 | case Intrinsics::kVarHandleWeakCompareAndSetAcquire: |
| 434 | case Intrinsics::kVarHandleWeakCompareAndSetPlain: |
| 435 | case Intrinsics::kVarHandleWeakCompareAndSetRelease: |
| 436 | // These intrinsics are on the blacklist and will fail a DCHECK in |
| 437 | // SetIntrinsic() if their flags change on the respective dex methods. |
| 438 | // Note that the DCHECK currently won't fail if the dex methods are |
| 439 | // whitelisted, e.g. in the core image (b/77733081). Given that they are |
| 440 | // exclusively VarHandle intrinsics, they should not be used outside |
| 441 | // tests that do not enable hidden API checks. |
| 442 | return HiddenApiAccessFlags::kBlacklist; |
| 443 | default: |
| 444 | // Remaining intrinsics are public API. We DCHECK that in SetIntrinsic(). |
| 445 | return HiddenApiAccessFlags::kWhitelist; |
| 446 | } |
| 447 | } else { |
| 448 | return HiddenApiAccessFlags::DecodeFromRuntime(GetAccessFlags()); |
David Brazdil | aa129ff | 2018-01-30 16:11:02 +0000 | [diff] [blame] | 449 | } |
| 450 | } |
| 451 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 452 | inline void ArtMethod::SetIntrinsic(uint32_t intrinsic) { |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 453 | // Currently we only do intrinsics for static/final methods or methods of final |
| 454 | // classes. We don't set kHasSingleImplementation for those methods. |
| 455 | DCHECK(IsStatic() || IsFinal() || GetDeclaringClass()->IsFinal()) << |
| 456 | "Potential conflict with kAccSingleImplementation"; |
Orion Hodson | cfcc9cf | 2017-09-29 15:07:27 +0100 | [diff] [blame] | 457 | static const int kAccFlagsShift = CTZ(kAccIntrinsicBits); |
| 458 | DCHECK_LE(intrinsic, kAccIntrinsicBits >> kAccFlagsShift); |
| 459 | uint32_t intrinsic_bits = intrinsic << kAccFlagsShift; |
| 460 | uint32_t new_value = (GetAccessFlags() & ~kAccIntrinsicBits) | kAccIntrinsic | intrinsic_bits; |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 461 | if (kIsDebugBuild) { |
| 462 | uint32_t java_flags = (GetAccessFlags() & kAccJavaFlagsMask); |
| 463 | bool is_constructor = IsConstructor(); |
| 464 | bool is_synchronized = IsSynchronized(); |
| 465 | bool skip_access_checks = SkipAccessChecks(); |
| 466 | bool is_fast_native = IsFastNative(); |
Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 467 | bool is_critical_native = IsCriticalNative(); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 468 | bool is_copied = IsCopied(); |
| 469 | bool is_miranda = IsMiranda(); |
| 470 | bool is_default = IsDefault(); |
| 471 | bool is_default_conflict = IsDefaultConflicting(); |
| 472 | bool is_compilable = IsCompilable(); |
| 473 | bool must_count_locks = MustCountLocks(); |
David Brazdil | 49dded0 | 2018-04-19 12:41:04 +0100 | [diff] [blame] | 474 | HiddenApiAccessFlags::ApiList hidden_api_flags = GetHiddenApiAccessFlags(); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 475 | SetAccessFlags(new_value); |
| 476 | DCHECK_EQ(java_flags, (GetAccessFlags() & kAccJavaFlagsMask)); |
| 477 | DCHECK_EQ(is_constructor, IsConstructor()); |
| 478 | DCHECK_EQ(is_synchronized, IsSynchronized()); |
| 479 | DCHECK_EQ(skip_access_checks, SkipAccessChecks()); |
| 480 | DCHECK_EQ(is_fast_native, IsFastNative()); |
Vladimir Marko | b0a6aee | 2017-10-27 10:34:04 +0100 | [diff] [blame] | 481 | DCHECK_EQ(is_critical_native, IsCriticalNative()); |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 482 | DCHECK_EQ(is_copied, IsCopied()); |
| 483 | DCHECK_EQ(is_miranda, IsMiranda()); |
| 484 | DCHECK_EQ(is_default, IsDefault()); |
| 485 | DCHECK_EQ(is_default_conflict, IsDefaultConflicting()); |
| 486 | DCHECK_EQ(is_compilable, IsCompilable()); |
| 487 | DCHECK_EQ(must_count_locks, MustCountLocks()); |
David Brazdil | 49dded0 | 2018-04-19 12:41:04 +0100 | [diff] [blame] | 488 | // Only DCHECK that we have preserved the hidden API access flags if the |
| 489 | // original method was not on the whitelist. This is because the core image |
| 490 | // does not have the access flags set (b/77733081). It is fine to hard-code |
| 491 | // these because (a) warnings on greylist do not change semantics, and |
| 492 | // (b) only VarHandle intrinsics are blacklisted at the moment and they |
| 493 | // should not be used outside tests with disabled API checks. |
| 494 | if (hidden_api_flags != HiddenApiAccessFlags::kWhitelist) { |
| 495 | DCHECK_EQ(hidden_api_flags, GetHiddenApiAccessFlags()); |
David Brazdil | 8714435 | 2018-01-24 12:50:01 +0000 | [diff] [blame] | 496 | } |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 497 | } else { |
| 498 | SetAccessFlags(new_value); |
| 499 | } |
| 500 | } |
| 501 | |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 502 | template<ReadBarrierOption kReadBarrierOption, typename RootVisitorType> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 503 | void ArtMethod::VisitRoots(RootVisitorType& visitor, PointerSize pointer_size) { |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 504 | if (LIKELY(!declaring_class_.IsNull())) { |
| 505 | visitor.VisitRoot(declaring_class_.AddressWithoutBarrier()); |
| 506 | mirror::Class* klass = declaring_class_.Read<kReadBarrierOption>(); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 507 | if (UNLIKELY(klass->IsProxyClass())) { |
| 508 | // For normal methods, dex cache shortcuts will be visited through the declaring class. |
| 509 | // 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] | 510 | ArtMethod* interface_method = GetInterfaceMethodForProxyUnchecked(pointer_size); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 511 | DCHECK(interface_method != nullptr); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 512 | interface_method->VisitRoots(visitor, pointer_size); |
| 513 | } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 514 | } |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 515 | } |
| 516 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 517 | template <typename Visitor> |
Vladimir Marko | 5122e6b | 2017-08-17 16:10:09 +0100 | [diff] [blame] | 518 | inline void ArtMethod::UpdateObjectsForImageRelocation(const Visitor& visitor) { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 519 | mirror::Class* old_class = GetDeclaringClassUnchecked<kWithoutReadBarrier>(); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 520 | mirror::Class* new_class = visitor(old_class); |
| 521 | if (old_class != new_class) { |
| 522 | SetDeclaringClass(new_class); |
| 523 | } |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 524 | } |
| 525 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 526 | template <ReadBarrierOption kReadBarrierOption, typename Visitor> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 527 | inline void ArtMethod::UpdateEntrypoints(const Visitor& visitor, PointerSize pointer_size) { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 528 | if (IsNative<kReadBarrierOption>()) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 529 | const void* old_native_code = GetEntryPointFromJniPtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 530 | const void* new_native_code = visitor(old_native_code); |
| 531 | if (old_native_code != new_native_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 532 | SetEntryPointFromJniPtrSize(new_native_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 533 | } |
| 534 | } else { |
Andreas Gampe | 75f0885 | 2016-07-19 08:06:07 -0700 | [diff] [blame] | 535 | DCHECK(GetDataPtrSize(pointer_size) == nullptr); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 536 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 537 | const void* old_code = GetEntryPointFromQuickCompiledCodePtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 538 | const void* new_code = visitor(old_code); |
| 539 | if (old_code != new_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 540 | SetEntryPointFromQuickCompiledCodePtrSize(new_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 541 | } |
| 542 | } |
| 543 | |
Mathieu Chartier | 808c7a5 | 2017-12-15 11:19:33 -0800 | [diff] [blame] | 544 | inline CodeItemInstructionAccessor ArtMethod::DexInstructions() { |
David Sehr | 0225f8e | 2018-01-31 08:52:24 +0000 | [diff] [blame] | 545 | return CodeItemInstructionAccessor(*GetDexFile(), GetCodeItem()); |
| 546 | } |
| 547 | |
| 548 | inline CodeItemDataAccessor ArtMethod::DexInstructionData() { |
| 549 | return CodeItemDataAccessor(*GetDexFile(), GetCodeItem()); |
| 550 | } |
| 551 | |
| 552 | inline CodeItemDebugInfoAccessor ArtMethod::DexInstructionDebugInfo() { |
| 553 | return CodeItemDebugInfoAccessor(*GetDexFile(), GetCodeItem(), GetDexMethodIndex()); |
Mathieu Chartier | 69147f1 | 2017-11-06 20:02:24 -0800 | [diff] [blame] | 554 | } |
| 555 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 556 | } // namespace art |
| 557 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 558 | #endif // ART_RUNTIME_ART_METHOD_INL_H_ |