diff options
author | Hans Boehm <hboehm@google.com> | 2021-08-02 17:12:29 -0700 |
---|---|---|
committer | Hans Boehm <hboehm@google.com> | 2021-08-06 18:26:56 -0700 |
commit | 6dcde8681c498f540e58d0e33282a6f67e4bdf1d (patch) | |
tree | 07523206750e416ddfd19192308065fdfa9259bd | |
parent | 55a2349d7b21a69f26b475912235ed530f4f1357 (diff) |
Make ClassLinker::DumpForSigQuit exclude gc
Otherwise we can get into a deadlock because we hold a critical lock
while waiting for weak reference access, thus potentially preventing
other threads from suspending properly to reenable weak reference
access.
Bug: 195261575
Test: TreeHugger
Change-Id: Ideb6199f597c4e06741c79bb2812661d88a42669
Merged-In: Ideb6199f597c4e06741c79bb2812661d88a42669
(cherry picked from commit 825e82972fe46fdb0419c42bd7df102df1989ff9)
-rw-r--r-- | runtime/class_linker.cc | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/runtime/class_linker.cc b/runtime/class_linker.cc index 8b9e42a572..b9751ab965 100644 --- a/runtime/class_linker.cc +++ b/runtime/class_linker.cc @@ -9814,16 +9814,22 @@ void ClassLinker::SetEntryPointsForObsoleteMethod(ArtMethod* method) const { } void ClassLinker::DumpForSigQuit(std::ostream& os) { - ScopedObjectAccess soa(Thread::Current()); - ReaderMutexLock mu(soa.Self(), *Locks::classlinker_classes_lock_); + // Avoid a deadlock between a garbage collecting thread running a checkpoint, + // a thread holding the dex or classlinker lock and blocking on a condition variable for + // weak references access, and a thread blocking on the dex or classlinker lock and thus + // unable to run the checkpoint. + Thread* self = Thread::Current(); + ScopedObjectAccess soa(self); + gc::ScopedGCCriticalSection gcs(self, gc::kGcCauseClassLinker, gc::kCollectorTypeClassLinker); + ReaderMutexLock mu(self, *Locks::classlinker_classes_lock_); os << "Zygote loaded classes=" << NumZygoteClasses() << " post zygote classes=" << NumNonZygoteClasses() << "\n"; - ReaderMutexLock mu2(soa.Self(), *Locks::dex_lock_); + ReaderMutexLock mu2(self, *Locks::dex_lock_); os << "Dumping registered class loaders\n"; size_t class_loader_index = 0; for (const ClassLoaderData& class_loader : class_loaders_) { ObjPtr<mirror::ClassLoader> loader = - ObjPtr<mirror::ClassLoader>::DownCast(soa.Self()->DecodeJObject(class_loader.weak_root)); + ObjPtr<mirror::ClassLoader>::DownCast(self->DecodeJObject(class_loader.weak_root)); if (loader != nullptr) { os << "#" << class_loader_index++ << " " << loader->GetClass()->PrettyDescriptor() << ": ["; bool saw_one_dex_file = false; @@ -9842,7 +9848,7 @@ void ClassLinker::DumpForSigQuit(std::ostream& os) { size_t parent_index = 0; for (const ClassLoaderData& class_loader2 : class_loaders_) { ObjPtr<mirror::ClassLoader> loader2 = ObjPtr<mirror::ClassLoader>::DownCast( - soa.Self()->DecodeJObject(class_loader2.weak_root)); + self->DecodeJObject(class_loader2.weak_root)); if (loader2 == loader->GetParent()) { os << ", parent #" << parent_index; found_parent = true; |