| HeapWorker.c uses pthreads. doing a quick check on one of the functions dvmLockMutex (in Thread.h) uses pthread_mutex_lock. // Grab a plain mutex. INLINE void dvmLockMutex(pthread_mutex_t pMutex)
{ int cc __attribute__ ((__unused__)) =
pthread_mutex_lock(pMutex); assert(cc == 0);
}and here's pthread_mutex_lock. int pthread_mutex_lock(pthread_mutex_t mutex)
{
if (mutex->kind == PTHREAD_MUTEX_NORMAL)
{
if (atomic_exchange(&mutex->lock, 1) != 0)
{
while (atomic_exchange(&mutex->lock, -1) != 0)
{ if (wait(mutex->event, INFINITE) != 0) return EINVAL;
}
}
}
else
{
pthread_t self = pthread_self();
if (atomic_exchange(&mutex->lock, 1) == 0)
{
mutex->recursion = 1;
mutex->owner = self;
}
else
{
if (pthread_equal(mutex->owner, self))
{
if (mutex->kind == PTHREAD_MUTEX_RECURSIVE)
mutex->recursion++;
else
return EDEADLK;
}
else
{
while (atomic_exchange(&mutex->lock, -1) != 0)
{
if (wait(mutex->event, INFINITE) != 0) return EINVAL;
mutex->recursion = 1;
mutex->owner = self;
}
}
}
}
return 0;
}and here's an excerpt of dalvik/vm/Thread.c Notes on Threading All threads are native pthreads. All threads, except the JDWP debugger
thread, are visible to code running in the VM and to the debugger. (We
don't want the debugger to try to manipulate the thread that listens for
instructions from the debugger.) Internal VM threads are in the "system"
ThreadGroup, all others are in the "main" ThreadGroup, per convention. The GC only runs when all threads have been suspended. ... |
Although I don't understand how the memory management makes use of mutexes (once a (any?) thread realizes that the GC needs to be run, how does it wait until all threads have reached a safe point?), and I don't have time to check ATM.
[1] http://www.insomniacgames.com/tech/articles/0807/files/multi... mentions the pthread_mutex_lock and unlock code including an implementation of atomic_exchange