[jboss-cvs] JBossAS SVN: r106445 - in projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins: bytecode and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jul 6 09:59:21 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-07-06 09:59:20 -0400 (Tue, 06 Jul 2010)
New Revision: 106445
Modified:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationHolder.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationInfoImpl.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationValueFactory.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/ClassInfoImpl.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/EnumInfoImpl.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/InheritableAnnotationHolder.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/TypeInfoAttachments.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeAnnotatedInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeAnnotationInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeEnumInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeInheritableAnnotationHolder.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/bytes/asm/AsmClassBytesFactory.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistEnumInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistInheritableAnnotationHolder.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistUtil.java
Log:
[JBREFLECT-132] Size collections and maps to avoid excessive memory consumption
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationHolder.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationHolder.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationHolder.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -91,7 +91,7 @@
if (annotations != null && annotations.length > 0)
{
this.annotationsArray = annotations;
- annotationMap = new HashMap<String, AnnotationValue>();
+ annotationMap = new HashMap<String, AnnotationValue>(annotations.length);
for (int i = 0; i < annotations.length; i++)
{
AnnotationInfo type = annotations[i].getAnnotationType();
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationInfoImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationInfoImpl.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationInfoImpl.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -72,7 +72,7 @@
if (attributes != null && attributes.length > 0)
{
this.attributes = attributes;
- attributeMap = new HashMap<String, AnnotationAttribute>();
+ attributeMap = new HashMap<String, AnnotationAttribute>(attributes.length);
for (int i = 0; i < attributes.length; i++)
{
attributeMap.put(attributes[i].getName(), attributes[i]);
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationValueFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationValueFactory.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/AnnotationValueFactory.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -106,8 +106,8 @@
Class<?> clazz = annotation.annotationType();
ClassInfo clazzInfo = (ClassInfo) typeInfoFactory.getTypeInfo(clazz);
- HashMap<String, Value> attributes = new HashMap<String, Value>();
MethodInfo[] methods = clazzInfo.getDeclaredMethods();
+ HashMap<String, Value> attributes = new HashMap<String, Value>(methods != null ? methods.length : 0);
if (methods != null)
{
for (int j = 0 ; j < methods.length ; j++)
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/ClassInfoImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/ClassInfoImpl.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/ClassInfoImpl.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -340,7 +340,7 @@
this.fields = fields;
if (fields != null)
{
- fieldMap = new HashMap<String, FieldInfo>();
+ fieldMap = new HashMap<String, FieldInfo>(fields.length);
for (int i = 0; i < fields.length; ++i)
{
fields[i].declaringClass = this;
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/EnumInfoImpl.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/EnumInfoImpl.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/EnumInfoImpl.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -41,7 +41,7 @@
protected EnumConstantInfoImpl[] enumConstants;
/** The constants */
- protected HashMap<String, EnumConstantInfo> constants = new HashMap<String, EnumConstantInfo>();
+ protected HashMap<String, EnumConstantInfo> constants = null;
/**
* Create a new EnumInfo.
@@ -68,6 +68,7 @@
*/
public void setEnumConstants(EnumConstantInfoImpl[] enumConstants)
{
+ constants = new HashMap<String, EnumConstantInfo>(enumConstants.length);
for (int i = 0; i < enumConstants.length; i++)
constants.put(enumConstants[i].getName(), enumConstants[i]);
this.enumConstants = enumConstants;
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/InheritableAnnotationHolder.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/InheritableAnnotationHolder.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/InheritableAnnotationHolder.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -44,7 +44,7 @@
private static final String INHERITED_NAME = Inherited.class.getName();//This
/** Unknown annotations map */
- static final Map<String, AnnotationValue> UNKNOWN_ANNOTATIONS_MAP = Collections.unmodifiableMap(new HashMap<String, AnnotationValue>());
+ static final Map<String, AnnotationValue> UNKNOWN_ANNOTATIONS_MAP = Collections.emptyMap();
/** Unknown annotations */
static final AnnotationValue[] UNKNOWN_ANNOTATIONS = new AnnotationValue[0];
@@ -167,11 +167,11 @@
if (annotations != null && annotations.length > 0)
{
- declaredAnnotations = new HashMap<String, AnnotationValue>();
+ declaredAnnotations = new HashMap<String, AnnotationValue>(annotations.length);
declaredAnnotationsArray = annotations;
for (int i = 0; i < annotations.length; i++)
declaredAnnotations.put(annotations[i].getAnnotationType().getName(), annotations[i]);
- allAnnotations = new HashMap<String, AnnotationValue>();
+ allAnnotations = new HashMap<String, AnnotationValue>(annotations.length);
if (superHolder != null && superAllAnnotations != null && superAllAnnotations.length != 0)
{
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/TypeInfoAttachments.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/TypeInfoAttachments.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/TypeInfoAttachments.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -60,7 +60,7 @@
synchronized (this)
{
if (attachments == null)
- attachments = new HashMap<String, Object>();
+ attachments = new HashMap<String, Object>(1);
attachments.put(name, attachment);
}
}
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeAnnotatedInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeAnnotatedInfo.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeAnnotatedInfo.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -22,6 +22,7 @@
package org.jboss.reflect.plugins.bytecode;
import java.util.HashMap;
+import java.util.Map;
import org.jboss.reflect.plugins.AbstractAnnotatedInfo;
import org.jboss.reflect.plugins.AnnotationHelper;
@@ -45,13 +46,13 @@
private static final AnnotationValue[] EMPTY_ANNOTATIONS_ARRAY = new AnnotationValue[0];
- private static final HashMap<String, AnnotationValue> EMPTY_ANNOTATION_MAP = new HashMap<String, AnnotationValue>();
+ private static final Map<String, AnnotationValue> EMPTY_ANNOTATION_MAP = new HashMap<String, AnnotationValue>();
/** The annotations */
protected volatile AnnotationValue[] annotationsArray = NOT_CONFIGURED;
/** Annotations map Map<String, AnnotationValue> */
- protected volatile HashMap<String, AnnotationValue> annotationMap;
+ protected volatile Map<String, AnnotationValue> annotationMap;
protected final AnnotationHelper annotationHelper;
@@ -99,7 +100,7 @@
if (annotations != null && annotations.length > 0)
{
- HashMap<String, AnnotationValue> annotationMap = new HashMap<String, AnnotationValue>();
+ HashMap<String, AnnotationValue> annotationMap = new HashMap<String, AnnotationValue>(annotations.length);
for (int i = 0; i < annotations.length; i++)
{
AnnotationInfo type = annotations[i].getAnnotationType();
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeAnnotationInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeAnnotationInfo.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeAnnotationInfo.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -61,7 +61,7 @@
if (attributes != null && attributes.length > 0)
{
this.attributes = attributes;
- attributeMap = new HashMap<String, AnnotationAttribute>();
+ attributeMap = new HashMap<String, AnnotationAttribute>(attributes.length);
for (int i = 0; i < attributes.length; i++)
{
attributeMap.put(attributes[i].getName(), attributes[i]);
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeEnumInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeEnumInfo.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeEnumInfo.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -21,7 +21,9 @@
*/
package org.jboss.reflect.plugins.bytecode;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.Map;
import org.jboss.reflect.plugins.EnumConstantInfoImpl;
import org.jboss.reflect.plugins.bytecode.bytes.ClassBytes;
@@ -42,7 +44,7 @@
protected volatile EnumConstantInfoImpl[] enumConstants;
/** The constants */
- protected final HashMap<String, EnumConstantInfo> constants = new HashMap<String, EnumConstantInfo>();
+ protected volatile Map<String, EnumConstantInfo> constants = Collections.emptyMap();;
/**
* Create a new JavassistEnumInfo.
@@ -63,6 +65,7 @@
*/
public void setEnumConstants(EnumConstantInfoImpl[] enumConstants)
{
+ constants = new HashMap<String, EnumConstantInfo>(enumConstants.length);
for (int i = 0; i < enumConstants.length; i++)
{
constants.put(enumConstants[i].getName(), enumConstants[i]);
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeInheritableAnnotationHolder.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeInheritableAnnotationHolder.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeInheritableAnnotationHolder.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -112,7 +112,7 @@
{
ClassInfo superHolder = getSuperHolder();
AnnotationValue[] superAllAnnotations = (superHolder != null) ? superHolder.getAnnotations() : null;
- allAnnotations = new HashMap<String, AnnotationValue>();
+ allAnnotations = new HashMap<String, AnnotationValue>(annotations.length);
if (annotations != null && annotations.length > 0)
{
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfo.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/BytecodeTypeInfo.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -26,10 +26,10 @@
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import javassist.NotFoundException;
@@ -86,6 +86,13 @@
throw new RuntimeException(e);
}
}
+
+ private final static Map<String, BytecodeFieldInfo> EMPTY_FIELDS = Collections.emptyMap();
+
+ private final static Map<SignatureKey, MethodInfo> EMPTY_METHODS = Collections.emptyMap();
+
+ private final Map<SignatureKey, List<MethodInfo>> EMPTY_VOLATILE_METHODS = Collections.emptyMap();
+
/** The factory */
private BytecodeTypeInfoFactoryImpl factory;
@@ -96,22 +103,24 @@
/** The class */
protected volatile Class<? extends Object> clazz;
+ private final static Map<SignatureKey, BytecodeConstructorInfo> EMPTY_CONSTRUCTORS = Collections.emptyMap();
+
/** The constructors */
- private final Map<SignatureKey, BytecodeConstructorInfo> constructors = new ConcurrentHashMap<SignatureKey, BytecodeConstructorInfo>();
+ private volatile Map<SignatureKey, BytecodeConstructorInfo> constructors = EMPTY_CONSTRUCTORS;;
/** The constructors */
private volatile ConstructorInfo[] constructorArray;
/** The fields */
- private final Map<String, BytecodeFieldInfo> fields = new ConcurrentHashMap<String, BytecodeFieldInfo>();
+ private volatile Map<String, BytecodeFieldInfo> fields = EMPTY_FIELDS;
/** The fields */
private volatile FieldInfo[] fieldArray;
/** The methods */
- private final Map<SignatureKey, MethodInfo> methods = new ConcurrentHashMap<SignatureKey, MethodInfo>();
+ private volatile Map<SignatureKey, MethodInfo> methods = EMPTY_METHODS;
- private final Map<SignatureKey, List<MethodInfo>> volatileMethods = new HashMap<SignatureKey, List<MethodInfo>>();
+ private volatile Map<SignatureKey, List<MethodInfo>> volatileMethods = EMPTY_VOLATILE_METHODS;
/** The methods */
private volatile MethodInfo[] methodArray;
@@ -367,8 +376,12 @@
{
for (int i = 0 ; i < declaredConstructors.length ; i++)
generateConstructorInfo(declaredConstructors[i]);
- Collection<BytecodeConstructorInfo> constructorCollection = constructors.values();
- constructorArray = constructorCollection.toArray(new ConstructorInfo[constructorCollection.size()]);
+
+ synchronized (constructors)
+ {
+ Collection<BytecodeConstructorInfo> constructorCollection = constructors.values();
+ constructorArray = constructorCollection.toArray(new ConstructorInfo[constructorCollection.size()]);
+ }
}
}
return constructorArray;
@@ -486,33 +499,6 @@
{
if (methodArray == null)
{
-// CtMethod[] declaredMethods = ctClass.getDeclaredMethods();
-// if (declaredMethods == null || declaredMethods.length == 0)
-// methodArray = new MutableMethodInfo[0];
-// else
-// {
-// synchronized (methods)
-// {
-// for (int i = 0; i < declaredMethods.length; ++i)
-// generateMethodInfo(declaredMethods[i]);
-// Collection<BytecodeMethodInfo> methodCollection = methods.values();
-//
-// if (volatileMethods.size() > 0)
-// {
-// Collection<BytecodeMethodInfo> allMethods = new ArrayList<BytecodeMethodInfo>();
-// allMethods.addAll(methodCollection);
-// methodCollection = allMethods;
-//
-// for (List<BytecodeMethodInfo> infos : volatileMethods.values())
-// {
-// if (infos.size() > 0)
-// methodCollection.addAll(infos);
-// }
-// }
-//
-// methodArray = methodCollection.toArray(new MutableMethodInfo[methodCollection.size()]);
-// }
-// }
MethodBytes[] declaredMethods = classBytes.getDeclaredMethodBytes();
if (declaredMethods.length == 0)
methodArray = ClassInfoImpl.UNKNOWN_METHODS;
@@ -708,6 +694,8 @@
BytecodeConstructorInfo info = new BytecodeConstructorInfo(factory, this, constructor);
synchronized (constructors)
{
+ if (constructors == EMPTY_CONSTRUCTORS)
+ constructors = new HashMap<SignatureKey, BytecodeConstructorInfo>(1);
constructors.put(constructor.getSignatureKey(), info);
}
return info;
@@ -741,6 +729,8 @@
BytecodeFieldInfo info = new BytecodeFieldInfo(factory, this, field);
synchronized (fields)
{
+ if (fields == EMPTY_FIELDS)
+ fields = new HashMap<String, BytecodeFieldInfo>(1);
fields.put(field.getName(), info);
}
return info;
@@ -780,12 +770,18 @@
if (infos == null)
{
infos = new CopyOnWriteArrayList<MethodInfo>();
+ if (volatileMethods == EMPTY_VOLATILE_METHODS)
+ volatileMethods = new HashMap<SignatureKey, List<MethodInfo>>(1);
volatileMethods.put(method.getSignatureKey(), infos);
}
infos.add(info);
}
else
+ {
+ if (methods == EMPTY_METHODS)
+ methods = new HashMap<SignatureKey, MethodInfo>(1);
methods.put(method.getSignatureKey(), info);
+ }
}
return info;
}
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/bytes/asm/AsmClassBytesFactory.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/bytes/asm/AsmClassBytesFactory.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/bytecode/bytes/asm/AsmClassBytesFactory.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -40,7 +40,7 @@
public class AsmClassBytesFactory implements ClassBytesFactory
{
ReadWriteLock lock = new ReentrantReadWriteLock();
- Map<ClassLoader, Map<String, ClassBytes>> cache = new WeakHashMap<ClassLoader, Map<String, ClassBytes>>();
+ Map<ClassLoader, Map<String, ClassBytes>> cache = new WeakHashMap<ClassLoader, Map<String, ClassBytes>>(1);
public static final AsmClassBytesFactory INSTANCE = new AsmClassBytesFactory();
@@ -83,14 +83,8 @@
if (name == null)
throw new IllegalArgumentException("Null classloader");
- //TODO some voodoo with the classloader
ClassLoader cl = initiating;
- //TODO handle arrays
- //TODO Currently assuming '/' as path separator in class fqn
-
- //String classname = new String(name + ".class");
-
ClassBytes clazz = findInCache(initiating, name);
if (clazz != null)
return clazz;
@@ -151,7 +145,7 @@
Map<String, ClassBytes> classes = cache.get(loader);
if (classes == null)
{
- classes = new HashMap<String, ClassBytes>();
+ classes = new HashMap<String, ClassBytes>(1);
cache.put(loader, classes);
}
classes.put(name, clazz);
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistEnumInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistEnumInfo.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistEnumInfo.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -21,7 +21,9 @@
*/
package org.jboss.reflect.plugins.javassist;
+import java.util.Collections;
import java.util.HashMap;
+import java.util.Map;
import javassist.CtClass;
@@ -43,7 +45,7 @@
protected volatile EnumConstantInfoImpl[] enumConstants;
/** The constants */
- protected final HashMap<String, EnumConstantInfo> constants = new HashMap<String, EnumConstantInfo>();
+ protected volatile Map<String, EnumConstantInfo> constants = Collections.emptyMap();
/**
* Create a new JavassistEnumInfo.
@@ -64,6 +66,7 @@
*/
public void setEnumConstants(EnumConstantInfoImpl[] enumConstants)
{
+ constants = new HashMap<String, EnumConstantInfo>(enumConstants.length);
for (int i = 0; i < enumConstants.length; i++)
constants.put(enumConstants[i].getName(), enumConstants[i]);
this.enumConstants = enumConstants;
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistInheritableAnnotationHolder.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistInheritableAnnotationHolder.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistInheritableAnnotationHolder.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -28,10 +28,8 @@
import javassist.CtClass;
import org.jboss.reflect.plugins.AnnotationHelper;
-import org.jboss.reflect.spi.AnnotatedInfo;
import org.jboss.reflect.spi.AnnotationValue;
import org.jboss.reflect.spi.ClassInfo;
-import org.jboss.reflect.spi.TypeInfo;
/**
*
@@ -111,14 +109,14 @@
@Override
public void setupAnnotations(AnnotationValue[] annotations)
{
- ClassInfo superHolder = (ClassInfo)getSuperHolder();
+ ClassInfo superHolder = getSuperHolder();
//JavassistInheritableAnnotationHolder superHolder = getSuperHolder();
AnnotationValue[] superAllAnnotations = (superHolder != null) ? superHolder.getAnnotations() : null;
- allAnnotations = new HashMap<String, AnnotationValue>();
+ allAnnotations = new HashMap<String, AnnotationValue>(annotations.length);
if (annotations != null && annotations.length > 0)
{
- annotationMap = new HashMap<String, AnnotationValue>();
+ annotationMap = new HashMap<String, AnnotationValue>(annotations.length);
annotationsArray = annotations;
for (int i = 0; i < annotations.length; i++)
{
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfo.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -27,10 +27,10 @@
import java.lang.reflect.Modifier;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import javassist.CannotCompileException;
@@ -72,6 +72,14 @@
/** The serialVersionUID */
private static final long serialVersionUID = -5072033691434335775L;
+ private static final Map<SignatureKey, JavassistConstructorInfo> EMPTY_CONSTRUCTORS = Collections.emptyMap();
+
+ private static final Map<String, JavassistFieldInfo> EMPTY_FIELDS = Collections.emptyMap();
+
+ private static final Map<SignatureKey, JavassistMethodInfo> EMPTY_METHODS = Collections.emptyMap();
+
+ private static final Map<SignatureKey, List<JavassistMethodInfo>> EMPTY_VOLATILE_METHODS = Collections.emptyMap();
+
/** The get classloader permission */
protected static final RuntimePermission GET_CLASSLOADER_PERMISSION = new RuntimePermission("getClassLoader");
@@ -100,21 +108,21 @@
private volatile Class<? extends Object> clazz;
/** The constructors */
- private final Map<SignatureKey, JavassistConstructorInfo> constructors = new ConcurrentHashMap<SignatureKey, JavassistConstructorInfo>();
+ private volatile Map<SignatureKey, JavassistConstructorInfo> constructors = EMPTY_CONSTRUCTORS;
/** The constructors */
private volatile MutableConstructorInfo[] constructorArray;
/** The fields */
- private final Map<String, JavassistFieldInfo> fields = new ConcurrentHashMap<String, JavassistFieldInfo>();
+ private volatile Map<String, JavassistFieldInfo> fields = EMPTY_FIELDS;
/** The fields */
private volatile MutableFieldInfo[] fieldArray;
/** The methods */
- private final Map<SignatureKey, JavassistMethodInfo> methods = new ConcurrentHashMap<SignatureKey, JavassistMethodInfo>();
+ private volatile Map<SignatureKey, JavassistMethodInfo> methods = EMPTY_METHODS;
- private final Map<SignatureKey, List<JavassistMethodInfo>> volatileMethods = new HashMap<SignatureKey, List<JavassistMethodInfo>>();
+ private volatile Map<SignatureKey, List<JavassistMethodInfo>> volatileMethods = EMPTY_VOLATILE_METHODS;
/** The methods */
private volatile MutableMethodInfo[] methodArray;
@@ -677,6 +685,8 @@
JavassistConstructorInfo info = new JavassistConstructorInfo(key, factory, this, constructor);
synchronized (constructors)
{
+ if (constructors == EMPTY_CONSTRUCTORS)
+ constructors = new HashMap<SignatureKey, JavassistConstructorInfo>(1);
constructors.put(key, info);
}
return info;
@@ -713,6 +723,8 @@
JavassistFieldInfo info = new JavassistFieldInfo(factory, this, field);
synchronized (fields)
{
+ if (fields == EMPTY_FIELDS)
+ fields = new HashMap<String, JavassistFieldInfo>(1);
fields.put(field.getName(), info);
}
return info;
@@ -772,12 +784,18 @@
if (infos == null)
{
infos = new CopyOnWriteArrayList<JavassistMethodInfo>();
+ if (volatileMethods == EMPTY_VOLATILE_METHODS)
+ volatileMethods = new HashMap<SignatureKey, List<JavassistMethodInfo>>(1);
volatileMethods.put(key, infos);
}
infos.add(info);
}
else
+ {
+ if (methods == EMPTY_METHODS)
+ methods = new HashMap<SignatureKey, JavassistMethodInfo>(1);
methods.put(key, info);
+ }
}
return info;
}
@@ -977,24 +995,33 @@
{
if(methodArray != null)
methodArray = null;
- if(methods.size() > 0)
- methods.clear();
+ synchronized (methods)
+ {
+ if(methods.size() > 0)
+ methods.clear();
+ }
}
protected void clearConstructorCache()
{
if(constructorArray != null)
constructorArray = null;
- if(constructors.size() > 0)
- constructors.clear();
+ synchronized (constructors)
+ {
+ if(constructors.size() > 0)
+ constructors.clear();
+ }
}
protected void clearFieldCache()
{
if(fieldArray != null)
fieldArray = null;
- if(fields.size() > 0)
- fields.clear();
+ synchronized (fields)
+ {
+ if(fields.size() > 0)
+ fields.clear();
+ }
}
public void addConstructor(MutableConstructorInfo mci)
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistUtil.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistUtil.java 2010-07-06 13:46:50 UTC (rev 106444)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistUtil.java 2010-07-06 13:59:20 UTC (rev 106445)
@@ -25,7 +25,6 @@
import javassist.CannotCompileException;
import javassist.ClassPool;
-import javassist.CtBehavior;
import javassist.CtClass;
import javassist.CtConstructor;
import javassist.CtField;
More information about the jboss-cvs-commits
mailing list