diff options
| -rw-r--r-- | src/oatexec.cc | 4 | ||||
| -rw-r--r-- | src/thread.cc | 8 |
2 files changed, 12 insertions, 0 deletions
diff --git a/src/oatexec.cc b/src/oatexec.cc index 4f7228bb75..4f068db9a2 100644 --- a/src/oatexec.cc +++ b/src/oatexec.cc @@ -172,10 +172,14 @@ int oatexec(int argc, char** argv) { int rc = InvokeMain(env, &argv[arg_idx]); +#if defined(NDEBUG) + // The DestroyJavaVM call will detach this thread for us. In debug builds, we don't want to + // detach because detaching disables the CheckSafeToLockOrUnlock checking. if (vm->DetachCurrentThread() != JNI_OK) { fprintf(stderr, "Warning: unable to detach main thread\n"); rc = EXIT_FAILURE; } +#endif if (vm->DestroyJavaVM() != 0) { fprintf(stderr, "Warning: runtime did not shut down cleanly\n"); diff --git a/src/thread.cc b/src/thread.cc index 37d366d215..10b099d48a 100644 --- a/src/thread.cc +++ b/src/thread.cc @@ -1753,6 +1753,10 @@ std::ostream& operator<<(std::ostream& os, const Thread& thread) { } void Thread::CheckSafeToLockOrUnlock(MutexRank rank, bool is_locking) { + if (this == NULL) { + CHECK(Runtime::Current()->IsShuttingDown()); + return; + } if (is_locking) { if (held_mutexes_[rank] == 0) { bool bad_mutexes_held = false; @@ -1772,6 +1776,10 @@ void Thread::CheckSafeToLockOrUnlock(MutexRank rank, bool is_locking) { } void Thread::CheckSafeToWait(MutexRank rank) { + if (this == NULL) { + CHECK(Runtime::Current()->IsShuttingDown()); + return; + } bool bad_mutexes_held = false; for (int i = kMaxMutexRank; i >= 0; --i) { if (i != rank && held_mutexes_[i] != 0) { |