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

(ann) Java level Deadlock in the Annotation API

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Won't Fix
    • Icon: P3 P3
    • None
    • 6
    • core-libs
    • x86
    • windows_xp

      FULL PRODUCT VERSION :
      C:\thilak>"C:\Program Files\Java\jdk1.6.0_02\bin\java.exe" -version
      java version "1.6.0_02"
      Java(TM) SE Runtime Environment (build 1.6.0_02-b06)
      Java HotSpot(TM) Client VM (build 1.6.0_02-b06, mixed mode, sharing)


      ADDITIONAL OS VERSION INFORMATION :
      C:\thilak>ver

      Microsoft Windows XP [Version 5.1.2600]

      EXTRA RELEVANT SYSTEM CONFIGURATION :
      This bug is reproducable with jdk1.5.0_08 as well, and on the GNU/Linux system also, where it was first detected.

      A DESCRIPTION OF THE PROBLEM :
      Below is reproduced a program that, on execution, deadlocks the executing JVM: The file-name is called "Dl.java".


      C:\thilak>"C:\Program Files\Java\jdk1.6.0_02\bin\javac.exe" Dl.java
      Dl.java:28: warning: sun.reflect.annotation.AnnotationType is Sun proprietary API and may be removed in a future release
      AnnotationType test = AnnotationType.getInstance (Class.forName(className));
      ^
      Dl.java:28: warning: sun.reflect.annotation.AnnotationType is Sun proprietary API and may be removed in a future release
      AnnotationType test = AnnotationType.getInstance (Class.forName(className));
                            ^
      2 warnings

      C:\thilak>"C:\Program Files\Java\jdk1.6.0_02\bin\java.exe" Dl Test
      2007-07-28 13:25:08
      Full thread dump Java HotSpot(TM) Client VM (1.6.0_02-b06 mixed mode, sharing):

      "DestroyJavaVM" prio=6 tid=0x002a5c00 nid=0xa74 waiting on condition [0x00000000..0x0090fd4c]
         java.lang.Thread.State: RUNNABLE

      "Thread-1" prio=6 tid=0x02a91c00 nid=0x16b0 waiting for monitor entry [0x02e6f000..0x02e6fb14]
         java.lang.Thread.State: BLOCKED (on object monitor)
              at java.lang.Class.initAnnotationsIfNecessary(Class.java:3069)
              - waiting to lock <0x26995b40> (a java.lang.Class for Test)
              at java.lang.Class.getAnnotation(Class.java:3029)
              at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:113)
              at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:66)
              - locked <0x26996d18> (a java.lang.Class for sun.reflect.annotation.AnnotationType)
              at Dl$Thread2.run(Dl.java:28)

      "Thread-0" prio=6 tid=0x02a90c00 nid=0x1254 waiting for monitor entry [0x02e1f000..0x02e1fb94]
         java.lang.Thread.State: BLOCKED (on object monitor)
              at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:63)
              - waiting to lock <0x26996d18> (a java.lang.Class for sun.reflect.annotation.AnnotationType)
              at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:202)
              at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
              at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
              at java.lang.Class.initAnnotationsIfNecessary(Class.java:3072)
              - locked <0x26995b40> (a java.lang.Class for Test)
              at java.lang.Class.getAnnotations(Class.java:3052)
              at Dl$Thread1.run(Dl.java:16)

      "Low Memory Detector" daemon prio=6 tid=0x02a7c800 nid=0x920 runnable [0x00000000..0x00000000]
         java.lang.Thread.State: RUNNABLE

      "CompilerThread0" daemon prio=10 tid=0x02a77c00 nid=0x10e0 waiting on condition [0x00000000..0x02d2f91c]
         java.lang.Thread.State: RUNNABLE

      "Attach Listener" daemon prio=10 tid=0x02a76800 nid=0xd4c runnable [0x00000000..0x00000000]
         java.lang.Thread.State: RUNNABLE

      "Signal Dispatcher" daemon prio=10 tid=0x02a75c00 nid=0x15e4 waiting on condition [0x00000000..0x00000000]
         java.lang.Thread.State: RUNNABLE

      "Finalizer" daemon prio=8 tid=0x02a6dc00 nid=0xeb4 in Object.wait() [0x02c3f000..0x02c3fa94]
         java.lang.Thread.State: WAITING (on object monitor)
              at java.lang.Object.wait(Native Method)
              - waiting on <0x22990b38> (a java.lang.ref.ReferenceQueue$Lock)
              at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:116)
              - locked <0x22990b38> (a java.lang.ref.ReferenceQueue$Lock)
              at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:132)
              at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:159)

      "Reference Handler" daemon prio=10 tid=0x02a6cc00 nid=0x7c4 in Object.wait() [0x02bef000..0x02befb14]
         java.lang.Thread.State: WAITING (on object monitor)
              at java.lang.Object.wait(Native Method)
              - waiting on <0x22990a38> (a java.lang.ref.Reference$Lock)
              at java.lang.Object.wait(Object.java:485)
              at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)
              - locked <0x22990a38> (a java.lang.ref.Reference$Lock)

      "VM Thread" prio=10 tid=0x02a63c00 nid=0xc0c runnable

      "VM Periodic Task Thread" prio=10 tid=0x02a7e000 nid=0x1d8 waiting on condition

      JNI global references: 571


      Found one Java-level deadlock:
      =============================
      "Thread-1":
        waiting to lock monitor 0x02a6ee5c (object 0x26995b40, a java.lang.Class),
        which is held by "Thread-0"
      "Thread-0":
        waiting to lock monitor 0x02a6eec4 (object 0x26996d18, a java.lang.Class),
        which is held by "Thread-1"

      Java stack information for the threads listed above:
      ===================================================
      "Thread-1":
              at java.lang.Class.initAnnotationsIfNecessary(Class.java:3069)
              - waiting to lock <0x26995b40> (a java.lang.Class for Test)
              at java.lang.Class.getAnnotation(Class.java:3029)
              at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:113)
              at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:66)
              - locked <0x26996d18> (a java.lang.Class for sun.reflect.annotation.AnnotationType)
              at Dl$Thread2.run(Dl.java:28)
      "Thread-0":
              at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:63)
              - waiting to lock <0x26996d18> (a java.lang.Class for sun.reflect.annotation.AnnotationType)
              at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:202)
              at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:69)
              at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:52)
              at java.lang.Class.initAnnotationsIfNecessary(Class.java:3072)
              - locked <0x26995b40> (a java.lang.Class for Test)
              at java.lang.Class.getAnnotations(Class.java:3052)
              at Dl$Thread1.run(Dl.java:16)

      Found 1 deadlock.


      STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
      Copy the java code from below into a text file called Dl.java.
      Compile it through using the javac Comnpiler to fetch Dl.class.
      Copy another peice of code below into a file called Test.java.
      Compile it through the use of javac compiler to fetch the file Test.class.

      On the command line execute the command: "java Dl Test".
      Often the command will just hang, implying that the executing jvm has deadlocked.
      Ctrl-break fetches the output pasted in the description above.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      The jvm neednot deadlock as it sometimes does when executing this otherwise perfectly legal, and well-formed java-program.
      ACTUAL -
      See description above.

      ERROR MESSAGES/STACK TRACES THAT OCCUR :
      See description above.

      REPRODUCIBILITY :
      This bug can be reproduced often.

      ---------- BEGIN SOURCE ----------
      Dl.java:
      import java.lang.annotation.Annotation;
      import sun.reflect.annotation.*;
      public class Dl {
          public Dl (String s) {
              new Thread1(s).start();
              new Thread2(s).start();
          }
          public static void main(String[] args) {
              Dl dl = new Dl(args[0]);
          }
          class Thread1 extends Thread {
              String className;
              public Thread1 (String name) { className = name; }
              public void run() {
                  try {
                      Annotation[] annArray = Class.forName(className).getAnnotations();
                      for (Annotation a: annArray) System.out.println (a);
                  } catch (Exception e) {
                      System.out.printf ("Thread1 failes: %s %n", e.getCause());
                  }
              }
          }
          class Thread2 extends Thread {
              String className;
              public Thread2 (String name) { className = name; }
              public void run() {
                  try {
                       AnnotationType test = AnnotationType.getInstance (Class.forName(className));
                       System.out.println (test);
                  } catch (Exception e) {
                       System.out.printf ("Thread2 failes: %s %n", e.getCause());
                  }
              }
          }
      }

      Test.java:
      import java.lang.annotation.*;
      @Retention(RetentionPolicy.RUNTIME)
      @Target(ElementType.METHOD)
      public @interface Test {}

      ---------- END SOURCE ----------

            darcy Joe Darcy
            ryeung Roger Yeung (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: