Session 2: AspectJ Mark Stobbe September 13, 2007 1.

Slides:



Advertisements
Similar presentations
AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
Advertisements

1..28 comparison of the leading aop tools report on February developerWorks articles Mik Kersten University of British Columbia.
Aspect Oriented Programming. AOP Contents 1 Overview 2 Terminology 3 The Problem 4 The Solution 4 Join point models 5 Implementation 6 Terminology Review.
Overview of AspectJ Aspect Oriented Software Development Seminar Technion presented by Oren Mishali.
Session 9 Crosscutting Techniques in Program Specification and Analysis Mark Stobbe October 8,
© Janice Regan, CMPT 102, Sept CMPT 102 Introduction to Scientific Computer Programming The software development method algorithms.
University of British Columbia Software Practices Lab 2005 CASCON A Fluid AOP Editor Terry Hon Gregor Kiczales.
The Java Programming Language
Slides prepared by Rose Williams, Binghamton University Chapter 1 Getting Started 1.1 Introduction to Java.
Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics.
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
Slides prepared by Rose Williams, Binghamton University Chapter 13 Interfaces and Inner Classes.
Aalborg Media Lab 21-Jun-15 Software Design Lecture 1 “ Introduction to Java and OOP”
Aspect-Oriented Software Development (AOSD) Tutorial #2 AspectJ Basics.
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
Session 15 Modeling Traceability of Concerns in Architectural Views Mark Stobbe October 29,
Aspect-Oriented Software Development (AOSD) Tutorial #3 AspectJ - continued.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
Introducing Java.
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.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Aspect Oriented Programming (AOP) in.NET Brent Krueger 12/20/13.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
© 2006 Pearson Education 1 Obj: cont 1.3 and 1.4, to become familiar with identifiers and to understand how programming languages work HW: p.51 #1.8 –
The Java Programming Language
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
POSL (Principles of Software Languages) Gr. Kyushu Institute of Technology, Japan Pointcut-based Architectural Interface.
What does a computer program look like: a general overview.
Lecture 1 Introduction Figures from Lewis, “C# Software Solutions”, Addison Wesley Richard Gesick.
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.
CCC: An Aspect-Oriented Intermediate Language on.Net Platform Yingfei Xiong and Feng Wan University of Electronic Science and Technology of China, China.
Virtual Support for Dynamic Join Points C. Bockisch, M. Haupt, M. Mezini, K. Ostermann Presented by Itai Sharon
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Inter-Type Declarations in AspectJ Awais Rashid Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
AspectJ – AOP for Java Tom Janofsky. Instructor at Penn State Abington Consultant with Chariot Solutions JUG Member.
1 CS161 Introduction to Computer Science Topic #9.
Weaving a Debugging Aspect into Domain-Specific Language Grammars SAC ’05 PSC Track Santa Fe, New Mexico USA March 17, 2005 Hui Wu, Jeff Gray, Marjan Mernik,
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Chapter 3 - Language Design Principles
Aspect Oriented Development Alex Beatty.  Purpose  Cross-cutting Concerns  Join Points, Pointcuts, and Advices  Weaving  Invasive vs. Non-Invasive.
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
Interfaces and Inner Classes
Aspect Oriented Programming Adlux Consultancy Services Pvt Ltd
问题 Code scattering Blocks of duplicated code Blocks of complementary code, and different modules implementing complementary parts of the concern Code.
Comparison of Different AOP Approaches Presented by: Xiaojing Wang.
aspectj tools new and noteworthy Mik Kersten University of British Columbia Adrian Colyer IBM Hursley OOPSLA, October
AOSD'04, Lancaster, UK 1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech) Shigeru Chiba (Tokyo Tech) Michiaki Tatsubori.
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.
Presented by Ted Higgins, SQL Server DBA An Introduction to Object – Oriented Programming.
AOP with AspectJ Awais Rashid, Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
AspectJ Development Tools Mik Kersten University of British Columbia October 28, 2003.
© Peter Andreae Java Programs COMP 102 # T1 Peter Andreae Computer Science Victoria University of Wellington.
aspectj tools new and noteworthy Mik Kersten University of British Columbia Andy Clement, George Harley IBM Hursley Labs.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
Chapter 1: Preliminaries Lecture # 2. Chapter 1: Preliminaries Reasons for Studying Concepts of Programming Languages Programming Domains Language Evaluation.
© 2011 Pearson Education, publishing as Addison-Wesley Chapter 1: Computer Systems Presentation slides for Java Software Solutions for AP* Computer Science.
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
1 Problem Solving  The purpose of writing a program is to solve a problem  The general steps in problem solving are: Understand the problem Dissect the.
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
Aspect-Oriented Programming
JAsCo an Aspect-Oriented approach tailored for
Tonga Institute of Higher Education IT 141: Information Systems
Object Oriented Programming in java
Tonga Institute of Higher Education IT 141: Information Systems
Refactoring the Aspectizable Interfaces: An Empirical Assessment
Presentation transcript:

