abc : the AspectBench Compiler for AspectJ - PowerPoint PPT Presentation

1 / 27
About This Presentation
Title:

abc : the AspectBench Compiler for AspectJ

Description:

No change whatsoever to abc base code. Performance of generated code. Memory usage ... used in a tool like abc? Frontend shopping list. Automated pass ordering ... – PowerPoint PPT presentation

Number of Views:89
Avg rating:3.0/5.0
Slides: 28
Provided by: oeged
Category:

less

Transcript and Presenter's Notes

Title: abc : the AspectBench Compiler for AspectJ


1
abc the AspectBench Compilerfor AspectJ
  • Oege de Moor
  • Programming Tools Group
  • University 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,
Ondrej Lhoták, Bruno Dufour, Christopher Goard,
Clark Verbrugge (McGill), Aske Simon Christensen
(Aarhus)
2
What is AspectJ?
  • Disciplined Metaprogramming

3
Bluffers guide to aspect-lingo
  • Static 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
4
Events, joinpoints and advice
events begin/end joinpoints boxes
begin call f() begin execution f()
begin get x end get x
begin set x end set x end execut
ion f() end call f()
Program int x void f() x x1
execute
f()
Advice can be run before a joinpoint (immediate
ly following begin event) after a joinpoint (i
mmediately preceding end event)
around a joinpoint (replacing whole contents of
box between begin/end)
5
Example aspects
  • AspectJ extension of Java

6
No allocations with new in inner loop
  • aspect 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)

7
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

8
Observing an oblivious subject
  • aspect 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()

9
AOP languages summary
  • Conceptual model
  • traces of (composite) events at runtime
  • Pointcuts
  • query language for events
  • Advice
  • run extra code before/after/around
  • selected events

10
Compiling AspectJ
  • Match events at compile timewhenever possible
    weaving

11
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

12
The AspectBench Compiler
.class
.java
parsing, type-checking
AspectJ AST
Polyglot-based frontend
separator
Java AST
Aspect Info
code generation static weaving
Soot-based backend
Jimple IR
advice weaving postprocessing
bytecode
13
Close-up of the advice weaver
Jimple IR for bytecode
IRfor pointcuts
Shadow finder
Shadows
Matcher
Weavinginstructions
Optimiser
Analysisresults
Weaver
Woven Jimple
Analyser
Jimple is a typed, stackless 3-address intermedia
te representation
of Java bytecode
Bytecode generator
14
Does this work? cflow benchmarks (1)
15
cflow benchmarks (2)
16
Sample language extension
  • Tracematches
  • match regular patterns
  • on sequences of begin/end events

17
Failsafe enumeration over vectors
  • public 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()


18
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()

19
Anatomy of an abc extension
  • abc.tm
  • glue for new, extended compiler
  • ast
  • 17 new AST node classes
  • new AST node factory
  • parse
  • new lexer and parser rules
  • visit
  • one new pass to translate tracematches to
    advice
  • weaving
  • aspectInfo
  • IR for tracematches (3 classes)
  • matching
  • compile-time state machines (5 classes)
  • weaver
  • Jimple code generation (4 classes)

No change whatsoever to abc base code
20
Performance of generated code
Memory usage of animations in JHotDraw FailSa
feEnum
NO leaks!
Running time of dbpooling (seconds)
Pure Java without pooling 6.0
with hand-coded pooling aspect 1.0
with tracematch 1.2
21
Sample of other abc extensions
  • Bruno HarbulotLoopsAJloop joinpoints for
    parallelisation
  • Aotani MasuharaSCoPEstatic evaluation of
    conditional pointcuts
  • Bodden StolzJ-LOrun-time checking of LTL
    properties

22
abc goes shopping at GPCE
  • What typical GPCE technologies might be used in
    a tool like abc?

23
Frontend shopping list
  • Automated pass ordering demand-driven attribute
    evaluation
  • Extending AST nodes in middle of
    hierarchy virtual classes nested inheritance
  • Rewrite rules and strategies

In the market for JastAdd (Hedin and Ekman) Str
atego (Visser et al)
24
Backend shopping list
  • Quotation for Jimple
  • Guarantees that generated Jimple iswell-formed

In the market for MetaBorg (Bravenboer and Visse
r)
Safegen (Huang et al)
25
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 the market for semantics!
26
Further informationhttp//aspectbench.org
  • Papers, dissertations, talks
  • Downloads
  • Bug reports
  • Mailing lists

27
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 available
  • further postdocs for a shorter period
  • ask Oege for further information
Write a Comment
User Comments (0)
About PowerShow.com