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

unmatching monitorenter/monitorexit and IllegalMonitorStateException

    Details

    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.4

      Description



      Name: akC45999 Date: 03/12/99



      The chapter 6 "The Java Virtual Machine Instruction Set" of revised
      VM specification reads:
      ...
      Otherwise, if the virtual machine implementation enforces the rules on
      structured use of locks described in 8.13 and if the first of those
      rules is violated during invocation of the current method, then return
      throws an IllegalMonitorStateException.
      ...

      The chapter 8.13 "Locks and Synchronization" of revised VM specification reads:
      ...
      Let T be a thread and L be a lock. Then:

       1.The number of lock operations performed by T on L during a method
          invocation must equal the number of unlock operations performed by T on L
          during the method invocation whether the method invocation completes
          normally or abruptly.
       2.At no point during a method invocation may the number of unlock operations
          performed by T on L since the method invocation exceed the number of lock
          operations performed by T on L since the method invocation.

      In less formal terms, during a method invocation every unlock operation on L
      must match some preceding lock operation on L.
      ...

      The following test shows JDK-1.2-V does not check violation of this rule.
      The same concerns JDK-1.2fcsQ.

      ------------------------------------- test.java --------------------------------

      import java.io.PrintStream;

      class test {

        public static void main(String argv[]) {

      try {
      Class.forName("BadClass");
      System.out.println("Expected exception was not thrown");
      } catch(Throwable e) {
      System.out.println(e);
      }
        }
      }

      ----------------------------------- BadClass.jasm ------------------------------

      class BadClass
      {

      static Method "<clinit>":"()V"
      stack 2 locals 1
      {
      new class java/lang/Object;
      dup;
      invokespecial Method java/lang/Object."<init>":"()V";
      monitorenter;
      return;
      }
      }

      --------------------------------------------------------------------------------

      novo48% javac test.java
      novo48% jasm BadClass.jasm
      novo48% java -fullversion
      java full version "JDK-1.2-V"
      novo48% java test
      Expected exception was not thrown
       
      ======================================================================

      ======================================================================

        Attachments

          Activity

            People

            • Assignee:
              apalanissunw Anand Palaniswamy (Inactive)
              Reporter:
              duke J. Duke (Inactive)
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                Imported:
                Indexed: