7037756: Deadlock in compiler thread similiar to 6789220
Summary: Avoid blocking in CompileBroker::compile_method_base() if the current thread holds the pending list lock.
Reviewed-by: never, brutisso, ysr
--- a/hotspot/src/share/vm/compiler/compileBroker.cpp Tue Apr 26 21:17:24 2011 -0700
+++ b/hotspot/src/share/vm/compiler/compileBroker.cpp Wed Apr 27 14:40:41 2011 -0700
@@ -976,6 +976,15 @@
return;
}
+ // If the requesting thread is holding the pending list lock
+ // then we just return. We can't risk blocking while holding
+ // the pending list lock or a 3-way deadlock may occur
+ // between the reference handler thread, a GC (instigated
+ // by a compiler thread), and compiled method registration.
+ if (instanceRefKlass::owns_pending_list_lock(JavaThread::current())) {
+ return;
+ }
+
// Outputs from the following MutexLocker block:
CompileTask* task = NULL;
bool blocking = false;
@@ -1304,17 +1313,8 @@
// Should the current thread be blocked until this compilation request
// has been fulfilled?
bool CompileBroker::is_compile_blocking(methodHandle method, int osr_bci) {
- if (!BackgroundCompilation) {
- Symbol* class_name = method->method_holder()->klass_part()->name();
- if (class_name->starts_with("java/lang/ref/Reference", 23)) {
- // The reference handler thread can dead lock with the GC if compilation is blocking,
- // so we avoid blocking compiles for anything in the java.lang.ref.Reference class,
- // including inner classes such as ReferenceHandler.
- return false;
- }
- return true;
- }
- return false;
+ assert(!instanceRefKlass::owns_pending_list_lock(JavaThread::current()), "possible deadlock");
+ return !BackgroundCompilation;
}