1 Contract-based Verification for Aspect-oriented Refactoring Naoyasu Ubayashi(Kyushu Institute of Technology) Jinji Piao(Kyushu Institute of Technology)

Slides:



Advertisements
Similar presentations
Mohamed ElBendary and John Boyland University of Wisconsin-Milwaukee.
Advertisements

Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
An Aspect-Oriented Approach For Web Application Access Control Presented by: Mohamed Hassan Carleton University Carleton University
ASTA Aspect Software Testing Assistant Juha Gustafsson, Juha Taina, Jukka Viljamaa University of Helsinki.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development.
1 Naoyasu Ubayashi (Toshiba Corporation) Tetsuo Tamai (University of Tokyo) AOSD st International Conference on Aspect-Oriented Software Development.
1 An Aspect-Aware Outline Viewer Michihiro Horie and Shigeru Chiba Tokyo Institute of Technology, Japan.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Modularization.
University of British Columbia Software Practices Lab Fluid AOP Join Point Models Terry Hon Gregor Kiczales.
Java.sun.com/javaone/sf | 2004 JavaOne SM Conference | Session BUS JavaOne 2004 What is AOP? Gregor Kiczales AspectMentor.com and University of.
359C 10/1/05 Eric Wohlstadter Introductions –Name –Degree objective/Year –Research Area (or interests) Syllabus Aspect-Oriented Programming –AspectJ –AspectC.
ASPECT ORIENTED SOFTWARE DEVELOPMENT Prepared By: Ebru Doğan.
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
Harmless Advice Daniel S Dantas Princeton University with Prof. David Walker.
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Session 15 Modeling Traceability of Concerns in Architectural Views Mark Stobbe October 29,
Aspect-Oriented Programming with AspectJ™ AspectJ.org Xerox PARC Erik Hilsdale Gregor Kiczales with Bill Griswold, Jim Hugunin, Wes Isberg, Mik Kersten.
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
Generative Programming. Generic vs Generative Generic Programming focuses on representing families of domain concepts Generic Programming focuses on representing.
A Formal Model of Modularity in Aspect-Oriented Programming Jonathan Aldrich : Objects and Aspects Carnegie Mellon University.
An Introduction to AOP Original slides developed by Julie Waterhouse and Mik Kersten for OOPSLA 2004 AspectJ Tutorial ( kerstens.org/mik/publications/aspectj-
Outline Introduction Problem Statement Object-Oriented Design Aspect-Oriented Design Conclusion Demo.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Taming Obliviousness in Aspects with Data-flow Analysis and Design by Contract Tim Molderez and Dirk Janssens Ansymo Antwerp Systems and Software Modelling.
1 Archface: Architectural Interface -- Bridging a Gap between Design Modeling and Implementation Naoyasu Ubayashi, Hidenori Akatoki, Jun Nomura Kyushu.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
Change Impact Analysis for AspectJ Programs Sai Zhang, Zhongxian Gu, Yu Lin and Jianjun Zhao Shanghai Jiao Tong University.
VERIFICATION OF ASPECT ORIENTED MODELS BY DON MARTIN JAYASHREE VENKIPURAM PATHANGI PIYUSH SRIVASTAVA REFERENCES F. Mostefaoui and J. Vachon,” Design level.
Tool support for crosscutting concerns of API documentation Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan.
1 Metamodel Access Protocols for Extensible Aspect-Oriented Modeling Naoyasu Ubayashi(Kyushu Institute of Technology, Japan) Shinji Sano(Kyushu Institute.
1 An Aspect-oriented Weaving Mechanism Based on Component-and-Connector Architecture Naoyasu Ubayashi (Kyushu Institute of Technology) February 12, 2008.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton February 28th, 2003 Advisor: David G. Hannay Client:
1 A Parameterized Interpreter for Modeling Different AOP Mechanisms Naoyasu Ubayashi(Kyushu Institute of Technology, Japan) Genki Moriyama(Kyushu Institute.
POSL (Principles of Software Languages) Gr. Kyushu Institute of Technology, Japan An Extensible Aspect-Oriented Modeling.
POSL (Principles of Software Languages) Gr. Kyushu Institute of Technology, Japan Pointcut-based Architectural Interface.
Aspect Oriented Programming Gülşah KARADUMAN.
Generative Programming. Automated Assembly Lines.
Kiczales and Mezini - FOAL AOP and Modular Reasoning [ICSE05] Start with first-principles definition of modularity and modular reasoning –localization,
A Meta-Level Specification and Profile for AspectJ in UML Joerg Evermann School of Information Management Victoria University of Wellington.
Methodology: The AOP Refactoring Process Aspect-Oriented Refactoring of the Apache Cocoon Shared-Object Resource Allocation System Jeff Dalton Advisor:
A Distributed Aspect-Oriented System for J2EE Applications Muga Nishizawa and Shigeru Chiba (Tokyo Institute of Technology, Japan) Background - As benefits.
Design Rules for Increasing Modularity with CaesarJ Carlos Eduardo Pontual Advisor: Paulo Borba 17/06/2010.
AOSD1 Aspect-Oriented Software Design Karl Lieberherr Theo Skotiniotis.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
1 Proving aspect-oriented programming laws Leonardo Cole Paulo Borba Alexandre Mota Informatics Center Federal University of.
1 An Aspect-Oriented Implementation Method Sérgio Soares CIn – UFPE Orientador: Paulo Borba.
Aspect-Oriented Programming and Modular Reasoning G. KiczalesM. Mezini Presented by Alex Berendeyev.
Architectural Point Mapping for Design Traceability Naoyasu Ubayashi and Yasutaka Kamei Kyushu University, Japan March 26, 2012 FOAL 2012 (AOSD Workshop)
IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University.
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Applying Translucid Contracts for Modular Reasoning about Aspect and Object Oriented Events Mehdi Bagherzadeh Gary T. Leavens Robert Dyer Foundations of.
Alloy-based Lightweight Verification for Aspect-oriented Architecture Naoyasu Ubayashi(Kyushu Institute of Technology) Yuki Sato(Kyushu Institute of Technology)
AOP and observer pattern. Design pattern General reusable solution to a commonly occurring problem in software design Not a finished design that can be.
1 Software Maintenance and Evolution CSSE 575: Session 3, Part 3 Dealing with Generalization Steve Chenoweth Office Phone: (812) Cell: (937)
1 Context-aware Feature-Oriented Modeling with an Aspect Extension of VDM Naoyasu Ubayashi (Kyushu Institute of Technology) Shin Nakajima (National Institute.
POSL (Principles of Software Languages) Gr. Kyushu Institute of Technology, Japan 1 A Verification Mechanism for Weaving.
1 Deriving Refactorings for AspectJ Leonardo Cole Paulo Borba Informatics Center Federal University of Pernambuco Brazil.
1 Separation of Context Concerns --- Applying Aspect Orientation to VDM Naoyasu Ubayashi (Kyushu Institute of Technology) Shin Nakajima (National Institute.
CSC450 Software Engineering Devon M. Simmonds University of North Carolina, Wilmington 1.
AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan.
1 An AOP Implementation Framework for Extending Join Point Models Naoyasu Ubayashi(Kyushu Institute of Technology, Japan) Hidehiko Masuhara(University.
1 Aspectual Caml an Aspect-Oriented Functional Language Hideaki Tatsuzawa Hidehiko Masuhara Akinori Yonezawa University of Tokyo.
An Interface Mechanism for Encapsulating Weaving in Class-based AOP
Aspect-Oriented Generation of the API Documentation for AspectJ
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
An Extensible Contract Verifier for AspectJ
Presentation transcript:

1 Contract-based Verification for Aspect-oriented Refactoring Naoyasu Ubayashi(Kyushu Institute of Technology) Jinji Piao(Kyushu Institute of Technology) Suguru Shinotsuka(Kyushu Institute of Technology) Tetsuo Tamai(University of Tokyo) April 11, 2008 ICST 2008

Refactoring in AOP  Refactoring is a method for improving a program‘s structure without changing its external behavior.  Refactoring is a promising approach to assisting reliable software evolution.  However, in AOP, refactoring is not easy ! 2 Unexpected Weaving Fragile Pointcuts

Today’s my talk  We propose the notion of RbC (Refactoring by Contract), an AO refactoring verification method based on first-order logic.  RbC originates in DbC. [Meyer] 3 before refactoring precondition postcondition invariant after refactoring Programmer Contract Check AO Program Program Structure Program Behavior Refactoring

4 Outline 1. Motivation 2. Refactoring by Contract 3. Contract template 4. Implementation 5. Related work 6. Conclusions

5 1. Motivation

6 Aspect-oriented programming AOP is a programming paradigm in which crosscutting concerns are modularized as aspects. after (Shape s): (execution(void set*(..) || execution(void Shape+.moveBy(int,int))) && target(s) { s.redraw(); } advice pointcut AspectJ UpdateSignaling

Refactoring catalogues for AOP 7 Refactoring catalogues [Cole 2005] [Monteiro 2005] No. Refactoring pattern 1-1 Change Abstract Class to Interface 1-2 Extract Feature into Aspect 1-3 Extract Fragment into Advice 1-4 Extract Inner Class to Standalone 1-5 Inline Class within Aspect 1-6 Inline Interface within Aspect 1-7 Move Field from Class to Inter-type 1-8 Move Method from Class to Inter-type 1-9 Replace Implements with Declare Parents 1-10 Split Abstract Class into Aspect and Interface 2-1 Extend Marker Interface with Signature 2-2 Generalize Target Type with Marker Interface 2-3 Introduce Aspect Protection 2-4 Replace Inter-type Field with Aspect Map 2-5 Replace Inter-type Method with AspectMethod 2-6 Tidy Up Internal Aspect Structure 3-1 Extract Superaspect 3-2 Pull Up Advice 3-3 Pull Up Declare Parents 3-4 Pull Up Inter-type Declaration 3-5 Pull Up Marker Interface 3-7 Push Down Advice 3-8 Push Down Declare Parents 3-9 Push Down Inter-type Declaration 3-10 Push Down Marker Interface 3-11 Push Down Pointcut 1. For extraction of crosscutting concerns 2. For restructuring the internals of aspects 3. For dealing with generalization 27 refactoring patterns proposed by Monterio Aspect Super Aspect 1 3 2

But, AO refactoring is not easy …  Correct refactoring should satisfy the following constraints 1.Behavior must be preserved before/after refactoring 2.Refactoring should improve the internal structure as defined by refactoring catalogues 8 Correct ? How to verify?

public class Line implements Shape { public void setP1(Point p1) { this.p1 = p1; } public void setP2(Point p2) { this.p2 = p2; } public void moveBy(intdx, intdy) { p1.x += dx; p1.y += dy; p2.x += dx; p2.y += dy; } public void redraw() { Display.update(); } } Example: 1st refactoring 9 public class Point implements Shape { public void setX(int x) { this.x = x; } public void setY(int y) { this.y = y; } public void moveBy(intdx, intdy) { x += dx; y += dy; } public void redraw() { Display.update(); } } aspect UpdateSignaling { pointcut change(Shape s): (execution(void set*(..) || execution(void Shape+.moveBy(int,int))) && target(s); after(Shape s) returning: change(s){ s.redraw(); } } Move Method from Class to Inter-type aspect UpdateSignaling { public void redraw() { Display.update(); } pointcut change(Shape s): (execution(void set*(..) || execution(void Shape+.moveBy(int,int))) && target(s); after(Shape s) returning: change(s){ s.redraw(); } } aspect UpdateSignaling { public void Shape.redraw() { Display.update(); } pointcut change(Shape s): (execution(void set*(..) || execution(void Shape+.moveBy(int,int))) && target(s); after(Shape s) returning: change(s){ s.redraw(); } } Forget to remove redraw() 1.Behavior preservation [OK] 2.Structure improvement [NG] Behave correctly

Example: 2nd refactoring 10 public class Line implements Shape { public void setP1(Point p1) { this.p1 = p1; } public void setP2(Point p2) { this.p2 = p2; } public void moveBy(intdx, intdy) { p1.x += dx; p1.y += dy; p2.x += dx; p2.y += dy; } public void redraw() { Display.update(); } } p1.moveBy(dx, dy); p2.moveBy(dx, dy); aspect UpdateSignaling { public void redraw() { Display.update(); } pointcut change(Shape s): (execution(void set*(..) || execution(void Shape+.moveBy(int,int))) && target(s); after(Shape s) returning: change(s){ s.redraw(); } } Redraw() is called three times! 1.Behavior preservation [NG] 2.Structure improvement [OK]

Problems in AO refactoring 11 In AOP, it is not necessarily easy for a programmer to understand the overall behavior of a woven program because the weaving modifies the behavior. Unexpected bugs can be embedded in a program if the programmer does not modify the program carefully.

Our approach 12 We apply logic programming to verify the accuracy of aspect-oriented refactoring. In AOP, primitive predicates for specifying constraints must check the impact of weaving. Challenge

2. Refactoring by Contract 13

RbC: Refactoring by Contract before refactoringprecondition postcondition invariant after refactoring Programmer Contract Check AO Program Precondition states under which conditions refactoring can be applied. Invariant states what conditions refactoring should preserve. Postcondition states what conditions should be verified after refactoring has been accomplished. Program Structure Program Behavior 14

COW: COntractWriting language 15 class, method, extends, owner, aspect, pointcut, intertypeOwner, beforeAdvice, afterAdvice, aroundAdvice, etc. COW is a language for describing predicates based on first-order logic. program structure program behavior call, write, read, controlFlow, dataFlow, etc.

contract MoveMethodFromClassToIntertype { requires( class(Point) && method(redraw) && owner(redraw, Point) ); ensures( // condition 1 aspect(UpdateSignaling) && method(redraw) && owner(redraw, UpdateSignaling) && // condition 2 intertypeOwner(redraw, Point) && // condition 3 class(Point) && !owner(redraw, Point) ); } Contract for 1st Refactoring 16 Precondition Postcondition

contract LineBehavior restricts Line { void moveBy(int, int){ invariant (Redrawing.once()); } } Contract for 2nd Refactoring 17 contract Redrawing { define statement(s) { target(t) && entry(t, e) &&controlFlow(t, s, e) } define updating() { statement(s) && call(s, Display.update) } define multiple() { statement(s1) && call(s1, Display.update) && statement(s2) && call(s2, Display.update) && !equal(s1, s2) } define once() { updating() && !multiple() } }

3. Contract template 18

Contract template 19 ctemplate T_MoveMethodFromClassToIntertype { requires( owner(, ) ); ensures( // condition 1 owner(, ) && // condition 2 intertypeOwner(, ) && // condition 3 !owner(, ) ); }

Ctemplate T_ReplaceIntertypeMethodWithAspectMethod { requires( // condition 1 owner(, ) && // condition 2 intertypeOwner(, ) ); ensures( // condition 1 owner(, ) && // condition 2 !intertypeOwner(, ) ); } ctemplate T_MoveMethodFromClassToIntertype { requires( owner(, ) ); ensures( // condition 1 owner(, ) && // condition 2 intertypeOwner(, ) && // condition 3 !owner(, ) ); } Template composition 20 Parameter matching If postconditions of contract X are stronger than preconditions of contraxt Y, these templates can be composed. Contract XContract Y

Evaluation: template coverage 21 No. Refactoring pattern 1-1 Change Abstract Class to Interface 1-2 Extract Feature into Aspect 1-3 Extract Fragment into Advice 1-4 Extract Inner Class to Standalone 1-5 Inline Class within Aspect 1-6 Inline Interface within Aspect 1-7 Move Field from Class to Inter-type 1-8 Move Method from Class to Inter-type 1-9 Replace Implements with Declare Parents 1-10 Split Abstract Class into Aspect and Interface 2-1 Extend Marker Interface with Signature 2-2 Generalize Target Type with Marker Interface 2-3 Introduce Aspect Protection 2-4 Replace Inter-type Field with Aspect Map 2-5 Replace Inter-type Method with AspectMethod 2-6 Tidy Up Internal Aspect Structure 3-1 Extract Superaspect 3-2 Pull Up Advice 3-3 Pull Up Declare Parents 3-4 Pull Up Inter-type Declaration 3-5 Pull Up Marker Interface 3-7 Push Down Advice 3-8 Push Down Declare Parents 3-9 Push Down Inter-type Declaration 3-10 Push Down Marker Interface 3-11 Push Down Pointcut Patterns: 27 Templates: 18 Coverage = 67 %

4. Implementation 22

COW Contract Verifier 23 Parser & Program Analyzer AspectJ Code Prolog facts (CFG) Prolog Query COW to Prolog Translator Contracts Contract Checker

CFG: Control Flow Graph s1: -in: Point.moveBy() call(’s1’, ’Point.moveBy(int,int)’) s2: Point.moveBy(intdx, intdy) entry(’Point.moveBy(int,int)’,’s2’) s3: Point.x += dx s4: Point.y += dy s5: -out: Point.moveBy() next(’s1’,’s2’,[’Line.moveBy(int,int)’]) next(’s2’,’s3’,[’Line.moveBy(int,int)’,’Point.moveBy(int,int)’]) next(’s3’,’s4’,[’Line.moveBy(int,int)’,’Point.moveBy(int,int)’]) next(’s4’,’s5’,[’Line.moveBy(int,int)’]) controlFlow(Scope, Goal, Start) :- traverse(Scope, Goal, Start, []). traverse(Scope, Goal, Start, Visited) :- next(Start, Next, ScopeList), member(Scope, ScopeList), \+member(Next, Visited), Next = Goal. … 24

5. Related Work 25

Related work  Logic-based verification AspectJ programming laws for deriving behavior- preserving transformations [Cole 2005] Domain-specific language for Refactoring [Verbaere 2006] 26 In RbC, domain-specific contract templates can be defined using COW predicates.

Related work (Cont’d)  Software Evolution and Interfaces Aspect-aware interface [Kiczales 2005] Crosscut programming interface (XPI) [Griswold 2006] Open Modules [Aldrich 2005] Harmless advice [Dantas 2006] Aspect integration contracts [Lagaisse2004] 27 AO refactoring can be considered a special case of software evolution in which AO interfaces play an important role. Contracts for refactoring should add the information that complements interfaces.

Related work (Cont’d)  Unit testing and DbC Contract4J JML Cona [Skotiniotis 2004] 28 All dynamic behavior cannot necessarily be checked in our approach based only on static program analysis. Unit testing helps our approach.

6. Conclusions 29

Conclusions  The notion of RbC and a contract description method using COW are given.  These mechanisms provide the foundation for verifying the correctness of AO refactoring. 30