aboutsummaryrefslogtreecommitdiffstats
path: root/runtime
diff options
context:
space:
mode:
authoracolyer <acolyer>2005-09-01 14:17:29 +0000
committeracolyer <acolyer>2005-09-01 14:17:29 +0000
commita5e645fa9a16aba627560d058be824438ddfc890 (patch)
tree741b266d5cca55d87020cb9b4311e8de6f6fd523 /runtime
parent0c44c16b6cd65aeca12a3627a8a0f22416c1801f (diff)
downloadaspectj-a5e645fa9a16aba627560d058be824438ddfc890.tar.gz
aspectj-a5e645fa9a16aba627560d058be824438ddfc890.zip
fix for pr59076, much more memory efficient creation of join point static parts
Diffstat (limited to 'runtime')
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/Factory.java156
-rw-r--r--runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java41
2 files changed, 159 insertions, 38 deletions
diff --git a/runtime/src/org/aspectj/runtime/reflect/Factory.java b/runtime/src/org/aspectj/runtime/reflect/Factory.java
index c3e662874..95c9de068 100644
--- a/runtime/src/org/aspectj/runtime/reflect/Factory.java
+++ b/runtime/src/org/aspectj/runtime/reflect/Factory.java
@@ -18,6 +18,8 @@ package org.aspectj.runtime.reflect;
import java.lang.reflect.Constructor;
import java.lang.reflect.Member;
import java.lang.reflect.Method;
+import java.util.Hashtable;
+import java.util.StringTokenizer;
import org.aspectj.lang.*;
import org.aspectj.lang.reflect.*;
@@ -26,6 +28,42 @@ public final class Factory {
Class lexicalClass;
ClassLoader lookupClassLoader;
String filename;
+
+ static Hashtable prims = new Hashtable();
+ static {
+ prims.put("void", Void.TYPE);
+ prims.put("boolean", Boolean.TYPE);
+ prims.put("byte", Byte.TYPE);
+ prims.put("char", Character.TYPE);
+ prims.put("short", Short.TYPE);
+ prims.put("int", Integer.TYPE);
+ prims.put("long", Long.TYPE);
+ prims.put("float", Float.TYPE);
+ prims.put("double", Double.TYPE);
+ }
+
+ static Class makeClass(String s, ClassLoader loader) {
+ if (s.equals("*")) return null;
+ Class ret = (Class)prims.get(s);
+ if (ret != null) return ret;
+ try {
+ /* The documentation of Class.forName explains why this is the right thing
+ * better than I could here.
+ */
+ if (loader == null) {
+ return Class.forName(s);
+ } else {
+ // used to be 'return loader.loadClass(s)' but that didn't cause
+ // array types to be created and loaded correctly. (pr70404)
+ return Class.forName(s,false,loader);
+ }
+ } catch (ClassNotFoundException e) {
+ //System.out.println("null for: " + s);
+ //XXX there should be a better return value for this
+ return ClassNotFoundException.class;
+ }
+ }
+
public Factory(String filename, Class lexicalClass) {
//System.out.println("making
this.filename = filename;
@@ -33,6 +71,8 @@ public final class Factory {
lookupClassLoader = lexicalClass.getClassLoader();
}
+
+
public JoinPoint.StaticPart makeSJP(String kind, Signature sig, SourceLocation loc) {
return new JoinPointImpl.StaticPartImpl(kind, sig, loc);
}
@@ -112,6 +152,35 @@ public final class Factory {
return ret;
}
+
+ public MethodSignature makeMethodSig(String modifiers, String methodName, String declaringType, String paramTypes, String paramNames, String exceptionTypes, String returnType) {
+ int modifiersAsInt = Integer.parseInt(modifiers, 16);
+
+ Class declaringTypeClass = makeClass(declaringType,lookupClassLoader);
+
+ StringTokenizer st = new StringTokenizer(paramTypes, ":");
+ int numParams = st.countTokens();
+ Class[] paramTypeClasses = new Class[numParams];
+ for(int i = 0; i < numParams; i++) paramTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader);
+
+ st = new StringTokenizer(paramNames, ":");
+ numParams = st.countTokens();
+ String[] paramNamesArray = new String[numParams];
+ for(int i = 0; i < numParams; i++) paramNamesArray[i] = st.nextToken();
+
+ st = new StringTokenizer(exceptionTypes, ":");
+ numParams = st.countTokens();
+ Class[] exceptionTypeClasses = new Class[numParams];
+ for(int i = 0; i < numParams; i++) exceptionTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader);
+
+ Class returnTypeClass = makeClass(returnType,lookupClassLoader);
+
+ MethodSignatureImpl ret =
+ new MethodSignatureImpl(modifiersAsInt, methodName, declaringTypeClass, paramTypeClasses, paramNamesArray, exceptionTypeClasses, returnTypeClass);
+
+ return ret;
+ }
+
public MethodSignature makeMethodSig(int modifiers, String name, Class declaringType,
Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes,
Class returnType) {
@@ -126,6 +195,32 @@ public final class Factory {
return ret;
}
+ public ConstructorSignature makeConstructorSig(String modifiers, String declaringType, String paramTypes, String paramNames, String exceptionTypes) {
+ int modifiersAsInt = Integer.parseInt(modifiers, 16);
+
+ Class declaringTypeClass = makeClass(declaringType,lookupClassLoader);
+
+ StringTokenizer st = new StringTokenizer(paramTypes, ":");
+ int numParams = st.countTokens();
+ Class[] paramTypeClasses = new Class[numParams];
+ for(int i = 0; i < numParams; i++) paramTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader);
+
+ st = new StringTokenizer(paramNames, ":");
+ numParams = st.countTokens();
+ String[] paramNamesArray = new String[numParams];
+ for(int i = 0; i < numParams; i++) paramNamesArray[i] = st.nextToken();
+
+ st = new StringTokenizer(exceptionTypes, ":");
+ numParams = st.countTokens();
+ Class[] exceptionTypeClasses = new Class[numParams];
+ for(int i = 0; i < numParams; i++) exceptionTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader);
+
+ ConstructorSignatureImpl ret = new ConstructorSignatureImpl(modifiersAsInt, declaringTypeClass, paramTypeClasses, paramNamesArray, exceptionTypeClasses);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
+
+
public ConstructorSignature makeConstructorSig(int modifiers, Class declaringType,
Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes) {
ConstructorSignatureImpl ret = new ConstructorSignatureImpl(modifiers,declaringType,parameterTypes,parameterNames,exceptionTypes);
@@ -139,6 +234,17 @@ public final class Factory {
return ret;
}
+
+ public FieldSignature makeFieldSig(String modifiers, String name, String declaringType, String fieldType) {
+ int modifiersAsInt = Integer.parseInt(modifiers, 16);
+ Class declaringTypeClass = makeClass(declaringType,lookupClassLoader);
+ Class fieldTypeClass = makeClass(fieldType,lookupClassLoader);
+
+ FieldSignatureImpl ret = new FieldSignatureImpl(modifiersAsInt, name, declaringTypeClass, fieldTypeClass);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
+
public FieldSignature makeFieldSig(int modifiers, String name, Class declaringType,
Class fieldType) {
FieldSignatureImpl ret = new FieldSignatureImpl(modifiers,name,declaringType,fieldType);
@@ -152,6 +258,33 @@ public final class Factory {
return ret;
}
+ public AdviceSignature makeAdviceSig(String modifiers, String name, String declaringType, String paramTypes, String paramNames, String exceptionTypes, String returnType) {
+ int modifiersAsInt = Integer.parseInt(modifiers, 16);
+
+ Class declaringTypeClass = makeClass(declaringType,lookupClassLoader);
+
+ StringTokenizer st = new StringTokenizer(paramTypes, ":");
+ int numParams = st.countTokens();
+ Class[] paramTypeClasses = new Class[numParams];
+ for(int i = 0; i < numParams; i++) paramTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader);
+
+ st = new StringTokenizer(paramNames, ":");
+ numParams = st.countTokens();
+ String[] paramNamesArray = new String[numParams];
+ for(int i = 0; i < numParams; i++) paramNamesArray[i] = st.nextToken();
+
+ st = new StringTokenizer(exceptionTypes, ":");
+ numParams = st.countTokens();
+ Class[] exceptionTypeClasses = new Class[numParams];
+ for(int i = 0; i < numParams; i++) exceptionTypeClasses[i] = makeClass(st.nextToken(),lookupClassLoader);;
+
+ Class returnTypeClass = makeClass(returnType,lookupClassLoader);
+
+ AdviceSignatureImpl ret = new AdviceSignatureImpl(modifiersAsInt, name, declaringTypeClass, paramTypeClasses, paramNamesArray, exceptionTypeClasses, returnTypeClass);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
+
public AdviceSignature makeAdviceSig(int modifiers, String name, Class declaringType,
Class[] parameterTypes, String[] parameterNames, Class[] exceptionTypes,
Class returnType) {
@@ -166,6 +299,15 @@ public final class Factory {
return ret;
}
+ public InitializerSignature makeInitializerSig(String modifiers, String declaringType) {
+ int modifiersAsInt = Integer.parseInt(modifiers, 16);
+ Class declaringTypeClass = makeClass(declaringType,lookupClassLoader);
+
+ InitializerSignatureImpl ret = new InitializerSignatureImpl(modifiersAsInt, declaringTypeClass);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
+
public InitializerSignature makeInitializerSig(int modifiers, Class declaringType) {
InitializerSignatureImpl ret = new InitializerSignatureImpl(modifiers,declaringType);
ret.setLookupClassLoader(lookupClassLoader);
@@ -177,6 +319,20 @@ public final class Factory {
ret.setLookupClassLoader(lookupClassLoader);
return ret;
}
+
+ public CatchClauseSignature makeCatchClauseSig(String declaringType, String parameterType, String parameterName) {
+ Class declaringTypeClass = makeClass(declaringType,lookupClassLoader);
+
+ StringTokenizer st = new StringTokenizer(parameterType, ":");
+ Class parameterTypeClass = makeClass(st.nextToken(),lookupClassLoader);
+
+ st = new StringTokenizer(parameterName, ":");
+ String parameterNameForReturn = st.nextToken();
+
+ CatchClauseSignatureImpl ret = new CatchClauseSignatureImpl(declaringTypeClass, parameterTypeClass, parameterNameForReturn);
+ ret.setLookupClassLoader(lookupClassLoader);
+ return ret;
+ }
public CatchClauseSignature makeCatchClauseSig(Class declaringType,
Class parameterType, String parameterName) {
diff --git a/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java b/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
index 9045880e0..127b39c25 100644
--- a/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
+++ b/runtime/src/org/aspectj/runtime/reflect/SignatureImpl.java
@@ -17,7 +17,6 @@ package org.aspectj.runtime.reflect;
import org.aspectj.lang.Signature;
import java.lang.ref.SoftReference;
-import java.util.Hashtable;
import java.util.StringTokenizer;
abstract class SignatureImpl implements Signature {
@@ -155,44 +154,10 @@ abstract class SignatureImpl implements Signature {
Class extractType(int n) {
String s = extractString(n);
- return makeClass(s);
+ return Factory.makeClass(s,getLookupClassLoader());
}
- static Hashtable prims = new Hashtable();
- static {
- prims.put("void", Void.TYPE);
- prims.put("boolean", Boolean.TYPE);
- prims.put("byte", Byte.TYPE);
- prims.put("char", Character.TYPE);
- prims.put("short", Short.TYPE);
- prims.put("int", Integer.TYPE);
- prims.put("long", Long.TYPE);
- prims.put("float", Float.TYPE);
- prims.put("double", Double.TYPE);
- }
-
- Class makeClass(String s) {
- if (s.equals("*")) return null;
- Class ret = (Class)prims.get(s);
- if (ret != null) return ret;
- try {
- /* The documentation of Class.forName explains why this is the right thing
- * better than I could here.
- */
- ClassLoader loader = getLookupClassLoader();
- if (loader == null) {
- return Class.forName(s);
- } else {
- // used to be 'return loader.loadClass(s)' but that didn't cause
- // array types to be created and loaded correctly. (pr70404)
- return Class.forName(s,false,loader);
- }
- } catch (ClassNotFoundException e) {
- //System.out.println("null for: " + s);
- //XXX there should be a better return value for this
- return ClassNotFoundException.class;
- }
- }
+
static String[] EMPTY_STRING_ARRAY = new String[0];
static Class[] EMPTY_CLASS_ARRAY = new Class[0];
@@ -212,7 +177,7 @@ abstract class SignatureImpl implements Signature {
StringTokenizer st = new StringTokenizer(s, INNER_SEP);
final int N = st.countTokens();
Class[] ret = new Class[N];
- for (int i = 0; i < N; i++) ret[i]= makeClass(st.nextToken());
+ for (int i = 0; i < N; i++) ret[i]= Factory.makeClass(st.nextToken(),getLookupClassLoader());
return ret;
}