1 /*
2 * Copyright (C) 2013 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
17 #ifndef ART_RUNTIME_MIRROR_DEX_CACHE_INL_H_
18 #define ART_RUNTIME_MIRROR_DEX_CACHE_INL_H_
19
20 #include "dex_cache.h"
21
22 #include <android-base/logging.h>
23
24 #include "art_field.h"
25 #include "art_method.h"
26 #include "base/casts.h"
27 #include "base/enums.h"
28 #include "class_linker.h"
29 #include "dex/dex_file.h"
30 #include "gc_root-inl.h"
31 #include "mirror/call_site.h"
32 #include "mirror/class.h"
33 #include "mirror/method_type.h"
34 #include "obj_ptr.h"
35 #include "object-inl.h"
36 #include "runtime.h"
37 #include "write_barrier-inl.h"
38
39 #include <atomic>
40
41 namespace art {
42 namespace mirror {
43
44 template <typename T>
DexCachePair(ObjPtr<T> object,uint32_t index)45 inline DexCachePair<T>::DexCachePair(ObjPtr<T> object, uint32_t index)
46 : object(object), index(index) {}
47
48 template <typename T>
Initialize(std::atomic<DexCachePair<T>> * dex_cache)49 inline void DexCachePair<T>::Initialize(std::atomic<DexCachePair<T>>* dex_cache) {
50 DexCachePair<T> first_elem;
51 first_elem.object = GcRoot<T>(nullptr);
52 first_elem.index = InvalidIndexForSlot(0);
53 dex_cache[0].store(first_elem, std::memory_order_relaxed);
54 }
55
56 template <typename T>
GetObjectForIndex(uint32_t idx)57 inline T* DexCachePair<T>::GetObjectForIndex(uint32_t idx) {
58 if (idx != index) {
59 return nullptr;
60 }
61 DCHECK(!object.IsNull());
62 return object.Read();
63 }
64
65 template <typename T>
Initialize(std::atomic<NativeDexCachePair<T>> * dex_cache,PointerSize pointer_size)66 inline void NativeDexCachePair<T>::Initialize(std::atomic<NativeDexCachePair<T>>* dex_cache,
67 PointerSize pointer_size) {
68 NativeDexCachePair<T> first_elem;
69 first_elem.object = nullptr;
70 first_elem.index = InvalidIndexForSlot(0);
71 DexCache::SetNativePairPtrSize(dex_cache, 0, first_elem, pointer_size);
72 }
73
ClassSize(PointerSize pointer_size)74 inline uint32_t DexCache::ClassSize(PointerSize pointer_size) {
75 const uint32_t vtable_entries = Object::kVTableLength;
76 return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0, pointer_size);
77 }
78
StringSlotIndex(dex::StringIndex string_idx)79 inline uint32_t DexCache::StringSlotIndex(dex::StringIndex string_idx) {
80 DCHECK_LT(string_idx.index_, GetDexFile()->NumStringIds());
81 const uint32_t slot_idx = string_idx.index_ % kDexCacheStringCacheSize;
82 DCHECK_LT(slot_idx, NumStrings());
83 return slot_idx;
84 }
85
GetResolvedString(dex::StringIndex string_idx)86 inline String* DexCache::GetResolvedString(dex::StringIndex string_idx) {
87 const uint32_t num_preresolved_strings = NumPreResolvedStrings();
88 if (num_preresolved_strings != 0u) {
89 GcRoot<mirror::String>* preresolved_strings = GetPreResolvedStrings();
90 // num_preresolved_strings can become 0 and preresolved_strings can become null in any order
91 // when ClearPreResolvedStrings is called.
92 if (preresolved_strings != nullptr) {
93 DCHECK_LT(string_idx.index_, num_preresolved_strings);
94 DCHECK_EQ(num_preresolved_strings, GetDexFile()->NumStringIds());
95 mirror::String* string = preresolved_strings[string_idx.index_].Read();
96 if (LIKELY(string != nullptr)) {
97 return string;
98 }
99 }
100 }
101 return GetStrings()[StringSlotIndex(string_idx)].load(
102 std::memory_order_relaxed).GetObjectForIndex(string_idx.index_);
103 }
104
SetResolvedString(dex::StringIndex string_idx,ObjPtr<String> resolved)105 inline void DexCache::SetResolvedString(dex::StringIndex string_idx, ObjPtr<String> resolved) {
106 DCHECK(resolved != nullptr);
107 GetStrings()[StringSlotIndex(string_idx)].store(
108 StringDexCachePair(resolved, string_idx.index_), std::memory_order_relaxed);
109 Runtime* const runtime = Runtime::Current();
110 if (UNLIKELY(runtime->IsActiveTransaction())) {
111 DCHECK(runtime->IsAotCompiler());
112 runtime->RecordResolveString(this, string_idx);
113 }
114 // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
115 WriteBarrier::ForEveryFieldWrite(this);
116 }
117
SetPreResolvedString(dex::StringIndex string_idx,ObjPtr<String> resolved)118 inline void DexCache::SetPreResolvedString(dex::StringIndex string_idx, ObjPtr<String> resolved) {
119 DCHECK(resolved != nullptr);
120 DCHECK_LT(string_idx.index_, GetDexFile()->NumStringIds());
121 GetPreResolvedStrings()[string_idx.index_] = GcRoot<mirror::String>(resolved);
122 Runtime* const runtime = Runtime::Current();
123 CHECK(runtime->IsAotCompiler());
124 CHECK(!runtime->IsActiveTransaction());
125 // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
126 WriteBarrier::ForEveryFieldWrite(this);
127 }
128
ClearPreResolvedStrings()129 inline void DexCache::ClearPreResolvedStrings() {
130 SetFieldPtr64</*kTransactionActive=*/false,
131 /*kCheckTransaction=*/false,
132 kVerifyNone,
133 GcRoot<mirror::String>*>(PreResolvedStringsOffset(), nullptr);
134 SetField32</*kTransactionActive=*/false,
135 /*bool kCheckTransaction=*/false,
136 kVerifyNone,
137 /*kIsVolatile=*/false>(NumPreResolvedStringsOffset(), 0);
138 }
139
ClearString(dex::StringIndex string_idx)140 inline void DexCache::ClearString(dex::StringIndex string_idx) {
141 DCHECK(Runtime::Current()->IsAotCompiler());
142 uint32_t slot_idx = StringSlotIndex(string_idx);
143 StringDexCacheType* slot = &GetStrings()[slot_idx];
144 // This is racy but should only be called from the transactional interpreter.
145 if (slot->load(std::memory_order_relaxed).index == string_idx.index_) {
146 StringDexCachePair cleared(nullptr, StringDexCachePair::InvalidIndexForSlot(slot_idx));
147 slot->store(cleared, std::memory_order_relaxed);
148 }
149 }
150
TypeSlotIndex(dex::TypeIndex type_idx)151 inline uint32_t DexCache::TypeSlotIndex(dex::TypeIndex type_idx) {
152 DCHECK_LT(type_idx.index_, GetDexFile()->NumTypeIds());
153 const uint32_t slot_idx = type_idx.index_ % kDexCacheTypeCacheSize;
154 DCHECK_LT(slot_idx, NumResolvedTypes());
155 return slot_idx;
156 }
157
GetResolvedType(dex::TypeIndex type_idx)158 inline Class* DexCache::GetResolvedType(dex::TypeIndex type_idx) {
159 // It is theorized that a load acquire is not required since obtaining the resolved class will
160 // always have an address dependency or a lock.
161 return GetResolvedTypes()[TypeSlotIndex(type_idx)].load(
162 std::memory_order_relaxed).GetObjectForIndex(type_idx.index_);
163 }
164
SetResolvedType(dex::TypeIndex type_idx,ObjPtr<Class> resolved)165 inline void DexCache::SetResolvedType(dex::TypeIndex type_idx, ObjPtr<Class> resolved) {
166 DCHECK(resolved != nullptr);
167 DCHECK(resolved->IsResolved()) << resolved->GetStatus();
168 // TODO default transaction support.
169 // Use a release store for SetResolvedType. This is done to prevent other threads from seeing a
170 // class but not necessarily seeing the loaded members like the static fields array.
171 // See b/32075261.
172 GetResolvedTypes()[TypeSlotIndex(type_idx)].store(
173 TypeDexCachePair(resolved, type_idx.index_), std::memory_order_release);
174 // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
175 WriteBarrier::ForEveryFieldWrite(this);
176 }
177
ClearResolvedType(dex::TypeIndex type_idx)178 inline void DexCache::ClearResolvedType(dex::TypeIndex type_idx) {
179 DCHECK(Runtime::Current()->IsAotCompiler());
180 uint32_t slot_idx = TypeSlotIndex(type_idx);
181 TypeDexCacheType* slot = &GetResolvedTypes()[slot_idx];
182 // This is racy but should only be called from the single-threaded ImageWriter and tests.
183 if (slot->load(std::memory_order_relaxed).index == type_idx.index_) {
184 TypeDexCachePair cleared(nullptr, TypeDexCachePair::InvalidIndexForSlot(slot_idx));
185 slot->store(cleared, std::memory_order_relaxed);
186 }
187 }
188
MethodTypeSlotIndex(dex::ProtoIndex proto_idx)189 inline uint32_t DexCache::MethodTypeSlotIndex(dex::ProtoIndex proto_idx) {
190 DCHECK(Runtime::Current()->IsMethodHandlesEnabled());
191 DCHECK_LT(proto_idx.index_, GetDexFile()->NumProtoIds());
192 const uint32_t slot_idx = proto_idx.index_ % kDexCacheMethodTypeCacheSize;
193 DCHECK_LT(slot_idx, NumResolvedMethodTypes());
194 return slot_idx;
195 }
196
GetResolvedMethodType(dex::ProtoIndex proto_idx)197 inline MethodType* DexCache::GetResolvedMethodType(dex::ProtoIndex proto_idx) {
198 return GetResolvedMethodTypes()[MethodTypeSlotIndex(proto_idx)].load(
199 std::memory_order_relaxed).GetObjectForIndex(proto_idx.index_);
200 }
201
SetResolvedMethodType(dex::ProtoIndex proto_idx,MethodType * resolved)202 inline void DexCache::SetResolvedMethodType(dex::ProtoIndex proto_idx, MethodType* resolved) {
203 DCHECK(resolved != nullptr);
204 GetResolvedMethodTypes()[MethodTypeSlotIndex(proto_idx)].store(
205 MethodTypeDexCachePair(resolved, proto_idx.index_), std::memory_order_relaxed);
206 // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
207 WriteBarrier::ForEveryFieldWrite(this);
208 }
209
GetResolvedCallSite(uint32_t call_site_idx)210 inline CallSite* DexCache::GetResolvedCallSite(uint32_t call_site_idx) {
211 DCHECK(Runtime::Current()->IsMethodHandlesEnabled());
212 DCHECK_LT(call_site_idx, GetDexFile()->NumCallSiteIds());
213 GcRoot<mirror::CallSite>& target = GetResolvedCallSites()[call_site_idx];
214 Atomic<GcRoot<mirror::CallSite>>& ref =
215 reinterpret_cast<Atomic<GcRoot<mirror::CallSite>>&>(target);
216 return ref.load(std::memory_order_seq_cst).Read();
217 }
218
SetResolvedCallSite(uint32_t call_site_idx,ObjPtr<CallSite> call_site)219 inline ObjPtr<CallSite> DexCache::SetResolvedCallSite(uint32_t call_site_idx,
220 ObjPtr<CallSite> call_site) {
221 DCHECK(Runtime::Current()->IsMethodHandlesEnabled());
222 DCHECK_LT(call_site_idx, GetDexFile()->NumCallSiteIds());
223
224 GcRoot<mirror::CallSite> null_call_site(nullptr);
225 GcRoot<mirror::CallSite> candidate(call_site);
226 GcRoot<mirror::CallSite>& target = GetResolvedCallSites()[call_site_idx];
227
228 // The first assignment for a given call site wins.
229 Atomic<GcRoot<mirror::CallSite>>& ref =
230 reinterpret_cast<Atomic<GcRoot<mirror::CallSite>>&>(target);
231 if (ref.CompareAndSetStrongSequentiallyConsistent(null_call_site, candidate)) {
232 // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
233 WriteBarrier::ForEveryFieldWrite(this);
234 return call_site;
235 } else {
236 return target.Read();
237 }
238 }
239
FieldSlotIndex(uint32_t field_idx)240 inline uint32_t DexCache::FieldSlotIndex(uint32_t field_idx) {
241 DCHECK_LT(field_idx, GetDexFile()->NumFieldIds());
242 const uint32_t slot_idx = field_idx % kDexCacheFieldCacheSize;
243 DCHECK_LT(slot_idx, NumResolvedFields());
244 return slot_idx;
245 }
246
GetResolvedField(uint32_t field_idx,PointerSize ptr_size)247 inline ArtField* DexCache::GetResolvedField(uint32_t field_idx, PointerSize ptr_size) {
248 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
249 auto pair = GetNativePairPtrSize(GetResolvedFields(), FieldSlotIndex(field_idx), ptr_size);
250 return pair.GetObjectForIndex(field_idx);
251 }
252
SetResolvedField(uint32_t field_idx,ArtField * field,PointerSize ptr_size)253 inline void DexCache::SetResolvedField(uint32_t field_idx, ArtField* field, PointerSize ptr_size) {
254 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
255 DCHECK(field != nullptr);
256 FieldDexCachePair pair(field, field_idx);
257 SetNativePairPtrSize(GetResolvedFields(), FieldSlotIndex(field_idx), pair, ptr_size);
258 }
259
ClearResolvedField(uint32_t field_idx,PointerSize ptr_size)260 inline void DexCache::ClearResolvedField(uint32_t field_idx, PointerSize ptr_size) {
261 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
262 uint32_t slot_idx = FieldSlotIndex(field_idx);
263 auto* resolved_fields = GetResolvedFields();
264 // This is racy but should only be called from the single-threaded ImageWriter.
265 DCHECK(Runtime::Current()->IsAotCompiler());
266 if (GetNativePairPtrSize(resolved_fields, slot_idx, ptr_size).index == field_idx) {
267 FieldDexCachePair cleared(nullptr, FieldDexCachePair::InvalidIndexForSlot(slot_idx));
268 SetNativePairPtrSize(resolved_fields, slot_idx, cleared, ptr_size);
269 }
270 }
271
MethodSlotIndex(uint32_t method_idx)272 inline uint32_t DexCache::MethodSlotIndex(uint32_t method_idx) {
273 DCHECK_LT(method_idx, GetDexFile()->NumMethodIds());
274 const uint32_t slot_idx = method_idx % kDexCacheMethodCacheSize;
275 DCHECK_LT(slot_idx, NumResolvedMethods());
276 return slot_idx;
277 }
278
GetResolvedMethod(uint32_t method_idx,PointerSize ptr_size)279 inline ArtMethod* DexCache::GetResolvedMethod(uint32_t method_idx, PointerSize ptr_size) {
280 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
281 auto pair = GetNativePairPtrSize(GetResolvedMethods(), MethodSlotIndex(method_idx), ptr_size);
282 return pair.GetObjectForIndex(method_idx);
283 }
284
SetResolvedMethod(uint32_t method_idx,ArtMethod * method,PointerSize ptr_size)285 inline void DexCache::SetResolvedMethod(uint32_t method_idx,
286 ArtMethod* method,
287 PointerSize ptr_size) {
288 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
289 DCHECK(method != nullptr);
290 MethodDexCachePair pair(method, method_idx);
291 SetNativePairPtrSize(GetResolvedMethods(), MethodSlotIndex(method_idx), pair, ptr_size);
292 }
293
ClearResolvedMethod(uint32_t method_idx,PointerSize ptr_size)294 inline void DexCache::ClearResolvedMethod(uint32_t method_idx, PointerSize ptr_size) {
295 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
296 uint32_t slot_idx = MethodSlotIndex(method_idx);
297 auto* resolved_methods = GetResolvedMethods();
298 // This is racy but should only be called from the single-threaded ImageWriter.
299 DCHECK(Runtime::Current()->IsAotCompiler());
300 if (GetNativePairPtrSize(resolved_methods, slot_idx, ptr_size).index == method_idx) {
301 MethodDexCachePair cleared(nullptr, MethodDexCachePair::InvalidIndexForSlot(slot_idx));
302 SetNativePairPtrSize(resolved_methods, slot_idx, cleared, ptr_size);
303 }
304 }
305
306 template <typename T>
GetNativePairPtrSize(std::atomic<NativeDexCachePair<T>> * pair_array,size_t idx,PointerSize ptr_size)307 NativeDexCachePair<T> DexCache::GetNativePairPtrSize(std::atomic<NativeDexCachePair<T>>* pair_array,
308 size_t idx,
309 PointerSize ptr_size) {
310 if (ptr_size == PointerSize::k64) {
311 auto* array = reinterpret_cast<std::atomic<ConversionPair64>*>(pair_array);
312 ConversionPair64 value = AtomicLoadRelaxed16B(&array[idx]);
313 return NativeDexCachePair<T>(reinterpret_cast64<T*>(value.first),
314 dchecked_integral_cast<size_t>(value.second));
315 } else {
316 auto* array = reinterpret_cast<std::atomic<ConversionPair32>*>(pair_array);
317 ConversionPair32 value = array[idx].load(std::memory_order_relaxed);
318 return NativeDexCachePair<T>(reinterpret_cast32<T*>(value.first), value.second);
319 }
320 }
321
322 template <typename T>
SetNativePairPtrSize(std::atomic<NativeDexCachePair<T>> * pair_array,size_t idx,NativeDexCachePair<T> pair,PointerSize ptr_size)323 void DexCache::SetNativePairPtrSize(std::atomic<NativeDexCachePair<T>>* pair_array,
324 size_t idx,
325 NativeDexCachePair<T> pair,
326 PointerSize ptr_size) {
327 if (ptr_size == PointerSize::k64) {
328 auto* array = reinterpret_cast<std::atomic<ConversionPair64>*>(pair_array);
329 ConversionPair64 v(reinterpret_cast64<uint64_t>(pair.object), pair.index);
330 AtomicStoreRelease16B(&array[idx], v);
331 } else {
332 auto* array = reinterpret_cast<std::atomic<ConversionPair32>*>(pair_array);
333 ConversionPair32 v(reinterpret_cast32<uint32_t>(pair.object),
334 dchecked_integral_cast<uint32_t>(pair.index));
335 array[idx].store(v, std::memory_order_release);
336 }
337 }
338
339 template <typename T,
340 ReadBarrierOption kReadBarrierOption,
341 typename Visitor>
VisitDexCachePairs(std::atomic<DexCachePair<T>> * pairs,size_t num_pairs,const Visitor & visitor)342 inline void VisitDexCachePairs(std::atomic<DexCachePair<T>>* pairs,
343 size_t num_pairs,
344 const Visitor& visitor)
345 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_) {
346 for (size_t i = 0; i < num_pairs; ++i) {
347 DexCachePair<T> source = pairs[i].load(std::memory_order_relaxed);
348 // NOTE: We need the "template" keyword here to avoid a compilation
349 // failure. GcRoot<T> is a template argument-dependent type and we need to
350 // tell the compiler to treat "Read" as a template rather than a field or
351 // function. Otherwise, on encountering the "<" token, the compiler would
352 // treat "Read" as a field.
353 T* const before = source.object.template Read<kReadBarrierOption>();
354 visitor.VisitRootIfNonNull(source.object.AddressWithoutBarrier());
355 if (source.object.template Read<kReadBarrierOption>() != before) {
356 pairs[i].store(source, std::memory_order_relaxed);
357 }
358 }
359 }
360
361 template <bool kVisitNativeRoots,
362 VerifyObjectFlags kVerifyFlags,
363 ReadBarrierOption kReadBarrierOption,
364 typename Visitor>
VisitReferences(ObjPtr<Class> klass,const Visitor & visitor)365 inline void DexCache::VisitReferences(ObjPtr<Class> klass, const Visitor& visitor) {
366 // Visit instance fields first.
367 VisitInstanceFieldsReferences<kVerifyFlags, kReadBarrierOption>(klass, visitor);
368 // Visit arrays after.
369 if (kVisitNativeRoots) {
370 VisitDexCachePairs<String, kReadBarrierOption, Visitor>(
371 GetStrings<kVerifyFlags>(), NumStrings<kVerifyFlags>(), visitor);
372
373 VisitDexCachePairs<Class, kReadBarrierOption, Visitor>(
374 GetResolvedTypes<kVerifyFlags>(), NumResolvedTypes<kVerifyFlags>(), visitor);
375
376 VisitDexCachePairs<MethodType, kReadBarrierOption, Visitor>(
377 GetResolvedMethodTypes<kVerifyFlags>(), NumResolvedMethodTypes<kVerifyFlags>(), visitor);
378
379 GcRoot<mirror::CallSite>* resolved_call_sites = GetResolvedCallSites<kVerifyFlags>();
380 size_t num_call_sites = NumResolvedCallSites<kVerifyFlags>();
381 for (size_t i = 0; i != num_call_sites; ++i) {
382 visitor.VisitRootIfNonNull(resolved_call_sites[i].AddressWithoutBarrier());
383 }
384
385 GcRoot<mirror::String>* const preresolved_strings = GetPreResolvedStrings();
386 if (preresolved_strings != nullptr) {
387 const size_t num_preresolved_strings = NumPreResolvedStrings();
388 for (size_t i = 0; i != num_preresolved_strings; ++i) {
389 visitor.VisitRootIfNonNull(preresolved_strings[i].AddressWithoutBarrier());
390 }
391 }
392 }
393 }
394
395 template <ReadBarrierOption kReadBarrierOption, typename Visitor>
FixupStrings(StringDexCacheType * dest,const Visitor & visitor)396 inline void DexCache::FixupStrings(StringDexCacheType* dest, const Visitor& visitor) {
397 StringDexCacheType* src = GetStrings();
398 for (size_t i = 0, count = NumStrings(); i < count; ++i) {
399 StringDexCachePair source = src[i].load(std::memory_order_relaxed);
400 String* ptr = source.object.Read<kReadBarrierOption>();
401 String* new_source = visitor(ptr);
402 source.object = GcRoot<String>(new_source);
403 dest[i].store(source, std::memory_order_relaxed);
404 }
405 }
406
407 template <ReadBarrierOption kReadBarrierOption, typename Visitor>
FixupResolvedTypes(TypeDexCacheType * dest,const Visitor & visitor)408 inline void DexCache::FixupResolvedTypes(TypeDexCacheType* dest, const Visitor& visitor) {
409 TypeDexCacheType* src = GetResolvedTypes();
410 for (size_t i = 0, count = NumResolvedTypes(); i < count; ++i) {
411 TypeDexCachePair source = src[i].load(std::memory_order_relaxed);
412 Class* ptr = source.object.Read<kReadBarrierOption>();
413 Class* new_source = visitor(ptr);
414 source.object = GcRoot<Class>(new_source);
415 dest[i].store(source, std::memory_order_relaxed);
416 }
417 }
418
419 template <ReadBarrierOption kReadBarrierOption, typename Visitor>
FixupResolvedMethodTypes(MethodTypeDexCacheType * dest,const Visitor & visitor)420 inline void DexCache::FixupResolvedMethodTypes(MethodTypeDexCacheType* dest,
421 const Visitor& visitor) {
422 MethodTypeDexCacheType* src = GetResolvedMethodTypes();
423 for (size_t i = 0, count = NumResolvedMethodTypes(); i < count; ++i) {
424 MethodTypeDexCachePair source = src[i].load(std::memory_order_relaxed);
425 MethodType* ptr = source.object.Read<kReadBarrierOption>();
426 MethodType* new_source = visitor(ptr);
427 source.object = GcRoot<MethodType>(new_source);
428 dest[i].store(source, std::memory_order_relaxed);
429 }
430 }
431
432 template <ReadBarrierOption kReadBarrierOption, typename Visitor>
FixupResolvedCallSites(GcRoot<mirror::CallSite> * dest,const Visitor & visitor)433 inline void DexCache::FixupResolvedCallSites(GcRoot<mirror::CallSite>* dest,
434 const Visitor& visitor) {
435 GcRoot<mirror::CallSite>* src = GetResolvedCallSites();
436 for (size_t i = 0, count = NumResolvedCallSites(); i < count; ++i) {
437 mirror::CallSite* source = src[i].Read<kReadBarrierOption>();
438 mirror::CallSite* new_source = visitor(source);
439 dest[i] = GcRoot<mirror::CallSite>(new_source);
440 }
441 }
442
GetLocation()443 inline ObjPtr<String> DexCache::GetLocation() {
444 return GetFieldObject<String>(OFFSET_OF_OBJECT_MEMBER(DexCache, location_));
445 }
446
447 } // namespace mirror
448 } // namespace art
449
450 #endif // ART_RUNTIME_MIRROR_DEX_CACHE_INL_H_
451