Region Pointcut for AspectJ Shumpei Akai Shigeru Chiba Muga Nishizawa.

Slides:



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

Towards a Standard Interface for Runtime Inspection in AOP Environments OOPSLA Workshop on Tool for AOSD, Seattle, November 2002 Katharina Mehner and Awais.
WEAVING CODE EXTENSIONS INTO JAVASCRIPT Benjamin Lerner, Herman Venter, and Dan Grossman University of Washington, Microsoft Research.
5/17/ Programming Constructs... There are several types of programming constructs in JAVA. - If-else construct or ternary operator - while - do-while.
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.
University of British Columbia Software Practices Lab 2005 CASCON A Fluid AOP Editor Terry Hon Gregor Kiczales.
University of British Columbia Software Practices Lab CAS Seminar 06 Fluid AJ - A Simple Fluid AOP Tool Terry Hon Gregor Kiczales.
COMP 14 Introduction to Programming Miguel A. Otaduy May 25, 2004.
CS Data Structures Appendix 1 How to transfer a simple loop- expression to a recursive function (factorial calculation)
PRESTO: Program Analyses and Software Tools Research Group, Ohio State University Regression Test Selection for AspectJ Software Guoqing Xu and Atanas.
The UNIVERSITY of NORTH CAROLINA at CHAPEL HILL Adrian Ilie COMP 14 Introduction to Programming Adrian Ilie July 8, 2005.
Aspect Oriented Programming Written by Michael Beder.
Chapter 7Louden, Programming Languages1 Chapter 7 - Control I: Expressions and Statements "Control" is the general study of the semantics of execution.
Inline Function. 2 Expanded in a line when it is invoked Ie compiler replace the function call with function code To make a function inline the function.
What Is a Factory Pattern?.  Factories are classes that create or construct something.  In the case of object-oriented code languages, factories construct.
A Formal Model of Modularity in Aspect-Oriented Programming Jonathan Aldrich : Objects and Aspects Carnegie Mellon University.
XFindBugs: eXtended FindBugs for AspectJ Haihao Shen, Sai Zhang, Jianjun Zhao, Jianhong Fang, Shiyuan Yao Software Theory and Practice Group (STAP) Shanghai.
A Bridge to Your First Computer Science Course Prof. H.E. Dunsmore Concurrent Programming Threads Synchronization.
Imperative Programming
Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Debugging Support.
Developing Adaptive J2ME Applications Using AspectJ Ayla Débora and Paulo Borba {add, Centro de Informática - UFPE.
Introduction to Aspect Oriented Programming Presented By: Kotaiah Choudary. Ravipati M.Tech IInd Year. School of Info. Tech.
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)
By Nicholas Policelli An Introduction to Java. Basic Program Structure public class ClassName { public static void main(String[] args) { program statements.
Adding Trace Matching with Free Variables to AspectJ Chris Allan, Pavel Avgustinov, Sascha Kuzins, Oege de Moor, Damien Sereni, Ganesh Sittampalam and.
Introduction to Programming David Goldschmidt, Ph.D. Computer Science The College of Saint Rose Java Fundamentals (Comments, Variables, etc.)
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.
POSL (Principles of Software Languages) Gr. Kyushu Institute of Technology, Japan Pointcut-based Architectural Interface.
Slide: 1 Copyright © AdaCore Subprograms Presented by Quentin Ochem university.adacore.com.
A Distributed Aspect-Oriented System for J2EE Applications Muga Nishizawa and Shigeru Chiba (Tokyo Institute of Technology, Japan) Background - As benefits.
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.
Design Issues. How to parallelize  Task decomposition  Data decomposition  Dataflow decomposition Jaruloj Chongstitvatana 2 Parallel Programming: Parallelization.
Introduction to Java Java Translation Program Structure
IDENTIFYING SEMANTIC DIFFERENCES IN ASPECTJ PROGRAMS Martin Görg and Jianjun Zhao Computer Science Department, Shanghai Jiao Tong University.
BEGINNING PROGRAMMING.  Literally – giving instructions to a computer so that it does what you want  Practically – using a programming language (such.
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.
Applying Translucid Contracts for Modular Reasoning about Aspect and Object Oriented Events Mehdi Bagherzadeh Gary T. Leavens Robert Dyer Foundations of.
Extending the Field Access Pointcuts of AspectJ to Arrays ICS 2006 – Taipei, December 2006 Kung Chen and Chin-Hung Chien* National Chengchi University.
 Control Flow statements ◦ Selection statements ◦ Iteration statements ◦ Jump statements.
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.
SCoPE: an AspectJ Compiler for Supporting User-Defined Analysis-Based Pointcuts Tomoyuki Aotani Hidehiko Masuhara
1 An AOP Implementation Framework for Extending Join Point Models Naoyasu Ubayashi(Kyushu Institute of Technology, Japan) Hidehiko Masuhara(University.
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.
PPL 2004, Gamagori, AICHI1 Remote Pointcut - A Language Construct for Distributed AOP Muga Nishizawa (Tokyo Tech, Japan) Shigeru Chiba (Tokyo Tech, Japan)
Information and Computer Sciences University of Hawaii, Manoa
Core Java Statements in Java.
Healing Data Races On-The-Fly
Aspect-Oriented Programming with the Eclipse AspectJ plug-in
11/10/2018.
Aspect-Oriented Programming
Chapter 1: Computer Systems
Object Oriented Programming
Distributed Dynamic Weaving is a Crosscutting Concern
C Programming Getting started Variables Basic C operators Conditionals
An Extensible Contract Verifier for AspectJ
Chenchen Xi CNC Supervisor: Prof. John R. Gurd
Aspect Oriented Programming
Corresponds with Chapter 5
Presentation transcript:

Region Pointcut for AspectJ Shumpei Akai Shigeru Chiba Muga Nishizawa

Background: Synchronization Granularity of synchronization alters performance – Fine-grained: Increase concurrency – Coarse-grained: Less overhead Which granularity is better on a given machine?

Motivating example: Javassist A bug report of synchronization for Javassist [ – Adding synchronization to fix the bug. – coarse-grained is chosen in this case. Separate synchronization code as an aspect – enable choosing appropriate granularity. public class ProxyFactory { public Class createClass() { if (thisClass == null) { ClassLoader cl = getClassLoader(); synchronized (proxyCache) { if (useCache){createClass2(cl);} else {createClass3(cl);} }} return thisClass;} private void createClass2(ClassLoader cl) { CacheKey key = new CacheKey(…); synchronized (proxyCache) { HashMap cacheForTheLoader =…; if (cacheForTheLoader == null) { cacheForTheLoader = new HashMap(); proxyCache.put(cl, cacheForTheLoader); cacheForTheLoader.put(key, key); }else {...}} synchronized (key) { Class c = isValidEntry(key); if (c == null) { createClass3(cl); key.proxyClass = new WeakReference(…); }else{thisClass = c;} }}} Coarse-grained candidate Fine-grained

Separating synchronization with AOP New pointcuts are needed – AspectJ provides execution, call, get, set pointcuts They pick out Join “points”. – But synchronization is applied to a “range” of code. Join points are not suitable Need to pick out regions (or pieces of code)

Region pointcut Regions are treated like join points – Use pattern matching – Static analysis and code transformation Regions are determined by static analysis. Extension to AspectJ

region[pc1;pc2;pc3;…] A new pointcut for a region – Specify a sequence of join points – Find a matching path public void foo() { … obj.criticalSectionBegin();//from here if(…){ a(); } … obj.criticalSectionEnd();//to here …} void around(): region[ call(* *. criticalSectionBegin()); call(* *.a()); call(* *. criticalSectionEnd()); ] { synchronized(someObject){ proceed(); }

New pointcut: all() all(pc1, pc2, pc3, …) – Matches a sequence including the join points all the pointcuts pc1, pc2, pc3, … match in some order. – The order of pointcuts does not matter. because the order of join points may be changed by refactoring

Example of all() region[ all( call(* *.a()), call(* *.b()), call(* *.c()) ) ] { a(); … b(); … c(); } { b(); … c(); … a(); } { c(); … b(); c(); … a(); } matches

A region may conflict with a control structure If a region intersects a control structure – we cannot weave an around advice public void foo() {... for(int i=0;i<100;i++){ bar(); beginCriticalSection(); // begin... } endCriticalSection(); // end... } void around(): region[ call(* *. criticalSectionBegin()); call(* *. criticalSectionEnd()) ]{ /* do something*/ }

Region adjustment Solves the conflict – Expand a selected region: to fit a control structure to include the first and the last selected join points – A minimum region satisfying the criteria above is selected public void foo() {... for(int i=0;i<100;i++){ bar(); beginCriticalSection(); // begin... } endCriticalSection(); // end... }

Context passing Synchronization needs a lock object – Contexts must be available in an advice body args(), target() are available in a pattern – Specified values must be accessible at the beginning of the region

Example of context passing … List list =... ;... for(int index = 0; i < 100; i++){ beginCriticalSection();... Object o=list.get(index);... endCriticalSection(); }... pointcut pc(List l,int i) : region[ call(* *.beginCriticalSection()); call(* List+.get(int)) && target(l) && args(i) ; call(* *.endCriticalSection()); ];

Implementation We implemented by extending abc – abc: The AspectBench Compiler for AspectJ Need information, where blocks, control structures and statements start/end – Add new instruction into Jimple

public void toBeAdvised(int x){ a(); b(x); c(); } original method Around advice In abc, some join points (e.g. execution) are split into static methods to weave an around advice – Local variables are passed through arguments – We adopt this mechanism This causes a few problems for the region pointcut public void toBeAdvised(int x){ advice(x); } public static void advice(int x){ beforeJoinPoint(); shadow(x); afterJoinPoint(); } public static shadow(int x){ a(); b(x); c(); } woven method advice original join point

Support an around advice : assignment (problem) Assignment does not change the value of the local variable – Local variables are replicated. public void toBeAdvised(int x){ String s="initial string"; a(); s="string was replaced"; b(); System.out.println(s); // what is the value of s? } void around(): region[call(* *.a());call(* *.b())] { proceed(); }

Support an around advice : assignment (solution) Share an object between the region and the original method – Each field contains a value of a local variable public void toBeAdvised(int x){ String s="initial string"; $localStorage = new LocalStorage(); $localStorage.s=s; s=$localStorage.s; a(); s="string was replaced"; b(); $localStorage.s=s; s=$localStorage.s; System.out.println(s); }

Support an around advice : jumps (problem) Jumps (break or continue) to outside of region are unavailable public void includeJump(){ labelOfFor: for(;;){ a(); if(isFinished()){ break; //goto label0; } b(); } //label0: } void around(): region[call(* *.a());call(* *.b())] { proceed(); }

Support an around advice : jumps (solution) Transform the bytecode – Share the ID for each jump target – Jump to the tail of the region – After region, check the ID and jump public void includeJump(){ labelOfFor: for(;;){ a(); if(isFinished()){ $i=0; goto endLabel; } b(); endLabel: switch($i){ case 0: goto label0; } label0: }

Applying to Javassist (coarse-grained) Fixed Javassist’s synchronization problem using region pointcut static WeakHashMap proxyCache; public Class createClass() { if (thisClass == null) { ClassLoader cl = …; if (useCache) createClass2(cl); else createClass3(cl); } return thisClass;} void around(): region[ get(static boolean *.useCache); call(* *.createClass2(..)); ] { synchronized(ProxyFactory.class) { proceed(); } }

Applying to javassist (fine-grained) void around(): region[ call(* WeakHashMap.get(..)); call(* WeakHashMap.put(..)); ]{ synchronized( ProxyFactory.proxyCache){ proceed(); }} static WeakHashMap proxyCache; private void createClass2(ClassLoader cl) { CacheKey key =…; HashMap cacheForTheLoader = (HashMap)proxyCache.get(cl); if (cacheForTheLoader == null) { proxyCache.put(...); }else{...}

Related work Tracematch [Allan et al. ’05] – History-based pointcut – Dynamic pattern matching with execution history LoopsAJ [Harbulot et al. ’06] – Picking out loops

Conclusion Region pointcut: – Picks out regions as join points – We extended abc Solved some design issues to weave an around advice Work in progress – Formalize the pattern matching semantics using hedge automata – Case study