blob: 4b317f886fbca74986a5765e42d1c78bc3a86785 [file] [log] [blame]
Ian Rogers2dd0e2c2013-01-24 12:42:14 -08001/*
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
Brian Carlstromfc0e3212013-07-17 14:40:12 -070017#ifndef ART_RUNTIME_CLASS_LINKER_INL_H_
18#define ART_RUNTIME_CLASS_LINKER_INL_H_
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080019
Mathieu Chartierc7853442015-03-27 14:35:38 -070020#include "art_field.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080021#include "class_linker.h"
Mathieu Chartier52e4b432014-06-10 11:22:31 -070022#include "gc/heap-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070023#include "gc_root-inl.h"
24#include "handle_scope-inl.h"
Mathieu Chartier590fee92013-09-13 13:46:47 -070025#include "mirror/class_loader.h"
Mathieu Chartierbc56fc32014-06-03 15:37:03 -070026#include "mirror/dex_cache-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080027#include "mirror/iftable.h"
Andreas Gampec15a2f42017-04-21 12:09:39 -070028#include "mirror/object_array-inl.h"
Andreas Gampe8cf9cb32017-07-19 09:28:38 -070029#include "obj_ptr-inl.h"
Mathieu Chartierc4f39252016-10-05 18:32:08 -070030#include "scoped_thread_state_change-inl.h"
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080031
Christina Wadsworthbf44e0e2016-08-18 10:37:42 -070032#include <atomic>
33
Ian Rogers2dd0e2c2013-01-24 12:42:14 -080034namespace art {
35
Mathieu Chartierbc5a7952016-10-17 15:46:31 -070036inline mirror::Class* ClassLinker::FindArrayClass(Thread* self,
37 ObjPtr<mirror::Class>* element_class) {
Ian Rogers98379392014-02-24 16:53:16 -080038 for (size_t i = 0; i < kFindArrayCacheSize; ++i) {
Ian Rogersa55cf412014-02-27 00:31:26 -080039 // Read the cached array class once to avoid races with other threads setting it.
Mathieu Chartier28357fa2016-10-18 16:27:40 -070040 ObjPtr<mirror::Class> array_class = find_array_class_cache_[i].Read();
Mathieu Chartierb74cd292014-05-29 14:31:33 -070041 if (array_class != nullptr && array_class->GetComponentType() == *element_class) {
Mathieu Chartier28357fa2016-10-18 16:27:40 -070042 return array_class.Ptr();
Ian Rogers98379392014-02-24 16:53:16 -080043 }
44 }
Ian Rogers1ff3c982014-08-12 02:30:58 -070045 std::string descriptor = "[";
46 std::string temp;
47 descriptor += (*element_class)->GetDescriptor(&temp);
Mathieu Chartierb74cd292014-05-29 14:31:33 -070048 StackHandleScope<2> hs(Thread::Current());
49 Handle<mirror::ClassLoader> class_loader(hs.NewHandle((*element_class)->GetClassLoader()));
Mathieu Chartierbc5a7952016-10-17 15:46:31 -070050 HandleWrapperObjPtr<mirror::Class> h_element_class(hs.NewHandleWrapper(element_class));
Mathieu Chartier28357fa2016-10-18 16:27:40 -070051 ObjPtr<mirror::Class> array_class = FindClass(self, descriptor.c_str(), class_loader);
Nicolas Geoffray9638b642015-06-23 18:16:46 +010052 if (array_class != nullptr) {
53 // Benign races in storing array class and incrementing index.
54 size_t victim_index = find_array_class_cache_next_victim_;
55 find_array_class_cache_[victim_index] = GcRoot<mirror::Class>(array_class);
56 find_array_class_cache_next_victim_ = (victim_index + 1) % kFindArrayCacheSize;
57 } else {
58 // We should have a NoClassDefFoundError.
59 self->AssertPendingException();
60 }
Mathieu Chartier28357fa2016-10-18 16:27:40 -070061 return array_class.Ptr();
Ian Rogers98379392014-02-24 16:53:16 -080062}
63
Vladimir Marko666ee3d2017-12-11 18:37:36 +000064inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
65 ObjPtr<mirror::Class> referrer) {
66 if (kObjPtrPoisoning) {
67 StackHandleScope<1> hs(Thread::Current());
68 HandleWrapperObjPtr<mirror::Class> referrer_wrapper = hs.NewHandleWrapper(&referrer);
69 Thread::Current()->PoisonObjectPointers();
Vladimir Marko8d6768d2017-03-14 10:13:21 +000070 }
Vladimir Marko666ee3d2017-12-11 18:37:36 +000071 if (kIsDebugBuild) {
72 Thread::Current()->AssertNoPendingException();
73 }
74 // We do not need the read barrier for getting the DexCache for the initial resolved type
75 // lookup as both from-space and to-space copies point to the same native resolved types array.
76 ObjPtr<mirror::Class> resolved_type =
77 referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx);
78 if (resolved_type == nullptr) {
79 StackHandleScope<2> hs(Thread::Current());
80 Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(referrer->GetDexCache()));
81 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referrer->GetClassLoader()));
82 resolved_type = DoResolveType(type_idx, h_dex_cache, class_loader);
83 }
84 return resolved_type;
Vladimir Marko8d6768d2017-03-14 10:13:21 +000085}
86
Vladimir Marko28e012a2017-12-07 11:22:59 +000087inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
88 ArtMethod* referrer) {
Mathieu Chartiera59d9b22016-09-26 18:13:17 -070089 Thread::PoisonObjectPointersIfDebug();
Mathieu Chartierfb568d32016-12-06 13:21:38 -080090 if (kIsDebugBuild) {
91 Thread::Current()->AssertNoPendingException();
92 }
Vladimir Marko666ee3d2017-12-11 18:37:36 +000093 // We do not need the read barrier for getting the DexCache for the initial resolved type
94 // lookup as both from-space and to-space copies point to the same native resolved types array.
95 ObjPtr<mirror::Class> resolved_type =
96 referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070097 if (UNLIKELY(resolved_type == nullptr)) {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -070098 StackHandleScope<2> hs(Thread::Current());
Vladimir Marko666ee3d2017-12-11 18:37:36 +000099 ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass();
Alex Light4ba388a2017-01-27 10:26:49 -0800100 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000101 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referring_class->GetClassLoader()));
102 resolved_type = DoResolveType(type_idx, dex_cache, class_loader);
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800103 }
Vladimir Marko28e012a2017-12-07 11:22:59 +0000104 return resolved_type;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800105}
106
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000107inline ObjPtr<mirror::Class> ClassLinker::ResolveType(dex::TypeIndex type_idx,
108 Handle<mirror::DexCache> dex_cache,
109 Handle<mirror::ClassLoader> class_loader) {
110 DCHECK(dex_cache != nullptr);
111 Thread::PoisonObjectPointersIfDebug();
112 ObjPtr<mirror::Class> resolved = dex_cache->GetResolvedType(type_idx);
113 if (resolved == nullptr) {
114 resolved = DoResolveType(type_idx, dex_cache, class_loader);
115 }
116 return resolved;
117}
118
119inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
120 ObjPtr<mirror::Class> referrer) {
121 // We do not need the read barrier for getting the DexCache for the initial resolved type
122 // lookup as both from-space and to-space copies point to the same native resolved types array.
123 ObjPtr<mirror::Class> type =
124 referrer->GetDexCache<kDefaultVerifyFlags, kWithoutReadBarrier>()->GetResolvedType(type_idx);
125 if (type == nullptr) {
126 type = DoLookupResolvedType(type_idx, referrer->GetDexCache(), referrer->GetClassLoader());
127 }
128 return type;
129}
130
131inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(dex::TypeIndex type_idx,
132 ArtMethod* referrer) {
133 // We do not need the read barrier for getting the DexCache for the initial resolved type
134 // lookup as both from-space and to-space copies point to the same native resolved types array.
135 ObjPtr<mirror::Class> type =
136 referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedType(type_idx);
137 if (type == nullptr) {
138 type = DoLookupResolvedType(type_idx, referrer->GetDexCache(), referrer->GetClassLoader());
139 }
140 return type;
141}
142
143inline ObjPtr<mirror::Class> ClassLinker::LookupResolvedType(
144 dex::TypeIndex type_idx,
145 ObjPtr<mirror::DexCache> dex_cache,
146 ObjPtr<mirror::ClassLoader> class_loader) {
147 ObjPtr<mirror::Class> type = dex_cache->GetResolvedType(type_idx);
148 if (type == nullptr) {
149 type = DoLookupResolvedType(type_idx, dex_cache, class_loader);
150 }
151 return type;
152}
153
Vladimir Markoba118822017-06-12 15:41:56 +0100154template <bool kThrowOnError, typename ClassGetter>
155inline bool ClassLinker::CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache,
156 InvokeType type,
157 ClassGetter class_getter) {
158 switch (type) {
159 case kStatic:
160 case kSuper:
161 break;
162 case kInterface: {
163 // We have to check whether the method id really belongs to an interface (dex static bytecode
164 // constraints A15, A16). Otherwise you must not invoke-interface on it.
165 ObjPtr<mirror::Class> klass = class_getter();
166 if (UNLIKELY(!klass->IsInterface())) {
167 if (kThrowOnError) {
168 ThrowIncompatibleClassChangeError(klass,
169 "Found class %s, but interface was expected",
170 klass->PrettyDescriptor().c_str());
171 }
172 return true;
173 }
174 break;
175 }
176 case kDirect:
177 if (dex_cache->GetDexFile()->GetVersion() >= DexFile::kDefaultMethodsVersion) {
178 break;
179 }
180 FALLTHROUGH_INTENDED;
181 case kVirtual: {
182 // Similarly, invoke-virtual (and invoke-direct without default methods) must reference
183 // a non-interface class (dex static bytecode constraint A24, A25).
184 ObjPtr<mirror::Class> klass = class_getter();
185 if (UNLIKELY(klass->IsInterface())) {
186 if (kThrowOnError) {
187 ThrowIncompatibleClassChangeError(klass,
188 "Found interface %s, but class was expected",
189 klass->PrettyDescriptor().c_str());
190 }
191 return true;
192 }
193 break;
194 }
195 default:
196 LOG(FATAL) << "Unreachable - invocation type: " << type;
197 UNREACHABLE();
198 }
199 return false;
200}
201
202template <bool kThrow>
203inline bool ClassLinker::CheckInvokeClassMismatch(ObjPtr<mirror::DexCache> dex_cache,
204 InvokeType type,
205 uint32_t method_idx,
206 ObjPtr<mirror::ClassLoader> class_loader) {
207 return CheckInvokeClassMismatch<kThrow>(
208 dex_cache,
209 type,
210 [this, dex_cache, method_idx, class_loader]() REQUIRES_SHARED(Locks::mutator_lock_) {
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000211 const DexFile::MethodId& method_id = dex_cache->GetDexFile()->GetMethodId(method_idx);
Vladimir Markoba118822017-06-12 15:41:56 +0100212 ObjPtr<mirror::Class> klass =
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000213 LookupResolvedType(method_id.class_idx_, dex_cache, class_loader);
Vladimir Markoba118822017-06-12 15:41:56 +0100214 DCHECK(klass != nullptr);
215 return klass;
216 });
217}
218
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100219inline ArtMethod* ClassLinker::LookupResolvedMethod(uint32_t method_idx,
220 ObjPtr<mirror::DexCache> dex_cache,
221 ObjPtr<mirror::ClassLoader> class_loader) {
222 PointerSize pointer_size = image_pointer_size_;
223 ArtMethod* resolved = dex_cache->GetResolvedMethod(method_idx, pointer_size);
224 if (resolved == nullptr) {
225 const DexFile& dex_file = *dex_cache->GetDexFile();
226 const DexFile::MethodId& method_id = dex_file.GetMethodId(method_idx);
227 ObjPtr<mirror::Class> klass = LookupResolvedType(method_id.class_idx_, dex_cache, class_loader);
228 if (klass != nullptr) {
229 if (klass->IsInterface()) {
230 resolved = klass->FindInterfaceMethod(dex_cache, method_idx, pointer_size);
231 } else {
232 resolved = klass->FindClassMethod(dex_cache, method_idx, pointer_size);
233 }
234 if (resolved != nullptr) {
235 dex_cache->SetResolvedMethod(method_idx, resolved, pointer_size);
236 }
237 }
238 }
239 return resolved;
240}
241
Vladimir Markoba118822017-06-12 15:41:56 +0100242template <InvokeType type, ClassLinker::ResolveMode kResolveMode>
Mathieu Chartiere401d142015-04-22 13:56:20 -0700243inline ArtMethod* ClassLinker::GetResolvedMethod(uint32_t method_idx, ArtMethod* referrer) {
Vladimir Markoba118822017-06-12 15:41:56 +0100244 DCHECK(referrer != nullptr);
245 // Note: The referrer can be a Proxy constructor. In that case, we need to do the
246 // lookup in the context of the original method from where it steals the code.
247 // However, we delay the GetInterfaceMethodIfProxy() until needed.
248 DCHECK(!referrer->IsProxyMethod() || referrer->IsConstructor());
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000249 // We do not need the read barrier for getting the DexCache for the initial resolved method
250 // lookup as both from-space and to-space copies point to the same native resolved methods array.
Vladimir Marko5122e6b2017-08-17 16:10:09 +0100251 ArtMethod* resolved_method = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedMethod(
252 method_idx, image_pointer_size_);
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100253 if (resolved_method == nullptr) {
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700254 return nullptr;
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800255 }
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100256 DCHECK(!resolved_method->IsRuntimeMethod());
Vladimir Markoba118822017-06-12 15:41:56 +0100257 if (kResolveMode == ResolveMode::kCheckICCEAndIAE) {
258 referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);
259 // Check if the invoke type matches the class type.
260 ObjPtr<mirror::DexCache> dex_cache = referrer->GetDexCache();
261 ObjPtr<mirror::ClassLoader> class_loader = referrer->GetClassLoader();
262 if (CheckInvokeClassMismatch</* kThrow */ false>(dex_cache, type, method_idx, class_loader)) {
263 return nullptr;
264 }
265 // Check access.
266 ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass();
267 if (!referring_class->CanAccessResolvedMethod(resolved_method->GetDeclaringClass(),
268 resolved_method,
269 dex_cache,
270 method_idx)) {
271 return nullptr;
272 }
273 // Check if the invoke type matches the method type.
274 if (UNLIKELY(resolved_method->CheckIncompatibleClassChange(type))) {
275 return nullptr;
276 }
Alex Lightfedd91d2016-01-07 14:49:16 -0800277 }
Vladimir Markoba118822017-06-12 15:41:56 +0100278 return resolved_method;
Alex Lightfedd91d2016-01-07 14:49:16 -0800279}
280
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800281template <ClassLinker::ResolveMode kResolveMode>
Mathieu Chartierc77f3ab2015-09-03 19:41:50 -0700282inline ArtMethod* ClassLinker::ResolveMethod(Thread* self,
283 uint32_t method_idx,
284 ArtMethod* referrer,
285 InvokeType type) {
Vladimir Markoba118822017-06-12 15:41:56 +0100286 DCHECK(referrer != nullptr);
287 // Note: The referrer can be a Proxy constructor. In that case, we need to do the
288 // lookup in the context of the original method from where it steals the code.
289 // However, we delay the GetInterfaceMethodIfProxy() until needed.
290 DCHECK(!referrer->IsProxyMethod() || referrer->IsConstructor());
Mathieu Chartiera59d9b22016-09-26 18:13:17 -0700291 Thread::PoisonObjectPointersIfDebug();
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000292 // We do not need the read barrier for getting the DexCache for the initial resolved method
293 // lookup as both from-space and to-space copies point to the same native resolved methods array.
Vladimir Marko5122e6b2017-08-17 16:10:09 +0100294 ArtMethod* resolved_method = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedMethod(
295 method_idx, image_pointer_size_);
Vladimir Marko07bfbac2017-07-06 14:55:02 +0100296 DCHECK(resolved_method == nullptr || !resolved_method->IsRuntimeMethod());
297 if (UNLIKELY(resolved_method == nullptr)) {
Vladimir Markoba118822017-06-12 15:41:56 +0100298 referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700299 ObjPtr<mirror::Class> declaring_class = referrer->GetDeclaringClass();
Mathieu Chartiere401d142015-04-22 13:56:20 -0700300 StackHandleScope<2> hs(self);
Alex Light4ba388a2017-01-27 10:26:49 -0800301 Handle<mirror::DexCache> h_dex_cache(hs.NewHandle(referrer->GetDexCache()));
Mathieu Chartiere401d142015-04-22 13:56:20 -0700302 Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(declaring_class->GetClassLoader()));
Vladimir Marko89011192017-12-11 13:45:05 +0000303 resolved_method = ResolveMethod<kResolveMode>(method_idx,
Andreas Gampe42ef8ab2015-12-03 17:27:32 -0800304 h_dex_cache,
305 h_class_loader,
306 referrer,
307 type);
Vladimir Markoba118822017-06-12 15:41:56 +0100308 } else if (kResolveMode == ResolveMode::kCheckICCEAndIAE) {
309 referrer = referrer->GetInterfaceMethodIfProxy(image_pointer_size_);
310 // Check if the invoke type matches the class type.
311 ObjPtr<mirror::DexCache> dex_cache = referrer->GetDexCache();
312 ObjPtr<mirror::ClassLoader> class_loader = referrer->GetClassLoader();
313 if (CheckInvokeClassMismatch</* kThrow */ true>(dex_cache, type, method_idx, class_loader)) {
314 DCHECK(Thread::Current()->IsExceptionPending());
315 return nullptr;
316 }
317 // Check access.
318 ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass();
319 if (!referring_class->CheckResolvedMethodAccess(resolved_method->GetDeclaringClass(),
320 resolved_method,
321 dex_cache,
322 method_idx,
323 type)) {
324 DCHECK(Thread::Current()->IsExceptionPending());
325 return nullptr;
326 }
327 // Check if the invoke type matches the method type.
328 if (UNLIKELY(resolved_method->CheckIncompatibleClassChange(type))) {
329 ThrowIncompatibleClassChangeError(type,
330 resolved_method->GetInvokeType(),
331 resolved_method,
332 referrer);
333 return nullptr;
334 }
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700335 }
Andreas Gampe58a5af82014-07-31 16:23:49 -0700336 // Note: We cannot check here to see whether we added the method to the cache. It
337 // might be an erroneous class, which results in it being hidden from us.
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700338 return resolved_method;
339}
340
Vladimir Markof44d36c2017-03-14 14:18:46 +0000341inline ArtField* ClassLinker::LookupResolvedField(uint32_t field_idx,
342 ArtMethod* referrer,
343 bool is_static) {
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000344 // We do not need the read barrier for getting the DexCache for the initial resolved field
345 // lookup as both from-space and to-space copies point to the same native resolved fields array.
346 ArtField* field = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedField(
347 field_idx, image_pointer_size_);
Vladimir Markof44d36c2017-03-14 14:18:46 +0000348 if (field == nullptr) {
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000349 ObjPtr<mirror::ClassLoader> class_loader = referrer->GetDeclaringClass()->GetClassLoader();
350 field = LookupResolvedField(field_idx, referrer->GetDexCache(), class_loader, is_static);
Vladimir Markof44d36c2017-03-14 14:18:46 +0000351 }
352 return field;
Mathieu Chartier0cd81352014-05-22 16:48:55 -0700353}
354
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700355inline ArtField* ClassLinker::ResolveField(uint32_t field_idx,
356 ArtMethod* referrer,
Mathieu Chartiere401d142015-04-22 13:56:20 -0700357 bool is_static) {
Mathieu Chartiera59d9b22016-09-26 18:13:17 -0700358 Thread::PoisonObjectPointersIfDebug();
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000359 // We do not need the read barrier for getting the DexCache for the initial resolved field
360 // lookup as both from-space and to-space copies point to the same native resolved fields array.
361 ArtField* resolved_field = referrer->GetDexCache<kWithoutReadBarrier>()->GetResolvedField(
362 field_idx, image_pointer_size_);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700363 if (UNLIKELY(resolved_field == nullptr)) {
Mathieu Chartiereb8167a2014-05-07 15:43:14 -0700364 StackHandleScope<2> hs(Thread::Current());
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000365 ObjPtr<mirror::Class> referring_class = referrer->GetDeclaringClass();
Alex Lightdba61482016-12-21 08:20:29 -0800366 Handle<mirror::DexCache> dex_cache(hs.NewHandle(referrer->GetDexCache()));
Vladimir Marko666ee3d2017-12-11 18:37:36 +0000367 Handle<mirror::ClassLoader> class_loader(hs.NewHandle(referring_class->GetClassLoader()));
Vladimir Markoe11dd502017-12-08 14:09:45 +0000368 resolved_field = ResolveField(field_idx, dex_cache, class_loader, is_static);
Andreas Gampe58a5af82014-07-31 16:23:49 -0700369 // Note: We cannot check here to see whether we added the field to the cache. The type
370 // might be an erroneous class, which results in it being hidden from us.
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800371 }
372 return resolved_field;
373}
374
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700375inline mirror::Class* ClassLinker::GetClassRoot(ClassRoot class_root) {
Hiroshi Yamauchi94f7b492014-07-22 18:08:23 -0700376 DCHECK(!class_roots_.IsNull());
377 mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read();
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700378 ObjPtr<mirror::Class> klass = class_roots->Get(class_root);
Mathieu Chartier2cebb242015-04-21 16:50:40 -0700379 DCHECK(klass != nullptr);
Mathieu Chartier28357fa2016-10-18 16:27:40 -0700380 return klass.Ptr();
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800381}
382
Mathieu Chartier72041a02017-07-14 18:23:25 -0700383template <class Visitor>
384inline void ClassLinker::VisitClassTables(const Visitor& visitor) {
385 Thread* const self = Thread::Current();
386 WriterMutexLock mu(self, *Locks::classlinker_classes_lock_);
387 for (const ClassLoaderData& data : class_loaders_) {
388 if (data.class_table != nullptr) {
389 visitor(data.class_table);
390 }
391 }
392}
393
Ian Rogers2dd0e2c2013-01-24 12:42:14 -0800394} // namespace art
395
Brian Carlstromfc0e3212013-07-17 14:40:12 -0700396#endif // ART_RUNTIME_CLASS_LINKER_INL_H_