JDK 8 RFR for JDK-7185456 : (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC (original) (raw)

Joe Darcy joe.darcy at oracle.com
Tue Mar 26 22:43:07 UTC 2013


Hello,

Please review this refactoring of how annotations objects are created:

 JDK-7185456 : (ann) Optimize Annotation handling in 

java/sun.reflect.* code for small number of annotationsC http://cr.openjdk.java.net/~darcy/7185456.0/

In brief, an annotation object is backed by a hash map with one entry per method defined on the annotation type. Currently the default HashMap constructor which uses a default capacity of 16 is used. Since most annotation type define many fewer methods, some space is wasted. The patch (inline below) "right sizes" the HashMap to match the number of methods in the annotation type.

Thanks,

-Joe

--- old/src/share/classes/sun/reflect/annotation/AnnotationType.java 2013-03-26 15:37:22.000000000 -0700 +++ new/src/share/classes/sun/reflect/annotation/AnnotationType.java 2013-03-26 15:37:22.000000000 -0700 @@ -45,19 +45,18 @@ * types. This matches the return value that must be used for a * dynamic proxy, allowing for a simple isInstance test. */

HashMap<String,Class<?>>();

AnnotationTypeMismatchExceptions. */

Method>();

@@ -105,6 +104,9 @@ } });



More information about the core-libs-dev mailing list