[jboss-cvs] JBossAS SVN: r104798 - projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri May 14 10:51:13 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-05-14 10:51:13 -0400 (Fri, 14 May 2010)
New Revision: 104798
Modified:
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java
projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java
Log:
[JBREFLECT-124] Optimize
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedInfo.java 2010-05-14 14:22:44 UTC (rev 104797)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedInfo.java 2010-05-14 14:51:13 UTC (rev 104798)
@@ -94,13 +94,15 @@
{
if (annotations != null && annotations.length > 0)
{
- this.annotationsArray = annotations;
- annotationMap = new HashMap<String, AnnotationValue>();
+
+ HashMap<String, AnnotationValue> annotationMap = new HashMap<String, AnnotationValue>();
for (int i = 0; i < annotations.length; i++)
{
AnnotationInfo type = annotations[i].getAnnotationType();
annotationMap.put(type.getName(), annotations[i]);
}
+ this.annotationsArray = annotations;
+ this.annotationMap = annotationMap;
}
else
{
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java 2010-05-14 14:22:44 UTC (rev 104797)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistAnnotatedParameterInfo.java 2010-05-14 14:51:13 UTC (rev 104798)
@@ -64,6 +64,9 @@
/** The constructor or method */
protected final CtBehavior ctBehavior;
+ private transient volatile boolean initializedModifiers;
+
+ private transient volatile int modifiers;
public JavassistAnnotatedParameterInfo(AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtBehavior ctBehavior)
{
@@ -74,22 +77,27 @@
public int getModifiers()
{
- return ctBehavior.getModifiers();
+ if (!initializedModifiers)
+ {
+ modifiers = ctBehavior.getModifiers();
+ initializedModifiers = true;
+ }
+ return modifiers;
}
public boolean isPublic()
{
- return Modifier.isPublic(ctBehavior.getModifiers());
+ return Modifier.isPublic(getModifiers());
}
public boolean isStatic()
{
- return Modifier.isStatic(ctBehavior.getModifiers());
+ return Modifier.isStatic(getModifiers());
}
public boolean isVolatile()
{
- return Modifier.isVolatile(ctBehavior.getModifiers());
+ return Modifier.isVolatile(getModifiers());
}
public ClassInfo getDeclaringClass()
@@ -118,7 +126,7 @@
return exceptionTypes;
}
- protected synchronized void generateParameters()
+ protected void generateParameters()
{
if (parameters != null)
return;
@@ -137,9 +145,10 @@
for (int i = 0; i < types.length; ++i)
parameterTypes[i] = typeInfo.getFactory().getTypeInfo(types[i]);
}
- parameters = new ParameterInfo[parameterTypes.length];
+ ParameterInfo[] parameters = new ParameterInfo[parameterTypes.length];
for (int i = 0; i < parameterTypes.length; ++i)
parameters[i] = new JavassistParameterInfo(annotationHelper, this, i, parameterTypes[i]);
+ this.parameters = parameters;
}
catch (NotFoundException e)
{
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java 2010-05-14 14:22:44 UTC (rev 104797)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistFieldInfo.java 2010-05-14 14:51:13 UTC (rev 104798)
@@ -68,6 +68,12 @@
/** The type info */
protected final JavassistTypeInfo typeInfo;
+ private transient volatile String name;
+
+ private transient volatile boolean initializedModifiers;
+
+ private transient volatile int modifiers;
+
/**
* Create a new JavassistFieldInfo.
*
@@ -84,12 +90,20 @@
public String getName()
{
- return ctField.getName();
+ if (name == null)
+ name = ctField.getName();
+ return name;
}
public int getModifiers()
{
- return ctField.getModifiers();
+ if (!initializedModifiers)
+ {
+ modifiers = ctField.getModifiers();
+ initializedModifiers = true;
+ }
+
+ return modifiers;
}
public boolean isPublic()
@@ -139,25 +153,30 @@
public Object get(Object target) throws Throwable
{
- if (field == null)
- field = JavassistReflectionFactory.INSTANCE.createField(this);
-
JavassistAccessController.checkAccess(this);
- return field.get(target);
+ return getJavassistField().get(target);
}
public Object set(Object target, Object value) throws Throwable
{
- if (field == null)
- field = JavassistReflectionFactory.INSTANCE.createField(this);
-
JavassistAccessController.checkAccess(this);
- field.set(target, value);
+ getJavassistField().set(target, value);
return null;
}
+ private JavassistField getJavassistField() throws Throwable
+ {
+ if (field == null)
+ {
+ JavassistField f = JavassistReflectionFactory.INSTANCE.createField(this);
+ if (field == null)
+ field = f;
+ }
+ return field;
+ }
+
@Override
protected int getHashCode()
{
Modified: projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java
===================================================================
--- projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java 2010-05-14 14:22:44 UTC (rev 104797)
+++ projects/jboss-reflect/trunk/src/main/java/org/jboss/reflect/plugins/javassist/JavassistMethodInfo.java 2010-05-14 14:51:13 UTC (rev 104798)
@@ -60,8 +60,10 @@
private transient volatile JavassistMethod method;
/** The return type */
- private transient TypeInfo returnType;
+ private transient volatile TypeInfo returnType;
+ private transient volatile String name;
+
/**
* Create a new JavassistMethodInfo.
*
@@ -72,12 +74,13 @@
public JavassistMethodInfo(AnnotationHelper annotationHelper, JavassistTypeInfo typeInfo, CtMethod ctMethod)
{
super(annotationHelper, typeInfo, ctMethod);
- //this.ctMethod = ctMethod;
}
public String getName()
{
- return ((CtMethod)ctBehavior).getName();
+ if (name == null)
+ name = getCtMethod().getName();
+ return name;
}
public ClassInfo getDeclaringClass()
@@ -100,18 +103,23 @@
}
CtClass clazz = ctMethod.getReturnType();
- return typeInfo.getFactory().getTypeInfo(clazz);
+ returnType = typeInfo.getFactory().getTypeInfo(clazz);
}
catch (NotFoundException e)
{
throw JavassistTypeInfoFactoryImpl.raiseClassNotFound("for return type of method " + getName(), e);
}
+ return returnType;
}
public Object invoke(Object target, Object[] args) throws Throwable
{
if (method == null)
- method = JavassistReflectionFactory.INSTANCE.createMethod(this);
+ {
+ JavassistMethod m = JavassistReflectionFactory.INSTANCE.createMethod(this);
+ if (method == null)
+ method = m;
+ }
JavassistAccessController.checkAccess(this);
More information about the jboss-cvs-commits
mailing list