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" |
Mathieu Chartier | 7c0fe5e | 2015-07-17 19:53:47 -0700 | [diff] [blame] | 23 | #include "base/logging.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" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 26 | #include "dex_file.h" |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 27 | #include "dex_file_annotations.h" |
Elliott Hughes | 956af0f | 2014-12-11 14:34:28 -0800 | [diff] [blame] | 28 | #include "dex_file-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 29 | #include "gc_root-inl.h" |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 30 | #include "jit/profiling_info.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 31 | #include "mirror/class-inl.h" |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 32 | #include "mirror/dex_cache-inl.h" |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 33 | #include "mirror/object-inl.h" |
| 34 | #include "mirror/object_array.h" |
Nicolas Geoffray | 4c0b4bc | 2017-03-17 13:08:26 +0000 | [diff] [blame] | 35 | #include "mirror/string.h" |
Vladimir Marko | 96c6ab9 | 2014-04-08 14:00:50 +0100 | [diff] [blame] | 36 | #include "oat.h" |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 37 | #include "obj_ptr-inl.h" |
Vladimir Marko | 7624d25 | 2014-05-02 14:40:15 +0100 | [diff] [blame] | 38 | #include "quick/quick_method_frame_info.h" |
| 39 | #include "runtime-inl.h" |
Mathieu Chartier | 0795f23 | 2016-09-27 18:43:30 -0700 | [diff] [blame] | 40 | #include "scoped_thread_state_change-inl.h" |
Andreas Gampe | b486a98 | 2017-06-01 13:45:54 -0700 | [diff] [blame^] | 41 | #include "thread-current-inl.h" |
Vladimir Marko | 80afd02 | 2015-05-19 18:08:00 +0100 | [diff] [blame] | 42 | #include "utils.h" |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 43 | |
| 44 | namespace art { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 45 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 46 | template <ReadBarrierOption kReadBarrierOption> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 47 | inline mirror::Class* ArtMethod::GetDeclaringClassUnchecked() { |
Hiroshi Yamauchi | 3f64f25 | 2015-06-12 18:35:06 -0700 | [diff] [blame] | 48 | GcRootSource gc_root_source(this); |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 49 | return declaring_class_.Read<kReadBarrierOption>(&gc_root_source); |
Mingyao Yang | 98d1cc8 | 2014-05-15 17:02:16 -0700 | [diff] [blame] | 50 | } |
| 51 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 52 | template <ReadBarrierOption kReadBarrierOption> |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 53 | inline mirror::Class* ArtMethod::GetDeclaringClass() { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 54 | mirror::Class* result = GetDeclaringClassUnchecked<kReadBarrierOption>(); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 55 | if (kIsDebugBuild) { |
| 56 | if (!IsRuntimeMethod()) { |
| 57 | CHECK(result != nullptr) << this; |
Andreas Gampe | b1106e2 | 2017-02-23 11:34:48 -0800 | [diff] [blame] | 58 | if (kCheckDeclaringClassState) { |
Nicolas Geoffray | 4c0b4bc | 2017-03-17 13:08:26 +0000 | [diff] [blame] | 59 | if (!(result->IsIdxLoaded() || result->IsErroneous())) { |
| 60 | LOG(FATAL_WITHOUT_ABORT) << "Class status: " << result->GetStatus(); |
| 61 | LOG(FATAL) << result->PrettyClass(); |
| 62 | } |
Andreas Gampe | b1106e2 | 2017-02-23 11:34:48 -0800 | [diff] [blame] | 63 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 64 | } else { |
| 65 | CHECK(result == nullptr) << this; |
| 66 | } |
| 67 | } |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 68 | return result; |
| 69 | } |
| 70 | |
Mathieu Chartier | 28357fa | 2016-10-18 16:27:40 -0700 | [diff] [blame] | 71 | inline void ArtMethod::SetDeclaringClass(ObjPtr<mirror::Class> new_declaring_class) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 72 | declaring_class_ = GcRoot<mirror::Class>(new_declaring_class); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 73 | } |
| 74 | |
Mathieu Chartier | 10e5ea9 | 2015-08-13 12:56:31 -0700 | [diff] [blame] | 75 | inline bool ArtMethod::CASDeclaringClass(mirror::Class* expected_class, |
| 76 | mirror::Class* desired_class) { |
| 77 | GcRoot<mirror::Class> expected_root(expected_class); |
| 78 | GcRoot<mirror::Class> desired_root(desired_class); |
| 79 | return reinterpret_cast<Atomic<GcRoot<mirror::Class>>*>(&declaring_class_)-> |
| 80 | CompareExchangeStrongSequentiallyConsistent( |
| 81 | expected_root, desired_root); |
| 82 | } |
| 83 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 84 | inline uint16_t ArtMethod::GetMethodIndex() { |
Vladimir Marko | 72ab684 | 2017-01-20 19:32:50 +0000 | [diff] [blame] | 85 | DCHECK(IsRuntimeMethod() || GetDeclaringClass()->IsResolved()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 86 | return method_index_; |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 87 | } |
| 88 | |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 89 | inline uint16_t ArtMethod::GetMethodIndexDuringLinking() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 90 | return method_index_; |
Mathieu Chartier | 9f3629d | 2014-10-28 18:23:02 -0700 | [diff] [blame] | 91 | } |
| 92 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 93 | inline uint32_t ArtMethod::GetDexMethodIndex() { |
Andreas Gampe | b1106e2 | 2017-02-23 11:34:48 -0800 | [diff] [blame] | 94 | if (kCheckDeclaringClassState) { |
| 95 | CHECK(IsRuntimeMethod() || GetDeclaringClass()->IsIdxLoaded() || |
| 96 | GetDeclaringClass()->IsErroneous()); |
| 97 | } |
Nicolas Geoffray | 5d37c15 | 2017-01-12 13:25:19 +0000 | [diff] [blame] | 98 | return GetDexMethodIndexUnchecked(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 99 | } |
| 100 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 101 | inline ArtMethod** ArtMethod::GetDexCacheResolvedMethods(PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 102 | return GetNativePointer<ArtMethod**>(DexCacheResolvedMethodsOffset(pointer_size), |
| 103 | pointer_size); |
Ian Rogers | 4f6ad8a | 2013-03-18 15:27:28 -0700 | [diff] [blame] | 104 | } |
| 105 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 106 | inline ArtMethod* ArtMethod::GetDexCacheResolvedMethod(uint16_t method_index, |
| 107 | PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 108 | // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here |
| 109 | // without accessing the DexCache and we don't want to do that in release build. |
| 110 | DCHECK_LT(method_index, |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 111 | GetInterfaceMethodIfProxy(pointer_size)->GetDexCache()->NumResolvedMethods()); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 112 | ArtMethod* method = mirror::DexCache::GetElementPtrSize(GetDexCacheResolvedMethods(pointer_size), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 113 | method_index, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 114 | pointer_size); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 115 | if (LIKELY(method != nullptr)) { |
| 116 | auto* declaring_class = method->GetDeclaringClass(); |
| 117 | if (LIKELY(declaring_class == nullptr || !declaring_class->IsErroneous())) { |
| 118 | return method; |
| 119 | } |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 120 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 121 | return nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 122 | } |
| 123 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 124 | inline void ArtMethod::SetDexCacheResolvedMethod(uint16_t method_index, |
| 125 | ArtMethod* new_method, |
| 126 | PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 127 | // NOTE: Unchecked, i.e. not throwing AIOOB. We don't even know the length here |
| 128 | // without accessing the DexCache and we don't want to do that in release build. |
| 129 | DCHECK_LT(method_index, |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 130 | GetInterfaceMethodIfProxy(pointer_size)->GetDexCache()->NumResolvedMethods()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 131 | DCHECK(new_method == nullptr || new_method->GetDeclaringClass() != nullptr); |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 132 | mirror::DexCache::SetElementPtrSize(GetDexCacheResolvedMethods(pointer_size), |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 133 | method_index, |
| 134 | new_method, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 135 | pointer_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 136 | } |
| 137 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 138 | inline bool ArtMethod::HasDexCacheResolvedMethods(PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 139 | return GetDexCacheResolvedMethods(pointer_size) != nullptr; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 140 | } |
| 141 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 142 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod** other_cache, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 143 | PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 144 | return GetDexCacheResolvedMethods(pointer_size) == other_cache; |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 145 | } |
| 146 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 147 | inline bool ArtMethod::HasSameDexCacheResolvedMethods(ArtMethod* other, PointerSize pointer_size) { |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 148 | return GetDexCacheResolvedMethods(pointer_size) == |
| 149 | other->GetDexCacheResolvedMethods(pointer_size); |
Andreas Gampe | 58a5af8 | 2014-07-31 16:23:49 -0700 | [diff] [blame] | 150 | } |
| 151 | |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 152 | inline mirror::Class* ArtMethod::GetClassFromTypeIndex(dex::TypeIndex type_idx, bool resolve) { |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 153 | // TODO: Refactor this function into two functions, Resolve...() and Lookup...() |
| 154 | // so that we can properly annotate it with no-suspension possible / suspension possible. |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 155 | ObjPtr<mirror::DexCache> dex_cache = GetDexCache(); |
| 156 | ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 157 | if (UNLIKELY(type == nullptr)) { |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 158 | ClassLinker* class_linker = Runtime::Current()->GetClassLinker(); |
Vladimir Marko | 8d6768d | 2017-03-14 10:13:21 +0000 | [diff] [blame] | 159 | if (resolve) { |
| 160 | type = class_linker->ResolveType(type_idx, this); |
| 161 | CHECK(type != nullptr || Thread::Current()->IsExceptionPending()); |
| 162 | } else { |
| 163 | type = class_linker->LookupResolvedType( |
| 164 | *dex_cache->GetDexFile(), type_idx, dex_cache, GetClassLoader()); |
| 165 | } |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 166 | } |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 167 | return type.Ptr(); |
Ian Rogers | a048560 | 2014-12-02 15:48:04 -0800 | [diff] [blame] | 168 | } |
| 169 | |
Brian Carlstrom | ea46f95 | 2013-07-30 01:26:50 -0700 | [diff] [blame] | 170 | inline bool ArtMethod::CheckIncompatibleClassChange(InvokeType type) { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 171 | switch (type) { |
| 172 | case kStatic: |
| 173 | return !IsStatic(); |
| 174 | case kDirect: |
| 175 | return !IsDirect() || IsStatic(); |
| 176 | case kVirtual: { |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 177 | // We have an error if we are direct or a non-copied (i.e. not part of a real class) interface |
| 178 | // method. |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 179 | mirror::Class* methods_class = GetDeclaringClass(); |
Alex Light | d6e0fa9 | 2016-10-17 13:02:39 -0700 | [diff] [blame] | 180 | return IsDirect() || (methods_class->IsInterface() && !IsCopied()); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 181 | } |
| 182 | case kSuper: |
Andreas Gampe | 8f252e6 | 2014-08-25 20:46:31 -0700 | [diff] [blame] | 183 | // Constructors and static methods are called with invoke-direct. |
Alex Light | 705ad49 | 2015-09-21 11:36:30 -0700 | [diff] [blame] | 184 | return IsConstructor() || IsStatic(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 185 | case kInterface: { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 186 | mirror::Class* methods_class = GetDeclaringClass(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 187 | return IsDirect() || !(methods_class->IsInterface() || methods_class->IsObjectClass()); |
| 188 | } |
| 189 | default: |
| 190 | LOG(FATAL) << "Unreachable - invocation type: " << type; |
Ian Rogers | 2c4257b | 2014-10-24 14:20:06 -0700 | [diff] [blame] | 191 | UNREACHABLE(); |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 192 | } |
| 193 | } |
| 194 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 195 | inline bool ArtMethod::IsCalleeSaveMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 196 | if (!IsRuntimeMethod()) { |
| 197 | return false; |
| 198 | } |
| 199 | Runtime* runtime = Runtime::Current(); |
| 200 | bool result = false; |
| 201 | for (int i = 0; i < Runtime::kLastCalleeSaveType; i++) { |
| 202 | if (this == runtime->GetCalleeSaveMethod(Runtime::CalleeSaveType(i))) { |
| 203 | result = true; |
| 204 | break; |
| 205 | } |
| 206 | } |
| 207 | return result; |
| 208 | } |
| 209 | |
Ian Rogers | ef7d42f | 2014-01-06 12:55:46 -0800 | [diff] [blame] | 210 | inline bool ArtMethod::IsResolutionMethod() { |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 211 | bool result = this == Runtime::Current()->GetResolutionMethod(); |
| 212 | // Check that if we do think it is phony it looks like the resolution method. |
| 213 | DCHECK(!result || IsRuntimeMethod()); |
| 214 | return result; |
| 215 | } |
Jeff Hao | 88474b4 | 2013-10-23 16:24:40 -0700 | [diff] [blame] | 216 | |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 217 | inline bool ArtMethod::IsImtUnimplementedMethod() { |
| 218 | bool result = this == Runtime::Current()->GetImtUnimplementedMethod(); |
| 219 | // Check that if we do think it is phony it looks like the imt unimplemented method. |
| 220 | DCHECK(!result || IsRuntimeMethod()); |
| 221 | return result; |
| 222 | } |
| 223 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 224 | inline const DexFile* ArtMethod::GetDexFile() { |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 225 | // It is safe to avoid the read barrier here since the dex file is constant, so if we read the |
| 226 | // from-space dex file pointer it will be equal to the to-space copy. |
| 227 | return GetDexCache<kWithoutReadBarrier>()->GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 228 | } |
| 229 | |
| 230 | inline const char* ArtMethod::GetDeclaringClassDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 231 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 232 | if (UNLIKELY(dex_method_idx == DexFile::kDexNoIndex)) { |
| 233 | return "<runtime method>"; |
| 234 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 235 | DCHECK(!IsProxyMethod()); |
| 236 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 237 | return dex_file->GetMethodDeclaringClassDescriptor(dex_file->GetMethodId(dex_method_idx)); |
| 238 | } |
| 239 | |
Andreas Gampe | c6ea7d0 | 2017-02-01 16:46:28 -0800 | [diff] [blame] | 240 | inline const char* ArtMethod::GetShorty() { |
| 241 | uint32_t unused_length; |
| 242 | return GetShorty(&unused_length); |
| 243 | } |
| 244 | |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 245 | inline const char* ArtMethod::GetShorty(uint32_t* out_length) { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 246 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 247 | const DexFile* dex_file = GetDexFile(); |
| 248 | return dex_file->GetMethodShorty(dex_file->GetMethodId(GetDexMethodIndex()), out_length); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | inline const Signature ArtMethod::GetSignature() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 252 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 253 | if (dex_method_idx != DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 254 | DCHECK(!IsProxyMethod()); |
| 255 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 256 | return dex_file->GetMethodSignature(dex_file->GetMethodId(dex_method_idx)); |
| 257 | } |
| 258 | return Signature::NoSignature(); |
| 259 | } |
| 260 | |
Ian Rogers | 1ff3c98 | 2014-08-12 02:30:58 -0700 | [diff] [blame] | 261 | inline const char* ArtMethod::GetName() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 262 | uint32_t dex_method_idx = GetDexMethodIndex(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 263 | if (LIKELY(dex_method_idx != DexFile::kDexNoIndex)) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 264 | DCHECK(!IsProxyMethod()); |
| 265 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 266 | return dex_file->GetMethodName(dex_file->GetMethodId(dex_method_idx)); |
| 267 | } |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 268 | Runtime* const runtime = Runtime::Current(); |
| 269 | if (this == runtime->GetResolutionMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 270 | return "<runtime internal resolution method>"; |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 271 | } else if (this == runtime->GetImtConflictMethod()) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 272 | return "<runtime internal imt conflict method>"; |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 273 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveAllCalleeSaves)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 274 | return "<runtime internal callee-save all registers method>"; |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 275 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveRefsOnly)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 276 | return "<runtime internal callee-save reference registers method>"; |
Vladimir Marko | fd36f1f | 2016-08-03 18:49:58 +0100 | [diff] [blame] | 277 | } else if (this == runtime->GetCalleeSaveMethod(Runtime::kSaveRefsAndArgs)) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 278 | return "<runtime internal callee-save reference and argument registers method>"; |
| 279 | } else { |
| 280 | return "<unknown runtime internal method>"; |
| 281 | } |
| 282 | } |
| 283 | |
| 284 | inline const DexFile::CodeItem* ArtMethod::GetCodeItem() { |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 285 | return GetDexFile()->GetCodeItem(GetCodeItemOffset()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 286 | } |
| 287 | |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 288 | inline bool ArtMethod::IsResolvedTypeIdx(dex::TypeIndex type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 289 | DCHECK(!IsProxyMethod()); |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 290 | return GetClassFromTypeIndex(type_idx, /* resolve */ false) != nullptr; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 291 | } |
| 292 | |
| 293 | inline int32_t ArtMethod::GetLineNumFromDexPC(uint32_t dex_pc) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 294 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 295 | if (dex_pc == DexFile::kDexNoIndex) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 296 | return IsNative() ? -2 : -1; |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 297 | } |
David Sehr | 9323e6e | 2016-09-13 08:58:35 -0700 | [diff] [blame] | 298 | return annotations::GetLineNumFromPC(GetDexFile(), this, dex_pc); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 299 | } |
| 300 | |
| 301 | inline const DexFile::ProtoId& ArtMethod::GetPrototype() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 302 | DCHECK(!IsProxyMethod()); |
| 303 | const DexFile* dex_file = GetDexFile(); |
| 304 | return dex_file->GetMethodPrototype(dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 305 | } |
| 306 | |
| 307 | inline const DexFile::TypeList* ArtMethod::GetParameterTypeList() { |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 308 | DCHECK(!IsProxyMethod()); |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 309 | const DexFile* dex_file = GetDexFile(); |
Nicolas Geoffray | 3a09092 | 2015-11-24 09:17:30 +0000 | [diff] [blame] | 310 | const DexFile::ProtoId& proto = dex_file->GetMethodPrototype( |
| 311 | dex_file->GetMethodId(GetDexMethodIndex())); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 312 | return dex_file->GetProtoParameters(proto); |
| 313 | } |
| 314 | |
| 315 | inline const char* ArtMethod::GetDeclaringClassSourceFile() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 316 | DCHECK(!IsProxyMethod()); |
| 317 | return GetDeclaringClass()->GetSourceFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | inline uint16_t ArtMethod::GetClassDefIndex() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 321 | DCHECK(!IsProxyMethod()); |
Alex Light | f2f1c9d | 2017-03-15 15:35:46 +0000 | [diff] [blame] | 322 | if (LIKELY(!IsObsolete())) { |
| 323 | return GetDeclaringClass()->GetDexClassDefIndex(); |
| 324 | } else { |
| 325 | return FindObsoleteDexClassDefIndex(); |
| 326 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | inline const DexFile::ClassDef& ArtMethod::GetClassDef() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 330 | DCHECK(!IsProxyMethod()); |
| 331 | return GetDexFile()->GetClassDef(GetClassDefIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 332 | } |
| 333 | |
| 334 | inline const char* ArtMethod::GetReturnTypeDescriptor() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 335 | DCHECK(!IsProxyMethod()); |
| 336 | const DexFile* dex_file = GetDexFile(); |
| 337 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 338 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 339 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(proto_id.return_type_idx_)); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 340 | } |
| 341 | |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 342 | inline const char* ArtMethod::GetTypeDescriptorFromTypeIdx(dex::TypeIndex type_idx) { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 343 | DCHECK(!IsProxyMethod()); |
| 344 | const DexFile* dex_file = GetDexFile(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 345 | return dex_file->GetTypeDescriptor(dex_file->GetTypeId(type_idx)); |
| 346 | } |
| 347 | |
| 348 | inline mirror::ClassLoader* ArtMethod::GetClassLoader() { |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 349 | DCHECK(!IsProxyMethod()); |
| 350 | return GetDeclaringClass()->GetClassLoader(); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 351 | } |
| 352 | |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 353 | template <ReadBarrierOption kReadBarrierOption> |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 354 | inline mirror::DexCache* ArtMethod::GetDexCache() { |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 355 | if (LIKELY(!IsObsolete())) { |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 356 | mirror::Class* klass = GetDeclaringClass<kReadBarrierOption>(); |
| 357 | return klass->GetDexCache<kDefaultVerifyFlags, kReadBarrierOption>(); |
Alex Light | dba6148 | 2016-12-21 08:20:29 -0800 | [diff] [blame] | 358 | } else { |
| 359 | DCHECK(!IsProxyMethod()); |
| 360 | return GetObsoleteDexCache(); |
Alex Light | a01de59 | 2016-11-15 10:43:06 -0800 | [diff] [blame] | 361 | } |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 362 | } |
| 363 | |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 364 | inline bool ArtMethod::IsProxyMethod() { |
Mathieu Chartier | 90c5a9b | 2017-02-01 13:10:06 -0800 | [diff] [blame] | 365 | // Avoid read barrier since the from-space version of the class will have the correct proxy class |
| 366 | // flags since they are constant for the lifetime of the class. |
| 367 | return GetDeclaringClass<kWithoutReadBarrier>()->IsProxyClass(); |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 368 | } |
| 369 | |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 370 | inline ArtMethod* ArtMethod::GetInterfaceMethodIfProxy(PointerSize pointer_size) { |
Ian Rogers | 03b6eaf | 2014-10-28 09:34:57 -0700 | [diff] [blame] | 371 | if (LIKELY(!IsProxyMethod())) { |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 372 | return this; |
| 373 | } |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 374 | ArtMethod* interface_method = mirror::DexCache::GetElementPtrSize( |
| 375 | GetDexCacheResolvedMethods(pointer_size), |
| 376 | GetDexMethodIndex(), |
| 377 | pointer_size); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 378 | DCHECK(interface_method != nullptr); |
| 379 | DCHECK_EQ(interface_method, |
Mathieu Chartier | 137cdfa | 2017-01-26 14:03:11 -0800 | [diff] [blame] | 380 | Runtime::Current()->GetClassLinker()->FindMethodForProxy(GetDeclaringClass(), this)); |
Mathieu Chartier | bfd9a43 | 2014-05-21 17:43:44 -0700 | [diff] [blame] | 381 | return interface_method; |
| 382 | } |
| 383 | |
Vladimir Marko | 05792b9 | 2015-08-03 11:56:49 +0100 | [diff] [blame] | 384 | inline void ArtMethod::SetDexCacheResolvedMethods(ArtMethod** new_dex_cache_methods, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 385 | PointerSize pointer_size) { |
| 386 | SetNativePointer(DexCacheResolvedMethodsOffset(pointer_size), |
| 387 | new_dex_cache_methods, |
| 388 | pointer_size); |
Mathieu Chartier | 2d2621a | 2014-10-23 16:48:06 -0700 | [diff] [blame] | 389 | } |
| 390 | |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 391 | inline mirror::Class* ArtMethod::GetReturnType(bool resolve) { |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 392 | DCHECK(!IsProxyMethod()); |
| 393 | const DexFile* dex_file = GetDexFile(); |
| 394 | const DexFile::MethodId& method_id = dex_file->GetMethodId(GetDexMethodIndex()); |
| 395 | const DexFile::ProtoId& proto_id = dex_file->GetMethodPrototype(method_id); |
Andreas Gampe | a5b09a6 | 2016-11-17 15:21:22 -0800 | [diff] [blame] | 396 | dex::TypeIndex return_type_idx = proto_id.return_type_idx_; |
Vladimir Marko | 942fd31 | 2017-01-16 20:52:19 +0000 | [diff] [blame] | 397 | return GetClassFromTypeIndex(return_type_idx, resolve); |
Ian Rogers | ded66a0 | 2014-10-28 18:12:55 -0700 | [diff] [blame] | 398 | } |
| 399 | |
Mingyao Yang | 063fc77 | 2016-08-02 11:02:54 -0700 | [diff] [blame] | 400 | inline bool ArtMethod::HasSingleImplementation() { |
| 401 | if (IsFinal() || GetDeclaringClass()->IsFinal()) { |
| 402 | // We don't set kAccSingleImplementation for these cases since intrinsic |
| 403 | // can use the flag also. |
| 404 | return true; |
| 405 | } |
| 406 | return (GetAccessFlags() & kAccSingleImplementation) != 0; |
| 407 | } |
| 408 | |
| 409 | inline void ArtMethod::SetIntrinsic(uint32_t intrinsic) { |
| 410 | DCHECK(IsUint<8>(intrinsic)); |
| 411 | // Currently we only do intrinsics for static/final methods or methods of final |
| 412 | // classes. We don't set kHasSingleImplementation for those methods. |
| 413 | DCHECK(IsStatic() || IsFinal() || GetDeclaringClass()->IsFinal()) << |
| 414 | "Potential conflict with kAccSingleImplementation"; |
| 415 | uint32_t new_value = (GetAccessFlags() & kAccFlagsNotUsedByIntrinsic) | |
| 416 | kAccIntrinsic | |
| 417 | (intrinsic << POPCOUNT(kAccFlagsNotUsedByIntrinsic)); |
| 418 | if (kIsDebugBuild) { |
| 419 | uint32_t java_flags = (GetAccessFlags() & kAccJavaFlagsMask); |
| 420 | bool is_constructor = IsConstructor(); |
| 421 | bool is_synchronized = IsSynchronized(); |
| 422 | bool skip_access_checks = SkipAccessChecks(); |
| 423 | bool is_fast_native = IsFastNative(); |
| 424 | bool is_copied = IsCopied(); |
| 425 | bool is_miranda = IsMiranda(); |
| 426 | bool is_default = IsDefault(); |
| 427 | bool is_default_conflict = IsDefaultConflicting(); |
| 428 | bool is_compilable = IsCompilable(); |
| 429 | bool must_count_locks = MustCountLocks(); |
| 430 | SetAccessFlags(new_value); |
| 431 | DCHECK_EQ(java_flags, (GetAccessFlags() & kAccJavaFlagsMask)); |
| 432 | DCHECK_EQ(is_constructor, IsConstructor()); |
| 433 | DCHECK_EQ(is_synchronized, IsSynchronized()); |
| 434 | DCHECK_EQ(skip_access_checks, SkipAccessChecks()); |
| 435 | DCHECK_EQ(is_fast_native, IsFastNative()); |
| 436 | DCHECK_EQ(is_copied, IsCopied()); |
| 437 | DCHECK_EQ(is_miranda, IsMiranda()); |
| 438 | DCHECK_EQ(is_default, IsDefault()); |
| 439 | DCHECK_EQ(is_default_conflict, IsDefaultConflicting()); |
| 440 | DCHECK_EQ(is_compilable, IsCompilable()); |
| 441 | DCHECK_EQ(must_count_locks, MustCountLocks()); |
| 442 | } else { |
| 443 | SetAccessFlags(new_value); |
| 444 | } |
| 445 | } |
| 446 | |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 447 | template<ReadBarrierOption kReadBarrierOption, typename RootVisitorType> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 448 | void ArtMethod::VisitRoots(RootVisitorType& visitor, PointerSize pointer_size) { |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 449 | if (LIKELY(!declaring_class_.IsNull())) { |
| 450 | visitor.VisitRoot(declaring_class_.AddressWithoutBarrier()); |
| 451 | mirror::Class* klass = declaring_class_.Read<kReadBarrierOption>(); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 452 | if (UNLIKELY(klass->IsProxyClass())) { |
| 453 | // For normal methods, dex cache shortcuts will be visited through the declaring class. |
| 454 | // However, for proxies we need to keep the interface method alive, so we visit its roots. |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 455 | ArtMethod* interface_method = mirror::DexCache::GetElementPtrSize( |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 456 | GetDexCacheResolvedMethods(pointer_size), |
| 457 | GetDexMethodIndex(), |
| 458 | pointer_size); |
| 459 | DCHECK(interface_method != nullptr); |
| 460 | DCHECK_EQ(interface_method, |
Hiroshi Yamauchi | 7a62e67 | 2016-06-10 17:22:48 -0700 | [diff] [blame] | 461 | Runtime::Current()->GetClassLinker()->FindMethodForProxy<kReadBarrierOption>( |
| 462 | klass, this)); |
Nicolas Geoffray | dec3a12 | 2016-02-13 12:38:36 +0000 | [diff] [blame] | 463 | interface_method->VisitRoots(visitor, pointer_size); |
| 464 | } |
Nicolas Geoffray | 5550ca8 | 2015-08-21 18:38:30 +0100 | [diff] [blame] | 465 | } |
Mathieu Chartier | 2d72101 | 2014-11-10 11:08:06 -0800 | [diff] [blame] | 466 | } |
| 467 | |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 468 | template <typename Visitor> |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 469 | inline void ArtMethod::UpdateObjectsForImageRelocation(const Visitor& visitor, |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 470 | PointerSize pointer_size) { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 471 | mirror::Class* old_class = GetDeclaringClassUnchecked<kWithoutReadBarrier>(); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 472 | mirror::Class* new_class = visitor(old_class); |
| 473 | if (old_class != new_class) { |
| 474 | SetDeclaringClass(new_class); |
| 475 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 476 | ArtMethod** old_methods = GetDexCacheResolvedMethods(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 477 | ArtMethod** new_methods = visitor(old_methods); |
| 478 | if (old_methods != new_methods) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 479 | SetDexCacheResolvedMethods(new_methods, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 480 | } |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 481 | } |
| 482 | |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 483 | template <ReadBarrierOption kReadBarrierOption, typename Visitor> |
Andreas Gampe | 542451c | 2016-07-26 09:02:02 -0700 | [diff] [blame] | 484 | inline void ArtMethod::UpdateEntrypoints(const Visitor& visitor, PointerSize pointer_size) { |
Mathieu Chartier | e7f75f3 | 2016-02-01 16:08:15 -0800 | [diff] [blame] | 485 | if (IsNative<kReadBarrierOption>()) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 486 | const void* old_native_code = GetEntryPointFromJniPtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 487 | const void* new_native_code = visitor(old_native_code); |
| 488 | if (old_native_code != new_native_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 489 | SetEntryPointFromJniPtrSize(new_native_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 490 | } |
| 491 | } else { |
Andreas Gampe | 75f0885 | 2016-07-19 08:06:07 -0700 | [diff] [blame] | 492 | DCHECK(GetDataPtrSize(pointer_size) == nullptr); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 493 | } |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 494 | const void* old_code = GetEntryPointFromQuickCompiledCodePtrSize(pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 495 | const void* new_code = visitor(old_code); |
| 496 | if (old_code != new_code) { |
Mathieu Chartier | 0b4cbd0 | 2016-03-08 16:49:58 -0800 | [diff] [blame] | 497 | SetEntryPointFromQuickCompiledCodePtrSize(new_code, pointer_size); |
Mathieu Chartier | fbc3108 | 2016-01-24 11:59:56 -0800 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
Ian Rogers | 2dd0e2c | 2013-01-24 12:42:14 -0800 | [diff] [blame] | 501 | } // namespace art |
| 502 | |
Mathieu Chartier | e401d14 | 2015-04-22 13:56:20 -0700 | [diff] [blame] | 503 | #endif // ART_RUNTIME_ART_METHOD_INL_H_ |