Runtime Aspect Weaving Through Metaprogramming Jason Baker and Wilson Hsieh Handi-Wrap.

Slides:



Advertisements
Similar presentations
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
Advertisements

Programming Languages and Paradigms
Chapter 7 User-Defined Methods. Chapter Objectives  Understand how methods are used in Java programming  Learn about standard (predefined) methods and.
1 JAC : Aspect Oriented Programming in Java An article review by Yuval Nir and Limor Lahiani.
Maya: Multiple-Dispatch Syntax Extension in Java Jason Baker and Wilson C. Hsieh University of Utah.
ASPECT ORIENTED SOFTWARE DEVELOPMENT Prepared By: Ebru Doğan.
© 2006 Pearson Addison-Wesley. All rights reserved4-1 Chapter 4 Data Abstraction: The Walls.
Chapter 10 Storage Management Implementation details beyond programmer’s control Storage/CPU time trade-off Binding times to storage.
Encapsulation by Subprograms and Type Definitions
Maya: Multiple-Dispatch Syntax Extension in Java Jason Baker and Wilson C. Hsieh University of Utah.
Inheritance and Polymorphism CS351 – Programming Paradigms.
Java CourseWinter 2009/10. Introduction Object oriented, imperative programming language. Developed: Inspired by C++ programming language.
OOP Languages: Java vs C++
Advanced Database CS-426 Week 2 – Logic Query Languages, Object Model.
Comparison of OO Programming Languages © Jason Voegele, 2003.
Programming Languages and Paradigms Object-Oriented Programming.
REFACTORING Lecture 4. Definition Refactoring is a process of changing the internal structure of the program, not affecting its external behavior and.
Imperative Programming
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Ceg860 (Prasad)L6MR1 Modularity Extendibility Reusability.
Extensible Plug-ins for Aspect-Oriented Programming Macneil Shonle*Ankit Shah.
1 Module Objective & Outline Module Objective: After completing this Module, you will be able to, appreciate java as a programming language, write java.
Features of Object Oriented Programming Lec.4. ABSTRACTION AND ENCAPSULATION Computer programs can be very complex, perhaps the most complicated artifact.
Programming Languages and Paradigms Object-Oriented Programming (Part II)
The Procedure Abstraction, Part VI: Inheritance in OOLs Comp 412 Copyright 2010, Keith D. Cooper & Linda Torczon, all rights reserved. Students enrolled.
Mads Torgersen, Microsoft.  Language INtegrated Query  An open multi-language query facility  Uses cool language stuff  Points into the future.
CSE 425: Object-Oriented Programming I Object-Oriented Programming A design method as well as a programming paradigm –For example, CRC cards, noun-verb.
Overloading Binary Operators Two ways to overload –As a member function of a class –As a friend function As member functions –General syntax Data Structures.
5-Aug-2002cse Arrays © 2002 University of Washington1 Arrays CSE 142, Summer 2002 Computer Programming 1
CSC 508 – Theory of Programming Languages, Spring, 2009 Week 3: Data Abstraction and Object Orientation.
Chapter 18 Object Database Management Systems. McGraw-Hill/Irwin © 2004 The McGraw-Hill Companies, Inc. All rights reserved. Outline Motivation for object.
CSC3315 (Spring 2008)1 CSC 3315 Subprograms Hamid Harroud School of Science and Engineering, Akhawayn University
CCC: An Aspect-Oriented Intermediate Language on.Net Platform Yingfei Xiong and Feng Wan University of Electronic Science and Technology of China, China.
OOP: Encapsulation,Abstraction & Polymorphism. What is Encapsulation Described as a protective barrier that prevents the code and data being randomly.
COP4020 Programming Languages Names, Scopes, and Bindings Prof. Xin Yuan.
Object Oriented Software Development
Summing Up Object Oriented Design. Four Major Components: Abstraction modeling real-life entities by essential information only Encapsulation clustering.
Demeter Aspects We study techniques for the emerging area of Aspect-Oriented Software Development and focus on the following areas:  Aspectual Collaborations.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 26 - Java Object-Based Programming Outline 26.1Introduction.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
 Objects versus Class  Three main concepts of OOP ◦ Encapsulation ◦ Inheritance ◦ Polymorphism  Method ◦ Parameterized ◦ Value-Returning.
CIS 270—Application Development II Chapter 8—Classes and Objects: A Deeper Look.
Testing OO software. State Based Testing State machine: implementation-independent specification (model) of the dynamic behaviour of the system State:
UMass Lowell Computer Science Java and Distributed Computing Prof. Karen Daniels Fall, 2000 Lecture 9 Java Fundamentals Objects/ClassesMethods Mon.
Composition When one class contains an instance variable whose type is another class, this is called composition. Instead of inheritance, which is based.
How to execute Program structure Variables name, keywords, binding, scope, lifetime Data types – type system – primitives, strings, arrays, hashes – pointers/references.
Java Programming, Second Edition Chapter Twelve Advanced Inheritance Concepts.
Chapter 11: Advanced Inheritance Concepts. Objectives Create and use abstract classes Use dynamic method binding Create arrays of subclass objects Use.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
Classes, Interfaces and Packages
Chapter 18 Object Database Management Systems. Outline Motivation for object database management Object-oriented principles Architectures for object database.
Chapter 1 Java Programming Review. Introduction Java is platform-independent, meaning that you can write a program once and run it anywhere. Java programs.
Zach Tatlock / Winter 2016 CSE 331 Software Design and Implementation Lecture 13 Generics 1.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
Author: DoanNX Time: 45’.  OOP concepts  OOP in Java.
C++ General Characteristics: - Mixed typing system - Constructors and destructors - Elaborate access controls to class entities.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
Lecture 6:Interfaces and Abstract Classes Michael Hsu CSULA.
Object Based Programming Chapter 8. 2 Contrast ____________________ Languages –Action oriented –Concentrate on writing ________________ –Data supports.
Polymorphism in Methods
/* LIFE RUNS ON CODE*/ Konstantinos Pantos Microsoft MVP ASP.NET
Inheritance and Polymorphism
Java Primer 1: Types, Classes and Operators
Array Array is a variable which holds multiple values (elements) of similar data types. All the values are having their own index with an array. Index.
Object Oriented Analysis and Design
Java Programming Language
Inheritance and Polymorphism
Subtype Substitution Principle
Presentation transcript:

Runtime Aspect Weaving Through Metaprogramming Jason Baker and Wilson Hsieh Handi-Wrap

Tightly integrated Java extension First-class advice objects ( Wrappers ) Weaving performed at runtime Implemented in the Maya syntax extension system

Problem: Caching Independent reuse of: –caching implementation –caching policy: shared, per-instance, single instance, others? –actual binding of method name

Advantages First-class advice increases reuse –Object composition –Explicit constructor parameters –Member and local advice Dynamic weaving also brings –Advice on libraries without source code –Less recompilation

Features Extends Java declaration, statement, and expression syntax Provides first-class notion of wrappers and procedures Hides an efficient calling convention through metaprogramming Supports binary libraries through bytecode rewriting

Wrappers and Procedures applying a wrapper to a method creates a procedure M W P

Wrappers and Procedures applying a wrapper to a method creates a procedure calls now go through the procedure

Wrappers and Procedures applying a wrapper to a method creates a procedure calls now go through the procedure each application creates a new procedure

Example: Caching Count redundant calls through tracing aspect Discover interactions between caches Does caching fit method semantics? Consider a class path search routine –compilers need caching –conventional class loaders don’t benefit –plugin loaders must not cache

Tracing a Method Let’s examine the arguments to a static method, ClassPath.lookup() ClassPath.Rsc wrapper lt(String name) { System.out.println(“lookup “ + name); return wrapped.apply(name); }; wrap ClassPath.lookup(String) with lt;

Wrapper Arguments Argument types are invariant Polymorphic arguments defined with Any type Wrappers may accept a variable number of arguments through rest array Type checking is in general dynamic

Reusable Wrappers General-purpose wrappers provided in maya.wrap.Wrappers tracer similar to lt, but takes any number of arguments, and returns any type wrap ClassPath.lookup(String) with Wrappers.tracer;

Wrapping Details Methods are advised by Wrapper instances Procedure objects represent method and wrapper bodies Generator takes an original method Procedure, and returns a wrapped Procedure

Composable Wrappers Explicitly use generator for greater flexibility CacheNth – caches return value based on n th argument makePerInstance – Generate and call through argument wrapper for each receiver instance makeConditionalWrapper – Call through wrapper based on boolean Procedure

Composing Caches We can build a lookup cache for each ClassPath instance cacheFirst avoids array overhead of CacheNth(1) wrap ClassPath.lookup(String) with Wrappers.makePerInstance(new CacheNth(1));

Composing Caches or one instance, using makeConditionalWrapper() final ClassPath p = new ClassPath(); wrap ClassPath.lookup(String) with makeConditionalWrapper( new boolean procedure(ClassPath r, String _) { return r == p; }, cacheFirst);

Performance Static transformation and dynamic code generation Avoids Java reflection API Efficient calling convention –avoids array allocation when possible –avoids allocating small integers

Interposing on Methods Each class includes Procedure[] Each method body calls through corresponding slot when non-null Innermost wrapper calls original method definition through Procedure object –method duplicated statically –Procedure subclass generated dynamically

Rewrite Overhead

Caching Performance

Related Work Reuse –Hanenburg and Unland [OOPLSA-ASC01] Dynamic weaving –JAC [Reflection 01] –David et al. [OOPSLA-ASC01] Separate compilation –Aspectual Components [?] –XOTCL [?]

Conclusions First-class advice is reusable –Application-specific cache policies built from reusable wrappers Binary libraries need advice –ClassPath cache useful to compiler Dynamic weaving can be efficient

Discussion Handi-Wrap