From 17195424dd56070a773e82ab5430c788e54a78c6 Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Tue, 19 Dec 2023 20:35:24 +0000 Subject: Revert^18 "Thread suspension cleanup and deadlock fix" This reverts commit 8bc6a58df7046b4d6f4b51eb274c7e60fea396ff. PS1 is identical to https://android-review.git.corp.google.com/c/platform/art/+/2746640 PS2 makes the following changes: - Remove one DCHECK each from the two WaitForFlipFunction variants. The DCHECK could fail if another GC was started in the interim. - Break up the WaitForSuspendBarrier timeout into shorter ones. so we don't time out as easily if our process is frozen. - Include the thread name for ThreadSuspendByThreadIdWarning, since we don't get complete tombstones for some failures. Test: Treehugger, host tests. Bug: 240742796 Bug: 203363895 Bug: 238032384 Bug: 253671779 Bug: 276660630 Bug: 295880862 Bug: 294334417 Bug: 301090887 Bug: 313347640 (and more) Change-Id: I12c5c01b1e006baab4ee4148aadbc721723fb89e --- runtime/gc/task_processor.cc | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) (limited to 'runtime/gc/task_processor.cc') diff --git a/runtime/gc/task_processor.cc b/runtime/gc/task_processor.cc index 494cf2bb79..e56dbd17c3 100644 --- a/runtime/gc/task_processor.cc +++ b/runtime/gc/task_processor.cc @@ -103,9 +103,31 @@ bool TaskProcessor::IsRunning() const { return is_running_; } -Thread* TaskProcessor::GetRunningThread() const { - MutexLock mu(Thread::Current(), lock_); - return running_thread_; +bool TaskProcessor::WaitForThread(Thread* self) { + // Waiting for too little time here may cause us to fail to get stack traces, since we can't + // safely do so without identifying a HeapTaskDaemon to avoid it. Waiting too long could + // conceivably deadlock if we somehow try to get a stack trace on the way to starting the + // HeapTaskDaemon. Under normal circumstances. this should terminate immediately, since + // HeapTaskDaemon should normally be running. + constexpr int kTotalWaitMillis = 100; + for (int i = 0; i < kTotalWaitMillis; ++i) { + if (is_running_) { + return true; + } + cond_.TimedWait(self, 1 /*msecs*/, 0 /*nsecs*/); + } + LOG(ERROR) << "No identifiable HeapTaskDaemon; unsafe to get thread stacks."; + return false; +} + +bool TaskProcessor::IsRunningThread(Thread* t, bool wait) { + Thread* self = Thread::Current(); + MutexLock mu(self, lock_); + if (wait && !WaitForThread(self)) { + // If Wait failed, either answer may be correct; in our case, true is safer. + return true; + } + return running_thread_ == t; } void TaskProcessor::Stop(Thread* self) { -- cgit v1.2.3-59-g8ed1b