Aspect-Oriented Programming and Aspectj

Total Page:16

File Type:pdf, Size:1020Kb

Aspect-Oriented Programming and Aspectj What is Aspect-Oriented Programming? Many possible answers: • a fad • a way-too-general collection of cross-cutting Aspect-Oriented programming techniques Programming and AspectJ • a new name for old ideas (generators, domain- specific languages, MOPs) • Aspect-oriented programming is a common buzzword lately • the solution to all our problems • Papers from ECOOP 1997 (early overview— My opinion: AOP is just a new name for old the manifesto), ECOOP 2001 (overview of ideas, but these ideas are good AspectJ) - dominant AOP implementations (e.g., AspectJ) are MOP-like, but they don’t • Kiczales (the team leader) was behind the need to be CLOS MOP An aspect is a piece of functionality that cross- cuts functional units of a system 1 of 18 2 of 18 Yannis Smaragdakis Yannis Smaragdakis Simple Working Example (bad, IMO) Aspect-Oriented Principles • Image processing application with filters • A component is a part of the implementation - filters need to be kept separate that is localized in traditional languages (Java/ - filters need to be fused together for C/C++, etc.) optimization (e.g., loop fusion) • An aspect is a part of the implementation that (defun or! (a b) is not well-localized with traditional languages (let ((result (new-image))) (code ends up being scattered everywhere) (loop for i from 1 to width do (loop for j from 1 to height do • AOP tries to offer language support for (set-pixel result i j expressing aspects concisely and separately (or (get-pixel a i j) (get-pixel b i j))))) from components result)) • Join points: the points where components • If another filter has the same looping structure, interact and aspects can influence them the two should be fused together (for locality, max memory consumption, etc.) • Elements of an AOP-based implementation: - a component language part • Better example: in distributed apps, - an aspect language part synchronization/serialization of data/failure - an aspect weaver applying the aspects to handling are orthogonal to other functionality components (really, a generator) 3 of 18 4 of 18 Yannis Smaragdakis Yannis Smaragdakis Image Processing Example Revisited Other Example Essentially, a domain-specific language is • How data is serialized (and, in particular, how designed for image processing much data is copied) in a distributed system is an issue independent of the system’s main • Component language: implicit loop structure functionality (define-filter or! (a b) • A communication aspect language can allow (pixelwise (a b) (aa bb) (or aa bb))) the programmer to describe how much of an (aa, bb are iterators—standard Lisp/Scheme object will be copied iterator binding semantics) - again, just a domain-specific language/ generator. You can call it AOP, but the • Aspect language: operations on nodes in the value is in the domain dataflow graph. E.g., if two loops have the - there is a general system called Doorastha same structure and inputs, fuse them together that does similar things in Java • Weaver: represent the component program as a • E.g., a digital library may have Book and flow graph, run aspect code on it, generate Repository classes. We can tell the system code from higher-level abstractions to only copy parts of a Book object when registering and unregistering it in a remote repository 5 of 18 6 of 18 Yannis Smaragdakis Yannis Smaragdakis Example aspect program: AspectJ remote Repository { void register (Book); • A very nice MOP/general compositional void unregister (Book: copy isbn); semantic extensibility facility for Java // Book class has “isbn” field Book: copy isbn lookup(String); - used entirely for interposing code, not // method: “lookup”, return type: Book changing how the object system works } - AspectJ is a transparent extension of Java, comes with IDE support (for easier editing, inspection of aspect code) • To demonstrate, consider an example application: a figure editor FigureEle incrXY Point Line getX getX setX setX incrXY incrXY move aspect 7 of 18 8 of 18 Yannis Smaragdakis Yannis Smaragdakis Join points Kinds of Pointcuts • Many possible join points in AspectJ. At: • Pointcuts can be thought of as runtime - method call (inside calling object) predicates: when they are true, we are at a join - method call reception by an object (any point described by the pointcut. method) - method execution (specific method) • Several kinds of pointcuts. E.g.: - field access (get/set) - call(signature) - constructor call (inside object doing new) - execution( signature) - constructor call reception (any constructor) - get/set(signature) - value can be matched with args - exception handler execution - args(Type) - class initialization (static initializers run) - handler(ThrowableClass) - this/target( Type) Pointcuts - within(Type) - withincode(signature) • Pointcut = set of join points + values from the - cflow(pointcut) context (e.g., the object, method this - initialization( ConstrSig) parameters, etc.) - staticinitialization( Type) call(void Point.setX(int)) • Also: boolean pointcut operators ( , , etc.) - all join points where the method called is && || and pointcut constants (user-defined pointcuts) void Point.setX(int) 9 of 18 10 of 18 Yannis Smaragdakis Yannis Smaragdakis Pointcut Example Aspects pointcut moves(): • Aspects have class-like syntax (and, to some call(void FigureElement.incrXY(int,int)) ||call(void Line.setP1(Point)) extent, semantics—e.g., for scoping). They can || call(void Line.setP2(Point)) contain pointcuts, advice, and regular class || call(void Point.setX(int)) || call(void Point.setY(int)); declarations (member vars/methods) aspect MoveTracking { • describes the join points where methods that static boolean flag = false; cause “movement” of a figure are called static boolean testAndClear() { - Note that a “user-defined” pointcut boolean result = flag; flag = false; (operator pointcut ) is used to give a return result; name (moves) to the pointcut } pointcut moves(): Advice call(void FigureElement.incrXY(int,int)) ||call(void Line.setP1(Point)) • Advice: specification of aspect code to be || call(void Line.setP2(Point)) || call(void Point.setX(int)) interposed at pointcuts || call(void Point.setY(int)); - before, after, or instead of (around) the code at a join point after(): moves() {// advice flag = true; - two special cases of “after”: after returning/after } throwing (for normal/exception exits) } 11 of 18 12 of 18 Yannis Smaragdakis Yannis Smaragdakis Aspects Pointcut Parameters • Aspects can have multiple instances • Advice and pointcut definitions can have parameters (see empty parentheses in previous • There are complex rules about how aspect examples) execution (advice application) is ordered - the rules take into account Aspect • The parameters can be used in pointcut relationships (e.g., if aspect A extends B, predicates instead of type variables and take then it’s considered more specific) the value of the instance matching the - there is a dominates keyword for aspects predicate that know about each other - this is overloading the existing syntax for an entirely different purpose Example (uses MoveTracking from last slide) before(Point p, int nval): call(void p.setX(nval)) { aspect Mobility dominates MoveTracking { System.out.println(“x value of” + p + static boolean enableMoves = true; “ will be set to ” + nval + “.”); } around() returns void: MoveTracking.moves() { if (enableMoves) proceed(); } To print a message every time the value of x for } a point changes defines an “around” (instead-of) method Example: Getting the current object preventing moves if the flag is not set 13 of 18 14 of 18 Yannis Smaragdakis Yannis Smaragdakis • regular pointcut definition: Abstract and Generic Aspects pointcutfoo(): instanceof(Point); A “virtual type”-like mechanism allows aspect genericity • pointcut with parameter: abstract aspect SimpleTracing { pointcut foo(Pointp): abstract pointcut tracePoints(); instanceof(p); //yet undefined before(): tracePoints() { • p is the object of class Point with which the printMessage(“Entering”,thisJoinPoint); join point is associated! } after(): tracePoints() { printMessage(“Exiting”,thisJointPoint); Example: Around Advice and Proceed } • We saw proceed earlier, but it can also be void printMessage(String s, JoinPoint tjp) called with parameters { ... } } • To ensure that a method is only called with aspect XYTracing extends SimpleTracing { non-negative int arguments: pointcut tracePoints(): call( around(int nv) returns void: void FigureElement.incrXY(int,int)); call(void Point.setX(nv)) } {proceed(Math.max(0, nv)); } - (note the thisJointPoint variable and the JoinPoint type: they reflectively export details of the AspectJ implementation) 15 of 18 16 of 18 Yannis Smaragdakis Yannis Smaragdakis Wildcards Introductions / Inter-type Declarations E.g., Can declare members and supertypes for existing classes! call(* Point.*(..)) call(Point.new(..)) A static transformation language. These “introductions” are not advice and are not Control-Flow Based Pointcuts associated with pointcuts The cflow operator is true on points under the dynamic extent of other join points (e.g., while Add an “enabled” field to all the methods corresponding to these join points FigureElement s: are still active on the execution stack) - boolean FigureElement.enabled=false; pointcut moves(FigureElement fe): Add a setter method: <see before>; - public FigureElement.setEnabled(boolean b) { pointcut topLevelMoves(FigureElement fe): this.enabled = b; moves(fe) &&!cflow(moves(FigureElement)); } Implementation Add superclasses to FigureElement: - declare parents: The AspectJ compiler inserts code to check and FigureElement extends Drawable call the right aspects at join points: efficient 17 of 18 18 of 18 Yannis Smaragdakis Yannis Smaragdakis.
Recommended publications
  • A Brief Introduction to Aspect-Oriented Programming
    R R R A Brief Introduction to Aspect-Oriented Programming" R R Historical View Of Languages" R •# Procedural language" •# Functional language" •# Object-Oriented language" 1 R R Acknowledgements" R •# Zhenxiao Yang" •# Gregor Kiczales" •# Eclipse website for AspectJ (www.eclipse.org/aspectj) " R R Procedural Language" R •# Also termed imperative language" •# Describe" –#An explicit sequence of steps to follow to produce a result" •# Examples: Basic, Pascal, C, Fortran" 2 R R Functional Language" R •# Describe everything as a function (e.g., data, operations)" •# (+ 3 4); (add (prod 4 5) 3)" •# Examples" –# LISP, Scheme, ML, Haskell" R R Logical Language" R •# Also termed declarative language" •# Establish causal relationships between terms" –#Conclusion :- Conditions" –#Read as: If Conditions then Conclusion" •# Examples: Prolog, Parlog" 3 R R Object-Oriented Programming" R •# Describe " –#A set of user-defined objects " –#And communications among them to produce a (user-defined) result" •# Basic features" –#Encapsulation" –#Inheritance" –#Polymorphism " R R OOP (cont$d)" R •# Example languages" –#First OOP language: SIMULA-67 (1970)" –#Smalltalk, C++, Java" –#Many other:" •# Ada, Object Pascal, Objective C, DRAGOON, BETA, Emerald, POOL, Eiffel, Self, Oblog, ESP, POLKA, Loops, Perl, VB" •# Are OOP languages procedural? " 4 R R We Need More" R •# Major advantage of OOP" –# Modular structure" •# Potential problems with OOP" –# Issues distributed in different modules result in tangled code." –# Example: error logging, failure handling, performance
    [Show full text]
  • Weaving Ontology Aspects Using a Catalog of Structural Ontology Design Patterns
    Weaving Ontology Aspects Using a Catalog of Structural Ontology Design Patterns Ralph Schäfermeier and Adrian Paschke Corporate Semantic Web Group, Institute of Computer Science, Freie Universität Berlin, Germany {schaef,paschke}@inf.fu-berlin.de http://www.csw.inf.fu-berlin.de Abstract. Modular development of ontologies proves beneficial at dif- ferent stages of the ontology lifecycle. In our previous work, we proposed aspect-oriented ontology development as a flexible approach to modular ontology development and a-posteriori modularization of existing mono- lithic ontologies, inspired by aspect-oriented programming and based on so called cross-cutting concerns. Similar to other formalisms for mod- ular ontologies (e.g. E-Connections), aspect-oriented ontologies rely on an extension of the used ontology language. This derivation from the standard in turn requires specially adapted tools in order to use these ontologies in applications. In this paper, we present an approach to the recombination of aspect-oriented ontology modules to standard OWL 2 ontologies by using an aspect-weaving service. The weaving service relies on a preconfigured catalog of structural ontology design patterns. We show that the use of the weaving service yields syntactically correct and semantically complete ontologies while still allowing ontology developers to fully benefit from modular ontology development. Keywords: Aspect-Oriented Ontology Development, Aspect-Oriented Programming, Ontology Modularization, Ontology Design Patterns 1 Introduction Modular ontology development has proved beneficial when it comes to improve- ment of reasoning and query result retrieval performance, scalability for ontol- ogy evolution and maintenance, complexity management, amelioration of un- derstandability, reuse, context-awareness, and personalization [17]. A significant amount of research work has been dedicated in the field of ontology modular- ization, and various kinds of approaches tackle the problem from different per- spectives.
    [Show full text]
  • Continuation Join Points
    Continuation Join Points Yusuke Endoh, Hidehiko Masuhara, Akinori Yonezawa (University of Tokyo) 1 Background: Aspects are reusable in AspectJ (1) Example: A generic logging aspect can log user inputs in a CUI program by defining a pointcut Login Generic Logging id = readLine(); Aspect Main CUI Aspect cmd = readLine(); pointcut input(): call(readLine()) logging return value 2 Background: Aspects are reusable in AspectJ (2) Example: A generic logging aspect can also log environment variable by also defining a pointcut Q. Now, if we want to log environment variable (getEnv) …? Generic Logging Aspect A. Merely concretize an aspect additionally Env Aspect CUI Aspect pointcut input(): pointcut input(): Aspect reusability call(getEnv()) call(readLine()) 3 Problem: Aspects are not as reusable as expected Example: A generic logging aspect can NOT log inputs in a GUI program by defining a pointcut Login Generic Logging void onSubmit(id) Aspect { … } Main void onSubmit(cmd) GUI Aspect { … } pointcut Input(): call(onSubmit(Str)) logging arguments 4 Why can’t we reuse the aspect? Timing of advice execution depends on both advice modifiers and pointcuts Logging Aspect (inner) Generic Logging abstract pointcut: input(); Aspect after() returning(String s) : input() { Log.add(s); } unable to change to before 5 Workaround in AspectJ is awkward: overview Required changes for more reusable aspect: generic aspect (e.g., logging) two abstract pointcuts, two advice decls. and an auxiliary method concrete aspects two concrete pointcuts even if they are not needed 6 Workaround in AspectJ is awkward: how to define generic aspect Simple Logging Aspect 1. define two pointcuts abstract pointcut: inputAfter(); for before and after abstract pointcut: inputBefore(); after() returning(String s) : inputAfter() { log(s); } 2.
    [Show full text]
  • Towards an Expressive and Scalable Framework for Expressing Join Point Models
    Towards an Expressive and Scalable Framework for expressing Join Point Models Pascal Durr, Lodewijk Bergmans, Gurcan Gulesir, Istvan Nagy University of Twente {durr,bergmans,ggulesir,nagyist}@ewi.utwente.nl ABSTRACT a more fine-grained join point model is required. Moreover, Join point models are one of the key features in aspect- these models are mostly rooted in control flow and call graph oriented programming languages and tools. They provide information, but sometimes a pointcut expression based on software engineers means to pinpoint the exact locations in data flow or data dependence is more suitable. programs (join points) to weave in advices. Our experi- ence in modularizing concerns in a large embedded system This paper proposes an expressive and scalable fine-grained showed that existing join point models and their underlying framework to define join point models that incorporate both program representations are not expressive enough. This data and control flow analysis. One can subsequently specify prevents the selection of some join points of our interest. In a pointcut language which implements (part of) this join this paper, we motivate the need for more fine-grained join point model. Allowing different implementation strategies point models within more expressive source code represen- and language independence is the strength of this model. tations. We propose a new program representation called a program graph, over which more fine-grained join point The paper is structured as follows: First, we will motivate models can be defined. In addition, we present a simple lan- this research with two example concerns we encountered in guage to manipulate program graphs to perform source code our IDEALS[6] project with ASML[2].
    [Show full text]
  • Aspectj in Action, Second Edition
    Introducing AspectJ This chapter covers ■ Writing an AspectJ “Hello, world!” application ■ Becoming familiar with the AspectJ language ■ Weaving mechanisms ■ Integrating with Spring In chapter 1, we focused on general concepts in AOP. With those behind us, we can now look at one specific AOP implementation: AspectJ. AspectJ is an aspect- oriented extension to the Java programming language. Like any AOP implementa- tion, AspectJ consists of two parts: the language specification, which defines the grammar and semantics of the language; and the language implementation, which includes weavers that take various forms such as a compiler and a linker. A weaver produces byte code that conforms to the Java byte-code specification, allowing any compliant Java virtual machine (VM) to execute those class files. The language implementation also offers support for integrated development environments (IDEs), to simplify building and debugging applications. AspectJ started and initially grew as a special language that extends the Java lan- guage with new keywords. It also provided a special compiler that could understand those extensions. But recently, a lot has changed in its form as a language, as well as 27 Licensed to Manning Marketing <[email protected]> 28 CHAPTER 2 Introducing AspectJ in the weaver. First, AspectJ offers an alternative syntax based on the Java annotation facil- ity to express crosscutting constructs. This lets you use a plain Java compiler instead of the special compiler. Second, AspectJ offers new options for weaving classes with aspects. Finally, it has gained a strong foothold in the Spring Framework with several integration options. All these changes have made adoption of AspectJ easier than ever before.
    [Show full text]
  • Flowr: Aspect Oriented Programming for Information Flow Control in Ruby
    FlowR: Aspect Oriented Programming for Information Flow Control in Ruby Thomas F. J.-M. Pasquier Jean Bacon Brian Shand University of Cambridge Public Health England fthomas.pasquier, [email protected] [email protected] Abstract Track, a taint-tracking system for Ruby, developed by the SafeWeb This paper reports on our experience with providing Information project [17]. Flow Control (IFC) as a library. Our aim was to support the use However, we came to realise certain limitations of the mech- of an unmodified Platform as a Service (PaaS) cloud infrastructure anisms we had deployed. For example, to enforce the required by IFC-aware web applications. We discuss how Aspect Oriented IFC policy, we manually inserted IFC checks at selected applica- Programming (AOP) overcomes the limitations of RubyTrack, our tion component boundaries. In practice, objects and classes are the first approach. Although use of AOP has been mentioned as a natural representation of application components within an object possibility in past IFC literature we believe this paper to be the oriented language and it seems natural to relate security concerns first illustration of how such an implementation can be attempted. with those objects. We should therefore associate the primitives and We discuss how we built FlowR (Information Flow Control for mechanisms to enforce IFC with selected objects. Furthermore, we Ruby), a library extending Ruby to provide IFC primitives using wish to be able to assign boundary checks on any class or object AOP via the Aquarium open source library. Previous attempts at without further development overhead. We also wish to be able providing IFC as a language extension required either modification to exploit the inheritance property to define rules that apply to of an interpreter or significant code rewriting.
    [Show full text]
  • Aspect-Oriented Software Development for Real-Time and Internet Applications
    International Research Journal of Engineering and Technology (IRJET) e-ISSN: 2395-0056 Volume: 05 Issue: 09 | Sep 2018 www.irjet.net p-ISSN: 2395-0072 Aspect-Oriented Software Development for Real-Time and Internet Applications Ogbonna J. C.1, Nwokoma F. O.2, Nwala K. T.3, Nwandu I. C.4 1,3Reseacher, Dept. of Computer Science, Clifford University Owerrinta, Abia State Nigeria 2,4Reseacher, Dept. of Computer Science, Federal University of Technology Owerri, Imo State Nigeria ---------------------------------------------------------------------***--------------------------------------------------------------------- Abstract - Software development evolution has introduced and increasing the reusability of a software product, which a number of useful software development methods. Efficient in turns results in better software development. modularization of program artifacts that cut across multiple AOP is based on the idea that computer systems are better locations during software development called crosscutting programmed by separately specifying the various concerns concerns have been a major drawback for these software (properties or areas of interest) of a system and some development methods including the almighty Object-Oriented description of their relationships, and then relying on Software Development method. Concerns like recovery, mechanisms in the underlying AOP environment to weave or synchronization, logging, encryption, authentication, compose them together into a coherent program (Elrad, authorization, validation, verification,
    [Show full text]
  • Model-Based Aspect Weaver Construction
    Model-based Aspect Weaver Construction Suman Roychoudhury1, Frédéric Jouault2,1, and Jeff Gray1 1 University of Alabama at Birmingham, Birmingham, AL 35294 {roychous, gray}@cis.uab.edu 2 ATLAS group (INRIA & LINA), University of Nantes, France [email protected] Abstract. This paper describes an approach that combines model engineering with program transformation techniques to construct aspect weavers for general-purpose programming languages. The front-end of the weaver uses a high-level language (i.e., an aspect language) to specify aspects and is designed with a metamodel-based approach using the AMMA toolsuite. The back-end of the weaver uses transformation rules, which are generated from these high-level aspect specifications, to perform the actual low-level weaving. Both the aspect specification (front-end) and transformation rules (back-end) are captured as models within the AMMA platform. The translation from source aspect model to target transformation model is achieved using ATL, which is a model transformation language. Keywords: model transformation, program transformation, model engineering, aspect-oriented-programming, software engineering. 1 Introduction Program transformation systems have been used in the past to construct aspect weavers for programming languages [1]. Program transformation engines (PTEs) such as the Design Maintenance System (DMS) [2], or ASF+SDF [3], provide direct availability of scalable parsers and an underlying low-level transformation framework to modify source programs. This low-level transformation framework (that generally uses term-rewriting or graph-rewriting techniques to modify base code) can form the basis of constructing aspect weavers [4]. In our previous research, we demonstrated how a term-rewriting PTE like DMS can be used to construct an aspect weaver for a general-purpose programming language (GPL) like ObjectPascal [1].
    [Show full text]
  • Aspectj Intertype Declaration Example
    Aspectj Intertype Declaration Example Untangible and suspensive Hagen hobbling her dischargers enforced equally or mithridatise satisfactorily, is Tiebold microcosmical? Yule excorticated ill-advisedly if Euro-American Lazare patronised or dislocate. Creakiest Jean-Christophe sometimes diapers his clipper bluely and revitalized so voicelessly! Here is important to form composite pattern determines what i ended up a crosscutting actions taken into account aspectj intertype declaration example. This structure aspectj intertype declaration example also hold between core library dependencies and clean as well as long. Spring boot and data, specific explanation of oop, it is discussed in aop implementation can make it for more modular. This works by aspectj intertype declaration example declarative aspect! So one in joinpoints where singleton, which is performed aspectj intertype declaration example they were taken. You only the switch aspectj intertype declaration example. That is expressed but still confused, and class methods and straightforward to modular reasoning, although support method is necessary to work being a pointcut designators match join us. Based injection as shown in this, and ui layer and advice, after and after a good to subscribe to a variety of an api. What i do not identical will only this requires an example projects. Which aop aspectj intertype declaration example that stripe represents the join point executes unless an exception has finished, as a teacher from is pretty printer. Additional options aspectj intertype declaration example for full details about it will be maintained. The requirements with references to aspectj intertype declaration example is essential way that? Exactly bud the code runs depends on the kind to advice.
    [Show full text]
  • Static and Dynamic Approaches to Weaving
    5th Slovakian-Hungarian Joint Symposium on Applied Machine Intelligence and Informatics January 25-26, 2007 ░ Poprad, Slovakia Static and Dynamic Approaches to Weaving Michal Forgáč, Ján Kollár Department of Computers and Informatics, Faculty of Electrical Engineering and Informatics, Technical University of Košice, Letná 9, 042 00 Košice, Slovakia [email protected], [email protected] Abstract: In this paper we present current state of principles and applications in static and dynamic weaving. We are concentrating on static weaving in AspectJ and dynamic weaving in PROSE - PROgrammable extenSions of sErvice. The contribution of this paper is in analyses of both approaches to weaving which we aim to apply as essential mechanisms when constructing software systems by automatic evolution. Keywords: Aspect oriented programming, systems engineering, weaving mechanisms, AspectJ, PROSE1 1 Introduction As a complexity of software systems grows, the need for advanced methods and tools of their specification and the development is the task of the high importance. Object oriented programming (OOP) has increased the productivity of systems rapidly. Benefits of object orientation include support for modular design, code sharing, and extensibility [15]. Object orientation has enabled using inheritance and polymorphism in sence of Strachey's original definition of polymorphism [16]. However, the key issue in application of object approach is that it is not sufficient for crosscutting concerns. One of the fundamental principles of the software engineering is a principle of separation of concerns. A concern is a particular goal, concept, or area of interest, it means that it is in substance semantical concern. From the structural point of view a concern may appear in source code as [4]: This work has been supported by the Scientific grant agency project (VEGA) No.
    [Show full text]
  • Aspect-Oriented Programmingprogramming Wes Weimer
    Aspect-OrientedAspect-Oriented ProgrammingProgramming Wes Weimer (slides adapted from Dave Matuszek, UPenn) Programming paradigms Procedural (or imperative) programming Executing a set of commands in a given sequence Fortran, C, Cobol Functional programming Evaluating a function defined in terms of other functions Scheme, Lisp, ML, OCaml Logic programming Proving a theorem by finding values for the free variables Prolog Object-oriented programming (OOP) Organizing a set of objects, each with its own set of responsibilities Smalltalk, Java, Ruby, C++ (to some extent) Aspect-oriented programming (AOP) = aka Aspect-Oriented Software Design (AOSD) Executing code whenever a program shows certain behaviors AspectJ (a Java extension), Aspect#, AspectC++, … Does not replace O-O programming, but rather complements it 2 Why Learn Aspect-Oriented Design? Pragmatics – Google stats (Apr '09): “guitar hero” 36.8 million “object-oriented” 11.2 million “cobol” 6.6 million “design patterns” 3.0 million “extreme programming” 1.0 million “functional programming” 0.8 million “aspect-oriented” or “AOSD” 0.3 million But it’s growing Just like OOP was years ago Especially in the Java / Eclipse / JBoss world 3 Motivation By Allegory Imagine that you’re the ruler of a fantasy monarchy 4 Motivation By Allegory (2) You announce Wedding 1.0, but must increase security 5 Motivation By Allegory (3) You must make changes everywhere: close the secret door 6 Motivation By Allegory (4) … form a brute squad … 7 Motivation By Allegory (5)
    [Show full text]
  • Efficient Runtime Aspect Weaving for Java Applications
    Efficient Runtime Aspect Weaving for Java Applications Oscar Rodriguez-Prietoa, Francisco Ortina,∗, Donna O'Sheab aUniversity of Oviedo, Computer Science Department, Calvo Sotelo s/n, 33007, Oviedo, Spain bCork Institute of Technology, Department of Computer Science, Rossa Avenue, Bishopstown, Cork, Ireland Abstract Context: The aspect-oriented paradigm is aimed at solving the code scattering and tangling problem, providing new mechanisms to support better separation of concerns. For specific scenarios where high runtime adaptability is an important requirement, dynamic Aspect-Oriented Programming (AOP) represents a useful tool. With dynamic AOP, components and aspects can be woven and unwoven at runtime, enabling appli- cations greater responsiveness when dealing with different or changing requirements. However, this responsiveness typically incurs a cost in terms of runtime performance and memory consumption. Objective: Build an efficient dynamic aspect weaver for Java that provides the best runtime performance compared to the existing approaches, minimum memory overhead consumption, and similar functionalities to the widespread runtime weavers. Method: We design and implement weaveJ, a dynamic aspect weaver for Java. This dynamic weaver leverages the invokedynamic opcode introduced in Java 7, which allows dynamic relinkage of method and field access. We compare the functionalities of weaveJ with the existing dynamic weavers for Java, and evaluate their runtime performance and memory consumption. Results: weaveJ shows the best runtime performance for all benchmarks and real applications executed. Method interception with invokedynamic is at least 142% faster than the techniques used by the existing runtime weavers. The average cost of dynamic weaving using invokedynamic is only 2.2% for short running programs, and 1.5% for long running applications.
    [Show full text]