Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 35292 Details for
Bug 129297
Contribution: support hollowing out BCEL objects with LTW
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
BCEL Delegate Hollowing patch for Weaver module
weaver.hollowBcel.patch.txt (text/plain), 29.96 KB, created by
Ron Bodkin
on 2006-02-24 03:51:56 EST
(
hide
)
Description:
BCEL Delegate Hollowing patch for Weaver module
Filename:
MIME Type:
Creator:
Ron Bodkin
Created:
2006-02-24 03:51:56 EST
Size:
29.96 KB
patch
obsolete
>Index: src/org/aspectj/weaver/BoundedReferenceType.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/BoundedReferenceType.java,v >retrieving revision 1.13 >diff -u -r1.13 BoundedReferenceType.java >--- src/org/aspectj/weaver/BoundedReferenceType.java 3 Feb 2006 11:00:46 -0000 1.13 >+++ src/org/aspectj/weaver/BoundedReferenceType.java 24 Feb 2006 08:18:13 -0000 >@@ -269,5 +269,7 @@ > resolvedTypeX.getDelegate().ensureDelegateConsistent(); > } > >+ public void evictReweavingState() {} >+ > } > } >Index: src/org/aspectj/weaver/CrosscuttingMembersSet.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java,v >retrieving revision 1.17 >diff -u -r1.17 CrosscuttingMembersSet.java >--- src/org/aspectj/weaver/CrosscuttingMembersSet.java 17 Jan 2006 15:33:02 -0000 1.17 >+++ src/org/aspectj/weaver/CrosscuttingMembersSet.java 24 Feb 2006 08:18:13 -0000 >@@ -20,6 +20,7 @@ > import java.util.List; > import java.util.Map; > import java.util.Set; >+import java.util.Map.Entry; > > import org.aspectj.weaver.patterns.CflowPointcut; > import org.aspectj.weaver.patterns.DeclareParents; >@@ -49,6 +50,11 @@ > this.world = world; > } > >+ public void evictReweavingState() { >+ for (Iterator it=members.keySet().iterator(); it.hasNext();) { >+ world.evictIfReferenceType(it.next()); >+ } >+ } > > /** > * @return whether or not that was a change to the global signature >Index: src/org/aspectj/weaver/ReferenceTypeDelegate.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/ReferenceTypeDelegate.java,v >retrieving revision 1.11 >diff -u -r1.11 ReferenceTypeDelegate.java >--- src/org/aspectj/weaver/ReferenceTypeDelegate.java 22 Feb 2006 15:26:26 -0000 1.11 >+++ src/org/aspectj/weaver/ReferenceTypeDelegate.java 24 Feb 2006 08:18:13 -0000 >@@ -66,5 +66,7 @@ > public String getSourcefilename(); > > public String getDeclaredGenericSignature(); >- >+ >+ /** optimization: tells the type to evict any state required solely to support reweaving */ >+ public void evictReweavingState(); > } >\ No newline at end of file >Index: src/org/aspectj/weaver/World.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/World.java,v >retrieving revision 1.76 >diff -u -r1.76 World.java >--- src/org/aspectj/weaver/World.java 22 Feb 2006 16:22:29 -0000 1.76 >+++ src/org/aspectj/weaver/World.java 24 Feb 2006 08:18:14 -0000 >@@ -24,6 +24,7 @@ > import java.util.Map; > import java.util.Properties; > import java.util.WeakHashMap; >+import java.util.Map.Entry; > > import org.aspectj.asm.IHierarchy; > import org.aspectj.bridge.IMessageHandler; >@@ -956,6 +957,20 @@ > ); > } > >+ public void evictReweavingState() { >+ evictReweavingState(typeMap.tMap); >+ evictReweavingState(typeMap.expendableMap); //XXX note interesting issue here: it is not safe to expend even not exposed/not reweavable aspects... yet they appear to end up here?! >+ crosscuttingMembersSet.evictReweavingState();//optimize: don't do this every time!! >+ } >+ private void evictReweavingState(Map map) { >+ for (Iterator it=map.entrySet().iterator(); it.hasNext();) { >+ Entry e = (Entry)it.next(); >+ evictIfReferenceType(e.getValue()); >+ } >+ } >+ public void evictIfReferenceType(Object resolvedType) { >+ } >+ > /** > * This class is used to compute and store precedence relationships between > * aspects. >Index: src/org/aspectj/weaver/asm/AsmDelegate.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/asm/AsmDelegate.java,v >retrieving revision 1.1 >diff -u -r1.1 AsmDelegate.java >--- src/org/aspectj/weaver/asm/AsmDelegate.java 22 Feb 2006 15:04:01 -0000 1.1 >+++ src/org/aspectj/weaver/asm/AsmDelegate.java 24 Feb 2006 08:18:14 -0000 >@@ -630,5 +630,10 @@ > // doesnt need to do anything until methods like addAnnotation() are implemented (i.e. methods that > // modify the delegate such that it differs from the on-disk contents) > } >+ >+ >+ public void evictReweavingState() { >+ // this is a NO-OP: the ASM delegate already has all this state evicted! >+ } > > } >Index: src/org/aspectj/weaver/bcel/BcelAdvice.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/bcel/BcelAdvice.java,v >retrieving revision 1.44 >diff -u -r1.44 BcelAdvice.java >--- src/org/aspectj/weaver/bcel/BcelAdvice.java 21 Dec 2005 17:22:08 -0000 1.44 >+++ src/org/aspectj/weaver/bcel/BcelAdvice.java 24 Feb 2006 08:18:15 -0000 >@@ -56,6 +56,7 @@ > private ExposedState exposedState; > > private boolean hasMatchedAtLeastOnce = false; >+ private boolean knownToBeWoven = false; > > public BcelAdvice( > AjAttribute.AdviceAttribute attribute, >@@ -179,7 +180,7 @@ > > if (concreteAspect.getWorld().isXnoInline()) return false; > //System.err.println("isWoven? " + ((BcelObjectType)concreteAspect).getLazyClassGen().getWeaverState()); >- return BcelWorld.getBcelObjectType(concreteAspect).getLazyClassGen().isWoven(); >+ return knownToBeWoven || BcelWorld.getBcelObjectType(concreteAspect).getLazyClassGen().isWoven(); > } > > public void implementOn(Shadow s) { >Index: src/org/aspectj/weaver/bcel/BcelMethod.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/bcel/BcelMethod.java,v >retrieving revision 1.37 >diff -u -r1.37 BcelMethod.java >--- src/org/aspectj/weaver/bcel/BcelMethod.java 22 Feb 2006 15:26:26 -0000 1.37 >+++ src/org/aspectj/weaver/bcel/BcelMethod.java 24 Feb 2006 08:18:15 -0000 >@@ -264,6 +264,9 @@ > } > > private void ensureAnnotationTypesRetrieved() { >+ if (method == null) { >+ return; // must be ok, we've evicted it >+ } > if (annotationTypes == null || method.getAnnotations().length!=annotations.length) { // sometimes the list changes underneath us! > Annotation annos[] = method.getAnnotations(); > annotationTypes = new HashSet(); >@@ -382,4 +385,13 @@ > genericParameterTypes = getParameterTypes(); > } > } >+ >+ public void evictMethodHandle() { >+ if (method != null) { >+ unpackGenericSignature(); >+ unpackJavaAttributes(); >+ determineParameterNames(); >+ method = null; >+ } >+ } > } >Index: src/org/aspectj/weaver/bcel/BcelObjectType.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/bcel/BcelObjectType.java,v >retrieving revision 1.52 >diff -u -r1.52 BcelObjectType.java >--- src/org/aspectj/weaver/bcel/BcelObjectType.java 22 Feb 2006 15:26:26 -0000 1.52 >+++ src/org/aspectj/weaver/bcel/BcelObjectType.java 24 Feb 2006 08:18:16 -0000 >@@ -26,6 +26,7 @@ > import org.aspectj.apache.bcel.classfile.JavaClass; > import org.aspectj.apache.bcel.classfile.Method; > import org.aspectj.apache.bcel.classfile.Signature; >+import org.aspectj.apache.bcel.classfile.Signature.ClassSignature; > import org.aspectj.apache.bcel.classfile.annotation.Annotation; > import org.aspectj.apache.bcel.classfile.annotation.ArrayElementValue; > import org.aspectj.apache.bcel.classfile.annotation.ElementNameValuePair; >@@ -92,7 +93,31 @@ > private String retentionPolicy; > private boolean discoveredAnnotationTargetKinds = false; > private AnnotationTargetKind[] annotationTargetKinds; >- >+ private int modifiers; >+ private String superclassName; >+ private String className; >+ >+ public void evictReweavingState() { >+ if (javaClass != null) { >+ // force retrieval of any lazy information >+ getDeclaredFields(); >+ getDeclaredInterfaces(); >+ getDeclaredMethods(); >+ getDeclaredPointcuts(); >+ getTypeVariables(); >+ ensureAnnotationTypesRetrieved(); >+ ensureGenericInfoProcessed(); >+ >+ if (weaverState != null) { >+ weaverState.setReweavable(false); >+ weaverState.setUnwovenClassFileData(null); >+ } >+ javaClass = null; >+ for (int i = methods.length - 1; i >= 0; i--) { >+ ((BcelMethod)methods[i]).evictMethodHandle(); >+ } >+ } >+ } > > /** > * A BcelObjectType is 'damaged' if it has been modified from what was original constructed from >@@ -100,6 +125,12 @@ > * ideally BcelObjectType should be immutable but that's a bigger piece of work!!!!!!!!!! XXX > */ > private boolean damaged = false; >+ private boolean isInterface; >+ private boolean isEnum; >+ private boolean isAnnotation; >+ private boolean isAnonymous; >+ private boolean isNested; >+ private ClassSignature cachedGenericClassTypeSignature; > > public Collection getTypeMungers() { > return typeMungers; >@@ -120,6 +151,7 @@ > BcelObjectType(ReferenceType resolvedTypeX, JavaClass javaClass, boolean exposedToWeaver) { > super(resolvedTypeX, exposedToWeaver); > this.javaClass = javaClass; >+ cacheFromJavaClass(); > > //ATAJ: set the delegate right now for @AJ pointcut, else it is done too late to lookup > // @AJ pc refs annotation in class hierarchy >@@ -143,8 +175,21 @@ > public void setJavaClass(JavaClass newclass) { > this.javaClass = newclass; > resetState(); >+ cacheFromJavaClass(); > } > >+ private void cacheFromJavaClass() { >+ isInterface=javaClass.isInterface(); >+ isEnum=javaClass.isEnum(); >+ isAnnotation=javaClass.isAnnotation(); >+ isAnonymous=javaClass.isAnonymous(); >+ isNested=javaClass.isNested(); >+ modifiers=javaClass.getAccessFlags(); >+ superclassName=javaClass.getSuperclassName(); >+ className=javaClass.getClassName(); >+ cachedGenericClassTypeSignature = javaClass.getGenericClassTypeSignature(); >+ } >+ > > > >@@ -174,7 +219,7 @@ > } > > public int getModifiers() { >- return javaClass.getAccessFlags(); >+ return modifiers; > } > > /** >@@ -184,7 +229,7 @@ > if (isObject) return null; > unpackGenericSignature(); > if (superClass == null) { >- superClass = getResolvedTypeX().getWorld().resolve(UnresolvedType.forName(javaClass.getSuperclassName())); >+ superClass = getResolvedTypeX().getWorld().resolve(UnresolvedType.forName(superclassName)); > } > return superClass; > } >@@ -273,7 +318,7 @@ > typeMungers = new ArrayList(); > declares = new ArrayList(); > // Pass in empty list that can store things for readAj5 to process >- List l = BcelAttributes.readAjAttributes(javaClass.getClassName(),javaClass.getAttributes(), getResolvedTypeX().getSourceContext(),getResolvedTypeX().getWorld().getMessageHandler(),AjAttribute.WeaverVersionInfo.UNKNOWN); >+ List l = BcelAttributes.readAjAttributes(className,javaClass.getAttributes(), getResolvedTypeX().getSourceContext(),getResolvedTypeX().getWorld().getMessageHandler(),AjAttribute.WeaverVersionInfo.UNKNOWN); > processAttributes(l,pointcuts,false); > l = AtAjAttributes.readAj5ClassAttributes(javaClass, getResolvedTypeX(), getResolvedTypeX().getSourceContext(), getResolvedTypeX().getWorld().getMessageHandler(),isCodeStyleAspect); > AjAttribute.Aspect deferredAspectAttribute = processAttributes(l,pointcuts,true); >@@ -332,7 +377,7 @@ > return perClause; > } > >- JavaClass getJavaClass() { >+ public JavaClass getJavaClass() { > return javaClass; > } > >@@ -341,6 +386,11 @@ > } > > public void resetState() { >+ if (javaClass == null) { >+ // we might store the classname and allow reloading? >+ // At this point we are relying on the world to not evict if it might want to reweave multiple times >+ throw new BCException("can't reweave evicted type"); >+ } > this.interfaces = null; > this.superClass = null; > this.fields = null; >@@ -401,7 +451,7 @@ > //System.err.println("creating lazy class gen for: " + this); > ret = new LazyClassGen(this); > //ret.print(System.err); >- //System.err.println("made LCG from : " + this.getJavaClass().getSuperclassName() ); >+ //System.err.println("made LCG from : " + this.getJavaClass().getSuperclassName ); > if (isAspect()) { > lazyClassGen = ret; > } >@@ -410,23 +460,23 @@ > } > > public boolean isInterface() { >- return javaClass.isInterface(); >+ return isInterface;//javaClass.isInterface(); > } > > public boolean isEnum() { >- return javaClass.isEnum(); >+ return isEnum;//javaClass.isEnum(); > } > > public boolean isAnnotation() { >- return javaClass.isAnnotation(); >+ return isAnnotation;//javaClass.isAnnotation(); > } > > public boolean isAnonymous() { >- return javaClass.isAnonymous(); >+ return isAnonymous;//javaClass.isAnonymous(); > } > > public boolean isNested() { >- return javaClass.isNested(); >+ return isNested;//javaClass.isNested(); > } > > public void addAnnotation(AnnotationX annotation) { >@@ -552,7 +602,7 @@ > > interfaces = newInterfaceNames; > } >- //System.err.println("javaClass: " + Arrays.asList(javaClass.getInterfaceNames()) + " super " + javaClass.getSuperclassName()); >+ //System.err.println("javaClass: " + Arrays.asList(javaClass.getInterfaceNames()) + " super " + superclassName); > //if (lazyClassGen != null) lazyClassGen.print(); > } > >@@ -609,7 +659,7 @@ > } > > Signature.ClassSignature getGenericClassTypeSignature() { >- return javaClass.getGenericClassTypeSignature(); >+ return cachedGenericClassTypeSignature; > } > > private boolean genericSignatureUnpacked = false; >@@ -647,7 +697,7 @@ > } catch (GenericSignatureFormatException e) { > // development bug, fail fast with good info > throw new IllegalStateException( >- "While determing the generic superclass of " + this.javaClass.getClassName() >+ "While determing the generic superclass of " + this.className > + " with generic signature " + this.javaClass.getGenericSignature() + " the following error was detected: " > + e.getMessage()); > } >@@ -662,7 +712,7 @@ > } catch (GenericSignatureFormatException e) { > // development bug, fail fast with good info > throw new IllegalStateException( >- "While determing the generic superinterfaces of " + this.javaClass.getClassName() >+ "While determing the generic superinterfaces of " + this.className > + " with generic signature " + this.javaClass.getGenericSignature() + " the following error was detected: " > + e.getMessage()); > } >@@ -687,13 +737,13 @@ > } > > private boolean isNestedClass() { >- return javaClass.getClassName().indexOf('$') != -1; >+ return className.indexOf('$') != -1; > } > > private ReferenceType getOuterClass() { > if (!isNestedClass()) throw new IllegalStateException("Can't get the outer class of a non-nested type"); >- int lastDollar = javaClass.getClassName().lastIndexOf('$'); >- String superClassName = javaClass.getClassName().substring(0,lastDollar); >+ int lastDollar = className.lastIndexOf('$'); >+ String superClassName = className.substring(0,lastDollar); > UnresolvedType outer = UnresolvedType.forName(superClassName); > return (ReferenceType) outer.resolve(getResolvedTypeX().getWorld()); > } >@@ -732,7 +782,7 @@ > } > > public String toString() { >- return (javaClass==null?"BcelObjectType":"BcelObjectTypeFor:"+javaClass.getClassName()); >+ return (javaClass==null?"BcelObjectType":"BcelObjectTypeFor:"+className); > } > > // for testing - if we have this attribute, return it - will return null if it doesnt know anything >Index: src/org/aspectj/weaver/bcel/BcelWorld.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/bcel/BcelWorld.java,v >retrieving revision 1.41 >diff -u -r1.41 BcelWorld.java >--- src/org/aspectj/weaver/bcel/BcelWorld.java 22 Feb 2006 15:23:49 -0000 1.41 >+++ src/org/aspectj/weaver/bcel/BcelWorld.java 24 Feb 2006 08:18:16 -0000 >@@ -17,10 +17,12 @@ > import java.io.ByteArrayInputStream; > import java.io.File; > import java.io.IOException; >+import java.lang.reflect.Field; > import java.lang.reflect.Modifier; > import java.util.ArrayList; > import java.util.Iterator; > import java.util.List; >+import java.util.Map; > import java.util.Properties; > import java.util.StringTokenizer; > >@@ -71,12 +73,14 @@ > import org.aspectj.weaver.patterns.PerClause; > import org.aspectj.weaver.patterns.Pointcut; > import org.aspectj.weaver.patterns.SimpleScope; >+import org.aspectj.weaver.reflect.ReflectionBasedReferenceTypeDelegate; > > public class BcelWorld extends World implements Repository { > private ClassPathManager classPath; > > private Repository delegate; > >+ > private boolean fastDelegateSupportEnabled = isASMAround; > private boolean checkedXsetAsmOffOption=false; > >@@ -217,6 +221,10 @@ > } > > // ---- various interactions with bcel >+ protected BcelObjectType makeBcelObjectType(ReferenceType resolvedTypeX, JavaClass jc, boolean exposedToWeaver) { >+ BcelObjectType ret = new BcelObjectType(resolvedTypeX, jc, exposedToWeaver); >+ return ret; >+ } > > public static Type makeBcelType(UnresolvedType type) { > return Type.getType(type.getErasureSignature()); >@@ -288,7 +296,6 @@ > protected ReferenceTypeDelegate resolveDelegate(ReferenceType ty) { > String name = ty.getName(); > JavaClass jc = null; >- > // Check *once* whether the user has switched asm support off > if (!checkedXsetAsmOffOption) { > if (isASMAround) { // dont bother if its not... >@@ -404,7 +411,7 @@ > return ret; > } > >- void deleteSourceObjectType(UnresolvedType ty) { >+ public void deleteSourceObjectType(UnresolvedType ty) { > typeMap.remove(ty.getSignature()); > } > >@@ -607,6 +614,9 @@ > * quite often when incrementally compiling. > */ > public static BcelObjectType getBcelObjectType(ResolvedType concreteAspect) { >+ if (concreteAspect.isMissing()) { >+ return null; >+ } > ReferenceTypeDelegate rtDelegate = ((ReferenceType)concreteAspect).getDelegate(); > if (rtDelegate instanceof BcelObjectType) { > return (BcelObjectType)rtDelegate; >@@ -638,9 +648,9 @@ > } > > public void removeClass(JavaClass clazz) { >- throw new RuntimeException("Not implemented"); >+ delegate.removeClass(clazz); > } >- >+ > public JavaClass loadClass(Class clazz) throws ClassNotFoundException { > throw new RuntimeException("Not implemented"); > } >@@ -671,7 +681,6 @@ > // e.printStackTrace(); > // } > } >- > /** > * Checks if given bytecode is an @AspectJ aspect > * >@@ -714,4 +723,23 @@ > return true; > } > } >+ >+ >+ protected void evictClassLoaderRepository() { >+ if (delegate != this) { >+ // debug only ... I don't think this has any effect >+// try { >+// Field loadedClasses = delegate.getClass().getDeclaredField("loadedClasses"); >+// loadedClasses.setAccessible(true); >+// Map map = (Map)loadedClasses.get(delegate); >+// if (map.size()>0) { >+// System.out.println(map.size()); >+// } >+// } catch (Throwable t) { >+// t.printStackTrace(); >+// } >+ >+ delegate.clear(); // shrink/crunch... >+ } >+ } > } >Index: src/org/aspectj/weaver/ltw/LTWWorld.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/ltw/LTWWorld.java,v >retrieving revision 1.2 >diff -u -r1.2 LTWWorld.java >--- src/org/aspectj/weaver/ltw/LTWWorld.java 23 Feb 2006 11:34:16 -0000 1.2 >+++ src/org/aspectj/weaver/ltw/LTWWorld.java 24 Feb 2006 08:18:16 -0000 >@@ -15,14 +15,21 @@ > import java.lang.ref.WeakReference; > import java.util.Collections; > import java.util.HashMap; >+import java.util.Iterator; >+import java.util.List; > import java.util.Map; >+import java.util.Map.Entry; > >+import org.aspectj.apache.bcel.classfile.JavaClass; > import org.aspectj.bridge.IMessageHandler; >+import org.aspectj.bridge.Message; > import org.aspectj.util.LangUtil; > import org.aspectj.weaver.ICrossReferenceHandler; > import org.aspectj.weaver.ReferenceType; > import org.aspectj.weaver.ReferenceTypeDelegate; > import org.aspectj.weaver.ResolvedType; >+import org.aspectj.weaver.UnresolvedType; >+import org.aspectj.weaver.bcel.BcelObjectType; > import org.aspectj.weaver.bcel.BcelWorld; > import org.aspectj.weaver.reflect.AnnotationFinder; > import org.aspectj.weaver.reflect.IReflectionWorld; >@@ -48,9 +55,17 @@ > private AnnotationFinder annotationFinder; > private ClassLoader loader; // weavingContext? > >+ private boolean loadingAspects = false; > protected final static Class concurrentMapClass = makeConcurrentMapClass(); > protected static Map/*<String, WeakReference<ReflectionBasedReferenceTypeDelegate>>*/ bootstrapTypes = makeConcurrentMap(); > >+ private static ThreadLocal loadingCount = new ThreadLocal() { >+ public Object initialValue() { >+ return new int[1]; >+ } >+ }; >+ private static MapThreadLocal processedRefTypes = new MapThreadLocal(); >+ > /** > * Build a World from a ClassLoader, for LTW support > */ >@@ -66,14 +81,69 @@ > return this.loader; > } > >- //TEST >+ public void setLoadingAspects(boolean isLoading) { >+ loadingAspects = isLoading; >+ flushOld(); >+ } >+ // this was created to try to avoid circularity errors using reflection delegates, but that's not practical in general >+ // now it's used to optimize performance, so we only evict objects when done with all local >+ // weaves... >+ // it looks like overkill in this simplified version of LTWWorld, but it is laying a foundation to allow load-time weaving worlds >+ // to share state, which ends up being quite important to optimize memory use >+ public void startLoading(String name) { >+ ((int[])loadingCount.get())[0]++; >+ } >+ >+ public void stopLoading(String name) { >+ int count = --((int[])loadingCount.get())[0]; >+ if (count == 0) { >+ // go back and swizzle out all those proxies >+ flushOld(); >+ } >+ } >+ >+ protected void flushOld() { >+ // we can unload when nothing is now being loaded... while >+ // a ClassLoader can be re-engaged in between preloading and defining the class >+ // it can't cycle, so we should be safe from cycles >+ // in the worst case, we'd just evict some bytecode and then reload from BCEL again... >+ if (!loadingAspects) { >+ evict(); >+ } >+ } >+ >+ /** Evict details not needed after weaving a type (keeping only a "shape") */ >+ protected void evict() { >+ // evicting can load new types when caching, requiring this loop >+ while (!processedRefTypes.isEmpty()) { >+ Map map = processedRefTypes.snapOffMap(); >+ for (Iterator it = map.entrySet().iterator(); it.hasNext();) { >+ Entry entry = (Entry)it.next(); >+ ReferenceType refType = (ReferenceType)(entry.getKey()); >+ LTWWorld world = (LTWWorld)(entry.getValue()); >+ world.evict(refType); >+ } >+ map.clear(); >+ evictReweavingState(); >+ } >+ evictClassLoaderRepository(); >+ } >+ >+ public BcelObjectType addSourceObjectType(JavaClass jc) { >+ BcelObjectType objectType = super.addSourceObjectType(jc); >+ >+ processedRefTypes.put(objectType.getResolvedTypeX(), this); >+ >+ return objectType; >+ } >+ > //this is probably easier: just mark anything loaded while loading aspects as not > //expendable... it also fixes a possible bug whereby non-rewoven aspects are deemed expendable > //<exclude within="org.foo.aspects..*"/> >-// protected boolean isExpendable(ResolvedType type) { >-// return ((type != null) && !loadingAspects && !type.isAspect() && (!type >-// .isPrimitiveType())); >-// } >+ protected boolean isExpendable(ResolvedType type) { >+ return !type.equals(UnresolvedType.OBJECT) && >+ ((type != null) && !loadingAspects && !type.isAspect() && (!type.isPrimitiveType())); >+ } > > /** > * @Override >@@ -87,6 +157,7 @@ > return bootstrapLoaderDelegate; > } > >+ processedRefTypes.put(ty, this); > return super.resolveDelegate(ty); > } > >@@ -181,4 +252,78 @@ > return null; > } > >+ protected void evict(ReferenceType refType) { >+ ReferenceTypeDelegate refDelegate = refType.getDelegate(); >+ if (refDelegate instanceof BcelObjectType) { >+ BcelObjectType bcelObject = (BcelObjectType)refDelegate; >+ if (bcelObject.getJavaClass() != null) { >+ // not needed: we are retaining the key information and we do proper hollowing >+ removeClass(bcelObject.getJavaClass()); >+ } >+ //this should probably be either/or: either we are removing the class altogether or we are keeping it and evicting reweaving state... >+ //bcelObject.evictReweavingState(); >+ } >+ // advice inlining uses the JavaClass later on for Lazy instantiation >+ if (refDelegate != null && !refType.isAspect()) { >+ refDelegate.evictReweavingState(); >+ } >+ } >+ >+ private static class MapThreadLocal { >+ private MapThreadLocalData mapHolder = new MapThreadLocalData(); >+ private MapThreadLocalData altHolder = new MapThreadLocalData(); >+ private static class MapThreadLocalData extends ThreadLocal/*<Map<Type, Ref>>*/ { >+ public Object initialValue() { >+ return new HashMap(); >+ } >+ }; >+ private Map getMap() { >+ return (Map)mapHolder.get(); >+ } >+ private Map snapOffMap() { >+ MapThreadLocalData alt = mapHolder; >+ mapHolder = altHolder; >+ altHolder = alt; >+ >+ getMap().clear(); >+ return (Map)altHolder.get(); >+ } >+ >+ public void put(Object key, Object val) { >+ getMap().put(key, val); >+ } >+ >+ public Object remove(Object key) { >+ return getMap().remove(key); >+ } >+ >+ public boolean isEmpty() { >+ return getMap().isEmpty(); >+ } >+ >+ public Iterator entryIterator() { >+ return getMap().entrySet().iterator(); >+ } >+ >+ public void clear() { >+ getMap().clear(); >+ } >+ }; >+ >+// /** >+// * Allow reweaving is used to control whether we expect to reweave types after they've been loaded once. >+// * This allows the world to evict bytecode for method implementations. >+// */ >+// public boolean isAllowReweaving() { >+// return allowReweaving; >+// } >+// >+// /** >+// * Sets whether we expect to reweave types after they've been loaded once. >+// * This allows the world to evict bytecode for method implementations after definition. >+// */ >+// public void setAllowReweaving(boolean allowReweaving) { >+// this.allowReweaving = allowReweaving; >+// } >+ > } >Index: src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java,v >retrieving revision 1.13 >diff -u -r1.13 ReflectionBasedReferenceTypeDelegate.java >--- src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java 22 Feb 2006 15:26:26 -0000 1.13 >+++ src/org/aspectj/weaver/reflect/ReflectionBasedReferenceTypeDelegate.java 24 Feb 2006 08:18:17 -0000 >@@ -17,6 +17,8 @@ > import java.lang.reflect.Method; > import java.util.Collection; > import java.util.Collections; >+import java.util.HashMap; >+import java.util.Iterator; > > import org.aspectj.weaver.AnnotationTargetKind; > import org.aspectj.weaver.AnnotationX; >@@ -362,5 +364,7 @@ > public ISourceContext getSourceContext() { > return SourceContextImpl.UNKNOWN_SOURCE_CONTEXT; > } >+ >+ public void evictReweavingState() {} > > } >Index: src/org/aspectj/weaver/tools/WeavingAdaptor.java >=================================================================== >RCS file: /home/technology/org.aspectj/modules/weaver/src/org/aspectj/weaver/tools/WeavingAdaptor.java,v >retrieving revision 1.26 >diff -u -r1.26 WeavingAdaptor.java >--- src/org/aspectj/weaver/tools/WeavingAdaptor.java 19 Dec 2005 21:20:07 -0000 1.26 >+++ src/org/aspectj/weaver/tools/WeavingAdaptor.java 24 Feb 2006 08:18:17 -0000 >@@ -44,6 +44,7 @@ > import org.aspectj.weaver.bcel.BcelWeaver; > import org.aspectj.weaver.bcel.BcelWorld; > import org.aspectj.weaver.bcel.UnwovenClassFile; >+import org.aspectj.weaver.ltw.LTWWorld; > > /** > * This adaptor allows the AspectJ compiler to be embedded in an existing >@@ -272,7 +273,7 @@ > * @return byte[] the woven bytes for the class > * @throws IOException > */ >- private byte[] getWovenBytes(String name, byte[] bytes) throws IOException { >+ protected byte[] getWovenBytes(String name, byte[] bytes) throws IOException { > WeavingClassFileProvider wcp = new WeavingClassFileProvider(name,bytes); > weaver.weave(wcp); > return wcp.getBytes(); >@@ -286,7 +287,7 @@ > * @return byte[] the woven bytes for the class > * @throws IOException > */ >- private byte[] getAtAspectJAspectBytes(String name, byte[] bytes) throws IOException { >+ protected byte[] getAtAspectJAspectBytes(String name, byte[] bytes) throws IOException { > WeavingClassFileProvider wcp = new WeavingClassFileProvider(name,bytes); > wcp.setApplyAtAspectJMungersOnly(); > weaver.weave(wcp);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 129297
:
35288
|
35289
|
35290
| 35292