blob: 582ecb23e50364921225ed7c9fd33790427fbbd2 [file] [log] [blame]
Ian Rogers39ebcb82013-05-30 16:57:23 -07001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_MIRROR_DEX_CACHE_INL_H_
18#define ART_RUNTIME_MIRROR_DEX_CACHE_INL_H_
Ian Rogers39ebcb82013-05-30 16:57:23 -070019
20#include "dex_cache.h"
21
Mathieu Chartierc7853442015-03-27 14:35:38 -070022#include "art_field-inl.h"
Mathieu Chartiere401d142015-04-22 13:56:20 -070023#include "art_method-inl.h"
Vladimir Marko05792b92015-08-03 11:56:49 +010024#include "base/casts.h"
Andreas Gampe542451c2016-07-26 09:02:02 -070025#include "base/enums.h"
Andreas Gampeaa910d52014-07-30 18:59:05 -070026#include "base/logging.h"
Vladimir Marko1aea3512016-12-08 11:39:42 +000027#include "dex_file.h"
Narayan Kamathd08e39b2016-10-19 14:16:35 +010028#include "gc_root.h"
Andreas Gampeaa910d52014-07-30 18:59:05 -070029#include "mirror/class.h"
Orion Hodsonc069a302017-01-18 09:23:12 +000030#include "mirror/call_site.h"
Narayan Kamath25352fc2016-08-03 12:46:58 +010031#include "mirror/method_type.h"
Mathieu Chartierbc56fc32014-06-03 15:37:03 -070032#include "runtime.h"
Mathieu Chartier31e88222016-10-14 18:43:19 -070033#include "obj_ptr.h"
Mathieu Chartierbc56fc32014-06-03 15:37:03 -070034
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -070035#include <atomic>
36
Ian Rogers39ebcb82013-05-30 16:57:23 -070037namespace art {
38namespace mirror {
39
Vladimir Marko1aea3512016-12-08 11:39:42 +000040template <typename T>
41inline void NativeDexCachePair<T>::Initialize(std::atomic<NativeDexCachePair<T>>* dex_cache,
42 PointerSize pointer_size) {
43 NativeDexCachePair<T> first_elem;
44 first_elem.object = nullptr;
45 first_elem.index = InvalidIndexForSlot(0);
46 DexCache::SetNativePairPtrSize(dex_cache, 0, first_elem, pointer_size);
47}
48
Andreas Gampe542451c2016-07-26 09:02:02 -070049inline uint32_t DexCache::ClassSize(PointerSize pointer_size) {
Vladimir Markoc1363122015-04-09 14:13:13 +010050 uint32_t vtable_entries = Object::kVTableLength + 5;
Mathieu Chartiere401d142015-04-22 13:56:20 -070051 return Class::ComputeClassSize(true, vtable_entries, 0, 0, 0, 0, 0, pointer_size);
Ian Rogers39ebcb82013-05-30 16:57:23 -070052}
53
Vladimir Markobfb80d22017-02-14 14:08:12 +000054inline uint32_t DexCache::StringSlotIndex(dex::StringIndex string_idx) {
Andreas Gampe8a0128a2016-11-28 07:38:35 -080055 DCHECK_LT(string_idx.index_, GetDexFile()->NumStringIds());
Vladimir Markobfb80d22017-02-14 14:08:12 +000056 const uint32_t slot_idx = string_idx.index_ % kDexCacheStringCacheSize;
57 DCHECK_LT(slot_idx, NumStrings());
58 return slot_idx;
Andreas Gampeaa910d52014-07-30 18:59:05 -070059}
60
Vladimir Markobfb80d22017-02-14 14:08:12 +000061inline String* DexCache::GetResolvedString(dex::StringIndex string_idx) {
62 return GetStrings()[StringSlotIndex(string_idx)].load(
63 std::memory_order_relaxed).GetObjectForIndex(string_idx.index_);
64}
65
66inline void DexCache::SetResolvedString(dex::StringIndex string_idx, ObjPtr<String> resolved) {
67 DCHECK(resolved != nullptr);
68 GetStrings()[StringSlotIndex(string_idx)].store(
69 StringDexCachePair(resolved, string_idx.index_), std::memory_order_relaxed);
Mathieu Chartierbb816d62016-09-07 10:17:46 -070070 Runtime* const runtime = Runtime::Current();
71 if (UNLIKELY(runtime->IsActiveTransaction())) {
72 DCHECK(runtime->IsAotCompiler());
73 runtime->RecordResolveString(this, string_idx);
74 }
Vladimir Marko05792b92015-08-03 11:56:49 +010075 // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
Mathieu Chartierbb816d62016-09-07 10:17:46 -070076 runtime->GetHeap()->WriteBarrierEveryFieldOf(this);
77}
78
Andreas Gampe8a0128a2016-11-28 07:38:35 -080079inline void DexCache::ClearString(dex::StringIndex string_idx) {
Mathieu Chartierbb816d62016-09-07 10:17:46 -070080 DCHECK(Runtime::Current()->IsAotCompiler());
Vladimir Markobfb80d22017-02-14 14:08:12 +000081 uint32_t slot_idx = StringSlotIndex(string_idx);
Mathieu Chartierbb816d62016-09-07 10:17:46 -070082 StringDexCacheType* slot = &GetStrings()[slot_idx];
83 // This is racy but should only be called from the transactional interpreter.
Andreas Gampe8a0128a2016-11-28 07:38:35 -080084 if (slot->load(std::memory_order_relaxed).index == string_idx.index_) {
Vladimir Markobfb80d22017-02-14 14:08:12 +000085 StringDexCachePair cleared(nullptr, StringDexCachePair::InvalidIndexForSlot(slot_idx));
Mathieu Chartierbb816d62016-09-07 10:17:46 -070086 slot->store(cleared, std::memory_order_relaxed);
87 }
Vladimir Marko05792b92015-08-03 11:56:49 +010088}
89
Vladimir Markobfb80d22017-02-14 14:08:12 +000090inline uint32_t DexCache::TypeSlotIndex(dex::TypeIndex type_idx) {
91 DCHECK_LT(type_idx.index_, GetDexFile()->NumTypeIds());
92 const uint32_t slot_idx = type_idx.index_ % kDexCacheTypeCacheSize;
93 DCHECK_LT(slot_idx, NumResolvedTypes());
94 return slot_idx;
95}
96
Andreas Gampea5b09a62016-11-17 15:21:22 -080097inline Class* DexCache::GetResolvedType(dex::TypeIndex type_idx) {
Mathieu Chartier5df32d32016-12-06 16:02:27 -080098 // It is theorized that a load acquire is not required since obtaining the resolved class will
Mathieu Chartierdb70ce52016-12-12 11:06:59 -080099 // always have an address dependency or a lock.
Vladimir Markobfb80d22017-02-14 14:08:12 +0000100 return GetResolvedTypes()[TypeSlotIndex(type_idx)].load(
101 std::memory_order_relaxed).GetObjectForIndex(type_idx.index_);
Vladimir Marko05792b92015-08-03 11:56:49 +0100102}
103
Andreas Gampea5b09a62016-11-17 15:21:22 -0800104inline void DexCache::SetResolvedType(dex::TypeIndex type_idx, ObjPtr<Class> resolved) {
Vladimir Markobfb80d22017-02-14 14:08:12 +0000105 DCHECK(resolved != nullptr);
Vladimir Marko05792b92015-08-03 11:56:49 +0100106 // TODO default transaction support.
Mathieu Chartier5df32d32016-12-06 16:02:27 -0800107 // Use a release store for SetResolvedType. This is done to prevent other threads from seeing a
108 // class but not necessarily seeing the loaded members like the static fields array.
109 // See b/32075261.
Vladimir Markobfb80d22017-02-14 14:08:12 +0000110 GetResolvedTypes()[TypeSlotIndex(type_idx)].store(
111 TypeDexCachePair(resolved, type_idx.index_), std::memory_order_release);
Vladimir Marko05792b92015-08-03 11:56:49 +0100112 // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
113 Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(this);
114}
115
Vladimir Markobfb80d22017-02-14 14:08:12 +0000116inline void DexCache::ClearResolvedType(dex::TypeIndex type_idx) {
117 DCHECK(Runtime::Current()->IsAotCompiler());
118 uint32_t slot_idx = TypeSlotIndex(type_idx);
119 TypeDexCacheType* slot = &GetResolvedTypes()[slot_idx];
120 // This is racy but should only be called from the single-threaded ImageWriter and tests.
121 if (slot->load(std::memory_order_relaxed).index == type_idx.index_) {
122 TypeDexCachePair cleared(nullptr, TypeDexCachePair::InvalidIndexForSlot(slot_idx));
123 slot->store(cleared, std::memory_order_relaxed);
124 }
125}
126
127inline uint32_t DexCache::MethodTypeSlotIndex(uint32_t proto_idx) {
Narayan Kamath25352fc2016-08-03 12:46:58 +0100128 DCHECK(Runtime::Current()->IsMethodHandlesEnabled());
129 DCHECK_LT(proto_idx, GetDexFile()->NumProtoIds());
Vladimir Markobfb80d22017-02-14 14:08:12 +0000130 const uint32_t slot_idx = proto_idx % kDexCacheMethodTypeCacheSize;
131 DCHECK_LT(slot_idx, NumResolvedMethodTypes());
132 return slot_idx;
133}
134
135inline MethodType* DexCache::GetResolvedMethodType(uint32_t proto_idx) {
136 return GetResolvedMethodTypes()[MethodTypeSlotIndex(proto_idx)].load(
137 std::memory_order_relaxed).GetObjectForIndex(proto_idx);
Narayan Kamath25352fc2016-08-03 12:46:58 +0100138}
139
140inline void DexCache::SetResolvedMethodType(uint32_t proto_idx, MethodType* resolved) {
Vladimir Markobfb80d22017-02-14 14:08:12 +0000141 DCHECK(resolved != nullptr);
142 GetResolvedMethodTypes()[MethodTypeSlotIndex(proto_idx)].store(
143 MethodTypeDexCachePair(resolved, proto_idx), std::memory_order_relaxed);
Narayan Kamath25352fc2016-08-03 12:46:58 +0100144 // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
145 Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(this);
146}
147
Orion Hodsonc069a302017-01-18 09:23:12 +0000148inline CallSite* DexCache::GetResolvedCallSite(uint32_t call_site_idx) {
149 DCHECK(Runtime::Current()->IsMethodHandlesEnabled());
150 DCHECK_LT(call_site_idx, GetDexFile()->NumCallSiteIds());
151 GcRoot<mirror::CallSite>& target = GetResolvedCallSites()[call_site_idx];
152 Atomic<GcRoot<mirror::CallSite>>& ref =
153 reinterpret_cast<Atomic<GcRoot<mirror::CallSite>>&>(target);
154 return ref.LoadSequentiallyConsistent().Read();
155}
156
157inline CallSite* DexCache::SetResolvedCallSite(uint32_t call_site_idx, CallSite* call_site) {
158 DCHECK(Runtime::Current()->IsMethodHandlesEnabled());
159 DCHECK_LT(call_site_idx, GetDexFile()->NumCallSiteIds());
160
161 GcRoot<mirror::CallSite> null_call_site(nullptr);
162 GcRoot<mirror::CallSite> candidate(call_site);
163 GcRoot<mirror::CallSite>& target = GetResolvedCallSites()[call_site_idx];
164
165 // The first assignment for a given call site wins.
166 Atomic<GcRoot<mirror::CallSite>>& ref =
167 reinterpret_cast<Atomic<GcRoot<mirror::CallSite>>&>(target);
168 if (ref.CompareExchangeStrongSequentiallyConsistent(null_call_site, candidate)) {
169 // TODO: Fine-grained marking, so that we don't need to go through all arrays in full.
170 Runtime::Current()->GetHeap()->WriteBarrierEveryFieldOf(this);
171 return call_site;
172 } else {
173 return target.Read();
174 }
175}
176
Vladimir Marko1aea3512016-12-08 11:39:42 +0000177inline uint32_t DexCache::FieldSlotIndex(uint32_t field_idx) {
178 DCHECK_LT(field_idx, GetDexFile()->NumFieldIds());
179 const uint32_t slot_idx = field_idx % kDexCacheFieldCacheSize;
180 DCHECK_LT(slot_idx, NumResolvedFields());
181 return slot_idx;
182}
183
Andreas Gampe542451c2016-07-26 09:02:02 -0700184inline ArtField* DexCache::GetResolvedField(uint32_t field_idx, PointerSize ptr_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700185 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
Vladimir Marko1aea3512016-12-08 11:39:42 +0000186 auto pair = GetNativePairPtrSize(GetResolvedFields(), FieldSlotIndex(field_idx), ptr_size);
187 return pair.GetObjectForIndex(field_idx);
Mathieu Chartierc7853442015-03-27 14:35:38 -0700188}
189
Andreas Gampe542451c2016-07-26 09:02:02 -0700190inline void DexCache::SetResolvedField(uint32_t field_idx, ArtField* field, PointerSize ptr_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700191 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
Vladimir Marko1aea3512016-12-08 11:39:42 +0000192 DCHECK(field != nullptr);
193 FieldDexCachePair pair(field, field_idx);
194 SetNativePairPtrSize(GetResolvedFields(), FieldSlotIndex(field_idx), pair, ptr_size);
195}
196
197inline void DexCache::ClearResolvedField(uint32_t field_idx, PointerSize ptr_size) {
198 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
199 uint32_t slot_idx = FieldSlotIndex(field_idx);
200 auto* resolved_fields = GetResolvedFields();
201 // This is racy but should only be called from the single-threaded ImageWriter.
202 DCHECK(Runtime::Current()->IsAotCompiler());
203 if (GetNativePairPtrSize(resolved_fields, slot_idx, ptr_size).index == field_idx) {
204 FieldDexCachePair cleared(nullptr, FieldDexCachePair::InvalidIndexForSlot(slot_idx));
205 SetNativePairPtrSize(resolved_fields, slot_idx, cleared, ptr_size);
206 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700207}
208
Andreas Gampe542451c2016-07-26 09:02:02 -0700209inline ArtMethod* DexCache::GetResolvedMethod(uint32_t method_idx, PointerSize ptr_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700210 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
Vladimir Marko05792b92015-08-03 11:56:49 +0100211 DCHECK_LT(method_idx, NumResolvedMethods()); // NOTE: Unchecked, i.e. not throwing AIOOB.
212 ArtMethod* method = GetElementPtrSize<ArtMethod*>(GetResolvedMethods(), method_idx, ptr_size);
Mathieu Chartiere401d142015-04-22 13:56:20 -0700213 // Hide resolution trampoline methods from the caller
214 if (method != nullptr && method->IsRuntimeMethod()) {
215 DCHECK_EQ(method, Runtime::Current()->GetResolutionMethod());
216 return nullptr;
Mathieu Chartierc7853442015-03-27 14:35:38 -0700217 }
Mathieu Chartiere401d142015-04-22 13:56:20 -0700218 return method;
219}
220
Andreas Gampe542451c2016-07-26 09:02:02 -0700221inline void DexCache::SetResolvedMethod(uint32_t method_idx,
222 ArtMethod* method,
223 PointerSize ptr_size) {
Mathieu Chartiere401d142015-04-22 13:56:20 -0700224 DCHECK_EQ(Runtime::Current()->GetClassLinker()->GetImagePointerSize(), ptr_size);
Vladimir Marko05792b92015-08-03 11:56:49 +0100225 DCHECK_LT(method_idx, NumResolvedMethods()); // NOTE: Unchecked, i.e. not throwing AIOOB.
226 SetElementPtrSize(GetResolvedMethods(), method_idx, method, ptr_size);
227}
228
229template <typename PtrType>
Andreas Gampe542451c2016-07-26 09:02:02 -0700230inline PtrType DexCache::GetElementPtrSize(PtrType* ptr_array, size_t idx, PointerSize ptr_size) {
231 if (ptr_size == PointerSize::k64) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100232 uint64_t element = reinterpret_cast<const uint64_t*>(ptr_array)[idx];
233 return reinterpret_cast<PtrType>(dchecked_integral_cast<uintptr_t>(element));
234 } else {
Vladimir Marko05792b92015-08-03 11:56:49 +0100235 uint32_t element = reinterpret_cast<const uint32_t*>(ptr_array)[idx];
236 return reinterpret_cast<PtrType>(dchecked_integral_cast<uintptr_t>(element));
237 }
238}
239
240template <typename PtrType>
241inline void DexCache::SetElementPtrSize(PtrType* ptr_array,
242 size_t idx,
243 PtrType ptr,
Andreas Gampe542451c2016-07-26 09:02:02 -0700244 PointerSize ptr_size) {
245 if (ptr_size == PointerSize::k64) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100246 reinterpret_cast<uint64_t*>(ptr_array)[idx] =
247 dchecked_integral_cast<uint64_t>(reinterpret_cast<uintptr_t>(ptr));
248 } else {
Vladimir Marko05792b92015-08-03 11:56:49 +0100249 reinterpret_cast<uint32_t*>(ptr_array)[idx] =
250 dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(ptr));
251 }
252}
253
Vladimir Marko1aea3512016-12-08 11:39:42 +0000254template <typename T>
255NativeDexCachePair<T> DexCache::GetNativePairPtrSize(std::atomic<NativeDexCachePair<T>>* pair_array,
256 size_t idx,
257 PointerSize ptr_size) {
258 if (ptr_size == PointerSize::k64) {
259 auto* array = reinterpret_cast<std::atomic<ConversionPair64>*>(pair_array);
260 ConversionPair64 value = AtomicLoadRelaxed16B(&array[idx]);
261 return NativeDexCachePair<T>(reinterpret_cast64<T*>(value.first),
262 dchecked_integral_cast<size_t>(value.second));
263 } else {
264 auto* array = reinterpret_cast<std::atomic<ConversionPair32>*>(pair_array);
265 ConversionPair32 value = array[idx].load(std::memory_order_relaxed);
266 return NativeDexCachePair<T>(reinterpret_cast<T*>(value.first), value.second);
267 }
268}
269
270template <typename T>
271void DexCache::SetNativePairPtrSize(std::atomic<NativeDexCachePair<T>>* pair_array,
272 size_t idx,
273 NativeDexCachePair<T> pair,
274 PointerSize ptr_size) {
275 if (ptr_size == PointerSize::k64) {
276 auto* array = reinterpret_cast<std::atomic<ConversionPair64>*>(pair_array);
277 ConversionPair64 v(reinterpret_cast64<uint64_t>(pair.object), pair.index);
278 AtomicStoreRelease16B(&array[idx], v);
279 } else {
280 auto* array = reinterpret_cast<std::atomic<ConversionPair32>*>(pair_array);
281 ConversionPair32 v(
282 dchecked_integral_cast<uint32_t>(reinterpret_cast<uintptr_t>(pair.object)),
283 dchecked_integral_cast<uint32_t>(pair.index));
284 array[idx].store(v, std::memory_order_release);
285 }
286}
287
Narayan Kamathd08e39b2016-10-19 14:16:35 +0100288template <typename T,
289 ReadBarrierOption kReadBarrierOption,
290 typename Visitor>
291inline void VisitDexCachePairs(std::atomic<DexCachePair<T>>* pairs,
292 size_t num_pairs,
293 const Visitor& visitor)
294 REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(Locks::heap_bitmap_lock_) {
295 for (size_t i = 0; i < num_pairs; ++i) {
296 DexCachePair<T> source = pairs[i].load(std::memory_order_relaxed);
297 // NOTE: We need the "template" keyword here to avoid a compilation
298 // failure. GcRoot<T> is a template argument-dependent type and we need to
299 // tell the compiler to treat "Read" as a template rather than a field or
300 // function. Otherwise, on encountering the "<" token, the compiler would
301 // treat "Read" as a field.
Mathieu Chartier6b4c2872016-11-01 14:45:26 -0700302 T* const before = source.object.template Read<kReadBarrierOption>();
303 visitor.VisitRootIfNonNull(source.object.AddressWithoutBarrier());
304 if (source.object.template Read<kReadBarrierOption>() != before) {
Narayan Kamathd08e39b2016-10-19 14:16:35 +0100305 pairs[i].store(source, std::memory_order_relaxed);
306 }
307 }
308}
309
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800310template <bool kVisitNativeRoots,
311 VerifyObjectFlags kVerifyFlags,
312 ReadBarrierOption kReadBarrierOption,
313 typename Visitor>
Mathieu Chartier31e88222016-10-14 18:43:19 -0700314inline void DexCache::VisitReferences(ObjPtr<Class> klass, const Visitor& visitor) {
Vladimir Marko05792b92015-08-03 11:56:49 +0100315 // Visit instance fields first.
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800316 VisitInstanceFieldsReferences<kVerifyFlags, kReadBarrierOption>(klass, visitor);
Vladimir Marko05792b92015-08-03 11:56:49 +0100317 // Visit arrays after.
Mathieu Chartierfbc31082016-01-24 11:59:56 -0800318 if (kVisitNativeRoots) {
Vladimir Markobfb80d22017-02-14 14:08:12 +0000319 VisitDexCachePairs<String, kReadBarrierOption, Visitor>(
Narayan Kamathd08e39b2016-10-19 14:16:35 +0100320 GetStrings(), NumStrings(), visitor);
321
Vladimir Markobfb80d22017-02-14 14:08:12 +0000322 VisitDexCachePairs<Class, kReadBarrierOption, Visitor>(
323 GetResolvedTypes(), NumResolvedTypes(), visitor);
Narayan Kamathd08e39b2016-10-19 14:16:35 +0100324
Vladimir Markobfb80d22017-02-14 14:08:12 +0000325 VisitDexCachePairs<MethodType, kReadBarrierOption, Visitor>(
Narayan Kamathd08e39b2016-10-19 14:16:35 +0100326 GetResolvedMethodTypes(), NumResolvedMethodTypes(), visitor);
Orion Hodsonc069a302017-01-18 09:23:12 +0000327
328 GcRoot<mirror::CallSite>* resolved_call_sites = GetResolvedCallSites();
329 for (size_t i = 0, num_call_sites = NumResolvedCallSites(); i != num_call_sites; ++i) {
330 visitor.VisitRootIfNonNull(resolved_call_sites[i].AddressWithoutBarrier());
331 }
Vladimir Marko05792b92015-08-03 11:56:49 +0100332 }
Mathieu Chartierc7853442015-03-27 14:35:38 -0700333}
334
Mathieu Chartier60bc39c2016-01-27 18:37:48 -0800335template <ReadBarrierOption kReadBarrierOption, typename Visitor>
Vladimir Markobfb80d22017-02-14 14:08:12 +0000336inline void DexCache::FixupStrings(StringDexCacheType* dest, const Visitor& visitor) {
337 StringDexCacheType* src = GetStrings();
Mathieu Chartier4b00d342015-11-13 10:42:08 -0800338 for (size_t i = 0, count = NumStrings(); i < count; ++i) {
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -0700339 StringDexCachePair source = src[i].load(std::memory_order_relaxed);
Vladimir Markobfb80d22017-02-14 14:08:12 +0000340 String* ptr = source.object.Read<kReadBarrierOption>();
341 String* new_source = visitor(ptr);
Narayan Kamathc38a6f82016-09-29 17:07:20 +0100342 source.object = GcRoot<String>(new_source);
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -0700343 dest[i].store(source, std::memory_order_relaxed);
Mathieu Chartier4b00d342015-11-13 10:42:08 -0800344 }
345}
346
Mathieu Chartier60bc39c2016-01-27 18:37:48 -0800347template <ReadBarrierOption kReadBarrierOption, typename Visitor>
Vladimir Markobfb80d22017-02-14 14:08:12 +0000348inline void DexCache::FixupResolvedTypes(TypeDexCacheType* dest, const Visitor& visitor) {
349 TypeDexCacheType* src = GetResolvedTypes();
Mathieu Chartier4b00d342015-11-13 10:42:08 -0800350 for (size_t i = 0, count = NumResolvedTypes(); i < count; ++i) {
Vladimir Markobfb80d22017-02-14 14:08:12 +0000351 TypeDexCachePair source = src[i].load(std::memory_order_relaxed);
352 Class* ptr = source.object.Read<kReadBarrierOption>();
353 Class* new_source = visitor(ptr);
354 source.object = GcRoot<Class>(new_source);
355 dest[i].store(source, std::memory_order_relaxed);
Mathieu Chartier4b00d342015-11-13 10:42:08 -0800356 }
357}
358
Narayan Kamath7fe56582016-10-14 18:49:12 +0100359template <ReadBarrierOption kReadBarrierOption, typename Visitor>
Vladimir Markobfb80d22017-02-14 14:08:12 +0000360inline void DexCache::FixupResolvedMethodTypes(MethodTypeDexCacheType* dest,
Narayan Kamath7fe56582016-10-14 18:49:12 +0100361 const Visitor& visitor) {
Vladimir Markobfb80d22017-02-14 14:08:12 +0000362 MethodTypeDexCacheType* src = GetResolvedMethodTypes();
Narayan Kamath7fe56582016-10-14 18:49:12 +0100363 for (size_t i = 0, count = NumResolvedMethodTypes(); i < count; ++i) {
364 MethodTypeDexCachePair source = src[i].load(std::memory_order_relaxed);
Vladimir Markobfb80d22017-02-14 14:08:12 +0000365 MethodType* ptr = source.object.Read<kReadBarrierOption>();
366 MethodType* new_source = visitor(ptr);
Narayan Kamath7fe56582016-10-14 18:49:12 +0100367 source.object = GcRoot<MethodType>(new_source);
368 dest[i].store(source, std::memory_order_relaxed);
369 }
370}
371
Orion Hodsonc069a302017-01-18 09:23:12 +0000372template <ReadBarrierOption kReadBarrierOption, typename Visitor>
373inline void DexCache::FixupResolvedCallSites(GcRoot<mirror::CallSite>* dest,
374 const Visitor& visitor) {
375 GcRoot<mirror::CallSite>* src = GetResolvedCallSites();
376 for (size_t i = 0, count = NumResolvedCallSites(); i < count; ++i) {
377 mirror::CallSite* source = src[i].Read<kReadBarrierOption>();
378 mirror::CallSite* new_source = visitor(source);
379 dest[i] = GcRoot<mirror::CallSite>(new_source);
380 }
381}
382
Ian Rogers39ebcb82013-05-30 16:57:23 -0700383} // namespace mirror
384} // namespace art
385
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700386#endif // ART_RUNTIME_MIRROR_DEX_CACHE_INL_H_