diff options
author | Sebastien Hertz <shertz@google.com> | 2014-03-25 17:53:48 +0100 |
---|---|---|
committer | Sebastien Hertz <shertz@google.com> | 2014-03-27 08:40:36 +0100 |
commit | 970c10e175b903c13fa3aea0231ce87834c4ca65 (patch) | |
tree | 51024460ff6da75eb016dbe62cb5d4f5e9c9a6c4 | |
parent | e1f77fde4e6f481dcf97512530a352e8d527033b (diff) | |
download | art-970c10e175b903c13fa3aea0231ce87834c4ca65.zip art-970c10e175b903c13fa3aea0231ce87834c4ca65.tar.gz art-970c10e175b903c13fa3aea0231ce87834c4ca65.tar.bz2 |
Do not suspend current thread to build stacktrace from DDMS
Avoids a failing CHECK in ThreadList::SuspendThreadByThreadId in the case we
try to suspend the current thread.
Bug: 12985512
Change-Id: I9434400a3625319855dd3841d8889117e57784e5
-rw-r--r-- | runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc index 1b9ebe4..a7ca0b8 100644 --- a/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc +++ b/runtime/native/org_apache_harmony_dalvik_ddmc_DdmVmInternal.cc @@ -44,23 +44,31 @@ static jboolean DdmVmInternal_getRecentAllocationStatus(JNIEnv*, jclass) { * NULL on failure, e.g. if the threadId couldn't be found. */ static jobjectArray DdmVmInternal_getStackTraceById(JNIEnv* env, jclass, jint thin_lock_id) { - // Suspend thread to build stack trace. - ThreadList* thread_list = Runtime::Current()->GetThreadList(); jobjectArray trace = nullptr; - bool timed_out; - Thread* thread = thread_list->SuspendThreadByThreadId(thin_lock_id, false, &timed_out); - if (thread != NULL) { - { - ScopedObjectAccess soa(env); - jobject internal_trace = thread->CreateInternalStackTrace(soa); - trace = Thread::InternalStackTraceToStackTraceElementArray(soa, internal_trace); - } - // Restart suspended thread. - thread_list->Resume(thread, false); + Thread* const self = Thread::Current(); + if (static_cast<uint32_t>(thin_lock_id) == self->GetThreadId()) { + // No need to suspend ourself to build stacktrace. + ScopedObjectAccess soa(env); + jobject internal_trace = self->CreateInternalStackTrace(soa); + trace = Thread::InternalStackTraceToStackTraceElementArray(soa, internal_trace); } else { - if (timed_out) { - LOG(ERROR) << "Trying to get thread's stack by id failed as the thread failed to suspend " - "within a generous timeout."; + // Suspend thread to build stack trace. + ThreadList* thread_list = Runtime::Current()->GetThreadList(); + bool timed_out; + Thread* thread = thread_list->SuspendThreadByThreadId(thin_lock_id, false, &timed_out); + if (thread != nullptr) { + { + ScopedObjectAccess soa(env); + jobject internal_trace = thread->CreateInternalStackTrace(soa); + trace = Thread::InternalStackTraceToStackTraceElementArray(soa, internal_trace); + } + // Restart suspended thread. + thread_list->Resume(thread, false); + } else { + if (timed_out) { + LOG(ERROR) << "Trying to get thread's stack by id failed as the thread failed to suspend " + "within a generous timeout."; + } } } return trace; |