Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4414755

Code gen'ed for synchronized(){} can cause VM to enter an infinite loop

    • Icon: Bug Bug
    • Resolution: Duplicate
    • Icon: P4 P4
    • None
    • 1.4.0
    • tools
    • generic
    • solaris_7

      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$

            gafter Neal Gafter (Inactive)
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: