wait until all non-daemon threads exit before invoking the class library shutdown method

Running the shutdown method prematurely can cause deadlock in
OpenJDK's AWT implementation and may have other nasty effects besides
that.
This commit is contained in:
Joel Dice 2013-05-13 13:17:42 -06:00
parent fcfdd6be3a
commit 6507150246

View File

@ -74,12 +74,20 @@ DetachCurrentThread(Machine* m)
uint64_t
destroyJavaVM(Thread* t, uintptr_t*)
{
// wait for other non-daemon threads to exit
{ ACQUIRE(t, t->m->stateLock);
while (t->m->liveCount - t->m->daemonCount > 1) {
t->m->stateLock->wait(t->systemThread, 0);
}
}
{ ENTER(t, Thread::ActiveState);
t->m->classpath->shutDown(t);
}
// wait for other non-daemon threads to exit
// wait again in case the Classpath::shutDown process started new
// threads:
{ ACQUIRE(t, t->m->stateLock);
while (t->m->liveCount - t->m->daemonCount > 1) {
t->m->stateLock->wait(t->systemThread, 0);