Dynamic AOP - PowerPoint PPT Presentation

1 / 51
About This Presentation
Title:

Dynamic AOP

Description:

Mismatch between AOP language and execution ... STATICS. All the methods. ALL. Method. Any instance(s) matching. Regexp for a name ... STATICS && CONTRUCTORS ... – PowerPoint PPT presentation

Number of Views:190
Avg rating:3.0/5.0
Slides: 52
Provided by: Yos49
Category:
Tags: aop | dynamic | statics

less

Transcript and Presenter's Notes

Title: Dynamic AOP


1
Dynamic AOP
  • Advanced Software Tools Seminar
  • Spring 2005
  • Yossi Peery

2
Agenda
  • Static vs. Dynamic Aspects
  • JAC
  • Steamloom
  • Toskana

3
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

4
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)

5
Static Aspects - AspectJ
6
Static Aspects
  • Dynamic checks are inserted to allow joinpoint
    flexibility at runtime
  • Example1
  • 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.

7
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)

8
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

9
Dynamic Aspects - Methods
  • Total Hook Weaving
  • Augment the entire code at each possible join
    point with a hook to which additional behavior
    could reference.
  • Actual Hook Weaving
  • Weave hooks only to a set of points of actual
    interest, not to every possible point of
    potential interest.
  • Collected Weaving
  • Weave in the advice code (not hooks) with the
    resulting code collecting the aspects and base in
    one unit.

10
Dynamic Aspects - Tools
  • AOP Frameworks
  • JAC
  • JBoss AOP
  • AspectWerkz
  • Virtual Machine Support
  • Steamloom
  • Prose
  • Kernel Code Splicing
  • TOSKANA

11
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/

12
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

13
JAC Programming Model
  • Aspect Components
  • Implementation units that define extra
    characteristics which crosscut a set of
    base-objects.
  • Functionality
  • Extending the base classes' semantics through the
    definition of structural meta-information.
  • 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)
  • Pointcuts adding extra treatments
    before/after/around sets of base-method
    executions.

14
JAC Aspect Component Example
15
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)

16
JAC Pointcut experssions keywords
Pointcut type Keyword/expression Matching entity
Class ALL All the classes
ltnamegt All the children classes of name
ltnamegt- All the parent classes of name
Regexp for a classpath Any class(es) matching
Object ALL All the instances
ltrootNamegtpath expr Any object in relation with rootName through the given path
Regexp for a name Any instance(s) matching
Method ALL All the methods
STATICS All the static methods
CONSTRUCTORS All the constructors
SETTER/GETTER(name) Setter/getter method for field name
COLSETTERS/COLGETTERS All setters/getters for collections
REFSETTERS/REFGETTERS All setters/getters for references
FIELDSETTERS/FIELDGETTERS All setters/getters for primitive fields
MODIFIERS/ACCESSORS All methods that change/read the state
Regexp for a signature Any method(s) matching
17
JAC - Pointcut sub-expressions samples
package. !A Matches all the classes that belong to a package except class A
.()int MODIFIERS Matches all the methods that take no parameters and return an int all the methods that modify the objects state
STATICS CONTRUCTORS Matches 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

18
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.

19
JAC Dynamic Wrappers
20
JAC A simple example
21
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

22
JAC Dynamic Wrapping Example
23
JAC Dynamic Wrapping Example
24
JAC Library Aspects
25
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

26
JAC - dynamic aspects installation process
Business classes
JAC loader (uses BCEL)
R.T.T.I
27
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

28
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

29
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

30
Steamloom Jikes RVM
  • VM_Class
  • Represents a loaded Class
  • Pointer to class TIB
  • TIB - Type Information Block
  • Contains a classs 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

31
Steamloom Jikes RVM
  • Method initially not compiled
  • Lazy compilation stub
  • Compiled and installed on first use
  • Re-compiled (optimized) according to profiling
    data

32
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

33
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

34
Steamloom Dynamic Aspects
  • Aspect (Un)Weaving
  • Affected methods byte code is modified in its
    VM_Method instance
  • Byte code is recompiled at the same optimization
    level

35
Steamloom Dynamic Aspects
  • Deployment of Instance-local aspects
  • TIB is cloned
  • VM_Method instance is cloned
  • Weaving performed on cloned instance

36
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

37
Steamloom Simple Example
38
Steamloom Simple Example
39
Steamloom Simple Example
40
Steamloom - Performance
41
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

42
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

43
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

44
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

45
TOSKANA Weaving
46
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.

47
TOSKANA Weaving
48
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

49
TOSKANA - Implmenetation
50
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

51
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
Write a Comment
User Comments (0)
About PowerShow.com