View | Details | Raw Unified | Return to bug 77638 | Differences between
and this patch

Collapse All | Expand All

(-).classpath (-12 / +11 lines)
Lines 1-15 Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
2
<classpath>
3
    <classpathentry kind="src" path="src"/>
3
	<classpathentry kind="src" path="src"/>
4
    <classpathentry kind="src" path="testsrc"/>
4
	<classpathentry kind="src" path="testsrc"/>
5
    <classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>
5
	<classpathentry sourcepath="JRE_SRC" kind="var" path="JRE_LIB"/>
6
    <classpathentry kind="src" path="/runtime"/>
6
	<classpathentry kind="src" path="/runtime"/>
7
    <classpathentry kind="lib" path="/lib/bcel/bcel.jar"
7
	<classpathentry kind="src" path="/util"/>
8
        rootpath="bcel-5.0/src/java" sourcepath="/lib/bcel/bcel-src.zip"/>
8
	<classpathentry kind="src" path="/testing-util"/>
9
    <classpathentry kind="lib" path="/lib/junit/junit.jar" sourcepath="/lib/junit/src.jar"/>
9
	<classpathentry kind="src" path="/bridge"/>
10
    <classpathentry kind="src" path="/util"/>
10
	<classpathentry kind="src" path="/asm"/>
11
    <classpathentry kind="src" path="/testing-util"/>
11
	<classpathentry kind="var" path="bcel"/>
12
    <classpathentry kind="src" path="/bridge"/>
12
	<classpathentry kind="var" path="junit"/>
13
    <classpathentry kind="src" path="/asm"/>
13
	<classpathentry kind="output" path="bin"/>
14
    <classpathentry kind="output" path="bin"/>
15
</classpath>
14
</classpath>
(-)src/org/aspectj/weaver/patterns/AndPointcut.java (-6 / +74 lines)
Lines 27-56 Link Here
27
27
28
public class AndPointcut extends Pointcut {
28
public class AndPointcut extends Pointcut {
29
	Pointcut left, right;  // exposed for testing
29
	Pointcut left, right;  // exposed for testing
30
	
31
	private final boolean evaluateLeftFirst;
30
32
31
	public AndPointcut(Pointcut left, Pointcut right) {
33
	public AndPointcut(Pointcut left, Pointcut right) {
32
		super();
34
		super();
33
		this.left = left;
35
		this.left = left;
34
		this.right = right;
36
		this.right = right;
35
		setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
37
		setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
38
		//if left pc is easier to match, match this one first
39
		this.evaluateLeftFirst = this.left.matchingCosts() < this.right.matchingCosts();
36
	}
40
	}
37
41
38
	public FuzzyBoolean fastMatch(FastMatchInfo type) {
42
	public FuzzyBoolean fastMatch(FastMatchInfo type) {
39
		return left.fastMatch(type).and(right.fastMatch(type));
43
		if(!Pointcut.USE_LAZY_EVAL)
44
			return this.left.fastMatch(type).and(this.right.fastMatch(type));
45
		if(this.evaluateLeftFirst) {
46
			FuzzyBoolean leftValue = left.fastMatch(type);
47
			if(leftValue.maybeTrue()) {
48
				return leftValue.and(right.fastMatch(type));
49
			} else {
50
				return leftValue;
51
			}
52
		} else {
53
			FuzzyBoolean rightValue = right.fastMatch(type);
54
			if(rightValue.maybeTrue()) {
55
				return rightValue.and(left.fastMatch(type));
56
			} else {
57
				return rightValue;
58
			}
59
		}
40
	}
60
	}
41
61
42
	public FuzzyBoolean match(Shadow shadow) {
62
	public FuzzyBoolean match(Shadow shadow) {
43
		return left.match(shadow).and(right.match(shadow));
63
		if(!Pointcut.USE_LAZY_EVAL)
64
			return this.left.match(shadow).and(this.right.match(shadow));
65
		if(this.evaluateLeftFirst) {
66
			FuzzyBoolean leftValue = left.match(shadow);
67
			if(leftValue.maybeTrue()) {
68
				return leftValue.and(right.match(shadow));
69
			} else {
70
				return leftValue;
71
			}
72
		} else {
73
			FuzzyBoolean rightValue = right.match(shadow);
74
			if(rightValue.maybeTrue()) {
75
				return rightValue.and(left.match(shadow));
76
			} else {
77
				return rightValue;
78
			}
79
		}
44
	}
80
	}
45
	
81
	
46
	public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart encJP) {
82
	public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart encJP) {
47
		return left.match(jp,encJP).and(right.match(jp,encJP));
83
		if(!Pointcut.USE_LAZY_EVAL)
84
			return this.left.match(jp,encJP).and(this.right.match(jp,encJP));
85
		if(this.evaluateLeftFirst) {
86
			FuzzyBoolean leftValue = left.match(jp,encJP);
87
			if(leftValue.maybeTrue()) {
88
				return leftValue.and(right.match(jp,encJP));
89
			} else {
90
				return leftValue;
91
			}
92
		} else {
93
			FuzzyBoolean rightValue = right.match(jp,encJP);
94
			if(rightValue.maybeTrue()) {
95
				return rightValue.and(left.match(jp,encJP));
96
			} else {
97
				return rightValue;
98
			}
99
		}
48
	}
100
	}
