1. Pointcuts and Analysis Oege de Moor, Oxford on behalf of the abc team: Pavel Avgustinov, Eric Bodden, Torbj ő rn Ekman, Elnar Hajiyev, Laurie Hendren, Ond ř ej Lhot á k, Oege de Moor, Neil Ongkingco, Damien Sereni, Ganesh Sittampalam, Julian Tibble
2. Swing thread safety (Ramnivas Laddad) Once a component is visible only the event-dispatching thread can safely access or modify the state of the realized component. (but some methods are exempt)
3. Doing it by hand… interface Runnable { void run(); } asynchronous invocation: EventQueue.invokeLater(Runnable run) synchronous invocation: EventQueue.invokeAndWait(Runnable run)
4. With an aspect… void around () : routedMethods() && voidReturnValueCalls() && !uiSyncMethodCalls() { Runnable worker = new Runnable() { public void run() { proceed (); }}; EventQueue.invokeLater(worker); } only once instead of scattered over Swing client program
5.
6.
7.
8.
9.
10. Semantics of static pointcuts Walker et al. : - formalise shadow matching via explicit labels - operational semantics for explicit labels
11.
12.
13.
14.
15.
16.
17.
18.
19. Example rule hasSubtype*( T : type , T : type ) . hasSubtype*( T : type , S : type ) Ã 9 U : type . hasSubtype( T , U ), hasSubtype*( U , S ) . hasSubtype is primitive (= stored in database)
20.
21. Example: call versus execution class A { void m() {} } class B extends A {} class C extends B { void m() {} } pointcut c() : call (* B.m(..)); pointcut e() : execution (* B.m(..)); (new A()).m(); (new B()).m(); (new C()).m(); QUIZ 2: Where does c() match? Where does e() match?
22. Query for c() : call (* B.m(..)) c( Context : type , Shadow : shadow ) 9 M : method , Recv : type , N : method . matchpat( Context , M , Recv ) , overrides( N , M ) , callShadow( Shadow , N , Recv ) . reflexive relation overrides(N,M)
23. Matching method patterns matchpat( Context : type , M : method , Recv : type ) T : type , MD : type . simpleTypeLookup( Context , ‘B’ , T ), hasSubtype*( T , Recv ), methodDecl( M , ‘ m ’ , _, MD , _), ( ( hasStrModifier( M , ‘static ’), MD = T ) ; ( not (hasStrModifier( M , ‘static’ )), hasSubtype*( MD , T ) ) ) .
24. Query for e() : execution (* B.m(..)) e( Context : type , Shadow : shadow ) M : method , Recv : type , N : method . matchpat( Context , M , Recv ), overrides( N , M ), hasChild( Recv , N ), executionShadow( Shadow , N ) . difference with call
25. Semantics of static AspectJ pointcuts All static pointcuts covered Only 90 rewrite rules Concrete syntax implementation with Stratego
26. Flavour of rewrite rules (0) aj2dl (pc1 && pc2, C , S ) aj2dl (pc1, C , S ), aj2dl (pc2, C , S ) aj2dl (pc1 || pc2, C , S ) aj2dl (pc1, C , S ) ; aj2dl (pc2, C , S ) aj2dl (not(pc), C , S ) not ( aj2dl (pc, C , S ))
27.
28. Implementation AspectJ program relational database (M$ SQL Server) pointcuts Datalog program Shadow Grab (modified abc) Strip from source Stratego rewrites Matched shadows Procedural SQL CodeQuest compiler primitives
33. No calls to UI methods from beans declare error : call (* java.awt..*.*(..)) && within (Bean+) : “ do not call GUI methods from Bean” only catches direct calls
34. Catching all errors maycall+( M : method , N : method ) Ã maycall( M , N ) ; 9 K : method . maycall( M , K ), maycall+( K , N ). declare warning at M : 9 T : type . bean( T ), methodDecl( M ,_,_, T ,_,_), 9 N : method . maycall+( M , N ), guiMethod( N ): “ may be calling a GUI method from this method”
38. Joinpoints = Jimple instructions int foo(int x, int y) { if (x<y) return (y-x); else return (x-y); } int foo( int , int ) { Example this; int x, y, $i0, $i1; this := @this:Example; x := @parameter0: int; y := @parameter1: int; if x >= y goto label0; $i0 = y - x; return $i0; label0: $i1 = x - y; return $i1; } Java: Jimple: Jimple: a typed, 3-address, stack-less representation of bytecode
39.
40. Disadvantage of Jimple = Joinpoints complete loss of encapsulation AspectJ does not have encapsulation, but now the problem is even worse…
41.
42. Open modules aspects aspects aspects aspects classes Open module: specifies what can be advised by which aspect
43. An example open module module FigureModule { class Point,Figure; advertise : call(Figure Figure.translate(int,int)); expose to MoveTrackAspect : call (* Point.translate(int,int)) && within (Figure); } classes that are affected only external calls are advised MoveTrackAspect may advise the specified joinpoints
44. Opening modules for debugging module Debug { open FigureModule; expose to debug.* : call (* *.*(..)); } another form of module inclusion constrains included module
45. Datalog for semantics-based control expose to <aspect-query> : <event-query> Current abc: aspect-query = classname pattern expression event-query = pointcut Using datalog queries, can express: pureaspect(A) = A’s only side effect is writing to System.err then expose to pureaspect(A) : call(* mysys..*(..))
46.
47. Hiding non-AspectJ joinpoints (1) module AspectJVisibility { constrain existingModule; expose (S) aspectjShadows(S) ; } only expose AspectJ joinpoints from an existing module: