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

synchronized methods with jsr's not unlocked correctly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 6
    • 6
    • hotspot
    • None
    • b88
    • sparc
    • solaris_9

      6320351 included changes to the way synchronized methods were unlocked to make the exception paths and jvmpi support simpler to implement. This broke the unlocking of synchonized methods when exceptions are thrown inside jsrs because the synthetic block handling the unlocking wasn't seen when processing exception edges while parsing jsrs. Here's a test case for this which must be compiled with a javac that uses jsr/ret for finally blocks.

      public class SyncJSR {
          private int count = 0;
          private int[] ia = new int[1];

          public synchronized void calc() {
              try {
                  count++;
              } finally {
                  // always throws a NullPointerException
                  ia[0] = 1;
              }
          }

          public void calcCatch() {
              try {
                  calc();
              } catch (NullPointerException ex) {
                  // catch the exception thrown in calc()
              }
          }

          public static void main(String[] args) {
              SyncJSR obj = new SyncJSR();

              for (int i = 0; i < 200000; i++) {
                  obj.calcCatch();
              }
              obj.ia = null;
              obj.calcCatch();

              try {
                  // Usually, this crashes the VM if the object was not unlocked correctly
                  obj.wait(1000);
              } catch (Exception ex) {
              }
          }
      }

            never Tom Rodriguez
            never Tom Rodriguez
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: