From bbe9ce4a1929279ddff6cda6394863a311beb231 Mon Sep 17 00:00:00 2001 From: aclement Date: Fri, 13 Nov 2009 18:23:55 +0000 Subject: [PATCH] weakref cache of resolved interfaces and supertype --- .../src/org/aspectj/weaver/ReferenceType.java | 38 ++++++++++++++++--- 1 file changed, 33 insertions(+), 5 deletions(-) diff --git a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java index e8e7e0b4c..5155c495b 100644 --- a/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java +++ b/org.aspectj.matcher/src/org/aspectj/weaver/ReferenceType.java @@ -12,6 +12,7 @@ * ******************************************************************/ package org.aspectj.weaver; +import java.lang.ref.WeakReference; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; @@ -570,9 +571,7 @@ public class ReferenceType extends ResolvedType { @Override public boolean isExposedToWeaver() { - return (delegate == null) || delegate.isExposedToWeaver(); // ??? where - // does this - // belong + return (delegate == null) || delegate.isExposedToWeaver(); } @Override @@ -649,9 +648,23 @@ public class ReferenceType extends ResolvedType { } return parameterizedInterfaces; } + if (delegate.isCacheable()) { + parameterizedInterfaces = delegateInterfaces; + } + return delegateInterfaces; } + private String toString(ResolvedType[] delegateInterfaces) { + StringBuffer sb = new StringBuffer(); + if (delegateInterfaces != null) { + for (ResolvedType rt : delegateInterfaces) { + sb.append(rt).append(" "); + } + } + return sb.toString(); + } + /** * Locates the named type variable in the list of those on this generic type and returns the type parameter from the second list * supplied. Returns null if it can't be found @@ -856,15 +869,23 @@ public class ReferenceType extends ResolvedType { return delegate.getModifiers(); } + WeakReference superclassReference = new WeakReference(null); + @Override public ResolvedType getSuperclass() { + ResolvedType ret = null;// superclassReference.get(); + if (ret != null) { + return ret; + } if (newSuperclass != null) { if (this.isParameterizedType() && newSuperclass.isParameterizedType()) { return newSuperclass.parameterize(getMemberParameterizationMap()).resolve(getWorld()); } + if (delegate.isCacheable()) { + superclassReference = new WeakReference(ret); + } return newSuperclass; } - ResolvedType ret = null; try { world.setTypeVariableLookupScope(this); ret = delegate.getSuperclass(); @@ -874,6 +895,9 @@ public class ReferenceType extends ResolvedType { if (this.isParameterizedType() && ret.isParameterizedType()) { ret = ret.parameterize(getMemberParameterizationMap()).resolve(getWorld()); } + if (delegate.isCacheable()) { + superclassReference = new WeakReference(ret); + } return ret; } @@ -911,6 +935,7 @@ public class ReferenceType extends ResolvedType { parameterizedInterfaces = null; parameterizedMethods = null; parameterizedPointcuts = null; + superclassReference = new WeakReference(null); } public int getEndPos() { @@ -1000,12 +1025,15 @@ public class ReferenceType extends ResolvedType { annotationTypes = null; newSuperclass = null; newInterfaces = null; + parameterizedInterfaces = null; + superclassReference = new WeakReference(null); } @Override public void addParent(ResolvedType newParent) { if (newParent.isClass()) { newSuperclass = newParent; + superclassReference = new WeakReference(null); } else { if (newInterfaces == null) { newInterfaces = new ResolvedType[1]; @@ -1023,8 +1051,8 @@ public class ReferenceType extends ResolvedType { System.arraycopy(newInterfaces, 0, newNewInterfaces, 1, newInterfaces.length); newNewInterfaces[0] = newParent; newInterfaces = newNewInterfaces; - parameterizedInterfaces = null;// invalidate cached info } + parameterizedInterfaces = null;// invalidate cached info } } } \ No newline at end of file -- 2.39.5