JDK 8 RFR for JDK-7185456 : (ann) Optimize Annotation handling in java/sun.reflect.* code for small number of annotationsC
Andrej Golovnin
golovnin at gmx.net
Wed Mar 27 07:00:35 UTC 2013
Hello Joe,
when you already going to change the AnnotationType class,
could you also please remove duplicate line (lines 115 and 121
are identical) in the for-loop in the constructor:
https://dl.dropbox.com/u/148428677/jdk8/AnnotationType/webrev.01/index.html
Thanks,
Andrej
On 26.03.2013, at 23:43, Joe Darcy <joe.darcy at oracle.com> wrote:
> 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.
> */
> - private final Map<String, Class<?>> memberTypes = new HashMap<String,Class<?>>();
> + private final Map<String, Class<?>> memberTypes;
>
> /**
> * Member name -> default value mapping.
> */
> - private final Map<String, Object> memberDefaults =
> - new HashMap<String, Object>();
> + private final Map<String, Object> memberDefaults;
>
> /**
> * Member name -> Method object mapping. This (and its assoicated
> * accessor) are used only to generate AnnotationTypeMismatchExceptions.
> */
> - private final Map<String, Method> members = new HashMap<String, Method>();
> + private final Map<String, Method> members;
>
> /**
> * The retention policy for this annotation type.
> @@ -105,6 +104,9 @@
> }
> });
>
> + memberTypes = new HashMap<String,Class<?>>(methods.length+1, 1.0f);
> + memberDefaults = new HashMap<String, Object>(0);
> + members = new HashMap<String, Method>(methods.length+1, 1.0f);
>
> for (Method method : methods) {
> if (method.getParameterTypes().length != 0)
More information about the core-libs-dev
mailing list