150 likes | 266 Views
Reasoning About Behavior of Aspect Oriented Programs. Neelam Soundarajan 1 Raffi Khatchadourian 1 Johan Dovland 2. 2 Dept. of Informatics University of Oslo. 1 Computer Sc. & Eng. Ohio State University. 2 Computer Sc. Dept. Clemson University. Background.
E N D
Reasoning About Behavior of Aspect Oriented Programs Neelam Soundarajan1 Raffi Khatchadourian1 Johan Dovland2 2 Dept. of Informatics University of Oslo 1 Computer Sc. & Eng. Ohio State University 2 Computer Sc. Dept. Clemson University
Background • AOP provides powerful mechanisms for: • Modifying behavior of existing code; • Writing code to address cross-cutting concerns; • ... etc. • An AOP program consists of: • One or more base code classes C1, C2, ...; • One or more aspects that apply to one or more Ci; Reasoning About Behavior of AOP Programs, SEA '07
Problem • How do we reason about the behavior of such a system? • Key point: Aspects are often developed long after the classes not together with them; Reasoning About Behavior of AOP Programs, SEA '07
Problem (contd.) • But ... the aspects often modify the behavior of the base code; • How do we ensure that the aspects don’t invalidate our base code reasoning? Reasoning About Behavior of AOP Programs, SEA '07
Analogy: Concurrent Programs • Problem similar to that of concurrent programs - the actions of one process P2 may invalidate the assertions used in reasoning about the other process P1; • Common solution: rely - guarantee clauses Reasoning About Behavior of AOP Programs, SEA '07
Concurrent Pgms: Rely-Guar • Rely/Guarantee clauses: rely1 : assumption about behavior of P2, used in reasoning about P1; guar1: guarantee that P1 provides about its behavior (for use in P2) • Parallel composition: Validate the respective rely clauses (using the guar clauses). Reasoning About Behavior of AOP Programs, SEA '07
AOP Primitives • Joinpoints: specific points in the execution of the base code where advice may be applied • Pointcuts: Allow us to specify groups of joinpoints (often uses quantification); • Advice: Code that applies at a pointcut, i.e., to all joinpoints in that pointcut. Reasoning About Behavior of AOP Programs, SEA '07
Reasoning Approach When reasoning about C.m(): • Define a set of spec pointcuts, s1, ... • For each spec pointcut si, specify a rely_i and a guar_i clause • When reasoning about C.m(), assume that any advice that applies at a given j.p. will satisfy corresponding rely_i • Check, at these points, that guar_i is satisfied. Reasoning About Behavior of AOP Programs, SEA '07
Reasoning Approach (contd.) When reasoning about an aspect: • Obtain rely_ and guar_ clauses for each spec pointcut that has a non-empty intersection with current pointcut; • Assume (guar_1 OR ... OR guar_k) will be satisfied at the start of the advice; • Show that (rely_1 & ... & rely_k’ ) will be satisfied when the advice finishes; Reasoning About Behavior of AOP Programs, SEA '07
Reasoning Approach (contd.) • Combine spec of C.m() and applicable advices to obtain resulting enriched behavior; • To do so ... need more than just post- condition of C.m(); ... • ... need info about flow-of-control through joinpoints. Reasoning About Behavior of AOP Programs, SEA '07
Example class Point { int x, y; ... public void move(int nx, int ny) { L1: x = nx; L2: y = nx; } } These pointscan move to arbitrary coordinates. How to ensure that pointsstay within bounds? Reasoning About Behavior of AOP Programs, SEA '07
Example (contd.) Answer: WrapAround aspect that resetscoordinates as necessary. aspect WrapAround { pointcut m(Point p) : (set (int Point p.x) && target(p) || set (int Point p.y) && target(p) ) && !within( WrapAround ) ; after( Point p) : m(p) { p.x = p.x % b.x; p.y = p.y % b.y; } } Reasoning About Behavior of AOP Programs, SEA '07
Example (contd.) Questions: Spec of Point.move()? Spec of WrapAround? Combined behavior? Important: point’s final state depends on: initial state; parameters; and states after advices at L1/L2 finish. Spec should capture this dependence. This can be combined with beh. of WrapAround() Details: In the paper. Reasoning About Behavior of AOP Programs, SEA '07
Results Specs of individual class methods: Written to account for flow through potential joinpoints and dependence of final state on the effects of advices at these points (and using info from rely clauses); Specs of aspects/advices: Arrived at making use of info from guar clauses; Combination: Arrived at without reanalyzing the method behaviors. Reasoning About Behavior of AOP Programs, SEA '07
Thanks! Questions? Reasoning About Behavior of AOP Programs, SEA '07