src/share/vm/runtime/thread.cpp
Print this page
@@ -1805,13 +1805,20 @@
// held by this thread must be released. A detach operation must only
// get here if there are no Java frames on the stack. Therefore, any
// owned monitors at this point MUST be JNI-acquired monitors which are
// pre-inflated and in the monitor cache.
//
- // ensure_join() ignores IllegalThreadStateExceptions, and so does this.
- if (exit_type == jni_detach && JNIDetachReleasesMonitors) {
- assert(!this->has_last_Java_frame(), "detaching with Java frames?");
+ // Optionally release any monitors for regular JavaThread exits. This
+ // is provided as a work around for any bugs in monitor enter-exit
+ // matching. This can be expensive so it is not enabled by default.
+ //
+ // ensure_join() ignores IllegalThreadStateExceptions, and so does
+ // ObjectSynchronizer::release_monitors_owned_by_thread().
+ if ((exit_type == jni_detach && JNIDetachReleasesMonitors) ||
+ JavaThreadExitReleasesMonitors) {
+ assert(!this->has_last_Java_frame(),
+ "should not have a Java frame when detaching or exiting");
ObjectSynchronizer::release_monitors_owned_by_thread(this);
assert(!this->has_pending_exception(), "release_monitors should have cleared");
}
// These things needs to be done while we are still a Java Thread. Make sure that thread