]> source.dussan.org Git - aspectj.git/commitdiff
230134: tests and fixes - move cflow caches from static state to crosscuttingmembers...
authoraclement <aclement>
Mon, 5 May 2008 18:55:47 +0000 (18:55 +0000)
committeraclement <aclement>
Mon, 5 May 2008 18:55:47 +0000 (18:55 +0000)
weaver/src/org/aspectj/weaver/CrosscuttingMembers.java
weaver/src/org/aspectj/weaver/CrosscuttingMembersSet.java
weaver/src/org/aspectj/weaver/bcel/BcelCflowCounterFieldAdder.java
weaver/src/org/aspectj/weaver/bcel/BcelWeaver.java
weaver/src/org/aspectj/weaver/patterns/CflowPointcut.java

index 3ff7d75aa5bbd9f551dc9834b2cafc6574f744db..783bacbb5d7d00b128b936ace4ae7837df6ec1b4 100644 (file)
@@ -14,8 +14,10 @@ package org.aspectj.weaver;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.HashSet;
+import java.util.Hashtable;
 import java.util.Iterator;
 import java.util.List;
+import java.util.Map;
 import java.util.Set;
 
 import org.aspectj.weaver.bcel.BcelAdvice;
@@ -71,6 +73,10 @@ public class CrosscuttingMembers {
                this.shouldConcretizeIfNeeded = shouldConcretizeIfNeeded;
        }
        
+
+       private Hashtable cflowFields = new Hashtable();
+       private Hashtable cflowBelowFields = new Hashtable();
+       
 //     public void addConcreteShadowMungers(Collection c) {
 //             shadowMungers.addAll(c);
 //     }
@@ -502,4 +508,17 @@ public class CrosscuttingMembers {
                return declareAnnotationsOnMethods;
        }
 
+       public Map getCflowBelowFields() {
+               return cflowBelowFields;
+       }
+
+       public Map getCflowFields() {
+               return cflowFields;
+       }
+       
+       public void clearCaches() {
+               cflowFields.clear();
+               cflowBelowFields.clear();
+       }
+
 }
