diff options
author | 2021-02-24 09:24:47 +0000 | |
---|---|---|
committer | 2021-02-25 12:12:16 +0000 | |
commit | b9b7d91f5ceb0b738e1774992fd6fe205c6091e9 (patch) | |
tree | 06210044d3f66a0eb72e491ba9effc13bb827ced /runtime/class_linker.cc | |
parent | 4c3ade67c470543562a0029e39b576954a807321 (diff) |
Revert "Lazily allocate DexCache arrays."
This reverts commit 1214319d27e7fb4c4ff00b39799df6f15288098a.
Reason for revert: Post-submit fails
Bug: b/181097963
Test: TH
Change-Id: I9fd21140f1703d0020458b786f48bd39889a9948
Diffstat (limited to 'runtime/class_linker.cc')
-rw-r--r-- | runtime/class_linker.cc | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 0fe8caa49e..b98708ebe5 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -1937,10 +1937,13 @@ bool ClassLinker::AddImageSpace( 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 @@ ObjPtr<mirror::DexCache> ClassLinker::AllocDexCache(Thread* self, const DexFile& 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::LoadMethod(const DexFile& dex_file, } 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 @@ ObjPtr<mirror::DexCache> ClassLinker::RegisterDexFile(const DexFile& dex_file, 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) { |