is join point a point
play

Is Join Point a Point? a pointcut and advice mechanism for making - PowerPoint PPT Presentation

Is Join Point a Point? a pointcut and advice mechanism for making aspects more reusable Hidehiko Masuhara University of Tokyo joint work with Yusuke Endoh and Aki Yonezawa 1 A secret of AspectJ AspectJ is based on join points A sceret


  1. Is Join Point a Point? a pointcut and advice mechanism for making aspects more reusable Hidehiko Masuhara University of Tokyo joint work with Yusuke Endoh and Aki Yonezawa 1

  2. A secret of AspectJ • AspectJ is based on join points • A sceret of AspectJ: join points are not points, but regions points t regions t – makes aspects hard to maintain • We propose an AOPL in which join points are points 2

  3. Aspect-oriented programming enables modularization of crosscutting concerns [Kiczales et al.1997] Display – e.g., logging, security, error handling update(FigureElement) display offers a mechanism: elements FigureElement join points, pointcut & advice Figure moveBy(int,int) Point Line Logging getX() getP1() after() returning(Str m): getY() getP2() call(readLine) { setX(int) setP1(Point) Logger.log(m); setY(int) setP2(Point) } base program aspects 3

  4. Join point, pointcut & advice in AspectJ Base: reads user’s inputs in several modules Logging: record all inputs from the console • Join points=actions like method calls, execs... • Pointcut: selects jps Main A Console • Advice: runs on selected jps readLine “john” after() returning(String x) : doSome call(String *.readLine()) { readLine Logger.log(x); “1” } 4

  5. Aspect maintainability: most changes are adapted by pointcuts Changes in aspect spec./base prog.  • log getenv as well after() returning(String x) : after() returning(String x) : after() returning(String x) : after() returning(String x) : • exclude calls from (call(String *.readLn()) (call(String *.readLine()) call(String *.readLine()) { call(String *.readLine()) ??? || call(String *.getenv())) || call(String *.getenv())) LogBrowser Logger.log(x); || call(String *.getenv()) { • rename readLine to } && !within(LogBrowser) { && !within(LogBrowser) { Logger.log(x); Logger.log(x); Logger.log(x); readLn } • log onSubmit as well } }  modifications to pointcuts to cope with changes 6

  6. Aspect maintainability: some changes can advice specifiers not be adapted by pointcuts (not pointcuts) Logging inputs from console & GUI widgets needs two advice decls. provide inputs thru i.e., can not be adapted callback methods by pointcuts Main A Console Field after() returning(String x) : readLine call(String *.readLine()) { Logger.log(x); “john” } onSubmit(“1”) before(String x): exec(* *.onSubmit(String)) && args(x) { Logger.log(x); } 7

  7. Another example: returning null vs. throwing exceptions r = find(...); after() returning (Result r): if (r==null) call(find)&&if(r==null) { handle not found case Logger.log(); process the result } try {r = find(...);} after() throwing (NotFound): catch (NotFound e) { call(find) { handle not found case Logger.log(); } } process the result 8

  8. Problem summary & analysis • Generalization: can not advise “beginnings of X and ends of Y” by one decl. – active / passive parameter passing – returning error values / throwing exceptions – direct style / continuation passing style (in FPL) • Reasons: Main Console – join points are regions w/ entry and exit – pointcuts select only join points – advice decls. specify entry or exit 9

  9. Proposal: AOP mechanism based on point-in-time join points • Overview • Aspect maintainability with point-in-time join points • Design issues of pointcuts and advice • Formalization 10

  10. AOP mechanism based on point-in-time join points • A join point is a point in time • New join points that represent ends of actions • New pointcuts that select new join points Main Console advice(String x) : call jp return (String *.readLine()) readLine && args(x) { return jp Logger.log(x); proceed x; “john” } 11

  11. Aspect maintainability with point-in-time join points: logging readLine & onSubmit • One advice decl. can log both – return values from readLine – parameters to onSubmit Main A Console Field advice(String x) : readLine (return(String *.readLine()) “john” || call(void *.onSubmit(String x))) onSubmit(“1”) && args(x) { Logger.log(x); proceed x; } 12

  12. Aspect maintainability with point-in-time join points: returning null vs. throwing exceptions r = find(...); if (r==null) advice(): ( return (find) && handle not found case args(r) && if(r==null)) || do with the result throw (find,NotFound) { Logger.log();proceed; try {r = find(...);} } catch (NotFound e) { handle not found case one advice decl. } for two do with the result 13

  13. Design issues of pointcuts & advice with point-in-time join points convert parameters to introduced a special • Designed to support most features in AspectJ onSubmit into lowercase form proceed to pass proceed to a return jp – run code before or after a jp new params to jp can replace return values – replace parameters to a jp introduced another form after() returning(String x) : advice(String x) : – replace a return value from a jp to skip to the caller call(String *.readLine()) { return(String *.readLine()) advice(String x) : void around(String x) : && args(x) { Logger.log(x); – skip execution of a jp call(*.onSubmit(String)) call(*.onSubmit(String)) region-in-time String around() : advice(String x) : Logger.log(x); proceed x; } (AspectJ) && args(x) { && args(x) { • ...but difficult to support some: call(readLine()) { return(readLine()) String around() : advice() : call(readLine()) { } proceed(x.lower()); proceed x.lower(); point-in-time (ours) return proceed().lower(); && args(x) { skip “dummy”; – repeat execution of a jp call(readLine()) { } } region-in-time point-in-time } proceed x.lower() ; region-in-time return “dummy”; } – run code before and after a jp point-in-time } point-in-time } region-in-time 14

  14. Design issues of pointcuts & advice with point-in-time join points void around(): • Designed to support most features in AspectJ call(*.onSubmit()) { – run code before or after a jp String around(): int start=getTime(); – replace parameters to a jp call(*.readLine()) { proceed(); – replace a return value from a jp print(getTime()-start); return proceed()+proceed(); } } – skip execution of a jp region-in-time region-in-time • ...but difficult to support some: – repeat execution of a jp – run code before and after a jp proceed won’t come back in point-in-time 15

  15. Formalization of pointcut & advice based on point-in-time join points Writing a denotational semantics • of an untyped FPL + pointcut&advice • by using a continuation passing style (CPS) – a return = application to a continuation • simpler in terms of advice exec. – no longer has specifiers like “before” • suitable to explore advanced features – e.g., advising exceptions 16

  16. Semantics of advice execution: a sample session Execution trace: An expression: 1. creates a jp “call f with 1” let f(x)=x+x in f(1) 2. matches pointcut “call(f)” with advice: 3. evaluates “proceed x+1” advice(x):call(f){ 4. calls f with 2 proceed x+1; 5. creates a jp } “return from f with 4” advice(x):return(f){ 6. matches pointcut “return(f)” proceed x/2; 7. evaluates “proceed x/2” } 8. yields 2 17

  17. Semantics of advice execution: function call w/o advice • semantic function E : Exp → Env → Ctn → Ans return Ctn = Val → Ans call E [( E 0 E 1 )]ρκ = E [ E 0 ]ρ (λf. E [ E 1 ] ρ (λv. f (λv’.κ v’) v )) a function is denoted by a term of type Ctn → Val → Ans 18

  18. Semantics of advice execution: function call with advice • semantic function E : Exp → Env → Ctn → Ans can treat call & return Ctn = Val → Ans jps uniformly E [( E 0 E 1 )]ρκ = E [ E 0 ]ρ W A  κ’ v (λf. E [ E 1 ] ρ (λv. f (λv’.κ v’) v )) jp “call f” λv’. W A  ’ κ v’ advice weaver jp “return f” decls. 19

  19. Semantics of advice execution: weaver • W : Adv → Jp → Ctn → Ctn W [advice(x): p {E}] θκv = if p matchesθ then E [E] [v/x] κ elseκ v 20

  20. Semantics of advanced features (ongoing) • Uniform representation of exception throwing mechanisms – represents exception handlers as continuations – creates “throw” join point at throwing exceptions • Support for history sensitive pointcuts – similar approach to tracecuts [Walker00] – would subsume cflow • Interaction with tail call elimination – crucial in FPL – folding eta-expanded continuations 21

  21. Related work: extension to pointcuts and advice • Poincuts that capture return values: dflow [APLAS’03] , Arachne [Douence’05] – based on region-in-time join points • Fine grained jps: LoopsAJ [Harbulot’05] , Eos-T [Rajan’05] , bugdel [Usui’05] – based on region-in-time join points 22

  22. Related work: semantic models • Aspect • MiniMAO [Clifton’05] – operational + static semantics SandBox – region-in-time, around only [Wand’02] – region-in-time, • MiniAML & AspectML denotational [Walker’03] – backend (MiniAML): & direct style calclus of labeled terms; – semantic labels = point-in-time function for join points each of – frontend (AspectML): before/after/ region-in-time join points around 23

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend