--- /dev/null
+package trace;
+
+public aspect HardTraceNothing extends MegaTrace {
+ pointcut where(): call(public * frotz(..));
+}
\ No newline at end of file
--- /dev/null
+package trace;
+
+public aspect ObviousTraceNothing extends MegaTrace {
+ pointcut where(): within(foo.bar..*);
+
+ declare parents: foo.bar..* implements Marker;
+}
\ No newline at end of file
makeJar1a();
makeJar2();
+ makeJarObviousNothing();
+ makeJarHardNothing();
+
+
makeTestJars();
}
}
+ public static void makeJarObviousNothing() throws IOException {
+ List args = new ArrayList();
+ args.add("-outjar");
+ args.add("../weaver/testdata/megatrace0easy.jar");
+
+ args.add("-classpath");
+ args.add("../runtime/bin");
+
+ args.add("testdata/src1/trace/MegaTrace.java");
+ args.add("testdata/src1/trace/ObviousTraceNothing.java");
+
+ CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS);
+ }
+
+ public static void makeJarHardNothing() throws IOException {
+ List args = new ArrayList();
+ args.add("-outjar");
+ args.add("../weaver/testdata/megatrace0hard.jar");
+
+ args.add("-classpath");
+ args.add("../runtime/bin");
+
+ args.add("testdata/src1/trace/MegaTrace.java");
+ args.add("testdata/src1/trace/HardTraceNothing.java");
+
+ CommandTestCase.runCompiler(args, CommandTestCase.NO_ERRORS);
+ }
+
+
public static void makeJar1a() throws IOException {
List args = new ArrayList();
args.add("-outjar");
package org.aspectj.weaver.bcel;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
-import java.util.zip.ZipOutputStream;
+import java.io.*;
+import java.util.*;
+import java.util.zip.*;
import org.apache.bcel.classfile.ClassParser;
import org.apache.bcel.classfile.JavaClass;
import org.aspectj.bridge.IMessage;
import org.aspectj.util.FileUtil;
-import org.aspectj.weaver.ConcreteTypeMunger;
-import org.aspectj.weaver.CrosscuttingMembersSet;
-import org.aspectj.weaver.IWeaver;
-import org.aspectj.weaver.ResolvedTypeX;
-import org.aspectj.weaver.TypeX;
+import org.aspectj.weaver.*;
+import org.aspectj.weaver.patterns.Pointcut;
public class BcelWeaver implements IWeaver {
private BcelWorld world;
}
JavaClass javaClass = classType.getJavaClass();
- List shadowMungers = fastMatch(shadowMungerList, javaClass);
- List typeMungers = fastMatch(classType.getResolvedTypeX().getInterTypeMungers(), javaClass);
+ List shadowMungers = fastMatch(shadowMungerList, classType.getResolvedTypeX());
+ List typeMungers = classType.getResolvedTypeX().getInterTypeMungers();
LazyClassGen clazz = null;
zipOutputStream.closeEntry();
}
- // ---- fast matching
-
-// boolean fastMatch(JavaClass jc) {
-// ConstantPool pool = jc.getConstantPool();
-// for (int i=0, len=pool.getLength(); i < len; i++) {
-// Constant c = pool.getConstant(i);
-// if (c instanceof ConstantNameAndType) {
-// ConstantNameAndType nt = (ConstantNameAndType)c;
-// if (nt.getName(pool).equals("toShortString")) {
-// //System.out.println("found in " + jc);
-// return true;
-// }
-// }
-// }
-// return false;
-// }
-
- //XXX need to implement a real fast-match here
- private List fastMatch(List list, JavaClass javaClass) {
+ private List fastMatch(List list, ResolvedTypeX type) {
if (list == null) return Collections.EMPTY_LIST;
- return list;
+
+ List result = new ArrayList();
+ Iterator iter = list.iterator();
+ while (iter.hasNext()) {
+ ShadowMunger munger = (ShadowMunger)iter.next();
+ if (munger.getPointcut().fastMatch(type).maybeTrue()) {
+ result.add(munger);
+ }
+ }
+ return result;
}
}
setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
}
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return left.fastMatch(type).and(right.fastMatch(type));
+ }
+
public FuzzyBoolean match(Shadow shadow) {
return left.match(shadow).and(right.match(shadow));
}
public ArgsPointcut(TypePatternList arguments) {
this.arguments = arguments;
}
+
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
public FuzzyBoolean match(Shadow shadow) {
FuzzyBoolean ret =
this.freeVars = freeVars;
}
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
+
public FuzzyBoolean match(Shadow shadow) {
//??? this is not maximally efficient
return FuzzyBoolean.MAYBE;
this.slots = slots;
}
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
+
public FuzzyBoolean match(Shadow shadow) {
//??? this is not maximally efficient
return FuzzyBoolean.MAYBE;
this.exceptionType = exceptionType;
}
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ //??? should be able to do better by finding all referenced types in type
+ return FuzzyBoolean.MAYBE;
+ }
public FuzzyBoolean match(Shadow shadow) {
if (shadow.getKind() != Shadow.ExceptionHandler) return FuzzyBoolean.NO;
this.testMethod = testMethod;
this.extraParameterFlags = extraParameterFlags;
}
+
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
public FuzzyBoolean match(Shadow shadow) {
//??? this is not maximally efficient
package org.aspectj.weaver.patterns;
-import java.io.DataInputStream;
-import java.io.DataOutputStream;
-import java.io.IOException;
+import java.io.*;
-import org.apache.bcel.classfile.JavaClass;
import org.aspectj.util.FuzzyBoolean;
-import org.aspectj.weaver.ISourceContext;
-import org.aspectj.weaver.IntMap;
-import org.aspectj.weaver.ResolvedTypeX;
-import org.aspectj.weaver.Shadow;
+import org.aspectj.weaver.*;
import org.aspectj.weaver.ast.Literal;
import org.aspectj.weaver.ast.Test;
this.signature = signature;
}
- public boolean fastMatch(JavaClass jc) { return true; }
-
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
public FuzzyBoolean match(Shadow shadow) {
if (shadow.getKind() != kind) return FuzzyBoolean.NO;
this.body = left;
}
- /**
- * Constructor NotPointcut.
- * @param pointcut
- * @param startPos
- */
public NotPointcut(Pointcut pointcut, int startPos) {
this(pointcut);
setLocation(pointcut.getSourceContext(), startPos, pointcut.getEnd());
}
- /**
- * @see org.aspectj.weaver.patterns.Pointcut#match(BcelShadow)
- */
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return body.fastMatch(type).not();
+ }
+
public FuzzyBoolean match(Shadow shadow) {
return body.match(shadow).not();
}
public class OrPointcut extends Pointcut {
private Pointcut left, right;
- /**
- * Constructor for AndPointcut.
- */
+
public OrPointcut(Pointcut left, Pointcut right) {
super();
this.left = left;
setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
}
- /**
- * @see org.aspectj.weaver.patterns.Pointcut#match(BcelShadow)
- */
+
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return left.fastMatch(type).or(right.fastMatch(type));
+ }
+
public FuzzyBoolean match(Shadow shadow) {
return left.match(shadow).or(right.match(shadow));
}
// -----
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
+
public FuzzyBoolean match(Shadow shadow) {
return FuzzyBoolean.YES;
}
import java.io.IOException;
import org.aspectj.util.TypeSafeEnum;
-import org.aspectj.weaver.BCException;
-import org.aspectj.weaver.ISourceContext;
-import org.aspectj.weaver.IntMap;
-import org.aspectj.weaver.ResolvedTypeX;
+import org.aspectj.weaver.*;
public abstract class PerClause extends Pointcut {
protected ResolvedTypeX inAspect;
public abstract PerClause concretize(ResolvedTypeX inAspect);
-
public abstract PerClause.Kind getKind();
-
public static class Kind extends TypeSafeEnum {
public Kind(String name, int key) { super(name, key); }
this.kind = kind;
}
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ throw new RuntimeException("unimplemented");
+ }
+
public FuzzyBoolean match(Shadow shadow) {
throw new RuntimeException("unimplemented");
}
}
// -----
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
+
public FuzzyBoolean match(Shadow shadow) {
//System.err.println("matches " + this + " ? " + shadow + ", " + shadow.hasTarget());
public PerSingleton() {
}
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.YES;
+ }
+
public FuzzyBoolean match(Shadow shadow) {
return FuzzyBoolean.YES;
}
/**
- * Could I match any shadows in this JavaClass
+ * Could I match any shadows in the code defined within this type?
*/
- public boolean fastMatch(JavaClass jc) { return true; }
+ public abstract FuzzyBoolean fastMatch(ResolvedTypeX type);
/**
* Do I really match this shadow?
return Literal.FALSE; // can only get here if an earlier error occurred
}
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.NO;
+ }
+
public FuzzyBoolean match(Shadow shadow) {
return FuzzyBoolean.NO;
}
this.arguments = arguments;
}
- /**
- * Could I match any shadows in this JavaClass
- */
- public boolean fastMatch(JavaClass jc) { return true; }
+
+ //??? do either of these match methods make any sense???
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
/**
* Do I really match this shadow?
public boolean matches(Member member, World world) {
//XXX performance gains would come from matching on name before resolving
- // to fail fast
+ // to fail fast
ResolvedMember sig = member.resolve(world);
if (sig == null) {
//XXX
this.type = type;
}
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
+
private boolean couldMatch(Shadow shadow) {
return isThis ? shadow.hasThis() : shadow.hasTarget();
}
WildTypePattern(NamePattern[] namePatterns, boolean includeSubtypes, int dim) {
super(includeSubtypes);
this.namePatterns = namePatterns;
- this.ellipsisCount = ellipsisCount;
this.dim = dim;
ellipsisCount = 0;
for (int i=0; i<namePatterns.length; i++) {
import org.aspectj.weaver.ast.Test;
public class WithinPointcut extends Pointcut {
- TypePattern type;
+ TypePattern typePattern;
public WithinPointcut(TypePattern type) {
- this.type = type;
+ this.typePattern = type;
}
-
- public FuzzyBoolean match(Shadow shadow) {
- ResolvedTypeX enclosingType = shadow.getIWorld().resolve(shadow.getEnclosingType());
- //System.err.println("enclosingType: " + enclosingType);
-// if (shadow.getKind() == Shadow.FieldSet) {
-// System.err.println("within?" + type + " matches " + enclosingType + " on " + shadow);
-// }
-
- while (enclosingType != null) {
- if (type.matchesStatically(enclosingType)) {
+
+ private FuzzyBoolean isWithinType(ResolvedTypeX type) {
+ while (type != null) {
+ if (typePattern.matchesStatically(type)) {
return FuzzyBoolean.YES;
}
- enclosingType = enclosingType.getDeclaringType();
+ type = type.getDeclaringType();
}
return FuzzyBoolean.NO;
}
+
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return isWithinType(type);
+ }
+
+ public FuzzyBoolean match(Shadow shadow) {
+ ResolvedTypeX enclosingType = shadow.getIWorld().resolve(shadow.getEnclosingType());
+ return isWithinType(enclosingType);
+ }
public void write(DataOutputStream s) throws IOException {
s.writeByte(Pointcut.WITHIN);
- type.write(s);
+ typePattern.write(s);
writeLocation(s);
}
public static Pointcut read(DataInputStream s, ISourceContext context) throws IOException {
}
public void resolveBindings(IScope scope, Bindings bindings) {
- type = type.resolveBindings(scope, bindings, false, false);
+ typePattern = typePattern.resolveBindings(scope, bindings, false, false);
}
public void postRead(ResolvedTypeX enclosingType) {
- type.postRead(enclosingType);
+ typePattern.postRead(enclosingType);
}
public boolean equals(Object other) {
if (!(other instanceof WithinPointcut)) return false;
WithinPointcut o = (WithinPointcut)other;
- return o.type.equals(this.type);
+ return o.typePattern.equals(this.typePattern);
}
public int hashCode() {
int result = 43;
- result = 37*result + type.hashCode();
+ result = 37*result + typePattern.hashCode();
return result;
}
public String toString() {
- return "within(" + type + ")";
+ return "within(" + typePattern + ")";
}
public Test findResidue(Shadow shadow, ExposedState state) {
this.signature = signature;
}
+ public FuzzyBoolean fastMatch(ResolvedTypeX type) {
+ return FuzzyBoolean.MAYBE;
+ }
+
public FuzzyBoolean match(Shadow shadow) {
//This will not match code in local or anonymous classes as if
//they were withincode of the outer signature
weaver.addLibraryJarFile(new File(aspectjar));
}
}
+ weaver.addLibraryJarFile(new File("testdata/Regex.jar")); //???
Collection woven = weaver.weave(outFile);
zipTest("testdata/Regex.jar", "testdata/megatraceNoweave.jar", true);
}
- // this is something we test every now and again.
+
public void testBig() throws IOException {
System.out.println("could take 4 seconds...");
zipTest("../lib/bcel/bcel.jar", null);
}
+
+
+ public void testBigWithEasyNoTrace() throws IOException {
+ System.out.println("could take 4 seconds...");
+ zipTest("../lib/bcel/bcel.jar", "testdata/megatrace0easy.jar");
+ }
+
+ // this is something we test every now and again.
+ public void xtestBigWithHardNoTrace() throws IOException {
+ System.out.println("could take 24 seconds...");
+ zipTest("../lib/bcel/bcel.jar", "testdata/megatrace0hard.jar");
+ }
+
public void xtestBigWithAspects() throws IOException {
System.out.println("could take 40 seconds...");