Aspect Oriented Programming in.NET with CodeBricks Antonio Cisternino Academic Days Milan, 2004 Università di Pisa Supported by Microsoft Research grant.

Slides:



Advertisements
Similar presentations
The Art of Avoiding Work
Advertisements

AspectWerkz 2 - and the road to AspectJ 5 Jonas Bonér Senior Software Engineer BEA Systems.
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 JAC : Aspect Oriented Programming in Java An article review by Yuval Nir and Limor Lahiani.
©Ian Sommerville 2006Software Engineering, 8th edition. Chapter 32 Slide 1 Aspect-oriented Software Development.
Aspect Oriented Programming - AspectJ Radhika Rajput.
 2005 Pearson Education, Inc. All rights reserved Introduction.
Ross Tate, Juan Chen, Chris Hawblitzel. Typed Assembly Languages Compilers are great but they make mistakes and can introduce vulnerabilities Typed assembly.
University of British Columbia Software Practices Lab Fluid AOP Join Point Models Terry Hon Gregor Kiczales.
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.
Antonio Cisternino & Diego Colombo VisualStorms Tools Another Brick in the Robot... Università degli Studi di Pisa.
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Efficient Runtime Code Generation in Rotor Antonio Cisternino 23/4/2003 Università di Pisa Supported by Microsoft Research grant.
Generative Programming. Generic vs Generative Generic Programming focuses on representing families of domain concepts Generic Programming focuses on representing.
Strategies to relate the program and problem domains using code instrumentation Mario Marcelo Berón University of Minho Pedro Rangel Henriques University.
Session-02. Objective In this session you will learn : What is Class Loader ? What is Byte Code Verifier? JIT & JAVA API Features of Java Java Environment.
Modern Concurrency Abstractions for C# by Nick Benton, Luca Cardelli & C´EDRIC FOURNET Microsoft Research.
The Metadata System1. 2 Introduction Metadata is data that describes data. Traditionally, metadata has been found in language- specific files (e.g. C/C++
GENERAL CONCEPTS OF OOPS INTRODUCTION With rapidly changing world and highly competitive and versatile nature of industry, the operations are becoming.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
Chapter 1 Introduction Dr. Frank Lee. 1.1 Why Study Compiler? To write more efficient code in a high-level language To provide solid foundation in parsing.
Spring core v3.x Prepared by: Nhan Le. History v3.0 Spring Expression Language Java based bean metadata v3.1 Cache Abstraction Bean Definition Profile.
Aspect Oriented Programming Razieh Asadi University of Science & Technology Mazandran Babol Aspect Component Based Software Engineering (ACBSE)
Session 2: AspectJ Mark Stobbe September 13,
Aspect Oriented Programming Scott Nykl CSSE 411 Senior Seminar.
Composing Adaptive Software Authors Philip K. McKinley, Seyed Masoud Sadjadi, Eric P. Kasten, Betty H.C. Cheng Presented by Ana Rodriguez June 21, 2006.
Mads Torgersen, Microsoft.  Language INtegrated Query  An open multi-language query facility  Uses cool language stuff  Points into the future.
Introduction to C++ Programming Language
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Aspect Oriented Programming Gülşah KARADUMAN.
Generative Programming. Automated Assembly Lines.
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:
Exception Handling Unit-6. Introduction An exception is a problem that arises during the execution of a program. An exception can occur for many different.
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.
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.
Slicing AspectJ Woven Code Luca Cavallaro Mattia Monga Antonio Castaldo D'Ursi Davide Balzarotti Politecnico di Milano.
AspectJ – AOP for Java Tom Janofsky. Instructor at Penn State Abington Consultant with Chariot Solutions JUG Member.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
Introduction to OOP CPS235: Introduction.
Aspect Oriented Programming Adlux Consultancy Services Pvt Ltd
Kansas City Java User’s Group Jason W. Bedell July 12, 2006
问题 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.
On Implementing High Level Concurrency in Java G Stewart von Itzstein Mark Jasiunas University of South Australia.
AOSD'04, Lancaster, UK 1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech) Shigeru Chiba (Tokyo Tech) Michiaki Tatsubori.
AOP/cross-cutting What is an aspect?. An aspect is a modular unit that cross-cuts other modular units. What means cross-cutting? Apply AOP to AOP. Tease.
Introduction to Yan Cui Aspect Oriented Programming by
1 Manipulating Managed Execution Runtimes to support Self-Healing Systems Rean Griffith‡, Gail Kaiser‡ Presented by Rean Griffith
AOP with AspectJ Awais Rashid, Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
ECE 750 Topic 8 Meta-programming languages, systems, and applications Automatic Program Specialization for J ava – U. P. Schultz, J. L. Lawall, C. Consel.
Some of the utilities associated with the development of programs. These program development tools allow users to write and construct programs that the.
Leveraging ColdSpring to build a robust Flex applications Chris Scott, Cynergy Systems.
Software Engineering Lecture 7
Visit for more Learning Resources
Java Primer 1: Types, Classes and Operators
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
Rean Griffith‡, Gail Kaiser‡ Presented by Rean Griffith
Demeter Aspects Who We Are Aspectual Collaborations
2.1. Compilers and Interpreters
Introduction to C# AKEEL AHMED.
CSE401 Introduction to Compiler Construction
Structuring Adaptive Applications using AspectJ and AOM
Presentation transcript:

Aspect Oriented Programming in.NET with CodeBricks Antonio Cisternino Academic Days Milan, 2004 Università di Pisa Supported by Microsoft Research grant

Introduction Aspect Oriented Programming is a way of modularize crosscutting concerns in computer programsAspect Oriented Programming is a way of modularize crosscutting concerns in computer programs AOP tools are responsible for synthesizing the program by combining different aspectsAOP tools are responsible for synthesizing the program by combining different aspects CodeBricks provides support for meta-programming within CLR: how can we use the code generation facilities to support AOP?CodeBricks provides support for meta-programming within CLR: how can we use the code generation facilities to support AOP?

Agenda AOP and Code Generation AOP and Code Generation CodeBricks: quick introCodeBricks: quick intro [a]C#: annotated join points[a]C#: annotated join points ARE: a generic program rewriting systemARE: a generic program rewriting system ConclusionsConclusions

Aspect Oriented Programming Traditional code organization privileges functional aspect of code: other aspects, like logging, security, concurrency, tend to crosscut the program.Traditional code organization privileges functional aspect of code: other aspects, like logging, security, concurrency, tend to crosscut the program. Aspect Oriented Programming aims to develop tools modularizing crosscutting concerns.Aspect Oriented Programming aims to develop tools modularizing crosscutting concerns. AOP languages (like AspectJ) are based on the single notion of join points: positions in the source code where the code of a crosscutting aspect should join the programAOP languages (like AspectJ) are based on the single notion of join points: positions in the source code where the code of a crosscutting aspect should join the program AOP is a form of generative programming: programs are synthesized from aspects and codeAOP is a form of generative programming: programs are synthesized from aspects and code

AspectJ: a shallow approach to AOP AspectJ is one of the most popular systems for AOPAspectJ is one of the most popular systems for AOP It extends the Java language with constructs to specify join points and how aspects are weaved into themIt extends the Java language with constructs to specify join points and how aspects are weaved into them Pointcuts are defined by means of pattern matchingPointcuts are defined by means of pattern matching It is possible to insert code before and after a given pointcutIt is possible to insert code before and after a given pointcut Inter-type declarations allow to interact with the static structure of a program (i.e. types)Inter-type declarations allow to interact with the static structure of a program (i.e. types)

AspectJ: a shallow approach to AOP public aspect AutoLog{ pointcut publicMethods() : pointcut publicMethods() : execution(public * org.apache.cactus..*(..)); execution(public * org.apache.cactus..*(..)); pointcut logObjectCalls() : pointcut logObjectCalls() : execution(* Logger.*(..)); execution(* Logger.*(..)); pointcut loggableCalls() : pointcut loggableCalls() : publicMethods() && ! logObjectCalls(); publicMethods() && ! logObjectCalls(); before() : loggableCalls(){ before() : loggableCalls(){ Logger.entry(thisJoinPoint.getSignature().toString()); Logger.entry(thisJoinPoint.getSignature().toString()); } after() : loggableCalls(){ after() : loggableCalls(){ Logger.exit(thisJoinPoint.getSignature().toString()); Logger.exit(thisJoinPoint.getSignature().toString()); }}

Aspectwerkz: runtime bytecode generation AspectWerkz provides AOP facilities in the form of Java library rather than languageAspectWerkz provides AOP facilities in the form of Java library rather than language The library is capable of manipulating bytecode inside the class loader for injecting aspect code into classesThe library is capable of manipulating bytecode inside the class loader for injecting aspect code into classes Aspects and join points are connected through XML filesAspects and join points are connected through XML files The library supports matching on code attributes, the new feature of Java 1.5 (custom attributes)The library supports matching on code attributes, the new feature of Java 1.5 (custom attributes)

Agenda AOP and Code GenerationAOP and Code Generation CodeBricks: quick intro CodeBricks: quick intro [a]C#: annotated join points[a]C#: annotated join points ARE: a generic program rewriting systemARE: a generic program rewriting system ConclusionsConclusions

Code Manipulation based on methods Programming language Intermediate (or machine) language Real transformation Perceived transformation Type T Source programTarget program

Partial application + inlining CodeBricks library is built around the notion of partial applicationCodeBricks library is built around the notion of partial application Code generation is expressed as partial application assuming that code is generated relying on an inlining strategyCode generation is expressed as partial application assuming that code is generated relying on an inlining strategy Code bricks are built around methods and represent high order valuesCode bricks are built around methods and represent high order values

Examples delegate int F(int v); delegate int G(int i, int j, int k); public int add(int x, int y) { return x+y; } //… Code c = new Code(typeof(Add).GetMethod(“add”)); Code inc = c.Bind(1, new Free()); // add(1, _) Free x = new Free(); Code twice = c.Bind(x, x); // add(_0, _0) Code threeAdd = c.Bind(c.Bind(new Free(), new Free()), new Free()); // add(add(_, _), _) F f = (F)inc.MakeDelegate(typeof(F)); f(2); G g = (G)threeAdd.MakeDelegate(typeof(G)); g(1, 2, 3);

High order splice delegate void Cmd(); void Log(string info, Cmd c) { Console.WriteLine(“Enter: {0}”, info); Console.WriteLine(“Enter: {0}”, info); c(); c(); Console.WriteLine(“Exit: {0}”, info); Console.WriteLine(“Exit: {0}”, info);} void SomeWork() {... } //... Code log = new Code(typeof(Exmp).GetMethod(“Log”)); Code tgt = new Code(typeof(Exmp).GetMethod(“SomeWork”)); Cmd norm = new Cmd(SomeWork); // Log(“info”, SomeWork) Cmd wlog = (Cmd)log.Bind(“SomeWork”, tgt).MakeDelegate(typeof(Cmd));

AOP with CodeBricks Previous example shows how CodeBricks can provide before and after code injectionsPrevious example shows how CodeBricks can provide before and after code injections But you always need to abstract the code you want to surround into a methodBut you always need to abstract the code you want to surround into a method The compiler can generate patterns based on CodeBricks for aspect waving (this allows for dynamic weaving of aspects)The compiler can generate patterns based on CodeBricks for aspect waving (this allows for dynamic weaving of aspects)

Agenda AOP and Code GenerationAOP and Code Generation CodeBricks: quick introCodeBricks: quick intro [a]C#: annotated join points [a]C#: annotated join points ARE: a generic program rewriting systemARE: a generic program rewriting system ConclusionsConclusions

Annotations for better join points? AspectWerkz shows that code with annotations may help to define better join pointsAspectWerkz shows that code with annotations may help to define better join points The annotation model of CLR and JVM is limited to methodsThe annotation model of CLR and JVM is limited to methods Join points are inside methodsJoin points are inside methods We have extended C# to allow annotations inside method bodiesWe have extended C# to allow annotations inside method bodies

[a]C# public void m() { Console.WriteLine("Parallelizable code sample"); Console.WriteLine("Parallelizable code sample"); [Parallel("Begin of a parallelizable block")] { [Parallel("Begin of a parallelizable block")] { Console.WriteLine("Code exec by the main thread"); Console.WriteLine("Code exec by the main thread"); [Process("First process")] { [Process("First process")] { // Computation here // Computation here } [Process] { [Process] { // Computation here // Computation here } } // Join of processes here } // Join of processes here Console.WriteLine("Here is sequential"); Console.WriteLine("Here is sequential");}

[a]C# runtime operations Operations available at runtime are:Operations available at runtime are: –Annotation tree inspection –Extrusion –Injection –Replacement

[a]C# and AOP Annotations may help to define pointcutsAnnotations may help to define pointcuts With code-level annotations programmers may declare join points:With code-level annotations programmers may declare join points: –AOP systems may get benefit from annotations –The main source code becomes a little aware of the subsequent code transformation [a]C# transformations are performed at runtime: but what does it means exactly runtime?[a]C# transformations are performed at runtime: but what does it means exactly runtime?

Agenda AOP and Code GenerationAOP and Code Generation CodeBricks: quick introCodeBricks: quick intro [a]C#: annotated join points[a]C#: annotated join points ARE: a generic program rewriting system ARE: a generic program rewriting system ConclusionsConclusions

Assembly Rewriting Engine It is possible to encode information into binaries so that the programmer perceives that the information is provided into its own languageIt is possible to encode information into binaries so that the programmer perceives that the information is provided into its own language A general rewriting system would support several applications in a standard way complementing the reflection support already available in STEEsA general rewriting system would support several applications in a standard way complementing the reflection support already available in STEEs Because the target program and the transformation system are expressed in the same language the program can be specialized by executing its own codeBecause the target program and the transformation system are expressed in the same language the program can be specialized by executing its own code AOP systems can rely on this general infrastructure for generating their own codeAOP systems can rely on this general infrastructure for generating their own code

Schema AR Stage name AR Stage name

The Algorithm We assume that a program that wants to perform a computation at stage n provide some metadata to indicate where and what to doWe assume that a program that wants to perform a computation at stage n provide some metadata to indicate where and what to do Methods handled by the rewriting engine should have a known signature: Code m(Context c);Methods handled by the rewriting engine should have a known signature: Code m(Context c); The basic operation is type safe code replacement of explicitly (annotations) or implicitly (method calls) annotated codeThe basic operation is type safe code replacement of explicitly (annotations) or implicitly (method calls) annotated code foreach (Method m in Assembly) if (annotated(m, stagename)) replaceCalls(m, a); if (annotated(m, stagename)) replaceCalls(m, a); else if (annotatedbody(m, stagename)) replace(m,a); else if (annotatedbody(m, stagename)) replace(m,a);

The logger example revised class LogAspect : Transformation { [MethodCall(SomeWork)] [MethodCall(SomeWork)] void Log(Context c) { void Log(Context c) { Console.WriteLine(“Entering SomeWork”); Console.WriteLine(“Entering SomeWork”); c.MethodCall(); c.MethodCall(); Console.WriteLine(“Exiting SomeWork”); Console.WriteLine(“Exiting SomeWork”); }}//... void SomeWork() {... } //...SomeWork();

And pattern matching? Transformations are expressed on the methods using custom attributesTransformations are expressed on the methods using custom attributes The transformation should be type-safeThe transformation should be type-safe ARE will not provide general support for pattern matching (maybe some restricted form)ARE will not provide general support for pattern matching (maybe some restricted form) An AOP compiler can anticipate pattern matching and output an appropriate transformation class.An AOP compiler can anticipate pattern matching and output an appropriate transformation class.

Agenda AOP and Code GenerationAOP and Code Generation CodeBricks: quick introCodeBricks: quick intro [a]C#: annotated join points[a]C#: annotated join points ARE: a generic program rewriting systemARE: a generic program rewriting system Conclusions Conclusions

Conclusions CodeBricks aims to become a general CLR support for meta-programming at runtimeCodeBricks aims to become a general CLR support for meta-programming at runtime We have discussed how the typical transformations of AOP could be mapped on CodeBricksWe have discussed how the typical transformations of AOP could be mapped on CodeBricks Annotations can help AOP systems to define better join pointsAnnotations can help AOP systems to define better join points A multi-stage code transformation system is required to have “before runtime stages”A multi-stage code transformation system is required to have “before runtime stages”