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

athrow does not throw an IllegalMonitorStateException

    XMLWordPrintable

Details

    • sparc
    • solaris_7

    Description



      Name: dkC59003 Date: 09/01/99



      The classic VM (J2SDK 1.3beta) does not throw an IllegalMonitorStateException
      when athrow instruction is executed in a synchronized method
      and the current thread is not the owner of the monitor.

      The athrow instruction specification (The JVM Specification (2nd edition),
      chapter 6, page 187) says:

      "...
       Otherwise, if the method of the current frame is a synchronized method and the
       current thread is not the owner of the monitor acquired or reentered on
       invocation of the method, athrow throws an IllegalMonitorStateException instead of
       the object previously being thrown. This can happen, for example, if an abruptly
       completing synchronized method contains a monitorexit instruction, but no
       monitorenter instruction, on the object on which the method is synchronized.
      ..."

      If the JVM corresponds to the considered assertion, then the test (below)
      must return the integer value 0 (expected result - STATUS_PASSED).

      Otherwise, the test must return the integer value 2
      (unexpected result - STATUS_FAILED).

      The execution of this test under HotSpot Client VM mode produces 0 as
      result, ie the test is PASSED. In this case athrow instruction correctly
      throws an IllegalMonitorStateException.

      But the execution of this test under Classic VM mode produces 2 as
      result, ie the test is FAILED. In this case athrow instruction throws
      ArithmeticException instead of IllegalMonitorStateException.

      See logs and source below.

      For HotSpot Client VM mode:

      % java -version
      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Java(TM) HotSpot Client VM (build 1.3beta-O-release, 1.3beta-O-release, interpreted mode)
      % java athrow013011
      % echo $status
      0

      For Classic VM mode:

      % java -green -version
      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Classic VM (build 1.3beta-O, green threads, nojit)
      novo73% java -green athrow013011
      novo73% echo $status
      2

      or

      % java -native -version
      java version "1.3beta"
      Java(TM) 2 Runtime Environment, Standard Edition (build 1.3beta-O)
      Classic VM (build 1.3beta-O, native threads, nojit)
      % java -native athrow013011
      % echo $status
      2

      NOTES
         Under JVM 1.1.8 the test produces unexpected result too but
         this result differs from one under Classic VM (J2SDK 1.3beta):

      % java -version
      java version "1.1.8"
      % java athrow013011
      java.lang.NoClassDefFoundError
      % echo $status
      1

      ------------------------------ source text of test -----------------------
      public class athrow013011
      extends java/lang/Object
      {

      static Field test_result:"I";

      public static Method main:"([Ljava/lang/String;)V"
      stack 2 locals 1
      {
      aload_0;
      getstatic Field java/lang/System.out:"Ljava/io/PrintStream;";
      invokestatic Method run:"([Ljava/lang/String;Ljava/io/PrintStream;)I";
      // on stack - test_result
      invokestatic Method java/lang/System.exit:"(I)V";
      return;
      }

      public static Method run:"([Ljava/lang/String;Ljava/io/PrintStream;)I"
      stack 2 locals 2
      {
      iconst_0/*STATUS_PASSED*/;
      putstatic Field test_result:"I";

      new class athrow013011;
      dup;
      invokespecial Method <init>:"()V";
      // on stack - athrow013011 object

      try TRY0; // for IllegalMonitorStateException

      try TRY1; // for ArithmeticException

      invokevirtual Method test_body:"()V";
                      iconst_2/*STATUS_FAILED*/;
                      ireturn;

                      endtry TRY1;

                      catch TRY1 java/lang/ArithmeticException;
                      pop;
                      iconst_2/*STATUS_FAILED*/;
                      ireturn;

                      endtry TRY0;

                      catch TRY0 java/lang/IllegalMonitorStateException;
                      pop;

      getstatic Field test_result:"I";
      ireturn;
      }

      synchronized Method test_body:"()V"
      stack 2 locals 1
      {
      aload_0;
                      monitorexit; // monitor is freed

      new class java/lang/ArithmeticException;
      dup;
      invokenonvirtual Method java/lang/ArithmeticException.<init>:"()V";
      athrow; // must throw java/lang/IllegalMonitorStateException

      // if no any exception will be thrown
      iconst_2/*STATUS_FAILED*/;
      putstatic Field test_result:"I";

      return; // must throw java/lang/IllegalMonitorStateException
      }

      public Method <init>:"()V"
      stack 1 locals 1
      {
      aload_0;
      invokespecial Method java/lang/Object.<init>:"()V";
      return;
      }


      } // end Class athrow013011
      -------------------------------------- end of text of test -----------------------

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

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

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              dkhukhrosunw Dmitry Khukhro (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: