A Formal Model of Modularity in Aspect-Oriented Programming Jonathan Aldrich 15-819: Objects and Aspects Carnegie Mellon University.

Slides:



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

Type Systems and Object- Oriented Programming (III) John C. Mitchell Stanford University.
Programming Paradigms Introduction. 6/15/2005 Copyright 2005, by the authors of these slides, and Ateneo de Manila University. All rights reserved. L1:
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
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.
ML Exceptions.1 Standard ML Exceptions. ML Exceptions.2 Exceptions – The Need  An extensive part of the code is error handling  A function can return.
CSE341: Programming Languages Lecture 12 Modules Dan Grossman Fall 2011.
An Untyped Calculus of Aspect- Oriented Programs Radha Jagadeesan Alan Jeffrey James Riely DEPAUL UNIVERSITY, CHICAGO.
Data Abstraction COS 441 Princeton University Fall 2004.
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
Good Advice for Type-directed Programming Aspect-oriented Programming and Extensible Generic Functions Geoffrey Washburn [ ] Joint.
Elaboration or: Semantic Analysis Compiler Baojian Hua
Modules in UHC A proposal by: Tom Hofte & Eric Eijkelenboom.
Harmless Advice Daniel S Dantas Princeton University with Prof. David Walker.
From Module Breakdown to Interface Specifications Completing the architectural design of Map Schematizer.
Session 15 Modeling Traceability of Concerns in Architectural Views Mark Stobbe October 29,
Subclasses and Subtypes CMPS Subclasses and Subtypes A class is a subclass if it has been built using inheritance. ▫ It says nothing about the meaning.
Type-Directed, Whitespace-Delimited Parsing for Embedded DSLs Cyrus Omar School of Computer Science Carnegie Mellon University [GlobalDSL13] Benjamin ChungAlex.
1 Aspects and Modularity: The Hope and the Challenge Jonathan Aldrich Institute for Software Research International School of Computer Science Carnegie.
C++ Object Oriented 1. Class and Object The main purpose of C++ programming is to add object orientation to the C programming language and classes are.
Taming Obliviousness in Aspects with Data-flow Analysis and Design by Contract Tim Molderez and Dirk Janssens Ansymo Antwerp Systems and Software Modelling.
Sadegh Aliakbary Sharif University of Technology Fall 2011.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Mathematical Modeling and Formal Specification Languages CIS 376 Bruce R. Maxim UM-Dearborn.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
VERIFICATION OF ASPECT ORIENTED MODELS BY DON MARTIN JAYASHREE VENKIPURAM PATHANGI PIYUSH SRIVASTAVA REFERENCES F. Mostefaoui and J. Vachon,” Design level.
What is “model transformation”? Distinction between source and target Source may be same as target May be multiple sources, or targets Reaching a fixed.
Computer Science and Engineering College of Engineering The Ohio State University Interfaces The credit for these slides goes to Professor Paul Sivilotti.
1 An Aspect-oriented Weaving Mechanism Based on Component-and-Connector Architecture Naoyasu Ubayashi (Kyushu Institute of Technology) February 12, 2008.
CSE 331 SOFTWARE DESIGN & IMPLEMENTATION MIDTERM REVIEW Autumn 2011.
POSL (Principles of Software Languages) Gr. Kyushu Institute of Technology, Japan Pointcut-based Architectural Interface.
Design Rules for Increasing Modularity with CaesarJ Carlos Eduardo Pontual Advisor: Paulo Borba 17/06/2010.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
OO as a language for acm l OO phrase l Mental model of key concepts.
Aspect-Oriented Programming and Modular Reasoning G. KiczalesM. Mezini Presented by Alex Berendeyev.
IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University.
Aspect-Oriented Action Semantics Descriptions Luis Menezes University of Pernambuco
1 Contract-based Verification for Aspect-oriented Refactoring Naoyasu Ubayashi(Kyushu Institute of Technology) Jinji Piao(Kyushu Institute of Technology)
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)
Just Enough Type Theory or, Featherweight Java A Simple Formal Model of Objects Jonathan Aldrich
Review of Parnas’ Criteria for Decomposing Systems into Modules Zheng Wang, Yuan Zhang Michigan State University 04/19/2002.
CSE 3302 Programming Languages Chengkai Li, Weimin He Spring 2008 Abstract Data Types and Modules Lecture 11 – ADT and Modules, Spring CSE3302 Programming.
A Type System for Higher-Order Modules Derek Dreyer, Karl Crary, and Robert Harper Carnegie Mellon University POPL 2003.
PROGRAMMING PRE- AND POSTCONDITIONS, INVARIANTS AND METHOD CONTRACTS B MODULE 2: SOFTWARE SYSTEMS 13 NOVEMBER 2013.
Cs776(Prasad)L112Modules1 Modules value : type : function :: structure : signature : functor.
CSSE501 Object-Oriented Development. Chapter 10: Subclasses and Subtypes  In this chapter we will explore the relationships between the two concepts.
R R R A Brief Introduction to Aspect-Oriented Programming.
Introduction to Aspect- Oriented Programming CS 3360 Gregor Kiczales, et. al. Getting started with AspectJ, CACM, 44(10):59-65, October Spring 2012.
AspectScope: An Outline Viewer for AspectJ Programs Michihiro Horie, Shigeru Chiba Tokyo Institute of Technology, Japan.
Soundness of Types Ensuring that a type system is not broken.
Type soundness In a more formal way. Proving Soundness of Type Systems Goal of a sound type system: –if the program type checks, then it never “crashes”
Types and Programming Languages Lecture 10 Simon Gay Department of Computing Science University of Glasgow 2006/07.
Duke CPS Programming Heuristics l Identify the aspects of your application that vary and separate them from what stays the same ä Take what varies.
1 Aspectual Caml an Aspect-Oriented Functional Language Hideaki Tatsuzawa Hidehiko Masuhara Akinori Yonezawa University of Tokyo.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
COMP 412, FALL Type Systems C OMP 412 Rice University Houston, Texas Fall 2000 Copyright 2000, Robert Cartwright, all rights reserved. Students.
An Interface Mechanism for Encapsulating Weaving in Class-based AOP
Demeter Aspects Who We Are Aspectual Collaborations
Objects and Aspects: What we’ve seen so far
CSE-321 Programming Languages Introduction to Functional Programming
An Extensible Contract Verifier for AspectJ
Programming Languages and Paradigms
CSE 341 Lecture 11 b closures; scoping rules
C++ Object Oriented 1.
Abstract Types Defined as Classes of Variables
Presentation transcript:

A Formal Model of Modularity in Aspect-Oriented Programming Jonathan Aldrich : Objects and Aspects Carnegie Mellon University

Outline AOP Modularity Challenges Open Modules A Bit of Formality Comparison to Aspect-Aware Interfaces Lessons Learned and Discussion

Modularity and Encapsulation Parnas’ advice: Modularize a system to hide information that may change Encapsulation A mechanism for enforcing information hiding Java classes & packages, ML modules… Aspect-oriented Programming More flexible ways of modularizing a system

Is AOP Modular? Back to Parnas: Does AOP hide information that is likely to change? Yes, within the aspect Aspect code can be evolved separately No, not within the base code Minor changes to base code break the aspect

Example: Assurance Aspect class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... }

Example: Assurance Aspect class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... } class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy;... }

Example: Assurance Aspect class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... } class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy;... } aspect AssureShapeInvariants { }

Example: Assurance Aspect class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... } class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy;... } aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); }

Example: Assurance Aspect class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... } class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy;... } aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); after(): moves() { scene.checkInvariants(); }

Example: Broken Assurance Aspect class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... } class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy;... } aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); after(): moves() { scene.checkInvariants(); } Change representation to use Point

Example: Broken Assurance Aspect class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... } class Rectangle extends Shape { void moveBy(int dx, int dy) { p1.moveBy(dx, dy); p2.moveBy(dx, dy);... } aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); after(): moves() { scene.checkInvariants(); } Change representation to use Point

Example: Broken Assurance Aspect class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... } class Rectangle extends Shape { void moveBy(int dx, int dy) { p1.moveBy(dx, dy); p2.moveBy(dx, dy);... } aspect AssureShapeInvariants { pointcut moves() = call(Shape+.moveBy(..)); after(): moves() { scene.checkInvariants(); } Change representation to use Point Now the scene invariants are checked in the middle of a Rectangle move—when they might be broken!

Analysis Aspects can violate information hiding Assurance aspect depends on Shape internals Similar to OO Fragile Base Class Problem Observing impl. dependant calling patterns Can fix each individual problem Better: use modules to forestall issue

Fix #1: external advice class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... } class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy;... } aspect AssureShapeInvariants { pointcut moves(): call(Shape+.moveBy(..)) && !within(shape.*); after(): moves() { scene.checkInvariants(); } Only specifies calls that are external to the shape package

Fix #2: semantic pointcut class Point extends Shape { void moveBy(int dx, int dy) { x += dx; y += dy;... } class Rectangle extends Shape { void moveBy(int dx, int dy) { p1x += dx; p1y += dy; p2x += dx; p2y += dy;... } class Shape { public pointcut moves(): call(Shape+.moveBy(..)); } aspect AssureShapeInvariants { after(): Shape.moves() { scene.checkInvariants(); } Move pointcut to the shape package Now the shape maintainer is responsible for preserving its semantics when shapes evolve

Open Modules void moveBy(int, int); void animate(Motion); Open Module Ordinary functional interface

Open Modules void moveBy(int, int); void animate(Motion); pointcut moves; Open Module Ordinary functional interface Semantic Pointcut Denotes some internal event Promise to maintain event semantics as code evolves [Gudmunson & Kiczales]

Open Modules void moveBy(int, int); void animate(Motion); pointcut moves; Open Module Clients can call interface functions

Open Modules void moveBy(int, int); void animate(Motion); pointcut moves; Open Module Clients can call interface functions Clients can advise external calls to interface functions

Open Modules void moveBy(int, int); void animate(Motion); pointcut moves; Open Module Clients can call interface functions Clients can advise external calls to interface functions Clients can advise pointcuts in interface

Open Modules void moveBy(int, int); void animate(Motion); pointcut moves; Open Module Clients can call interface functions Clients can advise external calls to interface functions Clients can advise pointcuts in interface Clients cannot advise any internal calls (not even to exported functions) X

Open Module Properties: Equivalence Motivation Rules describe when changes could affect clients Can be used to prove correctness of refactorings Bisimulation-based equivalence All functions map args to same results Invoke internal pointcuts in same way Same sequence, same context

Open Module Properties: Abstraction Verifies correctness of equivalence rules Shows that information hiding works Informal statement of theorem Consider two module implementations that are equivalent according to the bisimulation rules No client code can distinguish the behavior of these modules (even by using aspects) Note: this would fail for AspectJ!

Comparison to Aspect-Aware Interfaces AAI: more obliviousness, extensibility Don’t have to anticipate semantic pointcuts OM: truly separate development AAI cannot be computed in this case OM: shows technical properties of AAI AAI is an OM interface computed by tools Abstraction supports evolvability Not all information in AAI is needed Don’t need exact advice Don’t need pointcuts for external calls to interface functions

Tool and Language Implications Tools: Provide editable interface pointcuts Change base code and affected pointcuts at the same time Tools: Support dependency tracking Let you know when you’re depending on impl. Warn you to re-check pointcuts when impl. Changes Language Make it easier to write non-invasive pointcuts

Discussion Extensibility vs. Reasoning Tool vs. Language-based reasoning Open Modules into real AOP systems Analysis based on Open Modules

End of Presentation/Extra Slides

TinyAspect Example (* fibonacci function *) val fib = fn x:int => 1 around call(fib) (x:int) = if (x > 2) then fib(x-1) + fib(x-2) else proceed x (* caching library *) val inCache = fn... val lookupCache = fn... val updateCache = fn... (* advice to cache calls to fib *) pointcut cacheFunction = call(fib) around cacheFunction(x:int) = if (inCache x) then lookupCache x else let v = proceed x in updateCache x v; v

TinyAspect: Syntax

Evaluation Environment captures advice Declarations add labels to environment Functions are looked up just before application

Evaluation Environment captures advice Declarations add labels to environment Advice updates environment

TinyAspect: Values and Contexts

TinyAspect: Reduction Rules

TinyAspect: Expression Typing

TinyAspect: Declaration Typing

TinyAspect: Properties

Open Modules: Syntax

Open Modules: Example structure Math = struct val fib = fn x:int => 1 around call(fib) (x:int) = … structure cacheFib = Cache(struct pointcut f = call(fib) end) end :> sig fib : int->int end structure Cache = functor(X : sig f : pc(int->int) end) => struct around X.f(x:int) =... (* same definition *) end

Open Modules: Semantics Standard type system Signature subtyping permitted Runtime semantics mostly standard E.g, functor application uses substitution

Sealing has operational effect Value bindings given fresh labels External advice doesn’t affect internal calls C.f. “freeze” operator in Jigsaw, other systems Pointcuts are unchanged Open Modules: Semantics

Reynolds’ Abstraction Property No client can distinguish two modules that are “observationally equivalent” (c.f. Pi-calculus) calling functions in interface advising external calls to interface advising pointcuts in interface Means that information hiding works You can change the internals of a module w/o affecting clients

Observational Equivalence Functions behave equivalently for all args Expression evaluation must be bisimilar w.r.t. a set of available labels  Can take any step other than looking up  Can both look up the same label in 

Formal Abstraction Theorem Proof insight Client can only advise labels in  Libraries treat these labels equivalently Key invariant Clients are structurally identical Except for embedded equivalent values