diff options
| author | 2019-11-27 14:35:24 -0800 | |
|---|---|---|
| committer | 2019-12-02 18:56:46 +0000 | |
| commit | 0a19e212e56fc6fe2809b58072ddcf4acfdc568d (patch) | |
| tree | 6e5ef4a1bd1d08917ada2a49d5f807cfbc9a4e1a /runtime/class_linker.cc | |
| parent | 42c52f53b3c85b5e3c984bca8eaec2e03893dd2e (diff) | |
Add null check in AppendToBootClassPath
Aim to diagnose test 1002 that crashed once due to having a null
element in ClassLinker::boot_class_path_.
Bug: 144895912
Test: test/testrunner/test.py --host -j32
Change-Id: Ibc072dbc1bd48cfde0ad5d3b56ebdc348d441085
Diffstat (limited to 'runtime/class_linker.cc')
| -rw-r--r-- | runtime/class_linker.cc | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 22841bdb50..a0a2365408 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -820,11 +820,11 @@ bool ClassLinker::InitWithoutImage(std::vector<std::unique_ptr<const DexFile>> b return false; } for (auto& dex_file : boot_class_path) { - if (dex_file.get() == nullptr) { + if (dex_file == nullptr) { *error_msg = "Null dex file."; return false; } - AppendToBootClassPath(self, *dex_file); + AppendToBootClassPath(self, dex_file.get()); boot_dex_files_.push_back(std::move(dex_file)); } @@ -1299,7 +1299,7 @@ void ClassLinker::AddExtraBootDexFiles( Thread* self, std::vector<std::unique_ptr<const DexFile>>&& additional_dex_files) { for (std::unique_ptr<const DexFile>& dex_file : additional_dex_files) { - AppendToBootClassPath(self, *dex_file); + AppendToBootClassPath(self, dex_file.get()); boot_dex_files_.push_back(std::move(dex_file)); } } @@ -2269,7 +2269,7 @@ bool ClassLinker::AddImageSpace( dex_cache->NumResolvedMethods()); } // Register dex files, keep track of existing ones that are conflicts. - AppendToBootClassPath(*dex_file.get(), dex_cache); + AppendToBootClassPath(dex_file.get(), dex_cache); } out_dex_files->push_back(std::move(dex_file)); } @@ -2959,6 +2959,7 @@ using ClassPathEntry = std::pair<const DexFile*, const dex::ClassDef*>; ClassPathEntry FindInClassPath(const char* descriptor, size_t hash, const std::vector<const DexFile*>& class_path) { for (const DexFile* dex_file : class_path) { + DCHECK(dex_file != nullptr); const dex::ClassDef* dex_class_def = OatDexFile::FindClassDef(*dex_file, descriptor, hash); if (dex_class_def != nullptr) { return ClassPathEntry(dex_file, dex_class_def); @@ -4139,21 +4140,22 @@ void ClassLinker::LoadMethod(const DexFile& dex_file, } } -void ClassLinker::AppendToBootClassPath(Thread* self, const DexFile& dex_file) { +void ClassLinker::AppendToBootClassPath(Thread* self, const DexFile* dex_file) { ObjPtr<mirror::DexCache> dex_cache = AllocAndInitializeDexCache( self, - dex_file, + *dex_file, Runtime::Current()->GetLinearAlloc()); - CHECK(dex_cache != nullptr) << "Failed to allocate dex cache for " << dex_file.GetLocation(); + CHECK(dex_cache != nullptr) << "Failed to allocate dex cache for " << dex_file->GetLocation(); AppendToBootClassPath(dex_file, dex_cache); } -void ClassLinker::AppendToBootClassPath(const DexFile& dex_file, +void ClassLinker::AppendToBootClassPath(const DexFile* dex_file, ObjPtr<mirror::DexCache> dex_cache) { - CHECK(dex_cache != nullptr) << dex_file.GetLocation(); - boot_class_path_.push_back(&dex_file); + CHECK(dex_file != nullptr); + CHECK(dex_cache != nullptr) << dex_file->GetLocation(); + boot_class_path_.push_back(dex_file); WriterMutexLock mu(Thread::Current(), *Locks::dex_lock_); - RegisterDexFileLocked(dex_file, dex_cache, /* class_loader= */ nullptr); + RegisterDexFileLocked(*dex_file, dex_cache, /* class_loader= */ nullptr); } void ClassLinker::RegisterDexFileLocked(const DexFile& dex_file, |