< 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


 571     }
 572 
 573     /**
 574      * {@inheritDoc}
 575      * @throws NullPointerException {@inheritDoc}
 576      */
 577     @Override
 578     public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
 579         Objects.requireNonNull(annotationClass);
 580 
 581         return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass);
 582     }
 583 
 584     /**
 585      * {@inheritDoc}
 586      */
 587     public Annotation[] getDeclaredAnnotations()  {
 588         return AnnotationParser.toArray(declaredAnnotations());
 589     }
 590 
 591     private transient Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 592 
 593     private synchronized  Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
 594         if (declaredAnnotations == null) {



 595             Executable root = getRoot();
 596             if (root != null) {
 597                 declaredAnnotations = root.declaredAnnotations();
 598             } else {
 599                 declaredAnnotations = AnnotationParser.parseAnnotations(
 600                     getAnnotationBytes(),
 601                     sun.misc.SharedSecrets.getJavaLangAccess().
 602                     getConstantPool(getDeclaringClass()),
 603                     getDeclaringClass());

 604             }

 605         }
 606         return declaredAnnotations;


 607     }
 608 
 609     /**
 610      * Returns an {@code AnnotatedType} object that represents the use of a type to
 611      * specify the return type of the method/constructor represented by this
 612      * Executable.
 613      *
 614      * If this {@code Executable} object represents a constructor, the {@code
 615      * AnnotatedType} object represents the type of the constructed object.
 616      *
 617      * If this {@code Executable} object represents a method, the {@code
 618      * AnnotatedType} object represents the use of a type to specify the return
 619      * type of the method.
 620      *
 621      * @return an object representing the return type of the method
 622      * or constructor represented by this {@code Executable}
 623      */
 624     public abstract AnnotatedType getAnnotatedReturnType();
 625 
 626     /* Helper for subclasses of Executable.




 571     }
 572 
 573     /**
 574      * {@inheritDoc}
 575      * @throws NullPointerException {@inheritDoc}
 576      */
 577     @Override
 578     public <T extends Annotation> T[] getAnnotationsByType(Class<T> annotationClass) {
 579         Objects.requireNonNull(annotationClass);
 580 
 581         return AnnotationSupport.getDirectlyAndIndirectlyPresent(declaredAnnotations(), annotationClass);
 582     }
 583 
 584     /**
 585      * {@inheritDoc}
 586      */
 587     public Annotation[] getDeclaredAnnotations()  {
 588         return AnnotationParser.toArray(declaredAnnotations());
 589     }
 590 
 591     private transient volatile Map<Class<? extends Annotation>, Annotation> declaredAnnotations;
 592 
 593     private Map<Class<? extends Annotation>, Annotation> declaredAnnotations() {
 594         Map<Class<? extends Annotation>, Annotation> declAnnos;
 595         if ((declAnnos = declaredAnnotations) == null) {
 596             synchronized (this) {
 597                 if ((declAnnos = declaredAnnotations) == null) {
 598                     Executable root = getRoot();
 599                     if (root != null) {
 600                         declAnnos = root.declaredAnnotations();
 601                     } else {
 602                         declAnnos = AnnotationParser.parseAnnotations(
 603                                 getAnnotationBytes(),
 604                                 sun.misc.SharedSecrets.getJavaLangAccess().
 605                                         getConstantPool(getDeclaringClass()),
 606                                 getDeclaringClass()
 607                         );
 608                     }
 609                     declaredAnnotations = declAnnos;
 610                 }
 611             }
 612         }
 613         return declAnnos;
 614     }
 615 
 616     /**
 617      * Returns an {@code AnnotatedType} object that represents the use of a type to
 618      * specify the return type of the method/constructor represented by this
 619      * Executable.
 620      *
 621      * If this {@code Executable} object represents a constructor, the {@code
 622      * AnnotatedType} object represents the type of the constructed object.
 623      *
 624      * If this {@code Executable} object represents a method, the {@code
 625      * AnnotatedType} object represents the use of a type to specify the return
 626      * type of the method.
 627      *
 628      * @return an object representing the return type of the method
 629      * or constructor represented by this {@code Executable}
 630      */
 631     public abstract AnnotatedType getAnnotatedReturnType();
 632 
 633     /* Helper for subclasses of Executable.


< prev index next >