summaryrefslogtreecommitdiff
path: root/runtime/native/java_lang_Thread.cc
diff options
context:
space:
mode:
author Hans Boehm <hboehm@google.com> 2023-03-29 01:24:05 +0000
committer Gerrit Code Review <noreply-gerritcodereview@google.com> 2023-03-29 01:24:05 +0000
commit63af30b8fe8d4e1dc32db4dcb5e5dae1efdc7f31 (patch)
tree2c4374ef7c7561d7e9157a8bd32d9e3bee069be5 /runtime/native/java_lang_Thread.cc
parent221b6c5fcd66d4b6f2626c311d03bde2fb1589f9 (diff)
Revert "Revert^8 "Thread suspension cleanup and deadlock fix""
This reverts commit 221b6c5fcd66d4b6f2626c311d03bde2fb1589f9. Reason for revert: Preemptive revert. Earlier versions have had a tendency to cause subtle breakage. Please do not submit unless something breaks. Change-Id: Iad2a7f920756f365789c422948632f5db5a28fd5
Diffstat (limited to 'runtime/native/java_lang_Thread.cc')
-rw-r--r--runtime/native/java_lang_Thread.cc8
1 files changed, 7 insertions, 1 deletions
diff --git a/runtime/native/java_lang_Thread.cc b/runtime/native/java_lang_Thread.cc
index fd67a0a7fa..570c554782 100644
--- a/runtime/native/java_lang_Thread.cc
+++ b/runtime/native/java_lang_Thread.cc
@@ -147,8 +147,11 @@ 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);
+ Thread* thread = thread_list->SuspendThreadByPeer(peer,
+ SuspendReason::kInternal,
+ &timed_out);
if (thread != nullptr) {
{
ScopedObjectAccess soa(env);
@@ -156,6 +159,9 @@ 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.";
}
}