SlideShare uma empresa Scribd logo
1 de 48
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
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)
Doing it by hand… interface  Runnable { void  run(); } asynchronous invocation: EventQueue.invokeLater(Runnable run) synchronous invocation: EventQueue.invokeAndWait(Runnable run)
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
Some of the pointcuts ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Nice example of aspects: ,[object Object],[object Object],[object Object]
QUIZ: pointcuts are intuitive? Given types with fully qualified names a.b.c.SomeType a.b.c.SomeType.ANestedType ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],(first prize: free copy of abc; second prize: free copy of ajc)
Rules for matching type patterns ,[object Object],[object Object],Adrian Colyer : Bug 141133.
This talk ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],POPL 2007 speculative
Semantics of static pointcuts Walker  et al. :  -  formalise shadow matching via explicit labels - operational semantics for explicit labels
From static pointcuts to label sets (0) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],aspect  A { pointcut  a ( int  n) :  call (* f*(..))  &&  args (n) &&  cflowbelow ( execution (* f3(..))); before ( int  n) : a(n) { System.out.println( thisJoinPoint  + ": n="+n); } }
From static pointcuts to label sets (1) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],aspect  A { pointcut  a ( int  n) :  label (L3,L5,L8,L9)  // call (* f*(..))   &&  args (n) &&  cflowbelow ( label (L4)  // execution (* f3(..)) ); before ( int  n) : a(n) { System.out.println( thisJoinPoint  + ": n="+n); } }
Pointcuts are queries (0) ,[object Object],[object Object],[object Object],[object Object],(Naïve) query for  pointcut “ call (* f*(..))”  : p( S )  Ã   9   M  :  method ,  N  :  string  . callShadow( S ,  M , _), methodDecl( M ,  N , _, _, _), regexpmatch(’f.*’,  N ).
Pointcuts are queries (1) ,[object Object],[object Object],[object Object],[object Object],(Naïve) query for  pointcut “ execution (* f3(..))”  : p( S )  Ã   9   M  :  method ,  N  :  string  . executionShadow( S ,  M ), methodDecl( M ,  N , _, _, _), regexpmatch(’f3’,  N ).
Overview of semantics ,[object Object],[object Object],[object Object],[object Object]
Query language: Datalog ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Powered by Tarski (1902-1983) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]
Datalog has two kinds of relations ,[object Object],[object Object]
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)
Mapping pointcuts to queries ,[object Object],[object Object],[object Object],[object Object]
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?
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)
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 ) ) )  .
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
Semantics of static AspectJ pointcuts All static pointcuts covered Only 90 rewrite rules Concrete syntax implementation with Stratego
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 ))
Flavour of rewrite rules (1) ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],this is as complex as it gets
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
It works! 2.81 43.50 14.93 32.25 101 jigsaw 2.84 26.58 9.94 19.89 51 reweave 4.94 12.15 7.73 5.05 21 jhotdraw 4.09 9.15 7.79 5.49 10 weka Ratio = (PI + AQ + AJC) / AJC Aggregate Query (AQ) Populate + index (PI) ajc ksloc project
Should all AspectJ users learn Datalog? NO But power users will learn it…
Conclusions of pointcut semantics ,[object Object],[object Object],[object Object]
Beyond AspectJ
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
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”
Other applications ,[object Object],[object Object],[object Object],BUT: we are limited by the joinpoint model of AspectJ
Everything is a joinpoint
The 11 joinpoint kinds of AspectJ ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],Why are these the right choice?
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
Advantages of Joinpoints = Jimple ,[object Object],[object Object],[object Object],[object Object]
Disadvantage of Jimple = Joinpoints complete loss of encapsulation AspectJ does not have encapsulation, but now the problem is even worse…
Aspect Interfaces ,[object Object],[object Object]
Open modules aspects aspects aspects aspects classes Open module: specifies what can be advised by which aspect
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
Opening modules for debugging module  Debug { open  FigureModule; expose to  debug.* :  call (* *.*(..)); } another form of module inclusion  constrains  included module
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..*(..))
Hiding non-AspectJ shadows (0) ,[object Object],[object Object],[object Object],[object Object],[object Object]
Hiding non-AspectJ joinpoints (1) module  AspectJVisibility { constrain  existingModule; expose (S)  aspectjShadows(S) ; } only expose AspectJ joinpoints from an existing module:
Discussion points ,[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object]

Mais conteúdo relacionado

Mais procurados

C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
Srikanth
 

Mais procurados (20)

Pj01 4-operators and control flow
Pj01 4-operators and control flowPj01 4-operators and control flow
Pj01 4-operators and control flow
 
C Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory managementC Recursion, Pointers, Dynamic memory management
C Recursion, Pointers, Dynamic memory management
 
C Programming Storage classes, Recursion
C Programming Storage classes, RecursionC Programming Storage classes, Recursion
C Programming Storage classes, Recursion
 
11. Java Objects and classes
11. Java  Objects and classes11. Java  Objects and classes
11. Java Objects and classes
 
05. Java Loops Methods and Classes
05. Java Loops Methods and Classes05. Java Loops Methods and Classes
05. Java Loops Methods and Classes
 
Oop objects_classes
Oop objects_classesOop objects_classes
Oop objects_classes
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
07. Arrays
07. Arrays07. Arrays
07. Arrays
 
Collection frame work
Collection  frame workCollection  frame work
Collection frame work
 
Advanced JavaScript
Advanced JavaScript Advanced JavaScript
Advanced JavaScript
 
19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity19. Data Structures and Algorithm Complexity
19. Data Structures and Algorithm Complexity
 
Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01Captitude 2doc-100627004318-phpapp01
Captitude 2doc-100627004318-phpapp01
 
C aptitude.2doc
C aptitude.2docC aptitude.2doc
C aptitude.2doc
 
Functional Programming You Already Know
Functional Programming You Already KnowFunctional Programming You Already Know
Functional Programming You Already Know
 
09. Java Methods
09. Java Methods09. Java Methods
09. Java Methods
 
Unit 3
Unit 3 Unit 3
Unit 3
 
Chapter 4 - Classes in Java
Chapter 4 - Classes in JavaChapter 4 - Classes in Java
Chapter 4 - Classes in Java
 
20.1 Java working with abstraction
20.1 Java working with abstraction20.1 Java working with abstraction
20.1 Java working with abstraction
 
Programming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture NotesProgramming For Problem Solving Lecture Notes
Programming For Problem Solving Lecture Notes
 
7
77
7
 

Destaque

Java : How to Program - 7e
Java : How to Program - 7eJava : How to Program - 7e
Java : How to Program - 7e
CHIH-PEI WEN
 
Probability and Stochastic Processes - A Friendly Introduction for Electrical...
Probability and Stochastic Processes - A Friendly Introduction for Electrical...Probability and Stochastic Processes - A Friendly Introduction for Electrical...
Probability and Stochastic Processes - A Friendly Introduction for Electrical...
CHIH-PEI WEN
 

Destaque (6)

Java : How to Program - 7e
Java : How to Program - 7eJava : How to Program - 7e
Java : How to Program - 7e
 
Probability and Stochastic Processes - A Friendly Introduction for Electrical...
Probability and Stochastic Processes - A Friendly Introduction for Electrical...Probability and Stochastic Processes - A Friendly Introduction for Electrical...
Probability and Stochastic Processes - A Friendly Introduction for Electrical...
 
Yes You Can Use Copyrighted Materials
Yes You Can Use Copyrighted MaterialsYes You Can Use Copyrighted Materials
Yes You Can Use Copyrighted Materials
 
Inaugural Addresses
Inaugural AddressesInaugural Addresses
Inaugural Addresses
 
SlideShare 101
SlideShare 101SlideShare 101
SlideShare 101
 
The Future of Everything
The Future of EverythingThe Future of Everything
The Future of Everything
 

Semelhante a Pointcuts and Analysis

Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
g3_nittala
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
gekiaruj
 

Semelhante a Pointcuts and Analysis (20)

R Language Introduction
R Language IntroductionR Language Introduction
R Language Introduction
 
Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)
Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)
Leveraging R in Big Data of Mobile Ads (R在行動廣告大數據的應用)
 
Best C++ Programming Homework Help
Best C++ Programming Homework HelpBest C++ Programming Homework Help
Best C++ Programming Homework Help
 
New C# features
New C# featuresNew C# features
New C# features
 
R Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In RR Programming: Learn To Manipulate Strings In R
R Programming: Learn To Manipulate Strings In R
 
Profiling and optimization
Profiling and optimizationProfiling and optimization
Profiling and optimization
 
Scala as a Declarative Language
Scala as a Declarative LanguageScala as a Declarative Language
Scala as a Declarative Language
 
numdoc
numdocnumdoc
numdoc
 
Visualizing the Model Selection Process
Visualizing the Model Selection ProcessVisualizing the Model Selection Process
Visualizing the Model Selection Process
 
01 - DAA - PPT.pptx
01 - DAA - PPT.pptx01 - DAA - PPT.pptx
01 - DAA - PPT.pptx
 
Python High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.pptPython High Level Functions_Ch 11.ppt
Python High Level Functions_Ch 11.ppt
 
Python 2.5 reference card (2009)
Python 2.5 reference card (2009)Python 2.5 reference card (2009)
Python 2.5 reference card (2009)
 
The Art of Java Type Patterns
The Art of Java Type PatternsThe Art of Java Type Patterns
The Art of Java Type Patterns
 
Writing beautiful code with Java 8
Writing beautiful code with Java 8Writing beautiful code with Java 8
Writing beautiful code with Java 8
 
06slide.ppt
06slide.ppt06slide.ppt
06slide.ppt
 
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
The Effect of Hierarchical Memory on the Design of Parallel Algorithms and th...
 
Java Keeps Throttling Up!
Java Keeps Throttling Up!Java Keeps Throttling Up!
Java Keeps Throttling Up!
 
JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020JCConf 2020 - New Java Features Released in 2020
JCConf 2020 - New Java Features Released in 2020
 
Design Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on ExamplesDesign Patterns - Compiler Case Study - Hands-on Examples
Design Patterns - Compiler Case Study - Hands-on Examples
 
Jeop game-final-review
Jeop game-final-reviewJeop game-final-review
Jeop game-final-review
 

Último

Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
panagenda
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
FIDO Alliance
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc
 

Último (20)

The Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and InsightThe Zero-ETL Approach: Enhancing Data Agility and Insight
The Zero-ETL Approach: Enhancing Data Agility and Insight
 
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
Easier, Faster, and More Powerful – Alles Neu macht der Mai -Wir durchleuchte...
 
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdfIntroduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
Introduction to FDO and How It works Applications _ Richard at FIDO Alliance.pdf
 
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdfHow Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
How Red Hat Uses FDO in Device Lifecycle _ Costin and Vitaliy at Red Hat.pdf
 
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The InsideCollecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
Collecting & Temporal Analysis of Behavioral Web Data - Tales From The Inside
 
Overview of Hyperledger Foundation
Overview of Hyperledger FoundationOverview of Hyperledger Foundation
Overview of Hyperledger Foundation
 
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdfWhere to Learn More About FDO _ Richard at FIDO Alliance.pdf
Where to Learn More About FDO _ Richard at FIDO Alliance.pdf
 
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
Event-Driven Architecture Masterclass: Engineering a Robust, High-performance...
 
WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024WebRTC and SIP not just audio and video @ OpenSIPS 2024
WebRTC and SIP not just audio and video @ OpenSIPS 2024
 
Generative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdfGenerative AI Use Cases and Applications.pdf
Generative AI Use Cases and Applications.pdf
 
Working together SRE & Platform Engineering
Working together SRE & Platform EngineeringWorking together SRE & Platform Engineering
Working together SRE & Platform Engineering
 
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdfThe Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
The Value of Certifying Products for FDO _ Paul at FIDO Alliance.pdf
 
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider  Progress from Awareness to Implementation.pptxTales from a Passkey Provider  Progress from Awareness to Implementation.pptx
Tales from a Passkey Provider Progress from Awareness to Implementation.pptx
 
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
Observability Concepts EVERY Developer Should Know (DevOpsDays Seattle)
 
Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024Extensible Python: Robustness through Addition - PyCon 2024
Extensible Python: Robustness through Addition - PyCon 2024
 
Introduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptxIntroduction to FIDO Authentication and Passkeys.pptx
Introduction to FIDO Authentication and Passkeys.pptx
 
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
Event-Driven Architecture Masterclass: Integrating Distributed Data Stores Ac...
 
Event-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream ProcessingEvent-Driven Architecture Masterclass: Challenges in Stream Processing
Event-Driven Architecture Masterclass: Challenges in Stream Processing
 
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
TrustArc Webinar - Unified Trust Center for Privacy, Security, Compliance, an...
 
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
ASRock Industrial FDO Solutions in Action for Industrial Edge AI _ Kenny at A...
 

Pointcuts and Analysis

  • 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
  • 29. It works! 2.81 43.50 14.93 32.25 101 jigsaw 2.84 26.58 9.94 19.89 51 reweave 4.94 12.15 7.73 5.05 21 jhotdraw 4.09 9.15 7.79 5.49 10 weka Ratio = (PI + AQ + AJC) / AJC Aggregate Query (AQ) Populate + index (PI) ajc ksloc project
  • 30. Should all AspectJ users learn Datalog? NO But power users will learn it…
  • 31.
  • 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”
  • 35.
  • 36. Everything is a joinpoint
  • 37.
  • 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:
  • 48.