ABC: an implementation of AspectJ Oege de Moor Programming Tools Group University of Oxford joint work with Ganesh Sittampalam, Sascha Kuzins, Chris Allan,

Slides:



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

Optional Static Typing Guido van Rossum (with Paul Prescod, Greg Stein, and the types-SIG)
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Java Review Interface, Casting, Generics, Iterator.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
A Regression Test Selection Technique for Aspect- Oriented Programs Guoqing Xu The Ohio State University
Overview of AspectJ Aspect Oriented Software Development Seminar Technion presented by Oren Mishali.
University of British Columbia Software Practices Lab Fluid AOP Join Point Models Terry Hon Gregor Kiczales.
Advice Weaving in AspectJ Alex Gontmakher. Outline Possible implementation approaches Quick JVM primer AJC implementation Performance Evaluation.
Objects and Classes David Walker CS 320. Advanced Languages advanced programming features –ML data types, exceptions, modules, objects, concurrency,...
Cse321, Programming Languages and Compilers 1 6/12/2015 Lecture #17, March 12, 2007 Procedure Abstraction, Name Spaces, Scoping Rules, Activation Records,
Optimizing AspectJ Pavel Avgustinov, Aske Simon Christensen, Laurie Hendren, Sascha Kuzins, Jennifer Lhotak, Ondrej Lhotak, Oege de Moor, Damien Sereni,
Exceptions Three categories of errors: Syntax errors Runtime errors Logic errors Syntax errors: rules of the language have not been followed. Runtime error:
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
Combining Static and Dynamic Data in Code Visualization David Eng Sable Research Group, McGill University PASTE 2002 Charleston, South Carolina November.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Regression Test Selection for AspectJ Software Guoqing Xu and Atanas.
More on AspectJ. aspect MoveTracking { private static boolean _flag = false; public static boolean testAndClear() { boolean result = _flag; _flag = false;
Compilation 2007 Scopes and Environments Michael I. Schwartzbach BRICS, University of Aarhus.
AOP and Aspect C++ presentation by Igor Kotenkov based on presentation by Andreas Gal, Daniel Lohmann and Olaf Spinczyk.
XFindBugs: eXtended FindBugs for AspectJ Haihao Shen, Sai Zhang, Jianjun Zhao, Jianhong Fang, Shiyuan Yao Software Theory and Practice Group (STAP) Shanghai.
Java and C++, The Difference An introduction Unit - 00.
“is a”  Define a new class DerivedClass which extends BaseClass class BaseClass { // class contents } class DerivedClass : BaseClass { // class.
06 Exception Handling. 2 Contents What is an Exception? Exception-handling in Java Types of Exceptions Exception Hierarchy try-catch()-finally Statement.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Debugging Support.
Cs3180 (Prasad)L8Packages1 Packages Organizing large programs => From monolithic programs to partitioning class name space Access control of names => Enforcing.
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.
Abc Compiler Zak Fry. Who and Where Programming Tools Group at Oxford University, UK – Oege de Moor Sable Research Group at McGill University, Quebec.
Change Impact Analysis for AspectJ Programs Sai Zhang, Zhongxian Gu, Yu Lin and Jianjun Zhao Shanghai Jiao Tong University.
Session 2: AspectJ Mark Stobbe September 13,
Muga Nishizawa and Shigeru Chiba (Tokyo Institute of Technology, Japan) 1 A Small Extension to Java for Class Refinement ACM SAC'08, March 18, 2008.
Adding Trace Matching with Free Variables to AspectJ Chris Allan, Pavel Avgustinov, Sascha Kuzins, Oege de Moor, Damien Sereni, Ganesh Sittampalam and.
2000 Jordan Anastasiade. All rights reserved. 1 Class In this lesson you will be learning about: Class. Inheritance. Polymorphism. Nested and.
Aspect Oriented Programming Sumathie Sundaresan CS590 :: Summer 2007 June 30, 2007.
Hello.java Program Output 1 public class Hello { 2 public static void main( String [] args ) 3 { 4 System.out.println( “Hello!" ); 5 } // end method main.
Spring/2002 Distributed Software Engineering C:\unocourses\4350\slides\DefiningThreads 1 RMI.
AOP-1 Aspect Oriented Programming. AOP-2 Aspects of AOP and Related Tools Limitation of OO Separation of Concerns Aspect Oriented programming AspectJ.
Introducing ABC: Programming Languages and AOP Oege de Moor Programming Tools Group University of Oxford joint work with Ganesh Sittampalam, Sascha Kuzins,
Programming in Java CSCI-2220 Object Oriented Programming.
Region Pointcut for AspectJ Shumpei Akai Shigeru Chiba Muga Nishizawa.
CS536 Semantic Analysis Introduction with Emphasis on Name Analysis 1.
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.
Course Progress Lecture 1 –Java data binding: Basket example: UML class diagram -> class dictionary without tokens-> language design -> class dictionary.
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University IWPSE 2003 Program.
Chapter 8 Class Inheritance and Interfaces F Superclasses and Subclasses  Keywords: super F Overriding methods  The Object Class  Modifiers: protected,
 In the java programming language, a keyword is one of 50 reserved words which have a predefined meaning in the language; because of this,
SOEN 343 Software Design Section H Fall 2006 Dr Greg Butler
Programming Languages and Paradigms Activation Records in Java.
Interfaces F What is an Interface? F Creating an Interface F Implementing an Interface F What is Marker Interface?
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
Access Specifier. Anything declared public can be accessed from anywhere. Anything declared private cannot be seen outside of its class. When a member.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
SCoPE: an AspectJ Compiler for Supporting User-Defined Analysis-Based Pointcuts Tomoyuki Aotani Hidehiko Masuhara
AOP with AspectJ Awais Rashid, Steffen Zschaler © Awais Rashid, Steffen Zschaler 2009.
1 Aspectual Caml an Aspect-Oriented Functional Language Hideaki Tatsuzawa Hidehiko Masuhara Akinori Yonezawa University of Tokyo.
A Synchronized Block Join Point for AspectJ Chenchen Xi, Bruno Harbulot and John Gurd The University of Manchester Brussels, April 2008.
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 10 Java Fundamentals Objects/ClassesMethods.
RealTimeSystems Lab Jong-Koo, Lim
Features of AOP languages AOP languages have the following main elements: –a join point model (JPM) wrt base PL –a specification language for expressing.
Design issues for Object-Oriented Languages
Inheritance Modern object-oriented (OO) programming languages provide 3 capabilities: encapsulation inheritance polymorphism which can improve the design,
Methods Attributes Method Modifiers ‘static’
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
Interface.
Java Programming Language
Generics, Lambdas, Reflections
Threads and concurrency / Safety
Presentation transcript:

ABC: an implementation of AspectJ Oege de Moor Programming Tools Group University of Oxford joint work with Ganesh Sittampalam, Sascha Kuzins, Chris Allan, Pavel Avgustinov, Julian Tibble, Damien Sereni (Oxford) Laurie Hendren, Jennifer Lhoták, Ondřej Lhoták, Bruno Dufour, Christopher Goard, Clark Verbrugge (McGill) Aske Simon Christensen (Århus)

What is AspectJ? disciplined metaprogramming

The bluffer's guide to aspect-lingo Intertype declarations: inject new members into existing classes at compile-time aspect observes base program when certain patterns of events happen, run some extra code Static: Dynamic : “join point” = event = node in (dynamic) call graph “pointcut” = pattern of events = set of nodes in call graph “shadow” = program point that corresponds to join point “advice” = extra code

EJB policy enforcement public aspect DetectEJBViolations { pointcut uiCalls() : call(* java.awt.*+.*(..)); before() : uiCalls() && cflow(call(* EnterpriseBean+.*(..))) { System.err.println("UI call from EJB"); } declare error : uiCalls() && within(EnterpriseBean+) : "UI call from EJB"; pointcut staticMemberAccess() : set(static * EnterpriseBean+.*); declare error : staticMemberAccess() : "EJBs are not allowed to have non-final static vars"; }

Counting live objects per class public aspect AllocFree { public interface Finalize {} declare parents: mypackage..* implements Finalize; public void Finalize.finalize() throws Throwable { LiveData.decr(this.getClass()); } before(Object tgt): initialization(mypackage..*.new(..)) && this(tgt) { LiveData.incr(tgt.getClass()); }

Authorisation public abstract aspect AbstractAuthAspect { private Subject _authenticatedSubject; public abstract pointcut authOperations();... Object around() : authOperations() && !cflowbelow(authOperations()) { try { return Subject.doAsPrivileged(_authenticatedSubject, new PrivilegedExceptionAction() { public Object run() throws Exception { return proceed(); }}, null); } catch (PrivilegedActionException ex) { throw new AuthorizationException(ex.getException()); }

New compiler pass public aspect AspectTransformPass { AspectTransformer Assign.aspectTransformEnter(AspectTransformer at) {.... } Node Assign.aspectTransformLeave(AspectTransformer at) {... } } AST node Assign has subclasses LocalAssign, FieldAssign,...

ajc: “standard” AspectJ compiler aspects java source jars ajc class files ● builds on Eclipse compiler ● weaving with BCEL ● incremental ● about 45KLOC, excluding IDE support “weaving” ● started out as source-to-source ● java parts may be aspect-aware Daniel Sabbah (VP of IBM): “critical to our survival”

Problems with jars vs source public class MethodMatch { public static void main(String[] args) { foo((Object)"Object"); foo("String"); } public static void foo(Object o) { System.out.println("An object: " + o); } public aspect NewFoo { public static void MethodMatch.foo(String s) { System.out.println("A string: " + s); } compile together from source: An object: Object A string: String weave aspect into MethodMatch.class: An object: Object An object: String

What do you pay at runtime? From the FAQ on aspectj.org: We aim for the performance of our implementation of AspectJ to be on par with the same functionality hand-coded in Java. Anything significantly less should be considered a bug....we believe that code generated by AspectJ has negligible performance overhead.

Measuring the cost with *J frontend tagging bytecode weaver modified ajc JVMPI interface standard JVM *J dynamic metric tool JVMPI agent metric analyser with tag propagator standard metrics AspectJ-specific metrics Dufour, Goard et al, OOPSLA 2004

ajc performance

The need for a second compiler ● language definition other than test suite ● explore AOP language design space ● experiment with better code generation ● experiment with static analyses for safety checks and optimisations

The AspectBench Compiler: ABC AspectJ extension AspectJ source, and jars Polyglot Java compiler aspectInfo Java extracts of source Jimple intertype adjuster advice weaver Soot analysis and transformation framework class files

Polyglot: scope for intertype decls public class A { int x; class B { int x; } aspect Aspect { static int x; static int y; int A.B.foo() { class C { int x = 3; int bar() {return x + A.this.x;} } return (new C()).bar() + x + y; } when does field or call refer to host class A.B? ● no explicit receiver? if it was introduced into environment via the ITD, give it “this” from host. ● explicit “this” or “super”? if there is no qualifier and we're not inside a local class, it refers to the host. If there is a qualifier Q, it refers to the host if the host has an enclosing instance of type Q. implementation: ● extend environment type ● new AST nodes “hostSpecial” (this/super) ● ITDs add accessible members from host ● rewrite rules to disambiguate this/super to “Special” or “hostSpecial” host class

Soot: Jimple int foo(int x, int y) { if (x<y) return (y-x); else return (x-y); } int foo(int, int) { Example this; int x, y, $i0, $i1; this x int; y int; if x >= y goto label0; $i0 = y - x; return $i0; label0: $i1 = x - y; return $i1; } want to weave: aspect Aspect { after() returning : execution(* foo(..)) { System.out.println("woven"); } after() returning(int x) : execution(int foo(..)) { System.out.println("result="+x); } normal compilation

Weaving at shadows this x int; y int; nop; if x >= y goto label0; $i0 = y - x; $i1 = $i0; goto label1; label0: $i1 = x - y; label1: nop; return $i1; } nop; theAspect = staticinvoke (); virtualinvoke theAspect. (); nop; theAspect1 = staticinvoke (); adviceformal = $i1; virtualinvoke theAspect1. (adviceformal); nop;

ABC performance

Win (1) : no closures for around public class ShadowClass implements AroundClosure$1 { public [ret-type] proceed(int shadowID, [arg-type] arg1,...) { switch(shadowID) { case 0:... do what first shadow did... case 1:... do what second shadow did... } public void shadowMethod() {... Aspect.aspectOf().adviceMethod$1(this,0,arg1,...);... } public void anotherShadowMethod() {... Aspect.aspectOf().adviceMethod$1(this,1,arg1,...);... } calls thisparam.proceed(0,...) calls thisparam.proceed(1,...)

Win (2) : no stacks for cflow cflow(call(* foo(..))) && call (* bar(..)) matches call stack: bar foo... ajc: ● simulates call stack by pushing and popping around foo calls ● one stack per thread abc: ● use counter in lieu of stack when possible ● CSE on cflow expressions ● look up thread-local stack/counter only once per body ● static estimate of possible call stacks can eliminate runtime cost completely allow cflow in declare warning/error Sereni et al, AOSD 2003.

Extensibility of abc three extensions: ● local variables in pointcuts ● cast pointcut ● global pointcuts ● 3 new ast classes ● 3 new weaver classes ● override 1 ast class ● 1 new node factory ● 1 new visitor pass ● total 946 lines ● enable with compiler flags in the works: pointcuts that query program trace “pure” modifier on aspects size of abc: 40KLOC polyglot: 60KLOC Soot: 180KLOC

ABC Summary ● Implements the same language as ajc ● Whole-program, aimed at – extensibility – static analysis – performance of compiled code ● Suite of associated tools: decompiler, performance measurement, visualisation in Eclipse ● Current status: – pass majority of ajc test suite – likely release mid-October: complete development in 9 months