Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer...
-
date post
19-Dec-2015 -
Category
Documents
-
view
215 -
download
0
Transcript of Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer...
![Page 1: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/1.jpg)
Optimizing AspectJ
Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak,
Oege de Moor, Damien Sereni, Ganesh Sittampalam, Julian Tibble
Oxford UniversityUniversity of Aarhus
McGill University
PLDI 2005
Presented by Geoff Hulette
![Page 2: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/2.jpg)
What is AspectJ?
• Aspect-Oriented Programming (AOP) language extension for Java
![Page 3: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/3.jpg)
What is AOP?
• AOP addresses cross-cutting concerns
• Examples: logging, debug traces, method-level security
• Goal: remove cross-cutting concerns from objects, put them in aspects
![Page 4: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/4.jpg)
What is an Aspect?
• Join point: span of code in the execution of a program
• Pointcut: query that picks out join points
• Advice: code to execute at a join point
![Page 5: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/5.jpg)
Why Optimize?
• Dynamic model naïve compilers add considerable overhead
• Fortunately, a lot of advice can be compiled statically
![Page 6: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/6.jpg)
Case 1: Around Advice
• Executes instead of a join point, but can transfer control back into the join point using proceed()
• Problem: how do you know where proceed should take you?
![Page 7: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/7.jpg)
Standard Solution
• Closures: pass an object to the advice method with the right code and context
• “Inlining”: duplicate the advice method for each join point
![Page 8: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/8.jpg)
ABC’s Solution
• Keep proceed method in the original class
• Call the advice method with IDs for the originating class and join point
• Sort it out with a switch statement
![Page 9: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/9.jpg)
Results
• Code is 25% smaller, on average.
• Recursive execution times are much faster (3 to 6 times) when recursive advice is applied, about the same otherwise
• ABC is insensitive to recursive advice
![Page 10: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/10.jpg)
Case 2: cflow
• Cflow(p): picks out join points in the control flow of p
• Example pointcut: cflow(call(bar())) && call(foo())
![Page 11: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/11.jpg)
AJC’s Solution
• Create a stack for each cflow
• Where p becomes true, push context
• At join points, test if stack is non-empty
![Page 12: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/12.jpg)
First the easy stuff
• Combine cflow stacks:
cflow(call(a())) && call(b)||cflow(call(a())) && call(c) cflow(call(a())) && (call(b)||call(c))
• Use counters instead of stacks, if possible
• Cache stacks/counters
![Page 13: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/13.jpg)
Then the hard stuff
• Goal: classify instructions to make dynamic checks into static ones
![Page 14: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/14.jpg)
Examples
![Page 15: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/15.jpg)
MayCflow
• Instructions are in mayCflow(sh) if they may be in the scope of update shadow sh
• If a query is not in mayCflow, we can replace it with neverMatch
![Page 16: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/16.jpg)
Compute MayFlow
• Begin with instructions in an update shadow (between push and pop)
• Add all instructions that might be called from within
![Page 17: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/17.jpg)
MustCflow
• Instructions are in MustCflow(stack) if that instruction is always in that cflow
• Replace queries in set with alwaysMatch
![Page 18: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/18.jpg)
Compute MustFlow
• Pre-compute a list of all statements within a cflow that have no dynamic queries
• Start with all statements
• Eliminate those that can be reached from entry points without passing through the pre-computed list
![Page 19: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/19.jpg)
NecessaryShadows
• Set of update shadows whose effects may be observed, and whose effects are not duplicated
• Any update shadow not in this set can be eliminated
![Page 20: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/20.jpg)
Compute NecessaryShadows
• The set of update shadows whose mayFlow sets contain no dynamic queries
• Also remove those that are in the mustflow of another update
![Page 21: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/21.jpg)
Results
• Easy stuff led to biggest gains (up to 54x)
• Hard stuff helped too, but generally not much
![Page 22: Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,](https://reader030.fdocuments.us/reader030/viewer/2022032800/56649d3f5503460f94a1842a/html5/thumbnails/22.jpg)
Other Optimizations
• Static Joinpoint data
• Eliminate boxing/unboxing
• Other standard optimizations