Top Banner
Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery
51

Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Dec 26, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Dynamic AOP

Advanced Software Tools Seminar

Spring 2005

Yossi Peery

Page 2: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Agenda

Static vs. Dynamic Aspects JAC Steamloom Toskana

Page 3: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Static Aspects

Join point locations determined statically Aspects inserted statically into base code

Source code instrumentation Compiler generated Bytecode Weaver Class Loader

Runtime environment unaware of aspects Weaving “flattens” the module structure Mismatch between AOP language and

execution model

Page 4: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Static Aspects - AspectJ

Java language extensions AspectJ Compiler – aspects turned to classes AspectJ Weaver – aspects weaved into

bytecode Weaving API for class loaders

Load-time weaving Implemented by users

Runtime classes (jar)

Page 5: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Static Aspects - AspectJ

Page 6: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Static Aspects

Dynamic checks are inserted to allow joinpoint flexibility at runtimeExample1:

before(String S): execution(void go(*)) && args(s)

Every possible joinpoint shadow checks for a string argument.

Example2: pointcut m2cf: cflow(call(void MyApp.m2(int)))

before(): execution(void MyApp.m1(int)) && m2cf()

Every possible joinpoint shadow for m1 checks for the context m2.

Page 7: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Dynamic Aspects

Aspects are woven/unwoven at runtime Changes application/aspects behavior at

runtime according to: User requirements Environment Changes System Configuration

Aspects become available/unavailable at runtime Logging (Verbose Mode) Security (Permission Levels)

Page 8: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Dynamic Aspects - Methods

Load-time weaving Byte code transformations at class loader level Subclass the Java class loader or replace it

JIT compiler weaving Byte code unaltered Alteration takes place when JIT compiler is employed

Reflection Base code transformed to reflect original code Dynamic Proxy solution using Java Reflection

Code Splicing Weaving changes on running native code

Page 9: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Dynamic Aspects - Methods

Total Hook WeavingAugment the entire code at each possible join point with a hook to which additional behavior could reference.

Actual Hook WeavingWeave hooks only to a set of points of actual interest, not to every possible point of potential interest.

Collected WeavingWeave in the advice code (not hooks) with the resulting code collecting the aspects and base in one unit.

Page 10: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Dynamic Aspects - Tools

AOP Frameworks JAC JBoss AOP AspectWerkz

Virtual Machine Support: Steamloom Prose

Kernel Code Splicing TOSKANA

Page 11: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC: Java Aspect Components

Renaud Pawlak Researcher at the LIFL laboratory in France JAC is based on his PhD Thesis

Open source SW developed by AOPSYS http://www.aopsys.com/ Collaboration with LIFL, LIP6, CEDRIC

(French Research Labs) Homepage

http://jac.objectweb.org/

Page 12: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC: Java Aspect Components

An AOP Framework for Java JAC Class Loader R.T.T.I Aspect Components AC Manager

Dynamic weaving achieved with wrappers Not a language – no changes to Java No changes to JVM No changes to Compiler

Page 13: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Programming Model

Aspect Components Implementation units that define extra characteristics

which crosscut a set of base-objects. Functionality

1. Extending the base classes' semantics through the definition of structural meta-information.

