Dead lock condition, GC Thread and HeapWorkerThread

272 views
Skip to first unread message

Neo

unread,
Sep 8, 2011, 2:34:36 AM9/8/11
to android-platform
There is a dead lock between main thread and HeapWorkerThread.
Is there any way to avoid dead lock condition??

1. GC thread requests a all thread to suspend.
(dvmCollectGarbageInternal -> dvmSuspendAllThreads)
2. HeapWorkerThread could suspend with heapWorkerLock mutex.
(doHeapWork -> callMethod -> lockMutex -> dvmChangeStatus ->
fullSuspendCheck -> dvmWaitCond)
3. GC thread request heapWorkerLock mutex. (dvmCollectGarbageInternal -
> dvmLockMutex)
4. GC thread could not acquire heapWorkerLock mutex because
HeapWorkerThread is sleep with heapWorkerLock mutex.


Main GC Thread
#0 __futex_syscall3 () at bionic/libc/arch-arm/bionic/atomics_arm.S:
200
#1 0xafd110fc in _normal_lock (mutex=0x802ac094) at bionic/libc/
bionic/pthread.c:937
#2 pthread_mutex_lock (mutex=0x802ac094) at bionic/libc/bionic/
pthread.c:1027
#3 0x802204c0 in dvmLockMutex (clearSoftRefs=<value optimized out>,
reason=GC_EXPLICIT) at dalvik/vm/Thread.h:366
#4 dvmCollectGarbageInternal (clearSoftRefs=<value optimized out>,
reason=GC_EXPLICIT) at dalvik/vm/alloc/Heap.c:644
#5 0x802552ee in dvmCollectGarbage (collectSoftReferences=false) at
dalvik/vm/alloc/Alloc.c:301
#6 0x80267348 in Dalvik_java_lang_Runtime_gc (args=<value optimized
out>, pResult=0x80) at dalvik/vm/native/java_lang_Runtime.c:34
#7 0x8021d1cc in dalvik_mterp () at dalvik/vm/mterp/out/InterpAsm-
armv7-a.S:10017
#8 0x802222f8 in dvmMterpStd (self=<value optimized out>,
glue=0xbef86498) at dalvik/vm/mterp/Mterp.c:105
#9 0x802211dc in dvmInterpret (self=0xd088, method=0x618cfb14,
pResult=<value optimized out>) at dalvik/vm/interp/Interp.c:1345
#10 0x80260220 in dvmInvokeMethod (obj=<value optimized out>,
method=0x618cfb14, argList=<value optimized out>,
params=<value optimized out>, returnType=0x40101320,
noAccessCheck=<value optimized out>) at dalvik/vm/interp/Stack.c:742
#11 0x80268036 in Dalvik_java_lang_reflect_Method_invokeNative
(args=<value optimized out>, pResult=0xbef867f0)


HeapWorkerThread
#0 __futex_syscall3 () at bionic/libc/arch-arm/bionic/atomics_arm.S:
200
#1 0xafd113e0 in __pthread_cond_timedwait_relative (cond=0x802abff8,
mutex=0x802abff4, reltime=0x0) at bionic/libc/bionic/pthread.c:1451
#2 0xafd114b4 in __pthread_cond_timedwait (cond=0x802abff8,
mutex=0x802abff4, abstime=0x0, clock=0) at bionic/libc/bionic/
pthread.c:1474
#3 0x8025276c in dvmWaitCond (self=0x101200) at dalvik/vm/Thread.h:
412
#4 fullSuspendCheck (self=0x101200) at dalvik/vm/Thread.c:3062
#5 0x802530fe in dvmChangeStatus (self=0xfffffe00,
newStatus=THREAD_RUNNING) at dalvik/vm/Thread.c:3163
#6 0x802563da in lockMutex (mu=<value optimized out>) at dalvik/vm/
alloc/HeapWorker.c:210
#7 0x80256442 in callMethod (self=0x101200, obj=0x407d0de8,
method=0x61854c10) at dalvik/vm/alloc/HeapWorker.c:249
#8 0x802564b8 in doHeapWork (self=0x101200) at dalvik/vm/alloc/
HeapWorker.c:307
#9 0x8025664a in heapWorkerThreadStart (arg=<value optimized out>) at
dalvik/vm/alloc/HeapWorker.c:437
#10 0x802544bc in internalThreadStart (arg=<value optimized out>) at
dalvik/vm/Thread.c:1915

Neo

unread,
Sep 8, 2011, 4:02:29 AM9/8/11
to android-platform

If i change order dvmLockMutex <-> dvmChangeStatus,
The dead lock would be clear. Is there any gool solution??
HeapWorkerThread would be suspend or running state after
dvmChangeStatus,
so, there is no reason acquire mutex before dvmChangeStatus.

199 static void lockMutex(pthread_mutex_t *mu)
200 {
201 Thread *self;
202 ThreadStatus oldStatus;
203
204 assert(mu != NULL);
205 if (dvmTryLockMutex(mu) != 0) {
206 self = dvmThreadSelf();
207 assert(self != NULL);
208 oldStatus = dvmChangeStatus(self, THREAD_VMWAIT);
209 dvmLockMutex(mu);
210 dvmChangeStatus(self, oldStatus);
211 }
212 }
Reply all
Reply to author
Forward
0 new messages