7122740: PropertyDescriptor Performance Slow
authormalenkov
Mon, 16 Jan 2012 18:28:56 +0400
changeset 11501 3c5730331052
parent 11500 36442b344961
child 11502 9d4e3b71c122
7122740: PropertyDescriptor Performance Slow Reviewed-by: rupashka
jdk/src/share/classes/com/sun/beans/TypeResolver.java
--- a/jdk/src/share/classes/com/sun/beans/TypeResolver.java	Fri Jan 13 12:39:23 2012 +0400
+++ b/jdk/src/share/classes/com/sun/beans/TypeResolver.java	Mon Jan 16 18:28:56 2012 +0400
@@ -154,7 +154,7 @@
      * @see #resolve(Type)
      */
     public static Type resolve(Type actual, Type formal) {
-        return new TypeResolver(actual).resolve(formal);
+        return getTypeResolver(actual).resolve(formal);
     }
 
     /**
@@ -169,7 +169,7 @@
      * @see #resolve(Type[])
      */
     public static Type[] resolve(Type actual, Type[] formals) {
-        return new TypeResolver(actual).resolve(formals);
+        return getTypeResolver(actual).resolve(formals);
     }
 
     /**
@@ -228,9 +228,20 @@
         return classes;
     }
 
+    public static TypeResolver getTypeResolver(Type type) {
+        synchronized (CACHE) {
+            TypeResolver resolver = CACHE.get(type);
+            if (resolver == null) {
+                resolver = new TypeResolver(type);
+                CACHE.put(type, resolver);
+            }
+            return resolver;
+        }
+    }
 
-    private final Map<TypeVariable<?>, Type> map
-        = new HashMap<TypeVariable<?>, Type>();
+    private static final WeakCache<Type, TypeResolver> CACHE = new WeakCache<>();
+
+    private final Map<TypeVariable<?>, Type> map = new HashMap<>();
 
     /**
      * Constructs the type resolver for the given actual type.