diff options
Diffstat (limited to 'runtime/class_linker-inl.h')
| -rw-r--r-- | runtime/class_linker-inl.h | 39 |
1 files changed, 16 insertions, 23 deletions
diff --git a/runtime/class_linker-inl.h b/runtime/class_linker-inl.h index 25eb3a342d..9921bddad8 100644 --- a/runtime/class_linker-inl.h +++ b/runtime/class_linker-inl.h @@ -18,6 +18,7 @@ #define ART_RUNTIME_CLASS_LINKER_INL_H_ #include "class_linker.h" +#include "gc_root-inl.h" #include "gc/heap-inl.h" #include "mirror/art_field.h" #include "mirror/class_loader.h" @@ -40,8 +41,7 @@ inline mirror::Class* ClassLinker::FindSystemClass(Thread* self, const char* des inline mirror::Class* ClassLinker::FindArrayClass(Thread* self, mirror::Class** element_class) { for (size_t i = 0; i < kFindArrayCacheSize; ++i) { // Read the cached array class once to avoid races with other threads setting it. - mirror::Class* array_class = ReadBarrier::BarrierForRoot<mirror::Class, kWithReadBarrier>( - &find_array_class_cache_[i]); + mirror::Class* array_class = find_array_class_cache_[i].Read(); if (array_class != nullptr && array_class->GetComponentType() == *element_class) { return array_class; } @@ -54,7 +54,7 @@ inline mirror::Class* ClassLinker::FindArrayClass(Thread* self, mirror::Class** mirror::Class* array_class = FindClass(self, descriptor.c_str(), class_loader); // Benign races in storing array class and incrementing index. size_t victim_index = find_array_class_cache_next_victim_; - find_array_class_cache_[victim_index] = array_class; + find_array_class_cache_[victim_index] = GcRoot<mirror::Class>(array_class); find_array_class_cache_next_victim_ = (victim_index + 1) % kFindArrayCacheSize; return array_class; } @@ -77,7 +77,7 @@ inline mirror::String* ClassLinker::ResolveString(uint32_t string_idx, inline mirror::Class* ClassLinker::ResolveType(uint16_t type_idx, mirror::ArtMethod* referrer) { - mirror::Class* resolved_type = referrer->GetDexCacheResolvedTypes()->Get(type_idx); + mirror::Class* resolved_type = referrer->GetDexCacheResolvedType(type_idx); if (UNLIKELY(resolved_type == nullptr)) { mirror::Class* declaring_class = referrer->GetDeclaringClass(); StackHandleScope<2> hs(Thread::Current()); @@ -85,9 +85,8 @@ inline mirror::Class* ClassLinker::ResolveType(uint16_t type_idx, Handle<mirror::ClassLoader> class_loader(hs.NewHandle(declaring_class->GetClassLoader())); const DexFile& dex_file = *dex_cache->GetDexFile(); resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader); - if (resolved_type != nullptr) { - DCHECK_EQ(dex_cache->GetResolvedType(type_idx), resolved_type); - } + // Note: We cannot check here to see whether we added the type to the cache. The type + // might be an erroneous class, which results in it being hidden from us. } return resolved_type; } @@ -102,9 +101,8 @@ inline mirror::Class* ClassLinker::ResolveType(uint16_t type_idx, mirror::ArtFie Handle<mirror::ClassLoader> class_loader(hs.NewHandle(declaring_class->GetClassLoader())); const DexFile& dex_file = *dex_cache->GetDexFile(); resolved_type = ResolveType(dex_file, type_idx, dex_cache, class_loader); - if (resolved_type != nullptr) { - DCHECK_EQ(dex_cache->GetResolvedType(type_idx), resolved_type); - } + // Note: We cannot check here to see whether we added the type to the cache. The type + // might be an erroneous class, which results in it being hidden from us. } return resolved_type; } @@ -112,8 +110,7 @@ inline mirror::Class* ClassLinker::ResolveType(uint16_t type_idx, mirror::ArtFie inline mirror::ArtMethod* ClassLinker::GetResolvedMethod(uint32_t method_idx, mirror::ArtMethod* referrer, InvokeType type) { - mirror::ArtMethod* resolved_method = - referrer->GetDexCacheResolvedMethods()->Get(method_idx); + mirror::ArtMethod* resolved_method = referrer->GetDexCacheResolvedMethod(method_idx); if (resolved_method == nullptr || resolved_method->IsRuntimeMethod()) { return nullptr; } @@ -135,9 +132,8 @@ inline mirror::ArtMethod* ClassLinker::ResolveMethod(Thread* self, uint32_t meth const DexFile* dex_file = h_dex_cache->GetDexFile(); resolved_method = ResolveMethod(*dex_file, method_idx, h_dex_cache, h_class_loader, h_referrer, type); - if (resolved_method != nullptr) { - DCHECK_EQ(h_dex_cache->GetResolvedMethod(method_idx), resolved_method); - } + // Note: We cannot check here to see whether we added the method to the cache. It + // might be an erroneous class, which results in it being hidden from us. return resolved_method; } @@ -156,9 +152,8 @@ inline mirror::ArtField* ClassLinker::ResolveField(uint32_t field_idx, mirror::A Handle<mirror::ClassLoader> class_loader(hs.NewHandle(declaring_class->GetClassLoader())); const DexFile& dex_file = *dex_cache->GetDexFile(); resolved_field = ResolveField(dex_file, field_idx, dex_cache, class_loader, is_static); - if (resolved_field != nullptr) { - DCHECK_EQ(dex_cache->GetResolvedField(field_idx), resolved_field); - } + // Note: We cannot check here to see whether we added the field to the cache. The type + // might be an erroneous class, which results in it being hidden from us. } return resolved_field; } @@ -204,10 +199,8 @@ inline mirror::ObjectArray<mirror::ArtField>* ClassLinker::AllocArtFieldArray(Th inline mirror::Class* ClassLinker::GetClassRoot(ClassRoot class_root) SHARED_LOCKS_REQUIRED(Locks::mutator_lock_) { - DCHECK(class_roots_ != NULL); - mirror::ObjectArray<mirror::Class>* class_roots = - ReadBarrier::BarrierForRoot<mirror::ObjectArray<mirror::Class>, kWithReadBarrier>( - &class_roots_); + DCHECK(!class_roots_.IsNull()); + mirror::ObjectArray<mirror::Class>* class_roots = class_roots_.Read(); mirror::Class* klass = class_roots->Get(class_root); DCHECK(klass != NULL); return klass; @@ -216,7 +209,7 @@ inline mirror::Class* ClassLinker::GetClassRoot(ClassRoot class_root) inline mirror::DexCache* ClassLinker::GetDexCache(size_t idx) { dex_lock_.AssertSharedHeld(Thread::Current()); DCHECK(idx < dex_caches_.size()); - return ReadBarrier::BarrierForRoot<mirror::DexCache, kWithReadBarrier>(&dex_caches_[idx]); + return dex_caches_[idx].Read(); } } // namespace art |