Call and Execution Semantics in AspectJ

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

description

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 - PowerPoint PPT Presentation

Transcript of Call and Execution Semantics in AspectJ

Page 1: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ

Ohad BarzilayYishai A. FeldmanShmuel TyszberowiczAmiram Yehudai

Page 2: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 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

Page 3: Call and Execution Semantics in AspectJ

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 pointwhose signature matches MethodPattern”

The semantics of “matches”:• Based on which type?

• Type of the object?

• Type of the reference?

• Does the match include subclasses as well?

• …

Page 4: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 4

Motivation

Automatically generated AOP code JOSE tool – enforcement of Design by

Contract methodology using AspectJ

Page 5: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 5

Class hierarchy

public class A1 { public void f() {} public void g() {}}

public class A2 extends A1 { public void h() {}}

public class A3 extends A2 { public void f() {}}

A1

f()

g()

A3

f()

A2

h()

Page 6: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 6

Calling who?

pointcut call(void A1.f())s1.f()s3.f()s1d3.f()

pointcut call(void A1.g()) s1.g()s3.g()s1d3.g()

A1 s1 = new A1();A3 s3 = new A3();A1 s1d3 = new A3();

A1

f()

g()

A3

f()

A2

h()

Page 7: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 7

Calling who?

pointcut call(void A1.f())s1.f()s3.f()s1d3.f()

pointcut call(void A1.g()) s1.g()s3.g()s1d3.g()

A1 s1 = new A1();A3 s3 = new A3();A1 s1d3 = new A3();

A1

f()

g()

A3

f()

A2

h()

Page 8: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 8

Calling who?

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?

A1 s1 = new A1();A3 s3 = new A3();A1 s1d3 = new A3();

A1

f()

g()

A3

f()

A2

h()

Page 9: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 9

Calling who?

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

A1 s1 = new A1();A3 s3 = new A3();A1 s1d3 = new A3();

A1

f()

g()

A3

f()

A2

h()

Page 10: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 10

Calling who?

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

A1 s1 = new A1();A3 s3 = new A3();A1 s1d3 = new A3();

A1

f()

g()

A3

f()

A2

h()

Page 11: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 11

The call model

Notation:• pointcut

• variable defined as

• join point

call(void . ())cpc C f = new ()S x D

. ()jp x f

Page 12: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 12

The call model

Notation:• pointcut

• variable defined as

• join point

For this to compile

call(void . ())cpc C f = new ()S x D

. ()jp x f

D S

Page 13: Call and Execution Semantics in AspectJ

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(void . ())cpc C f = new ()S x D

. ()jp x f

is lexically defined in cjp pc S C f C

D S

Page 14: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 14

Executing what?

pointcut execution(void A1.f())s1.f()s3.f()s1d3.f()

A1 s1 = new A1();A3 s3 = new A3();A1 s1d3 = new A3();

A1

f()

g()

A3

f()

A2

h()

Page 15: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 15

Executing what?

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

A1 s1 = new A1();A3 s3 = new A3();A1 s1d3 = new A3();

A1

f()

g()

A3

f()

A2

h()

Page 16: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 16

Executing what?

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

A1 s1 = new A1();A3 s3 = new A3();A1 s1d3 = new A3();

A1

f()

g()

A3

f()

A2

h()

Page 17: Call and Execution Semantics in AspectJ

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!

Page 18: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 18

The execution model

Notation:• pointcut

• variable defined as

• join point

execution(void . ())epc C f = new ()S x D

. ()jp x f

Page 19: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 19

The execution model

Notation:• pointcut

• variable defined as

• join point

And we get:

execution(void . ())epc C f = new ()S x D

. ()jp x f

is lexically defined in ejp pc D C f C

Page 20: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 20

Running in the family

s3.h() call(void A1+.h())

call(void A3+.h())

Consistent, but surprising due to previous problems

A1 s1 = new A1();A3 s3 = new A3();A1 s1d3 = new A3();

A1

f()

g()

A3

f()

A2

h()

Page 21: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 21

The subtype pattern model Notation:

• call pointcut

• execution pointcut

• variable defined as

• join point

call(void . ())cpc C f

= new ()S x D. ()jp x f

execution(void . ())epc C f

Page 22: Call and Execution Semantics in AspectJ

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(void . ())cpc C f

= new ()S x D. ()jp x f

is lexically defined in some s.t. cjp pc S C

f F S F C

execution(void . ())epc C f

is lexically defined in some s.t. ejp pc C

f F

D

D F C

Page 23: Call and Execution Semantics in AspectJ

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.

Page 24: Call and Execution Semantics in AspectJ

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.

Page 25: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 25

Alternative semantics

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?

Page 26: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 26

call pointcut in the proposed semantics call(void . ())cpc C f

= new ()S x D. ()jp x f

exists in C f CS exists in C f CS

exists in C f CD exists in C f CD

Narrow Broad

Static

Dynamic

...cjp pc

Page 27: Call and Execution Semantics in AspectJ

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

Page 28: Call and Execution Semantics in AspectJ

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

Page 29: Call and Execution Semantics in AspectJ

Call and Execution Semantics in AspectJ, FOAL 2004 29

Related workA Calculus of Untyped Aspect-Oriented Programs

R. Jagadeesan, A. Jeffrey, and J. Reily

A Theory of AspectsD. Walker, S. Zdancewic, and J. Ligatti

A Semantical Approach to Method-Call InterceptionR. Lämmel

Compilation semantics of aspect-oriented programs H. Masuhara, G. Kiczales, and C. Dutchyn

A semantics for pointcuts and advice in higher-order languagesD. B. Tucker and S. Krishnamurthi

A semantics for advice and dynamic join points in aspect-oriented Programming

M. Wand, G. Kiczales, and C. Dutchyn

Page 30: Call and Execution Semantics in AspectJ

Questions ?

A Discussion