abc : the aspectbench compiler for aspectj
DESCRIPTION
abc : the AspectBench Compiler for AspectJ. Oege de Moor Programming Tools Group University of Oxford. Joint work with: Chris Allan, Pavel Avgustinov, Sascha Kuzins, Neil Ongkingco, - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/1.jpg)
abc :the AspectBench Compilerfor AspectJ Oege de Moor
Programming Tools GroupUniversity of Oxford
Joint work with: Chris Allan, Pavel Avgustinov, Sascha Kuzins, Neil Ongkingco, Damien Sereni, Ganesh Sittampalam, Julian Tibble (Oxford), Laurie Hendren, Jennifer Lhoták, Ondřej Lhoták, Bruno Dufour, Christopher Goard, Clark Verbrugge (McGill), Aske Simon Christensen (Aarhus)
![Page 2: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/2.jpg)
What is AspectJ?
Disciplined Metaprogramming
![Page 3: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/3.jpg)
Bluffer’s guide to aspect-lingoStatic: inject new members into existing
classes at compile-time
Dynamic: aspects observe composite events in
base program; run extra code at
begin/end of certain events
joinpoint = composite event = node in generalised dynamic call graph
pointcut = pattern of events = set of nodes in call graph
advice = extra code
shadow = program point that corresponds to joinpoint
![Page 4: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/4.jpg)
Events, joinpoints and adviceProgram:
int x;void f() { x = x+1;}
execute:
… f(); …
events: begin/end joinpoints: boxes
begin call f();
begin execution f();
begin get x; end get x;
begin set x; end set x;
end execution f();
end call f();Advice can be run: before a joinpoint (immediately following “begin” event) after a joinpoint (immediately preceding “end” event) around a joinpoint (replacing whole contents of box between begin/end)
![Page 5: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/5.jpg)
Example aspects
AspectJ: extension of Java
![Page 6: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/6.jpg)
No allocations with “new” in inner loopaspect NoNewInRound { private int allocations;
before() : call(* World.play(..)) { allocations = 0; }
before() : cflow(call(* World.play(..))) && call(*.new(..)) &&
!within(NoNewInRound) { System.err.println("alloc at: "+ thisJoinPoint.getSourceLocation()); allocations++; }
after() : call(* World.play(..)) { if (allocations > 0) System.err.println("allocations per game "+allocations); }}
![Page 7: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/7.jpg)
Memoisation
aspect Memo {Hashtable table;
pointcut toMemo() : call(Integer ackermann(Integer));
before() : toMemo() && !cflowbelow(toMemo()) {table = new Hashtable();
}
Integer around(Integer n) : toMemo() && args(n) { Integer entry = (Integer) table.get(n);
if (entry == null) { entry = proceed(n); table.put(n, entry);
} return entry; } }
![Page 8: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/8.jpg)
Observing an oblivious subjectaspect Observe {
List Subject.observers = new ArrayList();
after(Subject s) returning(Observer o) :call(Observer.new(..)) && args(s) {
s.observers.add(o);}
after(Subject s) : call(* Subject.update(..)) && target(s) {for (Iterator obsit = s.observers.iterator(); obsit.hasnext(); ) {
Observer o = (Observer) obsit.next();o.refreshView();
}}
}
![Page 9: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/9.jpg)
AOP languages: summary
Conceptual model:traces of (composite) events at runtime
Pointcuts: query language for events
Advice:run extra code before/after/aroundselected events
![Page 10: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/10.jpg)
Compiling AspectJ
Match events at compile timewhenever possible: “weaving”
![Page 11: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/11.jpg)
AspectJ compilers
ajc: • de facto standard• developed at Xerox, then IBM• extends Eclipse compiler• integrated with Eclipse IDE
abc:• research compiler• extensible for experiments in language design• aggressive optimisation• no IDE integration
![Page 12: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/12.jpg)
The AspectBench Compiler
.class .java
bytecode
AspectJ
AST
parsing, type-checking
separator
advice weaving + postprocessing
Jimple IR
code generation + static weaving
Java
AST
Aspect
Info
Pol
yglo
t-ba
sed
fron
tend
Soo
t-ba
sed
back
end
![Page 13: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/13.jpg)
Close-up of the advice weaverJimple IR
for bytecodeIR
for pointcuts
Shadowfinder Shadows Matcher Weaving
instructionsOptimiser
Analysisresults
Weaver
Woven Jimple
Analyser
Bytecodegenerator
Jimple is a typed, stackless3-address intermediate representationof Java bytecode
![Page 14: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/14.jpg)
Does this work? cflow benchmarks (1)
figure quicksort sablecc ants LoD-sim LoD-weka Cona-stack Cona-sim0
1000
2000
3000
4000
5000
6000
abc-none
abc-intra
abc-inter
ajc 1.2
ajc 1.2.1
![Page 15: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/15.jpg)
cflow benchmarks (2)
figure quicksort sablecc ants LoD-sim LoD-weka Cona-stack Cona-sim0
50
100
150
200
250
abc-intra
abc-inter
ajc 1.2.1
![Page 16: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/16.jpg)
Sample language extension
Tracematches:
match regular patterns
on sequences of begin/end events
![Page 17: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/17.jpg)
Failsafe enumeration over vectorspublic aspect FailSafeEnum {
pointcut vector_update() : call(* Vector.add*(..)) || … ;
tracematch(Vector ds, Enumeration e) {
sym create_enum after returning(e) : call(Enumeration+.new(..)) && args(ds);
sym call_next before : call(Object Enumeration.nextElement()) && target(e);
sym update_source after : vector_update() && target(ds);
create_enum call_next* update_source+ call_next
{ throw new ConcurrentModificationException(); }
}}
![Page 18: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/18.jpg)
Database connection pooling
public aspect DBConnectionPoolingTM { …Connection tracematch(Connection connection, String url, String uid, String password) { sym get_connection1 after returning(connection) :
connectionCreation(url, uid, password); sym get_connection2 around (url, uid, password):
connectionCreation(url, uid, password); sym release_connection before:
connectionRelease(connection); get_connection1 release_connection get_connection2 { return connection; } }
void around() : connectionRelease(*) { }}
![Page 19: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/19.jpg)
Anatomy of an abc extension
abc.tmglue for new, extended compiler
ast17 new AST node classesnew AST node factory
parsenew lexer and parser rules
visitone new pass to translate tracematches to advice
weavingaspectInfo
IR for tracematches (3 classes)matching
compile-time state machines (5 classes)weaver
Jimple code generation (4 classes)
No change w
hatsoever to abc base code
![Page 20: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/20.jpg)
Performance of generated code
Memory usageof animations inJHotDraw +FailSafeEnum:NO leaks!
Running time of dbpooling: (seconds)Pure Java without pooling: 6.0with hand-coded pooling aspect: 1.0with tracematch 1.2
![Page 21: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/21.jpg)
Sample of other abc extensions Bruno Harbulot:
LoopsAJloop joinpoints for parallelisation
Aotani & Masuhara:SCoPEstatic evaluation of conditional pointcuts
Bodden & Stolz:J-LOrun-time checking of LTL properties
![Page 22: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/22.jpg)
abc goes shopping at GPCE
What typical GPCE technologies might be used in a tool like abc?
![Page 23: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/23.jpg)
Frontend shopping list
Automated pass orderingdemand-driven attribute evaluation
Extending AST nodes in middle of hierarchyvirtual classes; nested inheritance
Rewrite rules and strategies
In the m
arket fo
r:
JastA
dd (Hedin and E
kman)
Stratego (V
isser e
t al)
![Page 24: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/24.jpg)
Backend shopping list
Quotation for Jimple
Guarantees that generated Jimple iswell-formed
In the market for:
MetaBorg (Bravenboer a
nd Visser)
Safegen (Huang et al)
![Page 25: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/25.jpg)
AspectJ design shopping list
Virtual classes in lieu of intertype declarations Regular query language (Datalog?) for
traces and static structure Hiding (and exposure) of implementation detail to
various degrees of “pure” advice(TR abc-2005-2)
Interaction of all this with generics
In th
e m
arke
t for
:
sem
antic
s!
![Page 26: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/26.jpg)
Further information:http://aspectbench.org
Papers, dissertations, talksDownloadsBug reportsMailing lists
![Page 27: abc : the AspectBench Compiler for AspectJ](https://reader035.vdocuments.site/reader035/viewer/2022062423/5681458f550346895db27d47/html5/thumbnails/27.jpg)
Oxford Centre for Metacomputation
Oxford University Computing Laboratory
A new EPSRC-funded venture led by:Samson Abramsky, Tom Melham,
Oege de Moor, and Luke Ong
types for reflection, termination analysis, compositional model checking of higher-order programs, games semantics for aspects
4-year postdoc position availablefurther postdocs for a shorter period
ask Oege for further information