From 3b6ee1a417a717c44e2a59ed73c930f4be8ea54b Mon Sep 17 00:00:00 2001 From: Andy McFadden Date: Tue, 24 Aug 2010 14:23:11 -0700 Subject: [PATCH] Fix a DDMS thread monitoring crash. We changed the order of events during thread attaches, which means it's now possible to have Thread structs with null threadObj fields. This bit of code didn't change with the times, which made it possible for a process being watched by DDMS to crash if we grabbed the thread state at just the wrong time. (cherry-pick from dalvik-dev) Change-Id: Icd7f523ee8327f00693e601c1c82d3a8defb247f --- vm/Ddm.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/vm/Ddm.c b/vm/Ddm.c index 1aaebe031..774ed3fc9 100644 --- a/vm/Ddm.c +++ b/vm/Ddm.c @@ -285,8 +285,13 @@ void dvmDdmSendThreadNotification(Thread* thread, bool started) if (!gDvm.ddmThreadNotification) return; - StringObject* nameObj = (StringObject*) - dvmGetFieldObject(thread->threadObj, gDvm.offJavaLangThread_name); + StringObject* nameObj = NULL; + Object* threadObj = thread->threadObj; + + if (threadObj != NULL) { + nameObj = (StringObject*) + dvmGetFieldObject(threadObj, gDvm.offJavaLangThread_name); + } int type, len; u1 buf[256]; @@ -500,15 +505,18 @@ ArrayObject* dvmDdmGenerateThreadStats(void) pid_t pid = getpid(); for (thread = gDvm.threadList; thread != NULL; thread = thread->next) { unsigned long utime, stime; - bool isDaemon; + bool isDaemon = false; if (!getThreadStats(pid, thread->systemTid, &utime, &stime)) { // failed; drop in empty values utime = stime = 0; } - isDaemon = dvmGetFieldBoolean(thread->threadObj, - gDvm.offJavaLangThread_daemon); + Object* threadObj = thread->threadObj; + if (threadObj != NULL) { + isDaemon = dvmGetFieldBoolean(threadObj, + gDvm.offJavaLangThread_daemon); + } set4BE(buf+0, thread->threadId); set1(buf+4, thread->status); -- 2.11.0