JDK-7130572 : deadlock when class initialisation fails
  • Type: Bug
  • Component: hotspot
  • Sub-Component: runtime
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Not an Issue
  • OS: linux
  • CPU: x86
  • Submitted: 2012-01-17
  • Updated: 2012-03-20
  • Resolved: 2012-02-27
Related Reports
Relates :  
Description
FULL PRODUCT VERSION :
java version "1.7.0_02"
Java(TM) SE Runtime Environment (build 1.7.0_02-b13)
Java HotSpot(TM) 64-Bit Server VM (build 22.0-b10, mixed mode)


FULL OS VERSION :
Linux i44pc43 2.6.32-27-generic #49-Ubuntu SMP Thu Dec 2 00:51:09 UTC 2010 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
Initialisation of mutually dependent classes deadlocks when two threads concurrently initialise these classes, but their initialisation terminates abruptly.

THE PROBLEM WAS REPRODUCIBLE WITH -Xint FLAG: Yes

THE PROBLEM WAS REPRODUCIBLE WITH -server FLAG: Yes

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. compile with javac
2. run as "java Main"

EXPECTED VERSUS ACTUAL BEHAVIOR :
Expected: terminate
Actual: deadlock
REPRODUCIBILITY :
This bug can be reproduced always.

---------- BEGIN SOURCE ----------
class A {
    static boolean x = B.b;
    static boolean a = true;
}
class B {
    static boolean b = true;
    static { if (A.a) throw new Error();  }
}
class Main {
    public static void main(String[] args) {
        Thread t1 = new Thread() {
                public void run() {
                    new A();
                }
            };
        Thread t2 = new Thread() {
                public void run() {
                    new B();
                }
            };
        t1.start();
        t2.start();
    }
}
---------- END SOURCE ----------

Comments
EVALUATION No further information was forthcoming. CR can be re-opened if new information is provided.
27-02-2012

EVALUATION I don't see anything special about the initialization failing. This is a classic class initialization deadlock as allowed by the specification for class initialization. The static initializer for A will initialize B and vice-versa. One thread initializes A first and the other B first. If each thread commences initialization of one class they will each hold the initialization lock for that class. When they try to initialize the other class they will both have to wait as the locks are held. Each thread is waiting for a lock held by the other - deadlock. Unless there is additional information to be provided here regarding the significance of the error condition I will close this as "not a defect".
19-01-2012