JDK-4414755 : Code gen'ed for synchronized(){} can cause VM to enter an infinite loop
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.4.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: solaris_7
  • CPU: generic
  • Submitted: 2001-02-13
  • Updated: 2001-09-24
  • Resolved: 2001-09-24
Related Reports
Duplicate :  
Description
The code we generate for

	synchronized {
		f();
	}

can cause the VM to enter an infinite loop if the monitor
is in an inconsistent state at the monitorexit instruction.
That is because we catch the IllegalMonitorStateException 
and retry the monitorexit. We should allow the 
IllegalMonitorStateException to propogate.

The interesting case in the code below is an exception
occurring at instruction 5 or 11.

frog$ cat -n T.java
     1  class T {
     2      void f() {
     3          synchronized (this) {
     4          }
     5      }
     6  }
frog$ javap -c T
Compiled from T.java
synchronized class T extends java.lang.Object 
    /* ACC_SUPER bit set */
{
    T();
    void f();
}

Method T()
   0 aload_0
   1 invokespecial #1 <Method java.lang.Object()>
   4 return

Method void f()
   0 aload_0
   1 astore_1
   2 aload_1
   3 monitorenter
   4 aload_1
   5 monitorexit
   6 goto 14
   9 astore_2
  10 aload_1
  11 monitorexit
  12 aload_2
  13 athrow
  14 return
Exception table:
   from   to  target type
     4     6     9   any
     9    12     9   any
frog$ 

Comments
EVALUATION Right. The second exception range should catch only ThreadDeath. neal.gafter@Eng 2001-02-13
13-02-2001

SUGGESTED FIX The second exception range should catch only ThreadDeath. neal.gafter@Eng 2001-02-13
13-02-2001