1 / 30

Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ. Ohad Barzilay Yishai A. Feldman Shmuel Tyszberowicz Amiram Yehudai. Agenda. Describe the current semantics of AspectJ call and execution join points with respect to inheritance Argue with the semantics of some of these constructs

ilar
Download Presentation

Call and Execution Semantics in AspectJ

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Call and Execution Semantics in AspectJ Ohad Barzilay Yishai A. Feldman Shmuel Tyszberowicz Amiram Yehudai

  2. Agenda • Describe the current semantics of AspectJ call and execution join points with respect to inheritance • Argue with the semantics of some of these constructs • Suggest some alternative semantics • Discuss the expressive power of the alternatives Call and Execution Semantics in AspectJ, FOAL 2004

  3. Scope of discussion • From the AspectJ Programming Guide: “call(MethodPattern): Picks out each method call join point whose signature matchesMethodPattern” • The semantics of “matches”: • Based on which type? • Type of the object? • Type of the reference? • Does the match include subclasses as well? • … Call and Execution Semantics in AspectJ, FOAL 2004

  4. Motivation • Automatically generated AOP code • JOSE tool – enforcement of Design by Contract methodology using AspectJ Call and Execution Semantics in AspectJ, FOAL 2004

  5. public class A1 { public void f() {} public void g() {} } A1 f() g() public class A2 extends A1 { public void h() {} } A2 h() public class A3 extends A2 { public void f() {} } A3 f() Class hierarchy Call and Execution Semantics in AspectJ, FOAL 2004

  6. A1 f() g() A2 h() A3 f() Calling who? A1 s1 = new A1(); A3 s3 = new A3(); A1 s1d3 = new A3(); • pointcut call(void A1.f()) • s1.f() • s3.f() • s1d3.f() • pointcut call(void A1.g()) • s1.g() • s3.g() • s1d3.g() Call and Execution Semantics in AspectJ, FOAL 2004

  7. A1 f() g() A2 h() A3 f() Calling who? A1 s1 = new A1(); A3 s3 = new A3(); A1 s1d3 = new A3(); • pointcut call(void A1.f()) • s1.f() • s3.f() • s1d3.f() • pointcut call(void A1.g()) • s1.g() • s3.g() • s1d3.g() Call and Execution Semantics in AspectJ, FOAL 2004

  8. A1 f() g() A2 h() A3 f() Calling who? A1 s1 = new A1(); A3 s3 = new A3(); A1 s1d3 = new A3(); • pointcut call(void A1.f()) • s1.f() • s3.f() • s1d3.f() • pointcut call(void A1.g()) • s1.g() • s3.g() • s1d3.g() • What is the ‘+’ modifier for? Call and Execution Semantics in AspectJ, FOAL 2004

  9. A1 f() g() A2 h() A3 f() Calling who? A1 s1 = new A1(); A3 s3 = new A3(); A1 s1d3 = new A3(); • pointcut call(void A3.f()) • s3.f() • s1d3.f() • The match here was based on the static type of the reference • Not consistent with java Call and Execution Semantics in AspectJ, FOAL 2004

  10. A1 f() g() A2 h() A3 f() Calling who? A1 s1 = new A1(); A3 s3 = new A3(); A1 s1d3 = new A3(); • pointcut call(void A3.g()) • s1.g() • s1d3.g() • s3.g() • Does not capture any of our join points • g() was not lexically defined in A3 • Not consistent with java Call and Execution Semantics in AspectJ, FOAL 2004

  11. The call model • Notation: • pointcut • variable defined as • join point Call and Execution Semantics in AspectJ, FOAL 2004

  12. The call model • Notation: • pointcut • variable defined as • join point • For this to compile Call and Execution Semantics in AspectJ, FOAL 2004

  13. The call model • Notation: • pointcut • variable defined as • join point • For this to compile • And we get: Call and Execution Semantics in AspectJ, FOAL 2004

  14. A1 f() g() A2 h() A3 f() Executing what? A1 s1 = new A1(); A3 s3 = new A3(); A1 s1d3 = new A3(); • pointcut execution(void A1.f()) • s1.f() • s3.f() • s1d3.f() Call and Execution Semantics in AspectJ, FOAL 2004

  15. A1 f() g() A2 h() A3 f() Executing what? A1 s1 = new A1(); A3 s3 = new A3(); A1 s1d3 = new A3(); • pointcut execution(void A1.f()) • s1.f() • s3.f() • s1d3.f() • The execution of f() from inside A3 matched A1.f() • Reasonable for call • Surprising for execution Call and Execution Semantics in AspectJ, FOAL 2004

  16. A1 f() g() A2 h() A3 f() Executing what? A1 s1 = new A1(); A3 s3 = new A3(); A1 s1d3 = new A3(); • Almost the same as call But: • s1d3.f() • execution(void A3.f()) • call(void A3.f()) • call and execution differ in more than just their context Call and Execution Semantics in AspectJ, FOAL 2004

  17. call vs. execution • From the AspectJ Programming Guide: “The rule of thumb is that if you want to pick a join point that runs when an actual piece of code runs (as is often the case for tracing), use execution, but if you want to pick one that runs when a particular signature is called (as is often the case for production aspects), use call.” • No! Call and Execution Semantics in AspectJ, FOAL 2004

  18. The execution model • Notation: • pointcut • variable defined as • join point Call and Execution Semantics in AspectJ, FOAL 2004

  19. The execution model • Notation: • pointcut • variable defined as • join point • And we get: Call and Execution Semantics in AspectJ, FOAL 2004

  20. A1 f() g() A2 h() A3 f() A1 s1 = new A1(); A3 s3 = new A3(); A1 s1d3 = new A3(); Running in the family • s3.h() • call(void A1+.h()) • call(void A3+.h()) • Consistent, but surprising due to previous problems Call and Execution Semantics in AspectJ, FOAL 2004

  21. The subtype pattern model • Notation: • call pointcut • execution pointcut • variable defined as • join point Call and Execution Semantics in AspectJ, FOAL 2004

  22. The subtype pattern model • Notation: • call pointcut • execution pointcut • variable defined as • join point • And we get: Call and Execution Semantics in AspectJ, FOAL 2004

  23. Summary • Intuitive: • Pointcuts with subtype patterns are equivalent to the union of all pointcuts with subtypes substituted for the given type. • The semantics of execution pointcuts is based on the dynamic type of the target. Call and Execution Semantics in AspectJ, FOAL 2004

  24. Summary • Unintuitive: • The semantics of call pointcuts depends on the static type of the target. • Call and execution pointcuts only capture join points for classes where the given method is lexically defined. • As a result of this, the difference between pointcuts with or without subtype patterns is subtle and unintuitive. Call and Execution Semantics in AspectJ, FOAL 2004

  25. Alternative semantics • In our opinion, the lexical definition requirement should be removed • Two questions remain: • Should subclasses be included when the subtype pattern modifier does not appear in the pointcut? (“narrow” vs. “broad”) • Should call join points based on their “static” or “dynamic” type? Call and Execution Semantics in AspectJ, FOAL 2004

  26. call pointcut in the proposed semantics Broad Narrow Static Dynamic Call and Execution Semantics in AspectJ, FOAL 2004

  27. Alternative semantics • Each of the four semantics is consistent and reasonable • Perhaps the broad–dynamic semantics best reflects object oriented principles, in that a reference to a class includes its subclasses • AspectJ has other constructs to get the desired behavior • within() • target() Call and Execution Semantics in AspectJ, FOAL 2004

  28. Bottom line • A starting point for a discussion of desired AspectJ semantics • Driving force should be user needs • Common tasks should be simple • Use other pointcut specifiers for less common tasks • Should conform with OOP methodology • Should be internally consistent Call and Execution Semantics in AspectJ, FOAL 2004

  29. Related work A Calculus of Untyped Aspect-Oriented Programs R. Jagadeesan, A. Jeffrey, and J. Reily A Theory of Aspects D. Walker, S. Zdancewic, and J. Ligatti A Semantical Approach to Method-Call Interception R. Lämmel Compilation semantics of aspect-oriented programs H. Masuhara, G. Kiczales, and C. Dutchyn A semantics for pointcuts and advice in higher-order languages D. B. Tucker and S. Krishnamurthi A semantics for advice and dynamic join points in aspect-oriented Programming M. Wand, G. Kiczales, and C. Dutchyn Call and Execution Semantics in AspectJ, FOAL 2004

  30. Questions ? A Discussion

More Related