Session 2: AspectJ Mark Stobbe September 13,

Overview Ingredients for Aspect Oriented Languages – Join Point Model The Big Players Who beats who – Language-specific – Development-specific Loose ends 2

Ingredients Join Point Model – Join points – Pointcuts – Advice Composition Naming Abstraction and concretization Exposing state Inter-type declarations Weaver 3

Join points – up-close 4 public class Example { int x; public static void main(String[] args) { Example ex = new Example(); ex.func(); } public Example() { x = 10; } public int func() { return x; } public class Example { int x; public static void main(String[] args) { Example ex = new Example(); ex.func(); } public Example() { x = 10; } public int func() { return x; } Before execution(void Example.main(String[])) 2. Before call(Example()) 3. Before execution(Example()) 4. Before set(int Example.x) 5. After set(int Example.x) 6. After execution(Example()) 7. After call(Example()) 8. Before call(int Example.func()) 9. Before execution(int Example.func()) 10. Before get(int Example.x) 11. After get(int Example.x) 12. After execution(int Example.func()) 13. After call(int Example.func()) 14. After execution(void Example.main(String[])) within(Example) withincode(int Example.func()) cflow(execution(Example.new())) cflowbelow(execution(int Example.func()))

Answering question 5 Answer 1. Before 2. Around 3. After Question Another question that I have is about precedence. Imagine defining before, after and around advices for the same pointcut, I wonder what the execution order of the advices will be? Will the order be before, around and then after or the other way around? (Alesya)

Answering question 6 Answer cflow is the collection of join points flowing from the argument pointcut. This means that cflow(P) && cflow(Q) is the intersection of the two collections, while cflow(P && Q) means that you first combine the pointcuts P and Q, and all the join points flowing from that are in this collection. Question Can you please discuss the primitive pointcut cflow in detail? I am particularly interested in the semantics of the composition of those pointcuts: cflow(P) && cflow(Q) and cflow(P && Q). This is explained briefly in the Programming Guide, but I find it very difficult to understand. Perhaps you can give a clear, concrete example? (Martijn)

public aspect ExampleAspect { pointcut P(): execution(* Example.P(..)); pointcut Q(): execution(* Example.Q(..)); pointcut flowP(): cflow(P()) && within(Example); pointcut flowQ(): cflow(Q()) && within(Example); pointcut flowPAndflowQ(): cflow(P()) && cflow(Q()) && within(Example); } public aspect ExampleAspect { pointcut P(): execution(* Example.P(..)); pointcut Q(): execution(* Example.Q(..)); pointcut flowP(): cflow(P()) && within(Example); pointcut flowQ(): cflow(Q()) && within(Example); pointcut flowPAndflowQ(): cflow(P()) && cflow(Q()) && within(Example); } Giving example 7 public class Example { public void P() { Q(); } public void Q() { } public static void main(String[] args) { new Example().P(); } public class Example { public void P() { Q(); } public void Q() { } public static void main(String[] args) { new Example().P(); } Flow from P - execution(void Example.P()) Flow from P - call(void Example.Q()) Flow from P - execution(void Example.Q()) Flow from Q - execution(void Example.Q()) Flow from P && flow from Q - execution(void Example.Q()) Flow from P - execution(void Example.P()) Flow from P - call(void Example.Q()) Flow from P - execution(void Example.Q()) Flow from Q - execution(void Example.Q()) Flow from P && flow from Q - execution(void Example.Q())

Answering question 8 Answer The difference between cflow and cflowbelow is whether the argument pointcut should be taken included or excluded. The difference between within and cflow is that within works on a TypePattern, while cflow works on a Pointcut. Question What is the difference between cflow and cflowbelow, and cflow and within ? Is within just a more specific version of cflow ? (Martijn)

public aspect ExampleB { pointcut P(): execution(* Example.P(..)); pointcut flowP(): cflow(P()) && within(Example); } public aspect ExampleB { pointcut P(): execution(* Example.P(..)); pointcut flowP(): cflow(P()) && within(Example); } Giving example 9 public class Example { public void P() { Q(); } public void Q() { } public static void main(String[] args) { new Example().P(); } public class Example { public void P() { Q(); } public void Q() { } public static void main(String[] args) { new Example().P(); } execution(void Example.P()) call(void Example.Q()) execution(void Example.Q()) execution(void Example.P()) call(void Example.Q()) execution(void Example.Q()) public aspect ExampleA { pointcut P(): execution(* Example.P(..)); pointcut flowP(): cflowbelow(P()) && within(Example); } public aspect ExampleA { pointcut P(): execution(* Example.P(..)); pointcut flowP(): cflowbelow(P()) && within(Example); } call(void Example.Q()) execution(void Example.Q()) call(void Example.Q()) execution(void Example.Q())

Answering question 10 Answer Line and Point are a subclass of FigureElement, this means the type matches and therefore you will indeed receive multiple matches for Line.incrXY and Point.incrXY. You can always specify precisely Line.incrXY(int,int) in your pointcut, if you only want that specific pointcut. Or you can use cflowbelow to retrieve only the first call to a FigureElement.incrXY call. Question When you have something like: receptions( void FigureElement.incrXY(int, int) ) and the example from Fig. 1 in the 2001-ecoop paper. If you call Line.incrXY(int,int) it will match, but what if that method forwards the call to Point.incrXY(int,int) ? Will it match again? And if so, is there a way to prevent this bubbling up effect? Or don't you need this in practice anyway? But at the top of page 17 they seem to say that you can do that with cflow, but it's still a bit unclear. Is this indeed the way to do it? (Christiaan)

public aspect ExampleAspect { pointcut all(): execution(* FigElem.move(..)); pointcut first(): all() && !cflowbelow(all()); } public aspect ExampleAspect { pointcut all(): execution(* FigElem.move(..)); pointcut first(): all() && !cflowbelow(all()); } Giving example 11 public class Example { public static void main(String[] args) { new Line().move(); new Point().move(); } interface FigElem { public void move(); } class Line implements FigElem { Point p; public void move() { p.move(); } } class Point implements FigElem { public void move() { } } public class Example { public static void main(String[] args) { new Line().move(); new Point().move(); } interface FigElem { public void move(); } class Line implements FigElem { Point p; public void move() { p.move(); } } class Point implements FigElem { public void move() { } } First: execution(void Line.move()) execution(void Point.move()) First: execution(void Point.move()) First: execution(void Line.move()) execution(void Point.move()) First: execution(void Point.move())

Big Players For Java – AspectJ – AspectWerkz – JBoss AOP – Spring AOP For non-Java – AspectC++ – Others, including comparison, can be found here: Spring 2.0 AOP includes AspectJ 12

Comparison - Syntax Language-like vs. Annotations vs. XML Concise and natural Language support, own compiler XML more familiar, easier to write tools Fine-grained annotations 13 Source: Mik Kersten – AOP Tools comparison

Answering question 14 Answer In AspectJ, no. There are a limited number of possible join points and since Java only allows for annotations outside methods, it is not possible. A workaround would be to extract the code into a method. Question The paper and tutorials on AspectJ say that the three types of advice that are available - before, after and around - allow applying advice to methods. But what if I want to insert a logging statement somewhere in the middle in the method code? Or when I do debugging and I want to see the intermediate results, I would have a log.debug statement inside a method. Is it possible to somehow accomplish that with AspectJ? I could think of writing a pointcut for every logging (debugging) statement that's in the middle of the method. But I was wondering if there is another way of doing this? (Alesya)

Comparison - Join points Expressiveness vs. simplicity Less join points, less to understand Regular Expressions, strong but hard to read Source: Mik Kersten – AOP Tools comparison 15

Comparison - Weaver Compile-Time vs. Run-Time Some join points always require RT check, like: cflow and instanceof Static-checks makes easy programming Fast compiling or fast running 16 Source: Mik Kersten – AOP Tools comparison

Answering question 17 Answer AspectJ tries solve most of these at compile-time. The overhead will then be a simple call to the advice body, which most of the time can be inlined by the virtual machine. Some pointcuts cannot be statically inferred, for example when using cflow or instanceof, these have an additional runtime check. In the paper they claim this overhead is relative small. Question At chapter 3.3 in the paper, they state that upon arrival at a join point, all advice in the system is examined to see whether any apply at the join point. It collects all advices and try to match those with the current evaluated method/function. Can this have some sort of influence on the system performance (especially on more advice given)? (Robin)

Answering question 18 Answer Both. The compiler is the static weaver, trying to weave all aspects at compile- time. The runtime library provides some extra classes, for example: JoinPoint. It is also used for runtime pointcuts like cflow and instanceof. Question At chapter 4 they say that the AspectJ language uses a compiler. At chapter 3.3 they talk about runtime (if I'm correct though). What's the implementation? Is it both a compiler and runtime library or just the compiler? (Robin)

Comparison - IDE Special AOP support Normal debugging No refactoring No UML 19 Source: Mik Kersten – AOP Tools comparison

Answering question 20 Answer For most editors there are tools written to support AspectJ or similar. These can again be used by developers to build their own tools on top. If you want to build support for your own IDE, AspectJ offers you the ADJE API. Question AspectJ and IDE integration: are there tools that allow for easy integration, like some tool that tells given some pointcut where it will crosscut the program (/source code)? Or should every IDE extension implement this logic itself? (Peter)

Loose ends 21 Answer It is possible to create an abstract aspect, which can be implemented by another aspect. This aspect will then have to implement the abstract pointcuts defined in the abstract aspect. It is useful for creating general-purpose aspects. Question Is it possible for an aspect to extend another aspect (maybe that would be another way of doing the MoveTracking and Mobile examples?). Or would that just come down to re-using the pointcuts? (Peter)