Hi Joe,

Looks good to me.

I would include Andrej's suggestion of removing one of the members.put(...).

cheers
/Joel

On 03/26/2013 11:43 PM, Joe Darcy 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)

Reply via email to