Title: AspectC and Its Tool Support
1AspectC and Its Tool Support
An STTR Phase-I Project
Paul Anderson GrammaTech, Inc. David Binkley
GrammaTech, Inc. and Loyola College Susan
Horwitz University of Wisconsin Tim Teitelbaum
GrammaTech, Inc. and Cornell University
2STTR Phase I Goals
- Generic Phase I Goals
- Plan a viable commercial product supporting the
program goals - Sustainable competitive advantage
- Leverage existing infrastructure
3STTR Phase I Goals
- Generic Phase I Goals
- Plan a viable commercial product supporting the
program goals - Sustainable competitive advantage
- Leverage existing infrastructure
- Our Phase I Goals as refined after last PCES
meeting - Design an AspectC1
- Plan associated tool support
- 1GrammaTechs take on what such a language could
be.
4STTR Phase I Goals
- Generic Phase I Goals
- Plan a viable commercial product supporting the
program goals - Sustainable competitive advantage
- Leverage existing infrastructure
- Our Phase I Goals as refined after last PCES
meeting - Design an AspectC1
- What can be mapped over from AspectJ?
- What features are enabled by our infrastructure?
- Plan associated tool support
- 1GrammaTechs take on what such a language could
be.
5STTR Phase I Goals
- Generic Phase I Goals
- Plan a viable commercial product supporting the
program goals - Sustainable competitive advantage
- Leverage existing infrastructure
- Our Phase I Goals as refined after last PCES
meeting - Design an AspectC1
- What can be mapped over from AspectJ?
- What features are enabled by our infrastructure?
- Plan associated tool support
- Understanding/debugging woven code
- Reengineering (find and extract latent aspects in
existing code) - Preventing/detecting aspect interference
- 1GrammaTechs take on what such a language could
be.
6GrammaTech Infrastructure
Analysis operations
FE1
C client code
A P I
Builder
...
IR
Pre-IR
GUI
FEm
Synthesis operations
Schemescripts
- ASTs
- symbol table
- local def, use, conditional kill, and pointer
info - CFGs
- Pre-IR
- points-to graph
- call multi-graph
- GMOD / GREF
- PDGs / SDG
- front ends
- EDG
- ANSI C
- other C
- C
- Java
- UML (Rose/RT)
- Verilog
- VHDL
- Jovial
-
- Precise interprocedural
- - predecessors and successors
- - slice
- - chop
- Boolean operations on sets of PDG nodes
- model checking
- semantics-based merging
Other infrastructure command-line, preprocessor,
library, and loader support
Color code done current work suspended
prototyped
7Dependence Graphs and Slicing
void main() int sum, i sum 0 i 1
while (ilt11) sum add(sum,i) i
add(i, 1) printf(sumd\n, sum)
printf(id\n, i) static int add(int a, int
b) return (ab)
The backward slice from printf(id\n,i)
shows all possible influences on that statement.
8AOP
- Reminder What is an aspect?
- An object (with fields and methods)
- Plus advice (code to be executed at pointcuts,
i.e., designated subsets of join points) - Plus introductions (new fields added to classes)
- Questions for AspectC
- What are the join points?
- How are pointcuts designated?
- Where are aspects instantiated?
9Join Points
- AspectJ
- Method and constructor call/reception/execution
- AspectC
- Function call/execution
10Join Points
- AspectJ
- Method and constructor call/reception/execution
- AspectC
- Function call/execution direct calls/indirect
calls - pointer analysis enables efficiency for calls via
function pointers!
11Join Points
- AspectJ
- Method and constructor call/reception/execution
- Field gets/sets
- AspectC
- Function call/execution direct calls/indirect
calls - pointer analysis enables efficiency for calls via
function pointers! - Location gets/sets
- heap/static/stack direct/indirect access union
casts - pointer analysis enables efficency for gets/sets
via pointer!
12Join Points
- AspectJ
- Method and constructor call/reception/execution
- Field gets/sets
- Exception handler execution
- AspectC
- Function call/execution direct calls/indirect
calls - pointer analysis enables efficiency for calls via
function pointers! - Location gets/sets
- heap/static/stack direct/indirect access union
casts - pointer analysis enables efficency for gets/sets
via pointer!
13Join Points
- AspectJ
- Method and constructor call/reception/execution
- Field gets/sets
- Exception handler execution
- AspectC
- Function call/execution direct calls/indirect
calls - pointer analysis enables efficiency for calls via
function pointers! - Location gets/sets
- heap/static/stack direct/indirect access union
casts - pointer analysis enables efficency for read/write
via pointer! - Exercising a def-use edge i.e., a get of v that
was set at p - e.g., for test-coverage monitoring
- Instantiating a points-to set fact i.e., p is
made to point to x
14Pointcuts
- AspectC
- Similar to AspectJ
- Designators based on static analysis results
- DFLOW(v, p) i.e., gets of v that were set
at p - POINTSTO(x,y) i.e., x is made to point to y
- GREF( , x ) i.e., executions of functions
that may use x - GMOD( , x ) i.e., executions of functions
that may modify x - Possible uses of GMOD/GREF
- Distribution aspect transform shared-variables
(in a uni-processor model) into message passing - Checkpointing aspect a function on entry that
may fail if it attempts to access a given
variable
15Pointcuts
- AspectC
- Same as AspectJ
- Designators based on static analysis results,
e.g., - GREF( , x ) executions of
functions that may use x - calls-to(GREF( , x )) calls to same
- GMOD( , x ) executions of
functions that may modify x - Example
- Suppose
- Functions that access variable x may fail
- Every possibly failing function must be
checkpointed on entry - The use of GREF( , x ) allows selective
checkpointing
16Aspect Instantiation
- AspectJ one per
- program execution
- class and method
- object instance
- control-flow root
- AspectC one per
- program execution
- file and function
- chunk of heap-allocated storage
- control-flow root
17AOP Tools
- Supporting
- Understanding
- what code is affected by an aspect?
- what aspects affect a piece of code?
- Reengineering (procedural gt aspect-oriented)
- Preventing/reporting aspect interference
18AOP Tools
- Supporting
- Understanding / debugging
- what code is affected by an aspect?
- forward slicing
- what aspects affect a piece of code?
- backward slicing
- Reengineering (procedural gt aspect-oriented)
- pattern matching in dependence graph
- Preventing/reporting aspect interference
- dependence-preserving code merging
19Understanding Example Adding Message Decoding /
Re-encoding
main
msg _at_?x
20Message Decoding / Re-encoding
main
msg _at_?x
decode msg
re-encode msg
high security
low security
21Bug
main
msg _at_?x
decode msg
high security
low security
print msg
22Show Code Affected by an Aspect Use Forward Slice
main
msg _at_?x
decode msg
high security
low security
print msg
23Show Code Affected by an Aspect Use Forward Slice
main
msg _at_?x
decode msg
high security
low security
print msg
24Show Code Affected by an Aspect Use Forward Slice
main
msg _at_?x
decode msg
high security
low security
print msg
25Show Code Affected by an Aspect Use Forward Slice
main
msg _at_?x
decode msg
high security
low security
print msg
26Show Code Affected by an Aspect Use Forward Slice
main
msg _at_?x
decode msg
high security
low security
print msg
Print statement is in the forward slice from the
decode advice, with no re-encode advice!
27Show Code Affected by an Aspect Use Backward
Slice
main
msg _at_?x
decode msg
high security
low security
print msg
28Show Code Affected by an Aspect Use Backward
Slice
main
msg _at_?x
decode msg
high security
low security
print msg
decode advice is in the backward slice from
the print , with no re-encode advice!
29Reengineering example find aspects
- Goal Find latent aspects, extract into advice
- Use partial backward slicing to find isomorphic
PDG subgraphs modulo possible parameterization
(clones).
30Step (1) Identify Aspect Clones
original program
clones
31Step (2) Extract Clones into Advice
aspect foo before bar
original program
clones
32Fragment 1
while (isalpha(c) c '_' c
'-') if (p token_buffermaxtoken) p
grow_token_buffer(p) if (c '-') c '_'
p c c getc(finput)
33Fragment 1
while (isalpha(c) c '_' c
'-') if (p token_buffermaxtoken) p
grow_token_buffer(p) if (c '-') c '_'
p c c getc(finput)
34Fragment 2
while (isdigit(c)) if (p
token_buffermaxtoken) p
grow_token_buffer(p) numval numval20 c -
0 p c c getc(finput)
35while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
36while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
37while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
38while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
39while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
40while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
41while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
42while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
43while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
44while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
45while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
46while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
47while(isalpha(c) c- c_)
if (p token_buffer maxtoken)
if(c-)
p c
c getc(finput)
p grow_token_buffer(p)
c _
while(isdigit(c))
if (p token_buffer maxtoken)
p c
c getc(finput)
numvalnumval20 c-0
p grow_token_buffer(p)
48Program Merging
B
X
Y
M
- Given base program B, and two variants X and Y,
- either derive a merged program M that preserves
the respective differences from B of variants X
and Y - or report that X and Y are incompatible variants
(i.e., it is not possible to preserve their
respective differences from B)
49Aspect Merging
B
X
Y
M
- variants X and Y are the result of weaving
aspects x and y into separate copies of program B
50Aspect Merging
B
X
Y
M
- variants X and Y are the result of weaving
aspects x and y into separate copies of program B - if no interference, then M is a safe composition
of the independently woven aspects x and y
51Aspect Merging
B
X
Y
M
- variants X and Y are the result of weaving
aspects x and y into separate copies of program
B. - if no interference, then M is a safe composition
of the independently woven aspects x and y. - if interference, then the programmer can be shown
the source of the problem.
52Example 1 Secret Message Aspects
- Aspect 1 Decode the secret message on every call
to a high-security operation, re-encode on
return. - Aspect 2 Write the (encoded) secret message to a
log file on every call to an operation that might
modify it.
53Which advice comes first?
main
msg _at_?x
decode msg
re-encode msg
print msg
order??
54Choose order consistent with merged PDG
Merged PDG
Merged PDG has no data dependence from decode
to print, so print must come first!
55Wrong order changes edges
Merged PDG
56Example 2 Two Decode Aspects
- Aspect 1 Decode the secret message on every call
to a high-security operation, re-encode on
return. - Aspect 2 Decode the secret message on every call
to a non low-security operation, re-encode on
return.
57Which advice comes first?
main
msg _at_?x
1 re-encode msg
1 decode msg
2 re-encode msg
2 decode msg
order??
order??
use msg
Double decode produces garbage unless it is
idempotent!
58Choose order consistent with merged PDG
main
msg _at_?x
1 re-encode msg
1 decode msg
2 re-encode msg
2 decode msg
use msg
No way to produce code without changing data
dependences interference!
59Merged PDG
60One order changes edges
Merged PDG
61Other order changes edges
Merged PDG
62Summary
- Preliminary design for an AspectC
- Follows example of AspectJ in many ways
- Availability of analysis results allows some
(old) features to be implemented more efficiently
(e.g., pointer analysis gt gets/sets) - Availability of analysis results allows some new
kinds of pointcut designators - PDG operations (slicing, clone finding, merging)
can support useful AOP tools