Continuation Join Points Yusuke Endoh Hidehiko Masuhara Akinori

  • Slides: 33
Download presentation
Continuation Join Points Yusuke Endoh, Hidehiko Masuhara, Akinori Yonezawa (University of Tokyo) 1

Continuation Join Points Yusuke Endoh, Hidehiko Masuhara, Akinori Yonezawa (University of Tokyo) 1

Background: Aspects are reusable in Aspect. J (1) n Example: A generic logging aspect

Background: Aspects are reusable in Aspect. J (1) n Example: A generic logging aspect q q can log user inputs in a CUI program by defining a pointcut Login Generic Logging Aspect id = read. Line(); Main cmd = read. Line(); logging return value CUI Aspect pointcut input(): call(read. Line()) 2

Background: Aspects are reusable in Aspect. J (2) n Example: A generic logging aspect

Background: Aspects are reusable in Aspect. J (2) n Example: A generic logging aspect q q can also log environment variable by also defining a pointcut Q. Now, if we want to log environment variable (get. Env) …? A. Merely concretize an aspect additionally Aspect reusability Generic Logging Aspect Env Aspect CUI Aspect pointcut input(): call(get. Env()) pointcut input(): call(read. Line()) 3

Problem: Aspects are not as reusable as expected n Example: A generic logging aspect

Problem: Aspects are not as reusable as expected n Example: A generic logging aspect q can NOT log inputs in a GUI program by defining a pointcut Login void on. Submit(id) {…} Generic Logging Aspect Main void on. Submit(cmd) {…} GUI Aspect pointcut Input(): call(on. Submit(Str)) logging arguments 4

Why can’t we reuse the aspect? n Timing of advice execution depends on both

Why can’t we reuse the aspect? n Timing of advice execution depends on both advice modifiers and pointcuts Logging Aspect (inner) abstract pointcut: input(); Generic Logging Aspect after() returning(String s) : input() { Log. add(s); } unable to change to before 5

Workaround in Aspect. J is awkward: overview n Required changes for more reusable aspect:

Workaround in Aspect. J is awkward: overview n Required changes for more reusable aspect: q generic aspect (e. g. , logging) n q two abstract pointcuts, two advice decls. and an auxiliary method concrete aspects n two concrete pointcuts even if they are not needed 6

Workaround in Aspect. J is awkward: how to define generic aspect Simple Logging Aspect

Workaround in Aspect. J is awkward: how to define generic aspect Simple Logging Aspect 1. define two pointcuts for before and after abstract pointcut: input. After(); abstract pointcut: input. Before(); 2. define two advice decls. for before and after() returning(String s) : input. After() { log(s); } before(String s) : input. Before() && args(s) { log(s); } 3. define auxiliary method void log(String s) { Log. add(s); } 7

Workaround in Aspect. J is awkward: how to define concrete aspects n always define

Workaround in Aspect. J is awkward: how to define concrete aspects n always define both pointcuts q even if not needed CUI Aspect pointcut input. After() : call(read. Line()); pointcut input. Before() : never(); Updated Logging Aspect GUI Aspect pointcut input. After() : never(); pointcut input. Before() : call(on. Submit(Str)); 8

Summary: Aspect Reusability Problem n Aspects are not reusable when advice modifiers need to

Summary: Aspect Reusability Problem n Aspects are not reusable when advice modifiers need to be changed q CUI/GUI is not an artificial example n n stand-alone application framework blocking I/O non-blocking I/O n Workaround is awkward n Cause: Timing of advice execution depends on both advice modifiers and pointcuts 9

Contributions n n The point-in-time join point model Pit. J: an experimental AOP language

Contributions n n The point-in-time join point model Pit. J: an experimental AOP language based on the model q n completed the language design Pitl: simplified version of Pit. J based on lcalculus q q a working interpreter formalized in CPS 10

Point-in-Time Join Point Model n Define ends of actions as different join points from

Point-in-Time Join Point Model n Define ends of actions as different join points from beginnings of actions region-in-time model (traditional) point-in-time model (proposed) read. Line(){ Aspect. J, Aspect. Werkz, JBoss AOP, … read. Line(); } call join point reception join point 11

Pit. J: An Experimental AOP Language Based on Point-in-Time Model n is more reusable

Pit. J: An Experimental AOP Language Based on Point-in-Time Model n is more reusable than Aspect. J because of point-in-time model is as expressive as Aspect. J n base language : Java (Aspect. J-like) n 12

Pit. J: Pointcuts n n n call(method): a call to method reception(method): a return

Pit. J: Pointcuts n n n call(method): a call to method reception(method): a return from method failure(method): an exceptional return from method q n i. e. , exception is thrown by method args(var): binding join point’s value to var q q q call join point’s value : argument reception join point’s value : return value failure join point’s value : exception object 13

Pit. J: Examples of Advice (1) n No need for advice modifiers q advice(Str

Pit. J: Examples of Advice (1) n No need for advice modifiers q advice(Str s): call(m) && args(s) { … } n n q advice(Str s): reception(m) && args(s) { … } n q advices at call join point of the method m in Aspect. J: before(): call(m) { … } in Aspect. J: after() returning(Str s): call(m) { … } advice(Obj e): failure(m) && args(e) { … } n in Aspect. J: after() throwing(Obj e): call(m) { … } 14

Pit. J: Examples of Advice (2) n before and after advice can be defined

Pit. J: Examples of Advice (2) n before and after advice can be defined in one advice declaration q advice(Str s): (call(on. Submit(Str)) || reception(read. Line())) && args(s) { … } n runs at both call join point of on. Submit and a reception join point of read. Line n in Aspect. J, corresponding to a pair of advice decls. before(String s): call(on. Submit(Str)) && args(s) { … } after() returning(String s): call(read. Line()) { … } n n 15

Reusable Logging Aspect in Pit. J Generic Logging Aspect abstract pointcut input(); advice(String s):

Reusable Logging Aspect in Pit. J Generic Logging Aspect abstract pointcut input(); advice(String s): input() && args(s) { Log. add(s); } CUI Aspect GUI Aspect pointcut input(): reception(read. Line()) call(on. Submit(Str)) 16

Pit. J: Around-like Advice n usages of around advice in Aspect. J 1. replace

Pit. J: Around-like Advice n usages of around advice in Aspect. J 1. replace the parameters to a join point with new ones 2. replace the return value to the caller of a join point 3. go back to the caller without executing a join point 4. execute a join point more than once n In Pit. J, these are realized by: q q q 1, 2 return in advice body 3 new construct: skip 4 special function: proceed 17

return in advice body (1) n replaces join point’s value n Example: at call

return in advice body (1) n replaces join point’s value n Example: at call join point q advice(Str s): call(m) && args(s) { return sanitize(s); } replaces the argument of m with the sanitized one q in Aspect. J: n around(Str s): call(m) && args(s) { return proceed(sanitize(s)); } 18

return in advice body (2) n Example: at reception join point q advice(Str s):

return in advice body (2) n Example: at reception join point q advice(Str s): reception(m) && args(s) { return sanitize(s); } replaces the return value of m with the sanitized one q in Aspect. J: n around(Str s): call(m) && args(s) { return sanitize(proceed(s)); } 19

new construct: skip n skip is evaluated in a call join point: q skips

new construct: skip n skip is evaluated in a call join point: q skips subsequent advice decls. and the call itself n n in a reception or failure join point: q n i. e. , jumps to the corresponding reception join point skips subsequent advice decls. Example: q advice(): call(read. Line()) { skip “dummy”; } q in Aspect. J: makes read. Line always return “dummy” n String around(): call(read. Line()) { return “dummy”; } 20

special function: proceed n proceed is evaluated in a call join point: q n

special function: proceed n proceed is evaluated in a call join point: q n in a reception or failure join point: q n executes the action until the corresponding reception join point no effect Example: q q q advice(): call(read. Line) { proceed(); } n let read. Line skip every other line advice(): call(read. Line) { skip(proceed() + proceed()); } n let read. Line return a concatenation of two lines advice(): call(read. Line) { skip(proceed()); } n no effect 21

Summary: Pit. J n n n No need for advice modifiers Advice decls. are

Summary: Pit. J n n n No need for advice modifiers Advice decls. are more reusable than Aspect. J’s due to the point-in-time model Pit. J is as expressive as Aspect. J’s advice mechanism q q q before : call join points after : reception or failure join point around-like : skip and proceed 22

Formalization of Point-in-Time Model n n target: Pitl q simplified version of Pit. J

Formalization of Point-in-Time Model n n target: Pitl q simplified version of Pit. J q base language: untyped l-calculus approach: q q denotational semantics in continuation-passing style key idea: denote join points as applications to continuation 23

Semantic Equations: Advice n A : advice list Event Ctn q q n Event

Semantic Equations: Advice n A : advice list Event Ctn q q n Event : kind of join point Ctn : continuation A [A] e k: return continuation that: q q q selects applicable advice decls. from A (list of advice) executes them, and executes k (continuation) n e: kind of join point 24

Semantic Equations: Expression n E : expression Ctn Ans q q n Ctn :

Semantic Equations: Expression n E : expression Ctn Ans q q n Ctn : continuation Ans : answer E [E] k: evaluates E and executes k q q E : expression k: continuation 25

Sample Program in Pitl advice call(f) && args(x) x+1 advice reception(f) && args(x) x+2

Sample Program in Pitl advice call(f) && args(x) x+1 advice reception(f) && args(x) x+2 let f x = x*2 in f 2 3 f 2 8 6 let f x = x*2 8 26

Semantics of Function Call (abridged) f 2 let f x = x*2 semantics of

Semantics of Function Call (abridged) f 2 let f x = x*2 semantics of l-calculus without aspect mechanism with advice mechanism E [E 0 E 1] k = E [E 0] (lf. E [E 1] (lv. f k v)) A[A] call (f k)(lv)) (lv. A[A] reception k v)) ) v)) application to continuation kv (ff kk): vcontinuation application to continuation = reception join point = call join we can define it in systematic way! 27

