From 9ef9d9619d8aee4a0805b304516d33e803483a1b Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Tue, 1 Feb 2011 17:45:43 -0700 Subject: [PATCH] avoid deadlock due to entering active state before running destroyJavaVM We risked deadlock when waiting for other non-daemon threads to exit since they could not exit without entering exclusive state, which required waiting for all other threads to go idle. --- src/jnienv.cpp | 2 +- src/machine.h | 11 +++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/jnienv.cpp b/src/jnienv.cpp index 479fe9deb5..eebbf2ad6d 100644 --- a/src/jnienv.cpp +++ b/src/jnienv.cpp @@ -91,7 +91,7 @@ DestroyJavaVM(Machine* m) { Thread* t; AttachCurrentThread(m, &t, 0); - if (run(t, destroyJavaVM, 0)) { + if (runRaw(t, destroyJavaVM, 0)) { t->exit(); return 0; } else { diff --git a/src/machine.h b/src/machine.h index e7b30539dd..cdaa703caa 100644 --- a/src/machine.h +++ b/src/machine.h @@ -1912,12 +1912,19 @@ instanceOf(Thread* t, object class_, object o); #include "type-declarations.cpp" +inline uint64_t +runRaw(Thread* t, + uint64_t (*function)(Thread*, uintptr_t*), uintptr_t* arguments) +{ + Thread::RunCheckpoint checkpoint(t); + return vmRun(function, arguments, &checkpoint); +} + inline uint64_t run(Thread* t, uint64_t (*function)(Thread*, uintptr_t*), uintptr_t* arguments) { ENTER(t, Thread::ActiveState); - Thread::RunCheckpoint checkpoint(t); - return vmRun(function, arguments, &checkpoint); + return runRaw(t, function, arguments); } inline void