1
Timna: A Framework for Automatically
Combining Aspect Mining Analyses
David Shepherd1
Jeffrey Palm2
Lori Pollock1
Mark Chu-Carroll3
1University of Delaware
2Northeastern University
3IBM
2
Introduction - What is AOP?
Aspect Oriented ProgrammingEach rectangle
represents a source file
Red lines represent source code lines implementing
concept A
figures from aspectj.com
Language Support for Crosscutting Concerns (CCCs)
3
Introduction - A Closer Look at AOP
• Benefits of Refactoring into AOP• Increased "ilities"
– readability– maintainability– extensibility
• Crosscutting concerns (CCCs) are explicit
aspect DisplayUpdating {
after(): call(void Line.setP1(Point)) || call(void Line.setP2(Point)) { Display.update(); }}
class Line { private Point p1, p2;
Point getP1() { return p1; } Point getP2() { return p2; }
void setP1(Point p1) { this.p1 = p1;
} void setP2(Point p2) { this.p2 = p2;
}}
figures from aspectj.com
Display.update();
Display.update();
Responsibility of A
OP Community
4
Working Assumptions
1.AOP can provide benefits in modularity for some problems
2.Crosscutting Concerns are dangerous; awareness is essential
5
Targeted Problem: Mining
• Legacy Applications– refactor into AOP
figures generated by the AJDT
Aspect Mining is the process of finding these candidates
6
Targeted Problem: Mining
3 different programmers implement 1 concept
Applications written with AOP, still problems...
7
State of the Art
Researchers currently create a single analysis to perform aspect mining
Examples• Fan-in Analysis [Marin et al, WCRE 05]
• Code Clone Analysis [Shepherd et al, SERP 05]
• Dynamic Analysis [Breu et al, ASE 04]
• ...Little work done on combining analysis
8
State of the Art• Fan-In public void credit(float amount) {
AccessController.checkPermission( new BankingPermission("accountOperation")); _balance = _balance + amount; } public void debit(float amount) throws InsufficientBalanceException { AccessController.checkPermission( new BankingPermission("accountOperation")); if (_balance < amount) { throw new InsufficientBalanceException("Insufficient total balance"); } else { _balance = _balance - amount; }
checkPermission
Good Candidate for Refactoring
public void checkOut(SpecialList items) { SpecialIterator it = items.iterator(); while(it.hasNext()) checkOut(it.next()); } public void markItems(SpecialList items) { SpecialIterator it = items.iterator(); while(it.hasNext()) ((Item)it.next()).mark();}
next
Bad Candidate for Refactoring
[Marin et al, WCRE 04]
9
State of the Art
• Clone Detection
public void debit(float amount) throws InsufficientBalanceException {UserTransaction ut = ...;try {
ut.begin();... business logic ...ut.commit()
} catch (Exception ex) {ut.rollback();// rethrow after logging and wrapping
}}
Conventional Transaction Management
public void credit(float amount) {UserTransaction ut = ...;try {
ut.begin();... business logic ...ut.commit()
} catch (Exception ex) {ut.rollback();// rethrow after logging and wrapping
}}
[Shepherd et al, SERP 05]
10
Remaining Challenges
• Combining Analyses– if (code clone & fan-in high), more
likely to be a refactoring candidate
• Running a large number of analyses– Methods with void return types– Getters and setters – ... Our framework (Timna) combines
analyses to make a decisionWe invented several new analyses,
use 11 total analyses
Humans do this during manual
mining
11
Key Insight
Currently, humans are the best miners.
What is their process?
1. Manual Inspection2. Learn to identify candidates in
specific system3. Generalize to other systems4. Apply in other systems
12
Automated Approach
1. Create Training Data1. Manual Tag Known Program2. Automatically Run Individual Mining
Analyses
2. Learn • Output: set of rules to classify
• boolean or categories
3. Classify Unknown programs• Output: refactoring candidates
13
Create Training Data
Approach - Learning
KnownProgram
ManualTagging
Method A Class 2
Method B Class 1
Method C Class 1
Method D Class 3
Fan-in
No Parameters
Code Clone
Pairings
Method A Attributes Class 2
Method B Attributes Class 1
Method C Attributes Class 1
Method D Attributes Class 3
MachineLearning
ClassificationRules
Classification Table
Augmented Classification Table
Mining Analyses
1. Create Training Data2. Learn3. Apply
Method Identifier
Attributes
Classification
toolDone {?, ?, ?} refactor
setTool {?, ?, ? } don't refactor
exit {?, ?, ?} don't refactor
Start {?, ?, ?} refactor
Learn Rules
14
Create Training Data
Learn Rules
Approach - Learning
ProgramManualTagging
Method A Class 2
Method B Class 1
Method C Class 1
Method D Class 3
Fan-in
No Parameters
Code Clone
Pairings
Method A Attributes Class 2
Method B Attributes Class 1
Method C Attributes Class 1
Method D Attributes Class 3
MachineLearning
ClassificationRules
Classification Table
Augmented Classification Table
Mining Analyses
1. Create Training Data2. Learn3. Apply
1. If( Fan-in > 5 and is-Void = true ), then (refactor)
2. If ( true ), then (don't refactor)
Method Identifier
Attributes
Classification
toolDone {6, false, 3}
refactor
setTool {1, true, 1 }
don't refactor
exit {0, false, 2}
don't refactor
Start {4, false, 2}
refactor
Final Result:Only output to Classifying
Phase
15
UnknownProgram
Approach - Classifying
Method A
Method B
Method C
Method D
Fan-in
No Parameters
Code Clone
Pairings
Method A Attributes
Method B Attributes
Method C Attributes
Method D Attributes
Classifier
Method A Attributes Class 2
Method B Attributes Class 1
Method C Attributes Class 1
Method D Attributes Class 3
Classification Table
Mining Analyses
Augmented Classification Table
Completed Classification Table
Classify Unknown Program
Method Identifier
Attributes
Classification
showPrompt {6, false, 3}
refactor
takeOrder {1, true, 1 }
don't refactor
sendMessage {0, false, 2}
don't refactor
end {4, false, 2}
refactor
ClassificationRules
Method Identifier
Attributes
Classification
showPrompt {6, false, 3}
takeOrder {1, true, 1 }
sendMessage {0, false, 2}
end {4, false, 2}
Method Identifier
Attributes
Classification
showPrompt {}
takeOrder {}
sendMessage {}
end {}
16
Evaluation Questions
1. Does combining analyses increase precision and recall?
2. Are generated rules effective on other programs?
3. Does categorical tagging increase performance?
4. What is the (time) overhead?5. Can rules help direct research
and evaluate new analyses?
Tagged in two different ways:Boolean: either refactor or
don't Categorical: either don't
refactor or a reason (category) why to refactor
17
Experimental SetupSubject Programs• Training Program (JHotDraw, 11K LOC)• Testing Program (PetStore, 9K LOC)Steps1. Train 2. Test on Training Program3. Test on Testing ProgramMetrics• Precision and Recall• Time
18
Experimental Results
Program not tagged, so can't calculate
recall
Timna: CatTimna: Bool
Timna: CatTimna: Bool
Precision = (number of good candidates returned) / (number of candidates returned)
Recall = (number of candidates returned) / (number of actual good candidates)
19
Experimental Results
1.Does combining analyses increase precision and recall?
Timna: CatTimna: Bool
Timna: CatTimna: Bool
Why is Fan-In performing poorly?
Single analyses work well for specific cases,
but fail to find all aspects.
In this case, combining analyses does increase precision and recall.
20
Experimental Results
2. Are generated rules effective on other programs?
Timna: CatTimna: Bool
Timna: CatTimna: Bool
In this case, the rules effectively mine from the testing program.
21
Experimental Results
3. Does categorical tagging increase performance?
Timna: CatTimna: Bool
Timna: CatTimna: Bool
In this case, the categorical tagging and the boolean tagging perform similarly.
22
Experimental Results
4. What is the (time) overhead?
Can be done incrementally, at each
compile/edit, or overnight
Only done onceCan be done
incrementally, at each compile/edit, or
overnight
Timna: CatTimna: Bool
Timna: CatTimna: Bool
From these results, we believe Timna could be integrated into an IDE without degrading
response time.
6.24s1.88s
----
5m28s5m28s2m04s2m04s
AnalyzeLearn
23
Experimental Results
5. Can rules help direct research and evaluate new analyses?
• [WARE 05] elaborates on use in evaluating new analyses• if analyses does not appear in
rules, it is providing no new information
• Human readable rules can help define style
24
Contributions
• Technique to combine mining analyses to automatically identify refactoring candidates
• Demonstrated how to apply machine learning to learn good AOP style from canonical examples– generate human readable rules
• Invented several (7) novel mining analyses during our initial use of Timna
• Experimentally shown evidence that combining analyses can improve performance
25
Possible Application
Of course! Whenever I change something in the drawing, I should
check to see if I damaged the drawing. Moving this concept to an aspect can eliminate a lot of similar
calls from my OOP code.
Provide hints, shaded by level of confidence