Call and Execution Semantics in Aspect J Ohad

  • Slides: 30
Download presentation
Call and Execution Semantics in Aspect. J Ohad Barzilay Yishai A. Feldman Shmuel Tyszberowicz

Call and Execution Semantics in Aspect. J Ohad Barzilay Yishai A. Feldman Shmuel Tyszberowicz Amiram Yehudai Call and Execution Semantics in Aspect. J, FOAL 2004

Agenda l l Describe the current semantics of Aspect. J call and execution join

Agenda l l Describe the current semantics of Aspect. J 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 Aspect. J, FOAL 2004 2

Scope of discussion l From the Aspect. J Programming Guide: “call(Method. Pattern): Picks out

Scope of discussion l From the Aspect. J Programming Guide: “call(Method. Pattern): Picks out each method call join point whose signature matches Method. Pattern” l 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 Aspect. J, FOAL 2004 3

Motivation l l Automatically generated AOP code JOSE tool – enforcement of Design by

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

Class hierarchy public class A 1 { public void f() {} public void g()

Class hierarchy public class A 1 { public void f() {} public void g() {} } public class A 2 extends A 1 { public void h() {} } public class A 3 extends A 2 { public void f() {} } A 1 f() g() A 2 h() A 3 f() Call and Execution Semantics in Aspect. J, FOAL 2004 5

Calling who? l l A 1 s 1 = new A 1(); A 3

Calling who? l l A 1 s 1 = new A 1(); A 3 s 3 = new A 3(); A 1 s 1 d 3 = new A 3(); pointcut call(void A 1. f()) üs 1. f() üs 3. f() üs 1 d 3. f() pointcut call(void A 1. g()) üs 1. g() üs 3. g() üs 1 d 3. g() A 1 f() g() A 2 h() A 3 f() Call and Execution Semantics in Aspect. J, FOAL 2004 6

Calling who? l l A 1 s 1 = new A 1(); A 3

Calling who? l l A 1 s 1 = new A 1(); A 3 s 3 = new A 3(); A 1 s 1 d 3 = new A 3(); pointcut call(void A 1. f()) üs 1. f() üs 3. f() üs 1 d 3. f() pointcut call(void A 1. g()) üs 1. g() üs 3. g() üs 1 d 3. g() A 1 f() g() A 2 h() A 3 f() Call and Execution Semantics in Aspect. J, FOAL 2004 7

Calling who? l l l A 1 s 1 = new A 1(); A

Calling who? l l l A 1 s 1 = new A 1(); A 3 s 3 = new A 3(); A 1 s 1 d 3 = new A 3(); pointcut call(void A 1. f()) üs 1. f() üs 3. f() üs 1 d 3. f() pointcut call(void A 1. g()) üs 1. g() üs 3. g() üs 1 d 3. g() What is the ‘+’ modifier for? Call and Execution Semantics in Aspect. J, FOAL 2004 A 1 f() g() A 2 h() A 3 f() 8

Calling who? l A 1 s 1 = new A 1(); A 3 s

Calling who? l A 1 s 1 = new A 1(); A 3 s 3 = new A 3(); A 1 s 1 d 3 = new A 3(); pointcut call(void A 3. f()) üs 3. f() s 1 d 3. f() l l The match here was based on the static type of the reference Not consistent with java A 1 f() g() A 2 h() A 3 f() Call and Execution Semantics in Aspect. J, FOAL 2004 9

Calling who? l A 1 s 1 = new A 1(); A 3 s

Calling who? l A 1 s 1 = new A 1(); A 3 s 3 = new A 3(); A 1 s 1 d 3 = new A 3(); pointcut call(void A 3. g()) s 1. g() s 1 d 3. g() s 3. g() l l l Does not capture any of our join points g() was not lexically defined in A 3 Not consistent with java Call and Execution Semantics in Aspect. J, FOAL 2004 A 1 f() g() A 2 h() A 3 f() 10

The call model l Notation: • • • pointcut variable defined as join point

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

The call model l l Notation: • • • pointcut variable defined as join

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

The call model l Notation: • • • pointcut variable defined as join point

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

Executing what? l A 1 s 1 = new A 1(); A 3 s

Executing what? l A 1 s 1 = new A 1(); A 3 s 3 = new A 3(); A 1 s 1 d 3 = new A 3(); pointcut execution(void A 1. f()) üs 1. f() üs 3. f() üs 1 d 3. f() A 1 f() g() A 2 h() A 3 f() Call and Execution Semantics in Aspect. J, FOAL 2004 14

Executing what? l l A 1 s 1 = new A 1(); A 3

Executing what? l l A 1 s 1 = new A 1(); A 3 s 3 = new A 3(); A 1 s 1 d 3 = new A 3(); pointcut execution(void A 1. f()) üs 1. f() üs 3. f() üs 1 d 3. f() The execution of f() from inside A 3 matched A 1. f() • • Reasonable for call Surprising for execution Call and Execution Semantics in Aspect. J, FOAL 2004 A 1 f() g() A 2 h() A 3 f() 15

Executing what? A 1 s 1 = new A 1(); A 3 s 3

Executing what? A 1 s 1 = new A 1(); A 3 s 3 = new A 3(); A 1 s 1 d 3 = new A 3(); Almost the same as call But: l s 1 d 3. f() l ü execution(void A 3. f()) call(void A 3. f()) A 1 f() g() A 2 h() l call and execution differ in more than just their context A 3 f() Call and Execution Semantics in Aspect. J, FOAL 2004 16

call vs. execution l From the Aspect. J Programming Guide: “The rule of thumb

call vs. execution l From the Aspect. J 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. ” l No! Call and Execution Semantics in Aspect. J, FOAL 2004 17

The execution model l Notation: • • • pointcut variable defined as join point

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

The execution model l l Notation: • • • pointcut variable defined as join

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

A 1 s 1 = new A 1(); A 3 s 3 = new

A 1 s 1 = new A 1(); A 3 s 3 = new A 3(); A 1 s 1 d 3 = new A 3(); Running in the family l l s 3. h() ü A 1 call(void A 1+. h()) call(void A 3+. h()) Consistent, but surprising due to previous problems f() g() A 2 h() A 3 f() Call and Execution Semantics in Aspect. J, FOAL 2004 20

The subtype pattern model l Notation: • • call pointcut execution pointcut variable defined

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

The subtype pattern model l l Notation: • • call pointcut execution pointcut variable

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

Summary l Intuitive: • Pointcuts with subtype patterns are equivalent • to the union

Summary l 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 Aspect. J, FOAL 2004 23

Summary l Unintuitive: • The semantics of call pointcuts depends on • • the

Summary l 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 Aspect. J, FOAL 2004 24

Alternative semantics l l In our opinion, the lexical definition requirement should be removed

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

call pointcut in the proposed semantics Narrow Broad Static Dynamic Call and Execution Semantics

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

Alternative semantics l l l Each of the four semantics is consistent and reasonable

Alternative semantics l l l 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 Aspect. J has other constructs to get the desired behavior • • within() target() Call and Execution Semantics in Aspect. J, FOAL 2004 27

Bottom line l A starting point for a discussion of desired Aspect. J semantics

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

Related work A Calculus of Untyped Aspect-Oriented Programs R. Jagadeesan, A. Jeffrey, and J.

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 Aspect. J, FOAL 2004 29

Questions? A Discussion Call and Execution Semantics in Aspect. J, FOAL 2004

Questions? A Discussion Call and Execution Semantics in Aspect. J, FOAL 2004