49
	
101
		
50
	public FuzzyBoolean match(JoinPoint.StaticPart jpsp) {
102
	public FuzzyBoolean match(JoinPoint.StaticPart jpsp) {
51
		return left.match(jpsp).and(right.match(jpsp));
103
		if(!Pointcut.USE_LAZY_EVAL)
104
			return this.left.match(jpsp).and(this.right.match(jpsp));
105
		if(this.evaluateLeftFirst) {
106
			FuzzyBoolean leftValue = left.match(jpsp);
107
			if(leftValue.maybeTrue()) {
108
				return leftValue.and(right.match(jpsp));
109
			} else {
110
				return leftValue;
111
			}
112
		} else {
113
			FuzzyBoolean rightValue = right.match(jpsp);
114
			if(rightValue.maybeTrue()) {
115
				return rightValue.and(left.match(jpsp));
116
			} else {
117
				return rightValue;
118
			}
119
		}
52
	}
120
	}
53
	
121
		
54
	public String toString() {
122
	public String toString() {
55
		return "(" + left.toString() + " && " + right.toString() + ")";
123
		return "(" + left.toString() + " && " + right.toString() + ")";
56
	}
124
	}
(-)src/org/aspectj/weaver/patterns/OrPointcut.java (-5 / +65 lines)
Lines 28-55 Link Here
28
public class OrPointcut extends Pointcut {
28
public class OrPointcut extends Pointcut {
29
	private Pointcut left, right;
29
	private Pointcut left, right;
30
30
31
	private final boolean evaluateLeftFirst;
32
31
	public OrPointcut(Pointcut left, Pointcut right) {
33
	public OrPointcut(Pointcut left, Pointcut right) {
32
		super();
34
		super();
33
		this.left = left;
35
		this.left = left;
34
		this.right = right;
36
		this.right = right;
35
		setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
37
		setLocation(left.getSourceContext(), left.getStart(), right.getEnd());
38
		//if left pc is easier to match, match this one first
39
		this.evaluateLeftFirst = this.left.matchingCosts() < this.right.matchingCosts();
36
	}
40
	}
37
41
38
42
39
	public FuzzyBoolean fastMatch(FastMatchInfo type) {
43
	public FuzzyBoolean fastMatch(FastMatchInfo type) {
40
		return left.fastMatch(type).or(right.fastMatch(type));
44
		if(this.evaluateLeftFirst) {
45
			FuzzyBoolean leftValue = left.fastMatch(type);
46
			if(leftValue.maybeFalse()) {
47
				return leftValue.or(right.fastMatch(type));
48
			} else {
49
				return leftValue;
50
			}
51
		} else {
52
			FuzzyBoolean rightValue = right.fastMatch(type);
53
			if(rightValue.maybeFalse()) {
54
				return rightValue.or(left.fastMatch(type));
55
			} else {
56
				return rightValue;
57
			}
58
		}
41
	}
59
	}
42
60
43
	public FuzzyBoolean match(Shadow shadow) {
61
	public FuzzyBoolean match(Shadow shadow) {
44
		return left.match(shadow).or(right.match(shadow));
62
		if(this.evaluateLeftFirst) {
63
			FuzzyBoolean leftValue = left.match(shadow);
64
			if(leftValue.maybeFalse()) {
65
				return leftValue.or(right.match(shadow));
66
			} else {
67
				return leftValue;
68
			}
69
		} else {
70
			FuzzyBoolean rightValue = right.match(shadow);
71
			if(rightValue.maybeFalse()) {
72
				return rightValue.or(left.match(shadow));
73
			} else {
74
				return rightValue;
75
			}
76
		}
45
	}
77
	}
46
	
78
	
47
	public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart encJP) {
79
	public FuzzyBoolean match(JoinPoint jp, JoinPoint.StaticPart encJP) {
48
		return left.match(jp,encJP).or(right.match(jp,encJP));
80
		if(this.evaluateLeftFirst) {
81
			FuzzyBoolean leftValue = left.match(jp,encJP);
82
			if(leftValue.maybeFalse()) {
83
				return leftValue.or(right.match(jp,encJP));
84
			} else {
85
				return leftValue;
86
			}
87
		} else {
88
			FuzzyBoolean rightValue = right.match(jp,encJP);
89
			if(rightValue.maybeFalse()) {
90
				return rightValue.or(left.match(jp,encJP));
91
			} else {
92
				return rightValue;
93
			}
94
		}
49
	}
95
	}
50
	
96
		
51
	public FuzzyBoolean match(JoinPoint.StaticPart jpsp) {
97
	public FuzzyBoolean match(JoinPoint.StaticPart jpsp) {
52
		return left.match(jpsp).or(right.match(jpsp));
98
		if(this.evaluateLeftFirst) {
99
			FuzzyBoolean leftValue = left.match(jpsp);
100
			if(leftValue.maybeFalse()) {
101
				return leftValue.or(right.match(jpsp));
102
			} else {
103
				return leftValue;
104
			}
105
		} else {
106
			FuzzyBoolean rightValue = right.match(jpsp);
107
			if(rightValue.maybeFalse()) {
108
				return rightValue.or(left.match(jpsp));
109
			} else {
110
				return rightValue;
111
			}
112
		}
53
	}
113
	}
54
	
114
	
55
	public String toString() {
115
	public String toString() {
(-)src/org/aspectj/weaver/patterns/Pointcut.java (-1 / +10 lines)
Lines 53-58 Link Here
53
53
54
54
55
	public State state;
55
	public State state;
56
	public static boolean USE_LAZY_EVAL;
56
57
57
	/**
58
	/**
58
	 * Constructor for Pattern.
59
	 * Constructor for Pattern.
Lines 62-68 Link Here
62
		this.state = SYMBOLIC;
63
		this.state = SYMBOLIC;
63
	}
64
	}
64
	
65
	
65
66
	/**
67
	 * @return The approximate costs of checking for a match
68
	 * of this pointcut. This should in most cases be implemented by subclasses.
69
	 */
70
	public int matchingCosts() {
71
		return 0;
72
	}
73
	
74
	
66
	/**
75
	/**
67
	 * Could I match any shadows in the code defined within this type?
76
	 * Could I match any shadows in the code defined within this type?
68
	 */
77
	 */
(-)testsrc/org/aspectj/weaver/patterns/AndOrPerformanceTestCase.java (+97 lines)
Added Link Here
1
/* *******************************************************************
2
 * Copyright (c) 2002 Palo Alto Research Center, Incorporated (PARC).
3
 * All rights reserved. 
4
 * This program and the accompanying materials are made available 
5
 * under the terms of the Common Public License v1.0 
6
 * which accompanies this distribution and is available at 
7
 * http://www.eclipse.org/legal/cpl-v10.html 
8
 *  
9
 * Contributors: 
10
 *     PARC     initial implementation 
11
 * ******************************************************************/
12
13
14
package org.aspectj.weaver.patterns;
15
16
import junit.framework.TestCase;
17
18
import org.aspectj.lang.JoinPoint;
19
import org.aspectj.lang.Signature;
20
import org.aspectj.runtime.reflect.Factory;
21
import org.aspectj.util.FuzzyBoolean;
22
23
/**
24
 * @author Eric Bodden
25
 * 
26
 * Runs performance tests measuring lazy evaluation of
27
 * pointcut matching.
28
 */
29
public class AndOrPerformanceTestCase extends TestCase {		
30
	private static final int INNER_ITERATIONS = 100000;
31
	private static final int GLOBAL_ITERATIONS = 10;
32
	/**
33
	 * Constructor for PatternTestCase.
34
	 * @param name
35
	 */
36
	public AndOrPerformanceTestCase(String name) {
37
		super(name);
38
	}
39
	
40
	public void testLazyEvalPerformance() {
41
42
		Pointcut foo = makePointcut("this(org.aspectj.weaver.patterns.AndOrPerformanceTestCase.Foo)").resolve();
43
		Pointcut bar = makePointcut("this(org.aspectj.weaver.patterns.AndOrPerformanceTestCase.Bar)").resolve();
44
		Pointcut c   = makePointcut("this(org.aspectj.weaver.patterns.AndOrPerformanceTestCase.C)").resolve();
45
		
46
		Factory f = new Factory("AndOrNotTestCase.java",AndOrPerformanceTestCase.class);
47
		
48
		Signature methodSig = f.makeMethodSig("void aMethod()");
49
		JoinPoint.StaticPart jpsp = f.makeSJP(JoinPoint.METHOD_EXECUTION,methodSig,1);
50
		JoinPoint jp = Factory.makeJP(jpsp,new Foo(),new Foo());
51
		
52
		long speedUp=0;
53
		long timeNonLazy=Long.MAX_VALUE;
54
55
		for(int iterations=0; iterations<GLOBAL_ITERATIONS; iterations++) {
56
			for(int caze=0; caze<2; caze++) {
57
				Pointcut.USE_LAZY_EVAL = (caze==1);
58
				long before = System.currentTimeMillis();
59
				for(int runs=0; runs<INNER_ITERATIONS; runs++) {
60
					checkMatches(new AndPointcut(foo,bar),jp,null,FuzzyBoolean.NO);
61
					checkMatches(new AndPointcut(foo,foo),jp,null,FuzzyBoolean.YES);
62
					checkMatches(new AndPointcut(bar,foo),jp,null,FuzzyBoolean.NO);
63
					checkMatches(new AndPointcut(bar,c),jp,null,FuzzyBoolean.NO);
64
					
65
					//checkMatches(new OrPointcut(foo,bar),jp,null,FuzzyBoolean.YES);
66
					//checkMatches(new OrPointcut(foo,foo),jp,null,FuzzyBoolean.YES);
67
					//checkMatches(new OrPointcut(bar,foo),jp,null,FuzzyBoolean.YES);
68
					//checkMatches(new OrPointcut(bar,c),jp,null,FuzzyBoolean.NO);				
69
				}
70
				long time = System.currentTimeMillis()-before;
71
				if(caze==0) {
72
					System.out.println("Non-Lazy Pointcut Matching took "+time+"ms");
73
					timeNonLazy = time;
74
				} else {
75
					System.out.println("Lazy Pointcut Matching took "+time+"ms");
76
					System.out.println("Speedup: "+(timeNonLazy-time)+"ms");
77
					speedUp += timeNonLazy-time;
78
				}			
79
			}			
80
		}
81
		
82
		assertTrue("Lazy evaluation should be faster than non-lazy one.",speedUp>0);
83
	}
84
85
	private Pointcut makePointcut(String pattern) {
86
		return new PatternParser(pattern).parsePointcut();
87
	}
88
	
89
	private void checkMatches(Pointcut p, JoinPoint jp, JoinPoint.StaticPart jpsp, FuzzyBoolean expected) {
90
		assertEquals(expected,p.match(jp,jpsp));
91
	}
92
	
93
	private static class Foo{};
94
	private static class Bar{};
95
	private static class C{};
96
	
97
}

Return to bug 77638