JDK-7171421 : deadlock in relection api
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 7
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: linux
  • CPU: x86
  • Submitted: 2012-05-24
  • Updated: 2012-05-24
  • Resolved: 2012-05-24
Related Reports
Duplicate :  
Description
FULL PRODUCT VERSION :
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) 64-Bit Server VM (build 21.0-b17, mixed mode)


ADDITIONAL OS VERSION INFORMATION :
Linux office604 2.6.32-41-generic #89-Ubuntu SMP Fri Apr 27 22:18:56 UTC 2012 x86_64 GNU/Linux

A DESCRIPTION OF THE PROBLEM :
  From jstack output below it is clear that 2 threads using java.lang.reflect apis may end up in a deadlock.


STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
reproducing deadlock is hard. I did not try.

ACTUAL -
I expect the java.lang.reflect api to never deadlock.

ERROR MESSAGES/STACK TRACES THAT OCCUR :

Found one Java-level deadlock:
=============================
"JLECThread":
  waiting to lock monitor 0x00007f8b48005bb8 (object 0x00000007f8fca6d8, a java.lang.Class),
  which is held by "main"
"main":
  waiting to lock monitor 0x00007f8b48003d88 (object 0x00000007f90b0920, a java.lang.Class),
  which is held by "JLECThread"

Java stack information for the threads listed above:
===================================================
"JLECThread":
	at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:81)
	- waiting to lock <0x00000007f8fca6d8> (a java.lang.Class for sun.reflect.annotation.AnnotationType)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:221)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
	at java.lang.Class.initAnnotationsIfNecessary(Class.java:3087)
	- locked <0x00000007f90b0920> (a java.lang.Class for c.i.f.m.s.MF)
	at java.lang.Class.getAnnotations(Class.java:3067)
	at org.springframework.core.type.classreading.AnnotationAttributesReadingVisitor.visitEnd(AnnotationAttributesReadingVisitor.java:131)
	at <snip snip>

"main":
	at java.lang.Class.initAnnotationsIfNecessary(Class.java:3084)
	- waiting to lock <0x00000007f90b0920> (a java.lang.Class for c.i.f.m.s.MF)
	at java.lang.Class.getAnnotation(Class.java:3046)
	at sun.reflect.annotation.AnnotationType.<init>(AnnotationType.java:131)
	at sun.reflect.annotation.AnnotationType.getInstance(AnnotationType.java:84)
	- locked <0x00000007f8fca6d8> (a java.lang.Class for sun.reflect.annotation.AnnotationType)
	at sun.reflect.annotation.AnnotationParser.parseAnnotation(AnnotationParser.java:221)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations2(AnnotationParser.java:88)
	at sun.reflect.annotation.AnnotationParser.parseAnnotations(AnnotationParser.java:70)
	at java.lang.reflect.Field.declaredAnnotations(Field.java:1032)
	- locked <0x000000074e674b38> (a java.lang.reflect.Field)
	at java.lang.reflect.Field.getAnnotation(Field.java:1018)
	at c.i.f.m.s.i.AR.f(AR.java:589)
	at <snip snip>

Found 1 deadlock.

REPRODUCIBILITY :
This bug can be reproduced rarely.