index 55d46b64263454a33e1e5f320b25bbeb33255aab..a57bbf0ac070ab2a11f5efd144da09e452842ab3 100644 (file)
@@ -78,13 +78,10 @@ public class CrosscuttingMembersSet {
                if (xcut == null) {
                        members.put(aspectType, aspectType.collectCrosscuttingMembers(inWeavingPhase));
                        clearCaches();
-                       CflowPointcut.clearCaches(aspectType);
                        change = true;
                } else {
                        if (xcut.replaceWith(aspectType.collectCrosscuttingMembers(inWeavingPhase),inWeavingPhase)) {
                                clearCaches();
-
-                               CflowPointcut.clearCaches(aspectType);
                                change = true;
                        } else {
                                if (!AsmManager.getDefault().getHandleProvider().dependsOnLocation()
index ceb471cf54bf3074fc856c5b598f951f52b748a1..558a98b64a242470c5147edc90b0c1da0efba821 100644 (file)
@@ -88,5 +88,9 @@ public class BcelCflowCounterFieldAdder extends BcelTypeMunger {
        public boolean existsToSupportShadowMunging() {
                return true;
        }
+       
+       public String toString() {
+               return "(BcelTypeMunger: CflowField "+cflowCounterField.getDeclaringType().getName()+" "+cflowCounterField.getName()+")";
+       }
 
 }
index 62c53629c1048dcc448fd2f0dae1088de84d9ffa..820ff77c4ed24170dd9d79305feb6fb953d92690 100644 (file)
@@ -470,8 +470,6 @@ public class BcelWeaver implements IWeaver {
     public void prepareForWeave() {
        if (trace.isTraceEnabled()) trace.enter("prepareForWeave",this);
        needToReweaveWorld = xcutSet.hasChangedSinceLastReset();
-
-       CflowPointcut.clearCaches();
        
        // update mungers
        for (Iterator i = addedClasses.iterator(); i.hasNext(); ) { 
index 1229cd473ed2c654b994d68f7ca3b6d4472c2fc9..887b5ac00658af0df5fc62e30d9bb5fa1c1673ea 100644 (file)
@@ -50,8 +50,6 @@ public class CflowPointcut extends Pointcut {
        boolean isBelow;// Is this cflowbelow?
        private int[] freeVars;
        
-       private static Hashtable cflowFields = new Hashtable();
-       private static Hashtable cflowBelowFields = new Hashtable();
        
        /**
         * Used to indicate that we're in the context of a cflow when concretizing if's
@@ -217,7 +215,7 @@ public class CflowPointcut extends Pointcut {
                if (freeVars==null || freeVars.length == 0) { // No state, so don't use a stack, use a counter.
                  ResolvedMember localCflowField = null;
 
-                 Object field = getCflowfield(concreteEntry,concreteAspect,"counter");
+                 Object field = getCflowfield(xcut, concreteEntry, concreteAspect, "counter");
                  
                  // Check if we have already got a counter for this cflow pointcut
                  if (field != null) {
@@ -236,7 +234,7 @@ public class CflowPointcut extends Pointcut {
                        concreteAspect.crosscuttingMembers.addConcreteShadowMunger(
                    Advice.makeCflowEntry(world,concreteEntry,isBelow,localCflowField,freeVars==null?0:freeVars.length,innerCflowEntries,inAspect));
            
-                       putCflowfield(concreteEntry,concreteAspect,localCflowField,"counter"); // Remember it
+                       putCflowfield(xcut,concreteEntry,concreteAspect,localCflowField,"counter"); // Remember it
              }
                    
                  Pointcut ret = new ConcreteCflowPointcut(localCflowField, null,true);
@@ -276,7 +274,7 @@ public class CflowPointcut extends Pointcut {
                                slots.add(slot);
                        }
                        ResolvedMember localCflowField = null;
-                       Object field = getCflowfield(concreteEntry,concreteAspect,"stack");
+                       Object field = getCflowfield(xcut,concreteEntry,concreteAspect,"stack");
                        if (field != null) {
                                localCflowField = (ResolvedMember)field;
                        } else {
@@ -295,7 +293,7 @@ public class CflowPointcut extends Pointcut {
                        
                          concreteAspect.crosscuttingMembers.addTypeMunger(
                                world.makeCflowStackFieldAdder(localCflowField));
-                         putCflowfield(concreteEntry,concreteAspect,localCflowField,"stack");
+                         putCflowfield(xcut,concreteEntry,concreteAspect,localCflowField,"stack");
                    }
                        Pointcut ret = new ConcreteCflowPointcut(localCflowField, slots,false);
                        ret.copyLocationFrom(this);
@@ -304,10 +302,6 @@ public class CflowPointcut extends Pointcut {
                
        }
        
-       public static void clearCaches() {
-               cflowFields.clear();
-               cflowBelowFields.clear();
-       }
        
        private String getKey(Pointcut p,ResolvedType a,String stackOrCounter) {
          StringBuffer sb = new StringBuffer();
@@ -319,22 +313,22 @@ public class CflowPointcut extends Pointcut {
          return sb.toString();
        }
        
-       private Object getCflowfield(Pointcut pcutkey, ResolvedType concreteAspect,String stackOrCounter) {
+       private Object getCflowfield(CrosscuttingMembers xcut, Pointcut pcutkey, ResolvedType concreteAspect,String stackOrCounter) {
                String key = getKey(pcutkey,concreteAspect,stackOrCounter);
                Object o =null;
-               if (isBelow) o = cflowBelowFields.get(key);
-               else         o = cflowFields.get(key);
+               if (isBelow) o = xcut.getCflowBelowFields().get(key);
+               else         o = xcut.getCflowFields().get(key);
                //System.err.println("Retrieving for key "+key+" returning "+o);
                return o;
        }
        
-       private void putCflowfield(Pointcut pcutkey,ResolvedType concreteAspect,Object o,String stackOrCounter) {
+       private void putCflowfield(CrosscuttingMembers xcut, Pointcut pcutkey,ResolvedType concreteAspect,Object o,String stackOrCounter) {
                String key = getKey(pcutkey,concreteAspect,stackOrCounter);
                //System.err.println("Storing cflow field for key"+key);
                if (isBelow) {
-                       cflowBelowFields.put(key,o);
+                       xcut.getCflowBelowFields().put(key,o);
                } else {
-                       cflowFields.put(key,o);
+                       xcut.getCflowFields().put(key,o);
                }
        }
 
@@ -342,23 +336,4 @@ public class CflowPointcut extends Pointcut {
         return visitor.visit(this, data);
        }
 
-       public static void clearCaches(ResolvedType aspectType) {
-               //System.err.println("Wiping entries starting "+aspectType.getName());
-               String key = aspectType.getName()+"::";
-               wipeKeys(key,cflowFields);
-               wipeKeys(key,cflowBelowFields);
-       }
-       
-       private static void wipeKeys(String keyPrefix,Hashtable ht) {
-               Enumeration keys = ht.keys();
-               List forRemoval = new ArrayList();
-               while (keys.hasMoreElements()) {
-                       String s = (String)keys.nextElement();
-                       if (s.startsWith(keyPrefix)) forRemoval.add(s);
-               }
-               for (Iterator iter = forRemoval.iterator(); iter.hasNext();) {
-                       String element = (String) iter.next();
-                       ht.remove(element);
-               }
-       }
 }