• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #ifndef ART_RUNTIME_CLASS_LINKER_INL_H_
18 #define ART_RUNTIME_CLASS_LINKER_INL_H_
19 
20 #include <atomic>
21 
22 #include "android-base/thread_annotations.h"
23 #include "art_field-inl.h"
24 #include "art_method-inl.h"
25 #include "base/mutex.h"
26 #include "class_linker.h"
27 #include "dex/dex_file.h"
28 #include "dex/dex_file_structs.h"
29 #include "gc_root-inl.h"
30 #include "handle_scope-inl.h"
31 #include "jni/jni_internal.h"
32 #include "mirror/class_loader.h"
33 #include "mirror/dex_cache-inl.h"
34 #include "mirror/iftable.h"
35 #include "mirror/object_array-inl.h"
36 #include "obj_ptr-inl.h"
37 #include "scoped_thread_state_change-inl.h"
38 #include "well_known_classes.h"
39 
40 namespace art {
41 
FindArrayClass(Thread * self,ObjPtr<mirror::Class> element_class)42 inline ObjPtr<mirror::Class> ClassLinker::FindArrayClass(Thread* self,
43                                                          ObjPtr<mirror::Class> element_class) {
44   for (size_t i = 0; i < kFindArrayCacheSize; ++i) {
45     // Read the cached array class once to avoid races with other threads setting it.
46     ObjPtr<mirror::Class> array_class = find_array_class_cache_[i].Read();
47     if (array_class != nullptr && array_class->GetComponentType() == element_class) {
48       return array_class;
49     }
50   }
51   std::string descriptor = "[";
52   std::string temp;
53   descriptor += element_class->GetDescriptor(&temp);
54   StackHandleScope<1> hs(Thread::Current());
55   Handle<mirror::ClassLoader> class_loader(hs.NewHandle(element_class->GetClassLoader()));
56   ObjPtr<mirror::Class> array_class = FindClass(self, descriptor.c_str(), class_loader);
57   if (array_class != nullptr) {
58     // Benign races in storing array class and incrementing index.
59     size_t victim_index = find_array_class_cache_next_victim_;
60     find_array_class_cache_[victim_index] = GcRoot<mirror::Class>(array_class);
61     find_array_class_cache_next_victim_ = (victim_index + 1) % kFindArrayCacheSize;
62   } else {
63     // We should have a NoClassDefFoundError.
64     self->AssertPendingException();
65   }
66   return array_class;
67 }
68 
ResolveString(dex::StringIndex string_idx,ArtField * referrer)69 inline ObjPtr<mirror::String> ClassLinker::ResolveString(dex::StringIndex string_idx,
70                                                          ArtField* referrer) {
71   Thread::PoisonObjectPointersIfDebug();
72   DCHECK(!Thread::Current()->IsExceptionPending());
73   // We do not need the read barrier for getting the DexCache for the initial resolved type
74   // lookup as both from-space and to-space copies point to the same native resolved types array.
75   ObjPtr<mirror::String> resolved =
76       referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedString(string_idx);
77   if (resolved == nullptr) {
78     resolved = DoResolveString(string_idx, referrer->GetDexCache());
79   }
80   return resolved;
81 }
82 
ResolveString(dex::StringIndex string_idx,ArtMethod * referrer)83 inline ObjPtr<mirror::String> ClassLinker::ResolveString(dex::StringIndex string_idx,
84                                                          ArtMethod* referrer) {
85   Thread::PoisonObjectPointersIfDebug();
86   DCHECK(!Thread::Current()->IsExceptionPending());
87   // We do not need the read barrier for getting the DexCache for the initial resolved type
88   // lookup as both from-space and to-space copies point to the same native resolved types array.
89   ObjPtr<mirror::String> resolved =
90       referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedString(string_idx);
91   if (resolved == nullptr) {
92     resolved = DoResolveString(string_idx, referrer->GetDexCache());
93   }
94   return resolved;
95 }
96 
ResolveString(dex::StringIndex string_idx,Handle<mirror::DexCache> dex_cache)97 inline ObjPtr<mirror::String> ClassLinker::ResolveString(dex::StringIndex string_idx,
98                                                          Handle<mirror::DexCache> dex_cache) {
99   Thread::PoisonObjectPointersIfDebug();
100   DCHECK(!Thread::Current()->IsExceptionPending());
101   ObjPtr<mirror::String> resolved = dex_cache->GetResolvedString(string_idx);
102   if (resolved == nullptr) {
103     resolved = DoResolveString(string_idx, dex_cache);
104   }
105   return resolved;
106 }
107 
LookupString(dex::StringIndex string_idx,ObjPtr<mirror::DexCache> dex_cache)108 inline ObjPtr<mirror::String> ClassLinker::LookupString(dex::StringIndex string_idx,
109                                                         ObjPtr<mirror::DexCache> dex_cache) {
110   ObjPtr<mirror::String> resolved = dex_cache->GetResolvedString(string_idx);
111   if (resolved == nullptr) {
112     resolved = DoLookupString(string_idx, dex_cache);
113   }
114   return resolved;
115 }
116 
ResolveType(dex::TypeIndex type_idx,ObjPtr<mirror::Class> referrer)117 inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
118                                                       ObjPtr<mirror::Class> referrer) {
119   if (kObjPtrPoisoning) {
120     StackHandleScope<1> hs(Thread::Current());
121     HandleWrapperObjPtr<mirror::Class> referrer_wrapper = hs.NewHandleWrapper(&referrer);
122     Thread::Current()->PoisonObjectPointers();
123   }
124   DCHECK(!Thread::Current()->IsExceptionPending());
125   // We do not need the read barrier for getting the DexCache for the initial resolved type
126   // lookup as both from-space and to-space copies point to the same native resolved types array.
127   ObjPtr<mirror::Class> resolved_type =
128       referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx);
129   if (resolved_type == nullptr) {
130     resolved_type = DoResolveType(type_idx, referrer);
131   }
132   return resolved_type;
133 }
134 
ResolveType(dex::TypeIndex type_idx,ArtField * referrer)135 inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
136                                                       ArtField* referrer) {
137   Thread::PoisonObjectPointersIfDebug();
138   DCHECK(!Thread::Current()->IsExceptionPending());
139   // We do not need the read barrier for getting the DexCache for the initial resolved type
140   // lookup as both from-space and to-space copies point to the same native resolved types array.
141   ObjPtr<mirror::Class> resolved_type =
142       referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
143   if (UNLIKELY(resolved_type == nullptr)) {
144     resolved_type = DoResolveType(type_idx, referrer);
145   }
146   return resolved_type;
147 }
148 
ResolveType(dex::TypeIndex type_idx,ArtMethod * referrer)149 inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
150                                                       ArtMethod* referrer) {
151   Thread::PoisonObjectPointersIfDebug();
152   DCHECK(!Thread::Current()->IsExceptionPending());
153   // We do not need the read barrier for getting the DexCache for the initial resolved type
154   // lookup as both from-space and to-space copies point to the same native resolved types array.
155   ObjPtr<mirror::Class> resolved_type =
156       referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
157   if (UNLIKELY(resolved_type == nullptr)) {
158     resolved_type = DoResolveType(type_idx, referrer);
159   }
160   return resolved_type;
161 }
162 
ResolveType(dex::TypeIndex type_idx,Handle<mirror::DexCache> dex_cache,Handle<mirror::ClassLoader> class_loader)163 inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
164                                                       Handle<mirror::DexCache> dex_cache,
165                                                       Handle<mirror::ClassLoader> class_loader) {
166   DCHECK(dex_cache != nullptr);
167   Thread::PoisonObjectPointersIfDebug();
168   ObjPtr<mirror::Class> resolved = dex_cache->GetResolvedType(type_idx);
169   if (resolved == nullptr) {
170     resolved = DoResolveType(type_idx, dex_cache, class_loader);
171   }
172   return resolved;
173 }
174 
LookupResolvedType(dex::TypeIndex type_idx,ObjPtr<mirror::Class> referrer)175 inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
176                                                              ObjPtr<mirror::Class> referrer) {
177   // We do not need the read barrier for getting the DexCache for the initial resolved type
178   // lookup as both from-space and to-space copies point to the same native resolved types array.
179   ObjPtr<mirror::Class> type =
180       referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx);
181   if (type == nullptr) {
182     type = DoLookupResolvedType(type_idx, referrer);
183   }
184   return type;
185 }
186 
LookupResolvedType(dex::TypeIndex type_idx,ArtField * referrer)187 inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
188                                                              ArtField* referrer) {
189   // We do not need the read barrier for getting the DexCache for the initial resolved type
190   // lookup as both from-space and to-space copies point to the same native resolved types array.
191   ObjPtr<mirror::Class> type =
192       referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
193   if (type == nullptr) {
194     type = DoLookupResolvedType(type_idx, referrer->GetDeclaringClass());
195   }
196   return type;
197 }
198 
LookupResolvedType(dex::TypeIndex type_idx,ArtMethod * referrer)199 inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
200                                                              ArtMethod* referrer) {
201   // We do not need the read barrier for getting the DexCache for the initial resolved type
202   // lookup as both from-space and to-space copies point to the same native resolved types array.
203   ObjPtr<mirror::Class> type =
204       referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
205   if (type == nullptr) {
206     type = DoLookupResolvedType(type_idx, referrer->GetDeclaringClass());
207   }
208   return type;
209 }
210 
LookupResolvedType(dex::TypeIndex type_idx,ObjPtr<mirror::DexCache> dex_cache,ObjPtr<mirror::ClassLoader> class_loader)211 inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(
212     dex::TypeIndex type_idx,
213     ObjPtr<mirror::DexCache> dex_cache,
214     ObjPtr<mirror::ClassLoader> class_loader) {
215   ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx);
216   if (type == nullptr) {
217     type = DoLookupResolvedType(type_idx, dex_cache, class_loader);
218   }
219   return type;
220 }
221 
222 template <bool kThrowOnError, typename ClassGetter>
CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache,InvokeType type,ClassGetter class_getter)223 inline bool ClassLinker::CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache,
224                                                   InvokeType type,
225                                                   ClassGetter class_getter) {
226   switch (type) {
227     case kStatic:
228     case kSuper:
229       break;
230     case kInterface: {
231       // We have to check whether the method id really belongs to an interface (dex static bytecode
232       // constraints A15, A16). Otherwise you must not invoke-interface on it.
233       ObjPtr<mirror::Class> klass = class_getter();
234       if (UNLIKELY(!klass->IsInterface())) {
235         if (kThrowOnError) {
236           ThrowIncompatibleClassChangeError(klass,
237                                             "Found class %s, but interface was expected",
238                                             klass->PrettyDescriptor().c_str());
239         }
240         return true;
241       }
242       break;
243     }
244     case kDirect:
245       if (dex_cache->GetDexFile()->SupportsDefaultMethods()) {
246         break;
247       }
248       FALLTHROUGH_INTENDED;
249     case kVirtual: {
250       // Similarly, invoke-virtual (and invoke-direct without default methods) must reference
251       // a non-interface class (dex static bytecode constraint A24, A25).
252       ObjPtr<mirror::Class> klass = class_getter();
253       if (UNLIKELY(klass->IsInterface())) {
254         if (kThrowOnError) {
255           ThrowIncompatibleClassChangeError(klass,
256                                             "Found interface %s, but class was expected",
257                                             klass->PrettyDescriptor().c_str());
258         }
259         return true;
260       }
261       break;
262     }
263     default:
264       LOG(FATAL) << "Unreachable - invocation type: " << type;
265       UNREACHABLE();
266   }
267   return false;
268 }
269 
270 template <bool kThrow>
CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache,InvokeType type,uint32_t method_idx,ObjPtr<mirror::ClassLoader> class_loader)271 inline bool ClassLinker::CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache,
272                                                   InvokeType type,
273                                                   uint32_t method_idx,
274                                                   ObjPtr<mirror::ClassLoader> class_loader) {
275   return CheckInvokeClassMismatch<kThrow>(
276       dex_cache,
277       type,
278       [this, dex_cache, method_idx, class_loader]() REQUIRES_SHARED(Locks::mutator_lock_) {
279         const dex::MethodId& method_id = dex_cache->GetDexFile()->GetMethodId(method_idx);
280         ObjPtr<mirror::Class> klass =
281             LookupResolvedType(method_id.class_idx_, dex_cache, class_loader);
282         DCHECK(klass != nullptr);
283         return klass;
284       });
285 }
286 
LookupResolvedMethod(uint32_t method_idx,ObjPtr<mirror::DexCache> dex_cache,ObjPtr<mirror::ClassLoader> class_loader)287 inline ArtMethod* ClassLinker::LookupResolvedMethod(uint32_t method_idx,
288                                                     ObjPtr<mirror::DexCache> dex_cache,
289                                                     ObjPtr<mirror::ClassLoader> class_loader) {
290   PointerSize pointer_size = image_pointer_size_;
291   ArtMethod* resolved = dex_cache->GetResolvedMethod(method_idx, pointer_size);
292   if (resolved == nullptr) {
293     const DexFile& dex_file = *dex_cache->GetDexFile();
294     const dex::MethodId& method_id = dex_file.GetMethodId(method_idx);
295     ObjPtr<mirror::Class> klass = LookupResolvedType(method_id.class_idx_, dex_cache, class_loader);
296     if (klass != nullptr) {
297       resolved = FindResolvedMethod(klass, dex_cache, class_loader, method_idx);
298     }
299   }
300   return resolved;
301 }
302 
303 template <InvokeType type, ClassLinker::ResolveMode kResolveMode>
GetResolvedMethod(uint32_t method_idx,ArtMethod * referrer)304 inline ArtMethod* ClassLinker::GetResolvedMethod(uint32_t method_idx, ArtMethod* referrer) {
305   DCHECK(referrer != nullptr);
306   // Note: The referrer can be a Proxy constructor. In that case, we need to do the
307   // lookup in the context of the original method from where it steals the code.
308   // However, we delay the GetInterfaceMethodIfProxy() until needed.
309   DCHECK(!referrer->IsProxyMethod() || referrer->IsConstructor());
310   // We do not need the read barrier for getting the DexCache for the initial resolved method
311   // lookup as both from-space and to-space copies point to the same native resolved methods array.
312   ArtMethod* resolved_method = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedMethod(
313       method_idx, image_pointer_size_);
314   if (resolved_method == nullptr) {
315     return nullptr;
316   }
317   DCHECK(!resolved_method->IsRuntimeMethod());
318   if (kResolveMode == ResolveMode::kCheckICCEAndIAE) {
319     referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);
320     // Check if the invoke type matches the class type.
321     ObjPtr<mirror::DexCache> dex_cache = referrer->GetDexCache();
322     ObjPtr<mirror::ClassLoader> class_loader = referrer->GetClassLoader();
323     if (CheckInvokeClassMismatch</* kThrow= */ false>(dex_cache, type, method_idx, class_loader)) {
324       return nullptr;
325     }
326     // Check access.
327     ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass();
328     if (!referring_class->CanAccessResolvedMethod(resolved_method->GetDeclaringClass(),
329                                                   resolved_method,
330                                                   dex_cache,
331                                                   method_idx)) {
332       return nullptr;
333     }
334     // Check if the invoke type matches the method type.
335     if (UNLIKELY(resolved_method->CheckIncompatibleClassChange(type))) {
336       return nullptr;
337     }
338   }
339   return resolved_method;
340 }
341 
342 template <ClassLinker::ResolveMode kResolveMode>
ResolveMethod(Thread * self,uint32_t method_idx,ArtMethod * referrer,InvokeType type)343 inline ArtMethod* ClassLinker::ResolveMethod(Thread* self,
344                                              uint32_t method_idx,
345                                              ArtMethod* referrer,
346                                              InvokeType type) {
347   DCHECK(referrer != nullptr);
348   // Note: The referrer can be a Proxy constructor. In that case, we need to do the
349   // lookup in the context of the original method from where it steals the code.
350   // However, we delay the GetInterfaceMethodIfProxy() until needed.
351   DCHECK(!referrer->IsProxyMethod() || referrer->IsConstructor());
352   Thread::PoisonObjectPointersIfDebug();
353   // We do not need the read barrier for getting the DexCache for the initial resolved method
354   // lookup as both from-space and to-space copies point to the same native resolved methods array.
355   ArtMethod* resolved_method = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedMethod(
356       method_idx, image_pointer_size_);
357   DCHECK(resolved_method == nullptr || !resolved_method->IsRuntimeMethod());
358   if (UNLIKELY(resolved_method == nullptr)) {
359     referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);
360     ObjPtr<mirror::Class> declaring_class = referrer->GetDeclaringClass();
361     StackHandleScope<2> hs(self);
362     Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(referrer->GetDexCache()));
363     Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(declaring_class->GetClassLoader()));
364     resolved_method = ResolveMethod<kResolveMode>(method_idx,
365                                                   h_dex_cache,
366                                                   h_class_loader,
367                                                   referrer,
368                                                   type);
369   } else if (kResolveMode == ResolveMode::kCheckICCEAndIAE) {
370     referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);
371     const dex::MethodId& method_id = referrer->GetDexFile()->GetMethodId(method_idx);
372     ObjPtr<mirror::Class> cls =
373         LookupResolvedType(method_id.class_idx_,
374                            referrer->GetDexCache(),
375                            referrer->GetClassLoader());
376     if (cls == nullptr) {
377       // The verifier breaks the invariant that a resolved method must have its
378       // class in the class table, so resolve the type in case we haven't found it.
379       // b/73760543
380       StackHandleScope<2> hs(Thread::Current());
381       Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(referrer->GetDexCache()));
382       Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(referrer->GetClassLoader()));
383       cls = ResolveType(method_id.class_idx_, h_dex_cache, h_class_loader);
384       if (hs.Self()->IsExceptionPending()) {
385         return nullptr;
386       }
387     }
388     // Check if the invoke type matches the class type.
389     if (CheckInvokeClassMismatch</* kThrow= */ true>(
390             referrer->GetDexCache(), type, [cls]() { return cls; })) {
391       DCHECK(Thread::Current()->IsExceptionPending());
392       return nullptr;
393     }
394     // Check access.
395     ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass();
396     if (!referring_class->CheckResolvedMethodAccess(resolved_method->GetDeclaringClass(),
397                                                     resolved_method,
398                                                     referrer->GetDexCache(),
399                                                     method_idx,
400                                                     type)) {
401       DCHECK(Thread::Current()->IsExceptionPending());
402       return nullptr;
403     }
404     // Check if the invoke type matches the method type.
405     if (UNLIKELY(resolved_method->CheckIncompatibleClassChange(type))) {
406       ThrowIncompatibleClassChangeError(type,
407                                         resolved_method->GetInvokeType(),
408                                         resolved_method,
409                                         referrer);
410       return nullptr;
411     }
412   }
413   // Note: We cannot check here to see whether we added the method to the cache. It
414   //       might be an erroneous class, which results in it being hidden from us.
415   return resolved_method;
416 }
417 
LookupResolvedField(uint32_t field_idx,ArtMethod * referrer,bool is_static)418 inline ArtField* ClassLinker::LookupResolvedField(uint32_t field_idx,
419                                                   ArtMethod* referrer,
420                                                   bool is_static) {
421   // We do not need the read barrier for getting the DexCache for the initial resolved field
422   // lookup as both from-space and to-space copies point to the same native resolved fields array.
423   ArtField* field = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedField(
424       field_idx, image_pointer_size_);
425   if (field == nullptr) {
426     ObjPtr<mirror::ClassLoader> class_loader = referrer->GetDeclaringClass()->GetClassLoader();
427     field = LookupResolvedField(field_idx, referrer->GetDexCache(), class_loader, is_static);
428   }
429   return field;
430 }
431 
ResolveField(uint32_t field_idx,ArtMethod * referrer,bool is_static)432 inline ArtField* ClassLinker::ResolveField(uint32_t field_idx,
433                                            ArtMethod* referrer,
434                                            bool is_static) {
435   Thread::PoisonObjectPointersIfDebug();
436   // We do not need the read barrier for getting the DexCache for the initial resolved field
437   // lookup as both from-space and to-space copies point to the same native resolved fields array.
438   ArtField* resolved_field = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedField(
439       field_idx, image_pointer_size_);
440   if (UNLIKELY(resolved_field == nullptr)) {
441     StackHandleScope<2> hs(Thread::Current());
442     ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass();
443     Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
444     Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referring_class->GetClassLoader()));
445     resolved_field = ResolveField(field_idx, dex_cache, class_loader, is_static);
446     // Note: We cannot check here to see whether we added the field to the cache. The type
447     //       might be an erroneous class, which results in it being hidden from us.
448   }
449   return resolved_field;
450 }
451 
452 template <class Visitor>
VisitClassTables(const Visitor & visitor)453 inline void ClassLinker::VisitClassTables(const Visitor& visitor) {
454   Thread* const self = Thread::Current();
455   WriterMutexLock mu(self, *Locks::classlinker_classes_lock_);
456   for (const ClassLoaderData& data : class_loaders_) {
457     if (data.class_table != nullptr) {
458       visitor(data.class_table);
459     }
460   }
461 }
462 
463 template <ReadBarrierOption kReadBarrierOption>
GetClassRoots()464 inline ObjPtr<mirror::ObjectArray<mirror::Class>> ClassLinker::GetClassRoots() {
465   ObjPtr<mirror::ObjectArray<mirror::Class>> class_roots =
466       class_roots_.Read<kReadBarrierOption>();
467   DCHECK(class_roots != nullptr);
468   return class_roots;
469 }
470 
471 template <typename Visitor>
VisitKnownDexFiles(Thread * self,Visitor visitor)472 void ClassLinker::VisitKnownDexFiles(Thread* self, Visitor visitor) {
473   ReaderMutexLock rmu(self, *Locks::dex_lock_);
474   std::for_each(dex_caches_.begin(),
475                 dex_caches_.end(),
476                 [&](DexCacheData& dcd) REQUIRES(Locks::mutator_lock_) {
477                   if (dcd.IsValid()) {
478                     visitor(dcd.dex_file);
479                   }
480                 });
481 }
482 
483 }  // namespace art
484 
485 #endif  // ART_RUNTIME_CLASS_LINKER_INL_H_
486