Revert "Lazily allocate DexCache arrays."
This reverts commit 1214319d27e7fb4c4ff00b39799df6f15288098a.
Reason for revert: Post-submit fails
Bug: b/181097963
Test: TH
Change-Id: I9fd21140f1703d0020458b786f48bd39889a9948
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc
index 0fe8caa..b98708e 100644
--- a/runtime/class_linker.cc
+++ b/runtime/class_linker.cc
@@ -1937,10 +1937,13 @@
return false;
}
+ LinearAlloc* linear_alloc = GetOrCreateAllocatorForClassLoader(class_loader.Get());
+ DCHECK(linear_alloc != nullptr);
+ DCHECK_EQ(linear_alloc == Runtime::Current()->GetLinearAlloc(), !app_image);
{
- // Native fields are all null. Initialize them.
+ // Native fields are all null. Initialize them and allocate native memory.
WriterMutexLock mu(self, *Locks::dex_lock_);
- dex_cache->Initialize(dex_file.get(), class_loader.Get());
+ dex_cache->InitializeNativeFields(dex_file.get(), linear_alloc);
}
if (!app_image) {
// Register dex files, keep track of existing ones that are conflicts.
@@ -2401,14 +2404,13 @@
return dex_cache.Get();
}
-ObjPtr<mirror::DexCache> ClassLinker::AllocAndInitializeDexCache(
- Thread* self, const DexFile& dex_file, ObjPtr<mirror::ClassLoader> class_loader) {
- StackHandleScope<1> hs(self);
- Handle<mirror::ClassLoader> h_class_loader(hs.NewHandle(class_loader));
+ObjPtr<mirror::DexCache> ClassLinker::AllocAndInitializeDexCache(Thread* self,
+ const DexFile& dex_file,
+ LinearAlloc* linear_alloc) {
ObjPtr<mirror::DexCache> dex_cache = AllocDexCache(self, dex_file);
if (dex_cache != nullptr) {
WriterMutexLock mu(self, *Locks::dex_lock_);
- dex_cache->Initialize(&dex_file, h_class_loader.Get());
+ dex_cache->InitializeNativeFields(&dex_file, linear_alloc);
}
return dex_cache;
}
@@ -3843,8 +3845,10 @@
}
void ClassLinker::AppendToBootClassPath(Thread* self, const DexFile* dex_file) {
- ObjPtr<mirror::DexCache> dex_cache =
- AllocAndInitializeDexCache(self, *dex_file, /* class_loader= */ nullptr);
+ ObjPtr<mirror::DexCache> dex_cache = AllocAndInitializeDexCache(
+ self,
+ *dex_file,
+ Runtime::Current()->GetLinearAlloc());
CHECK(dex_cache != nullptr) << "Failed to allocate dex cache for " << dex_file->GetLocation();
AppendToBootClassPath(dex_file, dex_cache);
}
@@ -4034,10 +4038,10 @@
const DexCacheData* old_data = FindDexCacheDataLocked(dex_file);
old_dex_cache = DecodeDexCacheLocked(self, old_data);
if (old_dex_cache == nullptr && h_dex_cache != nullptr) {
- // Do Initialize while holding dex lock to make sure two threads don't call it
+ // Do InitializeNativeFields while holding dex lock to make sure two threads don't call it
// at the same time with the same dex cache. Since the .bss is shared this can cause failing
// DCHECK that the arrays are null.
- h_dex_cache->Initialize(&dex_file, h_class_loader.Get());
+ h_dex_cache->InitializeNativeFields(&dex_file, linear_alloc);
RegisterDexFileLocked(dex_file, h_dex_cache.Get(), h_class_loader.Get());
}
if (old_dex_cache != nullptr) {