]> source.dussan.org Git - aspectj.git/commitdiff
optimization: dont capture lowest level context info unless -Xset:captureAllContext...
authoraclement <aclement>
Wed, 22 Feb 2006 16:22:26 +0000 (16:22 +0000)
committeraclement <aclement>
Wed, 22 Feb 2006 16:22:26 +0000 (16:22 +0000)
weaver/src/org/aspectj/weaver/World.java
weaver/src/org/aspectj/weaver/bcel/BcelClassWeaver.java

index f01b4001c34774121531cff70c13b8452a0d3a33..5f9cf6d013499dddd41dffef04702efbf884c8d5 100644 (file)
@@ -702,6 +702,8 @@ public abstract class World implements Dump.INode {
        public Properties getExtraConfiguration() {
                return extraConfiguration;
        }
+       public final static String xsetCAPTURE_ALL_CONTEXT = "captureAllContext"; // default false
+       
        
        public boolean isInJava5Mode() {
                return behaveInJava5Way;
index b40fa9b93f4118864f127bbf3c3a45deac28cf60..63a916ca1fe800cc1fde48520e3edc4914733aac 100644 (file)
@@ -23,6 +23,7 @@ import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
+import java.util.Properties;
 import java.util.Set;
 
 import org.aspectj.apache.bcel.Constants;
@@ -61,6 +62,7 @@ import org.aspectj.apache.bcel.generic.annotation.AnnotationGen;
 import org.aspectj.bridge.IMessage;
 import org.aspectj.bridge.ISourceLocation;
 import org.aspectj.bridge.Message;
+import org.aspectj.bridge.MessageUtil;
 import org.aspectj.bridge.WeaveMessage;
 import org.aspectj.bridge.context.CompilationAndWeavingContext;
 import org.aspectj.bridge.context.ContextToken;
@@ -88,6 +90,7 @@ import org.aspectj.weaver.UnresolvedType;
 import org.aspectj.weaver.WeaverMessages;
 import org.aspectj.weaver.WeaverMetrics;
 import org.aspectj.weaver.WeaverStateInfo;
+import org.aspectj.weaver.World;
 import org.aspectj.weaver.patterns.DeclareAnnotation;
 import org.aspectj.weaver.patterns.ExactTypePattern;
 
@@ -167,6 +170,16 @@ class BcelClassWeaver implements IClassWeaver {
                fastMatchShadowMungers(shadowMungers);
                
                initializeSuperInitializerMap(ty.getResolvedTypeX());
+               if (!checkedXsetForLowLevelContextCapturing) {
+                       Properties p = world.getExtraConfiguration();
+               if (p!=null) {
+                       String s = p.getProperty(World.xsetCAPTURE_ALL_CONTEXT,"false");
+                       captureLowLevelContext = s.equalsIgnoreCase("true");
+                       if (captureLowLevelContext) 
+                               world.getMessageHandler().handleMessage(MessageUtil.info("["+World.xsetCAPTURE_ALL_CONTEXT+"=true] Enabling collection of low level context for debug/crash messages"));
+               }
+                       checkedXsetForLowLevelContextCapturing=true;
+               }
        } 
        
 
@@ -2148,31 +2161,49 @@ class BcelClassWeaver implements IClassWeaver {
                }
        }
        
+       // static ... so all worlds will share the config for the first one created...
+       private static boolean checkedXsetForLowLevelContextCapturing = false;
+       private static boolean captureLowLevelContext = false;
+       
     private boolean match(BcelShadow shadow, List shadowAccumulator) {
        //System.err.println("match: " + shadow);
-       ContextToken shadowMatchToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.MATCHING_SHADOW, shadow);
-        boolean isMatched = false;
-        for (Iterator i = shadowMungers.iterator(); i.hasNext(); ) {
-            ShadowMunger munger = (ShadowMunger)i.next();
-            ContextToken mungerMatchToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.MATCHING_POINTCUT, munger.getPointcut());
-            if (munger.match(shadow, world)) {
-               
-                               WeaverMetrics.recordMatchResult(true);// Could pass: munger
-                shadow.addMunger(munger);
-                isMatched = true;
-                           if (shadow.getKind() == Shadow.StaticInitialization) {
-                                 clazz.warnOnAddedStaticInitializer(shadow,munger.getSourceLocation());
-                           }
-                               
-            } else {
-               WeaverMetrics.recordMatchResult(false); // Could pass: munger
-               }
-            CompilationAndWeavingContext.leavingPhase(mungerMatchToken);
-        }       
-
-        if (isMatched) shadowAccumulator.add(shadow);
-        CompilationAndWeavingContext.leavingPhase(shadowMatchToken);
-        return isMatched;
+       if (captureLowLevelContext) { // duplicate blocks - one with context capture, one without, seems faster than multiple 'ifs()'
+               ContextToken shadowMatchToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.MATCHING_SHADOW, shadow);
+               boolean isMatched = false;
+               for (Iterator i = shadowMungers.iterator(); i.hasNext(); ) {
+                   ShadowMunger munger = (ShadowMunger)i.next();
+                   ContextToken mungerMatchToken = CompilationAndWeavingContext.enteringPhase(CompilationAndWeavingContext.MATCHING_POINTCUT, munger.getPointcut());
+                   if (munger.match(shadow, world)) {
+                                       WeaverMetrics.recordMatchResult(true);// Could pass: munger
+                       shadow.addMunger(munger);
+                       isMatched = true;
+                                   if (shadow.getKind() == Shadow.StaticInitialization) {
+                                         clazz.warnOnAddedStaticInitializer(shadow,munger.getSourceLocation());
+                                   }
+                   } else {
+                       WeaverMetrics.recordMatchResult(false); // Could pass: munger
+                       }
+                   CompilationAndWeavingContext.leavingPhase(mungerMatchToken);
+               }       
+       
+               if (isMatched) shadowAccumulator.add(shadow);
+               CompilationAndWeavingContext.leavingPhase(shadowMatchToken);
+               return isMatched;
+       } else {
+               boolean isMatched = false;
+               for (Iterator i = shadowMungers.iterator(); i.hasNext(); ) {
+                   ShadowMunger munger = (ShadowMunger)i.next();
+                   if (munger.match(shadow, world)) {
+                       shadow.addMunger(munger);
+                       isMatched = true;
+                                   if (shadow.getKind() == Shadow.StaticInitialization) {
+                                         clazz.warnOnAddedStaticInitializer(shadow,munger.getSourceLocation());
+                                   }
+                       }
+               }               
+               if (isMatched) shadowAccumulator.add(shadow);
+               return isMatched;
+       }
     }
     
     // ----