< prev index next >
src/java.base/share/classes/java/lang/reflect/Executable.java
Print this page
rev 11212 : 8068736: Avoid synchronization on Executable/Field.declaredAnnotations
Reviewed-by: jfranck
*** 586,611 ****
*/
public Annotation[] getDeclaredAnnotations() {
return AnnotationParser.toArray(declaredAnnotations());
}
! private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
! private synchronized Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
! if (declaredAnnotations == null) {
Executable root = getRoot();
if (root != null) {
! declaredAnnotations = root.declaredAnnotations();
} else {
! declaredAnnotations = AnnotationParser.parseAnnotations(
getAnnotationBytes(),
sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()),
! getDeclaringClass());
}
}
! return declaredAnnotations;
}
/**
* Returns an {@code AnnotatedType} object that represents the use of a type to
* specify the return type of the method/constructor represented by this
--- 586,618 ----
*/
public Annotation[] getDeclaredAnnotations() {
return AnnotationParser.toArray(declaredAnnotations());
}
! private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
! private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
! Map<Class<? extends Annotation>, Annotation> declAnnos;
! if ((declAnnos = declaredAnnotations) == null) {
! synchronized (this) {
! if ((declAnnos = declaredAnnotations) == null) {
Executable root = getRoot();
if (root != null) {
! declAnnos = root.declaredAnnotations();
} else {
! declAnnos = AnnotationParser.parseAnnotations(
getAnnotationBytes(),
sun.misc.SharedSecrets.getJavaLangAccess().
getConstantPool(getDeclaringClass()),
! getDeclaringClass()
! );
}
+ declaredAnnotations = declAnnos;
}
! }
! }
! return declAnnos;
}
/**
* Returns an {@code AnnotatedType} object that represents the use of a type to
* specify the return type of the method/constructor represented by this
< prev index next >