IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University
Outline Motivation and Background Difference Analysis Algorithm Evaluation of Quality and Feasibility Conclusions
Motivation and Background
Static Semantic Difference Analysis static: source code analysis at compile time semantic: differences in behavior PP’ modified
Why solve the Problem? Motivation Reduce testing costs Produce correct software Possible applications Debugging support Regression test selection Program slicing
AOP and AspectJ AOP encapsulates crosscutting concerns AspectJ implementation of AOP extension to Java public class C { int i; void m1() { } … } Base Code aspect A { double C.d; before() : … { } …. } Aspect Code Introduce Advise
AspectJ Example 1 aspect Constraints { 2 public boolean Shape.immovable = false; 2 void around(Shape s) : execution (public Shape+.set*(..)) && target(s) { 3 if (!s.immovable) {proceed( ) ; } } } ITD around advice
Hammocks Single entry Single exit For any directed graph S E
Motivational Example 1 public class Point extends Shape { 2 private int x, y; 3 public void setX(int i){ 4 x = i; } 5 public void setY(int i){ 6 y = i; } 1 public class Point extends Shape { 2 private int x, y; 3 public void setX(int i){ 4 x = i; } 5 void setY(int i){ 6 y = i; } a change in visibility alters program execution
for AspectJ Programs Difference Analysis Algorithm
Algorithm Outline 1. For every module in P find a matching module in P’ (module-level matching) 2. Build extended CFGs for all modules in P and P’ and identify hammocks 3. Perform node-by-node comparison on every pair of hammock graphs (node-level matching)
Matching at Module Level Signature matching Disjunctive matching Obtain best match from multiple candidates public void p1.C1.add(int, Object) P:P: boolean p1.C1.add(int, Object) P’: public void p1.C1.add(int, Object) P:P: boolean p1.C1.add(double, Object) P’:
1. Matching at Module Level Problem: Not every AspectJ construct has a signature (most importantly: advices) Solution: a)Define new AspectJ signatures (e.g. [strictfp] before (Formals) : [throws TypeList] : Pointcut {Body} ) b)Define disjunctive patterns for these signatures
2. Build CFGs and Hammocks
3. Matching at Node Level Simultaneous graph traversal Node-by-node comparison Recursive Two user inputs Similarity threshold (S) Maximum lookahead (LH)
3. Matching at Node Level X E Y H P X E Y H P’ S UV e P S UV’ e P’ Similarity Threshold S = 0.5; Lookahead LH = 1
Quality and Feasibility Tests and Evaluation
ProgramLOCDiffsAffectedMatchedErrors ants (100%)0 bean (100%)0 cona-stack (100%)0 dcm (100%)0 figure (100%)0 introduction (98.3%)6 nullcheck (98.2%)78 quicksort (100%)0 spacewar (100%)0 tracing (100%)0 Signature definitions and disjunctive matching Minimal change with maximal effect Deficits: some combinations and swapped statements
S < 0.6: LH has only minor impact LH 20: within one minute S 0.6: slow for LH > 20, but not needed
New Findings and Open Tasks Conclusions
What we did New signatures for AspectJ modules Disjunctive matching for AspectJ and Java modules a solution for modified signatures Application of hammock algorithm from OO to AO Evaluations using a tool implementation
Conclusions Disjunctive matching is a good idea modules are correctly matched more work for node-level matching eliminates work of type-level matching replaces user interaction Type-level matching is not required Hammock graph matching can be applied given: a) correctly matched modules b) appropriately modeled and labeled CFGs
Future Work Improve disjunctive matching patterns Extend CFG representations Solve the swapping problem Handle dynamic pointcuts
Questions? Thank You for listening