The concurrent collector may initiate a collection, holding the heap
worker lock, while the heap worker thread starts up. This causes the
thread suspension to wait indefinitely for the heap worker thread and
forces a VM abort. The following stack trace is logged:
#00 __futex_syscall3
#01 pthread_mutex_lock<-_normal_lock
#02 heapWorkerThreadStart<-dvmLockMutex
#03 internalThreadStart
#04 __thread_entry
#05 pthread_create
This change puts the heap worker thread in to the VM wait state while
it acquires its locks during startup thereby avoiding the crash. The
first dvmLockMutex substituted seems to have quelled the crashes at
startup. The second may be unnecessary but seems benign.
Change-Id: I208b559bcd01de6628f1b79ed6eef17f1536cbbc
LOGV("HeapWorker thread started (threadid=%d)\n", self->threadId);
/* tell the main thread that we're ready */
- dvmLockMutex(&gDvm.heapWorkerLock);
+ lockMutex(&gDvm.heapWorkerLock);
gDvm.heapWorkerReady = true;
dvmSignalCond(&gDvm.heapWorkerCond);
dvmUnlockMutex(&gDvm.heapWorkerLock);
- dvmLockMutex(&gDvm.heapWorkerLock);
+ lockMutex(&gDvm.heapWorkerLock);
while (!gDvm.haltHeapWorker) {
struct timespec trimtime;
bool timedwait = false;