Advantages of Our Formalization n simpler than existing formalizations [Wand ’ 02] [Walker ’

Advantages of Our Formalization n simpler than existing formalizations [Wand ’ 02] [Walker ’ 03] q q n no need for rules for each advice modifier beginnings and ends of actions are represented symmetrically easier to support advanced features q q q exception handling context sensitive pointcuts (cflow) around advice 28

exception handling (sketch) n give a standard semantics q n by adding continuation that

exception handling (sketch) n give a standard semantics q n by adding continuation that represents current handler identify failure join point semantics of l-calculus with advice mechanism without aspect mechanism E [E 0 E 1] k kh = E [E 0] (lf. E [E 1] (lv. A[A] call (f (lv. A[A] reception k kh v) (lv. A[A] failure kh kkhh v) v) )) kh v) kh 29

around-like advice (concept) n using idea of partial continuation [Danvy ’ 89] q a

around-like advice (concept) n using idea of partial continuation [Danvy ’ 89] q a part of the rest of computation, rather than the whole rest f 2 let f x = x*2 partial continuation = skip / proceed n we currently formalized by using continuationcomposing style 30

Related Work n approaches based on the region-in-time model: q n Aspect Sand. Box[Wand

Related Work n approaches based on the region-in-time model: q n Aspect Sand. Box[Wand ’ 02], Tucker et al. ’ 03, Mini. MAO[Clifton ‘ 05], some approaches treat beginning and end of an event as different join points, but that have different motivations q q Walker et al. ’ 03: propose a low-level language that serves as a target of translation from a high-level AOP language Douence et al. ’ 04: define a formal semantics of cflow by using calling contexts from execution history 31

Conclusion n a new join point model that defines beginnings and ends of actions

Conclusion n a new join point model that defines beginnings and ends of actions as different join points q q Point-in-time vs. Region-in-time designed Pit. J based on the model n q improves aspect reusability by enhancing expressiveness of pointcuts formalized the model in continuation-passing style n n simpler than some existing formalizations easier to support advanced features 32

Future Work n integrate more advanced features q q q n dflow pointcut [Kawauchi

Future Work n integrate more advanced features q q q n dflow pointcut [Kawauchi ’ 03] first-class continuation tail-call elimination implement a compiler for Pit. J language q Java bytecode should be made without CPS transformation 33