From fe9b34f845e8e439b4ae47ae999ef2cfdbd66462 Mon Sep 17 00:00:00 2001 From: Hans Boehm Date: Tue, 25 Oct 2022 00:32:26 +0000 Subject: Revert^6 "Thread suspension cleanup and deadlock fix" This reverts commit 0db9605ec8bd3158f4f0107a511dd09a889c9341. PS1: Identical to aosp/2255904 PS2: Detect and report excessive waiting for a suspend-friendly state. Add internal timeout to 129-ThreadGetId, so that we can print more state information on exit. We explicitly avoid suspending the HeapTaskDaemon to retrieve its stack trace. Fix a race that allowed this to happen anyway (with very low probability). Includes a slightly nontrivial rebase. PS3: Address a couple of minor comments. PS4: Reformatted, as suggested by the upload script, except for tls_ptr_sized_values, where it seemed too likely to cause unnecessary merge conflicts. PS5: SuspendAllInternal does not hold mutator lock, but may take a long time with suspend_all_count_ = 1. Another thread waiting for suspend_all_count_ could sleep many times. Explicitly wait on a condition variable instead. This intentionally has a low kMaxSuspendRetries so that we can see whether it is hit in presubmit. PS6: Adjust kMaxSuspendRetries to a bit lower than the PS3/PS4 version, but much higher than the PS5 debug version. Test: Build and boot AOSP, Treehugger Bug: 240742796 Bug: 203363895 Bug: 238032384 Bug: 253671779 Change-Id: I58d63f494a7454e00473b23864f8952abed7bf6f --- runtime/native/java_lang_Thread.cc | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) (limited to 'runtime/native/java_lang_Thread.cc') diff --git a/runtime/native/java_lang_Thread.cc b/runtime/native/java_lang_Thread.cc index 570c554782..fd67a0a7fa 100644 --- a/runtime/native/java_lang_Thread.cc +++ b/runtime/native/java_lang_Thread.cc @@ -147,11 +147,8 @@ static void Thread_setNativeName(JNIEnv* env, jobject peer, jstring java_name) { // thread list lock to avoid this, as setting the thread name causes mutator to lock/unlock // in the DDMS send code. ThreadList* thread_list = Runtime::Current()->GetThreadList(); - bool timed_out; // Take suspend thread lock to avoid races with threads trying to suspend this one. - Thread* thread = thread_list->SuspendThreadByPeer(peer, - SuspendReason::kInternal, - &timed_out); + Thread* thread = thread_list->SuspendThreadByPeer(peer, SuspendReason::kInternal); if (thread != nullptr) { { ScopedObjectAccess soa(env); @@ -159,9 +156,6 @@ static void Thread_setNativeName(JNIEnv* env, jobject peer, jstring java_name) { } bool resumed = thread_list->Resume(thread, SuspendReason::kInternal); DCHECK(resumed); - } else if (timed_out) { - LOG(ERROR) << "Trying to set thread name to '" << name.c_str() << "' failed as the thread " - "failed to suspend within a generous timeout."; } } -- cgit v1.2.3-59-g8ed1b