2. Aspect components to react on some events occurring within the system (e.g. a system shutdown, garbage collection, an application's launching, and so on)

3. Pointcuts: adding extra treatments before/after/around sets of base-method executions.

Page 14: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Aspect Component Example

Page 15: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Pointcut Specification

Pointcut must be specified through 3 sub-expressions (class, object, method) and a wrapping method.

On a particular joinpoint, the wrapping method will be applied if the 3 sub-expressions match the joinpoint charaterics.

Pointcut expressions are based on regular expressions but can include specific keywords or constructions (see next slide).

Regular expressions and keywords can be composed with logical operators: || (logical or) && (logical and) ! (logical not)

Page 16: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Pointcut experssions & keywords

Pointcut typeKeyword/expressionMatching entity

ClassALLAll the classes

<name>+All the children classes of name

<name>-All the parent classes of name

Regexp for a classpathAny class(es) matching

ObjectALLAll the instances

<rootName>path exprAny object in relation with rootName through the given path

Regexp for a nameAny instance(s) matching

MethodALLAll the methods

STATICSAll the static methods

CONSTRUCTORSAll the constructors

SETTER/GETTER(name)Setter/getter method for field name

COLSETTERS/COLGETTERSAll setters/getters for collections

REFSETTERS/REFGETTERSAll setters/getters for references

FIELDSETTERS/FIELDGETTERSAll setters/getters for primitive fields

MODIFIERS/ACCESSORSAll methods that change/read the state

Regexp for a signatureAny method(s) matching

Page 17: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC - Pointcut sub-expressions samples

package.* && !AMatches all the classes that belong to a package except class A

.*():int || MODIFIERSMatches all the methods that take no parameters and return an int + all the methods that modify the object’s state

STATICS && CONTRUCTORSMatches all the static and contruction methods

bank0/accounts/.*Matches all the objects that are related to the object called bank0 through the collection accounts

Information about methods is collected at load time using bytecode analysis and naming convetions

All such information is stored in the RTTI

Page 18: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Dynamic Wrappers

Wrapping Methods: They can perform treatments before and after the

regular objects methods they are applied to (same as the around advice in AspectJ).

Role Methods: That can extend regular objects interfaces (similarly to

the introduce statement in AspectJ). Exception Handlers :

That can handle exceptions that are raised by server objects in theobject the wrapper is applied to.

Page 19: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Dynamic Wrappers

Page 20: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – A simple example

Page 21: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Dynamic Wrappers Impl.

Load time transformation inserting hooks towards wrappers Actual wrapping method resolved at runtime Original class methods are renamed and

replaced by stubs that wrap them More then one wrappers for a single method

will form a “wrapping chain” JAC Composition Aspect

Wrappers ordering rules Wrapper Dependency or Incompatibility

Page 22: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Dynamic Wrapping Example

Page 23: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Dynamic Wrapping Example

Page 24: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC – Library Aspects

Page 25: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC –Dynamic Aspect Management

ACC files configure and initialize aspects Configuration files are loaded by the

framework before and during execution Register/Unregister Aspects Configure Pointcuts Invoke AC method calls

AC Manager Links Aspects to base objects Notifies AC on base object instantiation in

order to create the pointcut wrappers

Page 26: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC Kernel (system objects)

Application repository

AC manager

Composition aspect

JAC container

JAC loader (uses BCEL)R.T.T.I

Business classes

Aspect

Aspect configuration

Aspect Component

Business object

Java loader

tags

generates metamodel

new

calls

dispatchesWrappers

creates

Pointcuts

creates

calls

ordersApplication descriptor

(.jac) reads

JAC.prop

reads

loads

Wrapable classes

translates

JAC - dynamic aspectsinstallation process

Page 27: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

JAC - Other Issues

Also a Distributive Framework Not efficient

Reflective calls reduces speed of function call by 2 orders of magnitude

Limit AOP to business logic For distributed applications overhead becomes

negligible GPL Current available version 0.12.1 Future Work Plan

Eclipse plug-in J2EE integration XDoclet integration

Page 28: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom

Darmstadt University of Technology Mira Mezini Klaus Ostermann

Aspect-Oriented Run-Time Architecture To establish native support for dynamic AOP

in run-time environments Code and Documentation

http://www.st.informatik.tu-darmstadt.de

Page 29: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Jikes RVM

Open source JVM built by IBM http://jikesrvm.sourceforge.net/

Completely based on JIT (no interpreter) “baseline” compiler “optimizing” compiler

AOS – Adaptive optimization system Uses both compiler Online profiling and optimization

Compiler architecture chosen at VM build

Page 30: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Jikes RVM

VM_Class Represents a loaded Class Pointer to class’ TIB

TIB - Type Information Block Contains a class’s virtual method dispatch table

VM_Method – runtime object representing a instance of a method.

JTOC – Jikes Table of Contents Static Methods TIBs for all loaded class

Page 31: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Jikes RVM

Method initially not compiled Lazy compilation stub

Compiled and installed on first use Re-compiled (optimized) according to profiling data

Page 32: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Dynamic Aspects

No compile-time or load-time weaving API providing aspect building and deploying

functionality Pointcuts, Advice, and Aspects modelled as first

class entities Pointcut: Before, After (no Around yet) Advice:

Instantiated by any Java Method API to Joinpoint context and parameter passing

infomration Aspect: Container, associating pointcuts and advice

Page 33: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Dynamic Aspects

Aspect Deployment deploy(): Globally deploys that aspect

instance. The aspect is weaved. undeploy() – Globally undepolys an aspect

instance. The aspect is unweaved. Deploy parameters:

Thread instance – for thread local aspects Object instance – for object local aspects

Deployment of aspects can be done dynamically throughout a program

Page 34: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Dynamic Aspects

Aspect (Un)Weaving Affected method’s byte code is modified in its

VM_Method instance Byte code is recompiled at the same optimization level

Page 35: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Dynamic Aspects

Deployment of Instance-local aspects TIB is cloned VM_Method instance is cloned Weaving performed on cloned instance

Page 36: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Dynamic Aspects

Thread-local weaving Dynamic Checks are added at byte code level

Inlining An algorithm that calculates the set of

methods in which a given method is inlined At recompilation of a method

The Above set is calculated All methods in the set are also recompiled

Inlining is not allowed for object-local aspects

Page 37: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Simple Example

Page 38: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Simple Example

Page 39: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom – Simple Example

Page 40: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Steamloom - Performance

Page 41: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA

Toolkit for Opertaion System Kernel Aspects with Nice Applications C Kernel Aspects for NetBSD

University of Marburg Distributed Systems Group Bernd Freisleben, Michael Engel

Part of the AOSTA project Aspects in OS - Tools and Applications http://ds.informatik.uni-marburg.de/de/index.php

Only research publication is available

Page 42: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA - NetBSD

Dynamic Aspects in Kernel Space Choosen Kernel: NetBSD version 2.0 Loadable kernel modules

Binary kernel modules that can be loaded and unloaded at runtime (ELF)

Used for aspect insertion Accessible kernel symbols

/dev/ksyms – kernel symbol table Allows finding the location of 94% of kernel

functions /dev/kmem – access to kernel memory Allows weaving of advice

Page 43: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA – Code Splicing

Native code replaced with branch to external function

Replaced code appended at the end of external function

Jump back to instruction after spliced location

Page 44: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA – Weaving

“Before” – simple case Splicing is done at the first instruction of the

function Location is found from symbol table

“After” – more difficult Function is searched for return instructions Advice is spliced at every possible point

Page 45: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA – Weaving

Page 46: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA – Weaving

“Around” – even more difficult Combines splicing techniques of “Before” and

“After” “Proceed” –

Return address back into advice code cannot be determined before running the advice

Original return locations from function are set to jump to a return function

Before executing “proceed” the address of the instruction after the proceed is replaced at all of these positions.

Page 47: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA – Weaving

Page 48: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA - Implmenetation

Every aspect is a kernel module

Aspect kernel library providing aspect functionality

Weaver daemon application responsible for weaving and unweaving at aspect loading

Page 49: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA - Implmenetation

Page 50: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

TOSKANA – Other issues

Autonomic Computing Functionality Self: Configuration, Healing, Optimization,

Protection Seen as a cross-cutting concern

Performance Run time:

“Before”, “After” - require 2 additional instructions “Proceed” – 15 + 22 x # of return statements

Load time Extra time for symbol table reading Extra time for weaving

Page 51: Dynamic AOP Advanced Software Tools Seminar Spring 2005 Yossi Peery.

Sources

Proceeding of the 2004 Dynamic Aspects Workshop (DAW04)

“JAC: An Aspect-Based Distributed Dynamic Framework”, Renaud Pawlak and partners

“Virtual Machine Support for Dynamic Join Points”, M. Mezini, K. Ostermann, M. Haupt

“Supporting Autonomic Computing Functionality via Dynamic Operating System Kernel Aspects”, Michael Engel, Bernd Freisleben

http://aspectprogrammer.org