diff options
author | 2019-11-27 14:35:24 -0800 | |
---|---|---|
committer | 2019-12-02 18:56:46 +0000 | |
commit | 0a19e212e56fc6fe2809b58072ddcf4acfdc568d (patch) | |
tree | 6e5ef4a1bd1d08917ada2a49d5f807cfbc9a4e1a | |
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
-rw-r--r-- | dex2oat/linker/image_test.h | 2 | ||||
-rw-r--r-- | openjdkjvmti/ti_class_loader.cc | 2 | ||||
-rw-r--r-- | openjdkjvmti/ti_redefine.cc | 2 | ||||
-rw-r--r-- | openjdkjvmti/ti_search.cc | 2 | ||||
-rw-r--r-- | runtime/class_linker.cc | 24 | ||||
-rw-r--r-- | runtime/class_linker.h | 4 | ||||
-rw-r--r-- | test/674-hiddenapi/hiddenapi.cc | 2 |
7 files changed, 20 insertions, 18 deletions
diff --git a/dex2oat/linker/image_test.h b/dex2oat/linker/image_test.h index 9ec6e56922..69e144c81c 100644 --- a/dex2oat/linker/image_test.h +++ b/dex2oat/linker/image_test.h @@ -156,7 +156,7 @@ inline void ImageTest::DoCompile(ImageHeader::StorageMode storage_mode, { ScopedObjectAccess soa(Thread::Current()); // Inject in boot class path so that the compiler driver can see it. - class_linker->AppendToBootClassPath(soa.Self(), *dex_file.get()); + class_linker->AppendToBootClassPath(soa.Self(), dex_file.get()); } class_path.push_back(dex_file.get()); } diff --git a/openjdkjvmti/ti_class_loader.cc b/openjdkjvmti/ti_class_loader.cc index 999b9d5720..d0a66343e7 100644 --- a/openjdkjvmti/ti_class_loader.cc +++ b/openjdkjvmti/ti_class_loader.cc @@ -66,7 +66,7 @@ bool ClassLoaderHelper::AddToClassLoader(art::Thread* self, art::ScopedObjectAccessUnchecked soa(self); art::StackHandleScope<3> hs(self); if (art::ClassLinker::IsBootClassLoader(soa, loader.Get())) { - art::Runtime::Current()->GetClassLinker()->AppendToBootClassPath(self, *dex_file); + art::Runtime::Current()->GetClassLinker()->AppendToBootClassPath(self, dex_file); return true; } art::Handle<art::mirror::Object> java_dex_file_obj( diff --git a/openjdkjvmti/ti_redefine.cc b/openjdkjvmti/ti_redefine.cc index ad681bc9eb..6314d42170 100644 --- a/openjdkjvmti/ti_redefine.cc +++ b/openjdkjvmti/ti_redefine.cc @@ -2352,7 +2352,7 @@ jvmtiError Redefiner::Run() { art::ClassLinker* cl = runtime_->GetClassLinker(); cl->RegisterExistingDexCache(data.GetNewDexCache(), data.GetSourceClassLoader()); if (data.GetSourceClassLoader() == nullptr) { - cl->AppendToBootClassPath(self_, data.GetRedefinition().GetDexFile()); + cl->AppendToBootClassPath(self_, &data.GetRedefinition().GetDexFile()); } } UnregisterAllBreakpoints(); diff --git a/openjdkjvmti/ti_search.cc b/openjdkjvmti/ti_search.cc index f4c3a2d9be..526836ecfd 100644 --- a/openjdkjvmti/ti_search.cc +++ b/openjdkjvmti/ti_search.cc @@ -249,7 +249,7 @@ jvmtiError SearchUtil::AddToBootstrapClassLoaderSearch(jvmtiEnv* env, art::ScopedObjectAccess soa(art::Thread::Current()); for (std::unique_ptr<const art::DexFile>& dex_file : dex_files) { - current->GetClassLinker()->AppendToBootClassPath(art::Thread::Current(), *dex_file.release()); + current->GetClassLinker()->AppendToBootClassPath(art::Thread::Current(), dex_file.release()); } return ERR(NONE); 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, diff --git a/runtime/class_linker.h b/runtime/class_linker.h index 2687b9a2cf..fc954da1be 100644 --- a/runtime/class_linker.h +++ b/runtime/class_linker.h @@ -738,7 +738,7 @@ class ClassLinker { REQUIRES_SHARED(Locks::mutator_lock_) NO_THREAD_SAFETY_ANALYSIS; - void AppendToBootClassPath(Thread* self, const DexFile& dex_file) + void AppendToBootClassPath(Thread* self, const DexFile* dex_file) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_); @@ -912,7 +912,7 @@ class ClassLinker { REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_, !Roles::uninterruptible_); - void AppendToBootClassPath(const DexFile& dex_file, ObjPtr<mirror::DexCache> dex_cache) + void AppendToBootClassPath(const DexFile* dex_file, ObjPtr<mirror::DexCache> dex_cache) REQUIRES_SHARED(Locks::mutator_lock_) REQUIRES(!Locks::dex_lock_); diff --git a/test/674-hiddenapi/hiddenapi.cc b/test/674-hiddenapi/hiddenapi.cc index 3dc27892aa..413c707902 100644 --- a/test/674-hiddenapi/hiddenapi.cc +++ b/test/674-hiddenapi/hiddenapi.cc @@ -76,7 +76,7 @@ extern "C" JNIEXPORT jint JNICALL Java_Main_appendToBootClassLoader( ScopedObjectAccess soa(Thread::Current()); for (std::unique_ptr<const DexFile>& dex_file : opened_dex_files[index]) { - Runtime::Current()->GetClassLinker()->AppendToBootClassPath(Thread::Current(), *dex_file.get()); + Runtime::Current()->GetClassLinker()->AppendToBootClassPath(Thread::Current(), dex_file.get()); } return int_index; |