A Framework for Source-Code-Level Interprocedural Dataflow Analysis of AspectJ Software

  • View
    34

  • Download
    0

Embed Size (px)

DESCRIPTION

A Framework for Source-Code-Level Interprocedural Dataflow Analysis of AspectJ Software. Guoqing Xu and Atanas Rountev Ohio State University Supported by NSF under CAREER grant CCF-0546040. Outline. Motivation Program representation Control flow representation Data flow representation - PowerPoint PPT Presentation

Text of A Framework for Source-Code-Level Interprocedural Dataflow Analysis of AspectJ Software

Sample PresentationPRESTO: Program Analyses and Software Tools Research Group, Ohio State University
A Framework for Source-Code-Level Interprocedural Dataflow Analysis of AspectJ Software
Guoqing Xu and Atanas Rountev
Ohio State University
Supported by NSF under CAREER grant CCF-0546040
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Outline
Motivation
Dependence-analysis-based slicing
Experimental evaluation
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Interprocedural Dataflow Analysis
For various software engineering and compiler construction tasks
e.g. performance optimization, static software verification, testing, software understanding and evolution
Powerful analyses for AspectJ are needed
AOP becomes more and more popular
Need good program representation
Need new algorithms
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Program Representation for AspectJ
Should be easy to use for various clients
Adapt existing Java analysis algorithm
Should provide clean separation between the base code and aspects
Automated reasoning of aspects-base-code interaction
Advantages of source-code-level over bytecode-level analysis
Produces more relevant results
Faster running time
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Proposed representation
Has both properties
Take the large body of existing analysis algorithms for Java, and adapt them easily to AspectJ
Define new analysis algorithms specifically for AspectJ features
Control flow representation [ICSE’07]
Complex interactions of advices
Using calls and returns along chains of nested advice invocations
Expose the decision-making data for dynamic advices
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Running Example
class Point {
int x;
static void main(String[] a) {
Point p = new Point();
setterX(p)
{ … proceed(p,x); … }
/* before2 */
after(Point p) : setterX(p) { … }
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Control-Flow Representation
No join points
Interaction graph
Calls to represent nesting relationships
Use ph_* placeholder method to represent call to proceed
Dynamic advices
Use ph_decision placeholder decision node to guard call sites of dynamic advices
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
root
around1
before2
p.setX
before1
after1
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
entry
exit
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Handling of Dynamic Advices
before1
return
around1
return
ph_decision
ph_decision
T
T
ph_proceed1
F
F
exit
return
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Data-flow Representation for IG
Declarations for placeholder methods
Create a formal parameter for (1) the receiver object or (2) a formal parameter of the crosscut method
e.g. for shadow p.setX(6), the entry method is declared as void ph_root(Point arg0, int arg1)
Declarations for non-around-advice
e.g.void before1(int arg0, Point arg1)
Call sites for advices are built with appropriate actual parameters
void ph_root(Point arg0, int arg1) { before1(arg1, arg0); }
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Handling of Around Advice
Handling of around advice is complicated
It must have all the necessary parameters of the shadow call site
Parameters needed by an around advice can be different for different shadows
abc solution: replicate the body of an around advice for each shadow that the around advice matches
Our solution: construct a globally valid list that includes parameters required at all matching shadows
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Example
double arg4, Point arg5, int dv)
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Handling of Around Advice
Call to around advice
Non-trivial actual parameters are passed to the call site only for the formals corresponding to the currently-active shadow
A unique shadow ID is given for dv
e.g. setX(Point arg0, int arg1)
setY(Point arg2, float arg3)
setZ(double arg4, Point arg5)
around(Point p):call(void Point.set*(*)) && target(p)
double arg4, Point arg5, int dv)
for p.setX(..), around(arg0, arg1, null, 0, 0, null, 0)
for p.setY(..), around(null, 0, arg2, arg3, 0, null, 1)
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Handling of Around Advice (Cond.)
Call to a placeholder method within an around advice
Use dv to select calls to placeholder methods
e.g.
switch(dv){
//corresponding to shadow setY
//corresponding to shadow setZ
case 2: ph_proceed2(arg4, arg5);
}
}
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Data with ph_decision Nodes
For a dynamic advice, the data that contributes to dynamic decision making is associated with the ph_decision node that guards the call to the advice
E.g.
both p and i are associated with the ph_decision node
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
So What?
Advice nesting relationship is clear
Ready for data-flow analysis
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Object Effect Analysis
Compute for each object passed from the base code into an advice, a state machine encoding all events that must happen on the object
The state machine is represented by a regular expression
Can directly be used for program verification (e.g. checking type-state based properties)
E.g.
(reset | ε) (( setX | ε) | ( getX (( setX | ε ) |( setRectangular | ε ))))
((wx wy | ε)) ( ( (wx | ε) | ( rx ( ( wx | ε) | (( wx wy) | ε)))))
At the core of this analysis is a must-alias analysis
A typical example of interprocedural analysis for AspectJ
Need to track the interprocedural flow of data
Need to be aware of the separation between base code and aspects
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Object Effect Analysis (Cond.)
Data flow problem
We define a lattice element for each reference-typed formal parameter of a ph_root method
E.g. for void ph_root(Point arg0, int arg1)
The lattice is {larg0, , }
v1 = v2.fld: fn(S) = S[v1 ]
v1.fld = v2: fn(S) = S
other nodes: fn(S) = S
Compute meet-over-all-valid-paths soluction MVPn
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Analysis Algorithm
Phase 1: relate formals to variables
For each variable in a method, compute a set of formal parameters that the variable may alias
Bottom-up traverse call graph to compute a summary function that relates the return value of a method to its parameter(s)
Phase 2: Propagation of lattice elements
Top-down traverse the call graph starting from each ph_root method
For each variable, replace the formal parameter associated to it with the corresponding lattice element(s)
Phase 3: Effect graph construction
Prune ICFG by removing nodes that do not have a lattice element
Compute SCC in the graph, and bottom-up traverse the SCC-DAGs
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Dependence-based Slicing
Another typical example of interprocedural dataflow analysis
Given existing slicing algorithms for Java, adapting it to AspectJ is very simple
Variables associated with ph_decision nodes are considered as used
The slice for a call to proceed in an around advice includes slices that are computed for the group of calls to ph_proceed methods in the advice
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Experimental Evaluation
Comparison of ICFG and SDG sizes between source-code analysis and bytecode analysis
Effect analysis results comparison between using must-alias analysis and may-alias analysis
Slice relevance comparison between source-code slicing and bytecode slicing
Implementation based on the abc compiler
Between static weaving and advice weaving
Intraprocedural representation based on Jimple from abc
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Numbers of Edges in ICFG and SDG
# ICFG edges 2X smaller
#SDG edges 3X smaller
- SDG Edges
- ICFG edges
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Object Effect Analysis
E.g. less than 3 sec for the largest program
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
Chart1
bean/v4
tracing
telecom/v7
quicksort/v2
nullcheck/v2
nullcheck/v5
lod/v1
lod/v2
dcm/v2
spacewar/v1
Must/May
100
100
100
100
100
100
92.3
91.4
90
76
Sheet1
bean/v4
tracing
telecom/v7
quicksort/v2
nullcheck/v2
nullcheck/v5
lod/v1
lod/v2
dcm/v2
spacewar/v1
100
100
100
100
100
100
92.3
91.4
90
76
Sheet1
0
0
0
0
0
0
0
0
0
0
Sheet2
Sheet3
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Slicing Relevance Ratio and Time
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
Chart2
bean/v4
bean/v4
tracing
tracing
telecom/v7
telecom/v7
quicksort/v2
quicksort/v2
nullcheck/v2
nullcheck/v2
nullcheck/v5
nullcheck/v5
lod/v1
lod/v1
lod/v2
lod/v2
dcm/v2
dcm/v2
spacewar/v1
spacewar/v1
Source
Bytecode
98.2
54.7
98.7
77.2
98.5
85.3
98
44.5
97.8
37.7
96.1
46
97.2
64.9
97.9
60.1
98.2
44.3
97.6
68.6
Sheet1
bean/v4
tracing
telecom/v7
quicksort/v2
nullcheck/v2
nullcheck/v5
lod/v1
lod/v2
dcm/v2
spacewar/v1
100
100
100
100
100
100
92.3
91.4
90
76
98.2
98.7
98.5
98
97.8
96.1
97.2
97.9
98.2
97.6
54.7
77.2
85.3
44.5
37.7
46
64.9
60.1
44.3
68.6
Sheet1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
SCL
BCL
Sheet2
Sheet3
Chart3
bean/v4
24.2
tracing
1.3
telecom/v7
0.8
quicksort/v2
542.7
nullcheck/v2
762.1
nullcheck/v5
105.1
lod/v1
956.7
lod/v2
1011.7
dcm/v2
62.8
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University
Conclusions
A control flow representation and a data flow representation
Two proof-of-concepts analyses
Both are IDE (Interprocedural Distributive Environment) problems, which require context-sensitivity and flow-sensitivity
Representative of (1) a large class of existing Java analysis algorithms and (2) potentially new algorithms designed specifically for AspectJ
Experimental results
Program representation is easy to use and adapt existing algorithms
New algorithms can be easily designed
PRESTO: Program Analyses and Software Tools Research Group, The Ohio State University
0
40
80
120
160
bean/v4tracing
telecom/v7
quicksort/v2nullcheck/v2nullcheck/v5
lod/v1lod/v2dcm/v2
ph_root
entry
return
exit
before1
return
around1