diff options
author | 2023-03-29 01:24:05 +0000 | |
---|---|---|
committer | 2023-03-29 01:24:05 +0000 | |
commit | 63af30b8fe8d4e1dc32db4dcb5e5dae1efdc7f31 (patch) | |
tree | 2c4374ef7c7561d7e9157a8bd32d9e3bee069be5 /runtime/native/dalvik_system_VMStack.cc | |
parent | 221b6c5fcd66d4b6f2626c311d03bde2fb1589f9 (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/dalvik_system_VMStack.cc')
-rw-r--r-- | runtime/native/dalvik_system_VMStack.cc | 29 |
1 files changed, 11 insertions, 18 deletions
diff --git a/runtime/native/dalvik_system_VMStack.cc b/runtime/native/dalvik_system_VMStack.cc index bf441b4b1d..71078c9ad2 100644 --- a/runtime/native/dalvik_system_VMStack.cc +++ b/runtime/native/dalvik_system_VMStack.cc @@ -48,29 +48,19 @@ static ResultT GetThreadStack(const ScopedFastNativeObjectAccess& soa, } else { // Never allow suspending the heap task thread since it may deadlock if allocations are // required for the stack trace. - Thread* heap_task_thread = nullptr; - for (int i = 0; i < 20; ++i) { - heap_task_thread = Runtime::Current()->GetHeap()->GetTaskProcessor()->GetRunningThread(); - if (heap_task_thread != nullptr) { - break; - } - // heap_task_thread could be null if the daemons aren't fully running yet. But it can appear - // in enumerations, and thus we could try to get its stack even before that. Try to wait - // for a non-null value so we can avoid suspending it. - static constexpr int kHeapTaskDaemonSleepMicros = 5000; - usleep(kHeapTaskDaemonSleepMicros); - } - if (heap_task_thread == nullptr) { - LOG(ERROR) << "No HeapTaskDaemon; refusing to get thread stack."; - return nullptr; - } - if (decoded_peer == heap_task_thread->GetPeerFromOtherThread()) { + Thread* heap_task_thread = + Runtime::Current()->GetHeap()->GetTaskProcessor()->GetRunningThread(); + // heap_task_thread could be null if the daemons aren't yet started. + if (heap_task_thread != nullptr && decoded_peer == heap_task_thread->GetPeerFromOtherThread()) { return nullptr; } // Suspend thread to build stack trace. ScopedThreadSuspension sts(soa.Self(), ThreadState::kNative); ThreadList* thread_list = Runtime::Current()->GetThreadList(); - Thread* thread = thread_list->SuspendThreadByPeer(peer, SuspendReason::kInternal); + bool timed_out; + Thread* thread = thread_list->SuspendThreadByPeer(peer, + SuspendReason::kInternal, + &timed_out); if (thread != nullptr) { // Must be runnable to create returned array. { @@ -80,6 +70,9 @@ static ResultT GetThreadStack(const ScopedFastNativeObjectAccess& soa, // Restart suspended thread. bool resumed = thread_list->Resume(thread, SuspendReason::kInternal); DCHECK(resumed); + } else if (timed_out) { + LOG(ERROR) << "Trying to get thread's stack failed as the thread failed to suspend within a " + "generous timeout."; } } return trace; |