Dynamic aspects and their application for autonomic computing

batterycopperInternet και Εφαρμογές Web

12 Νοε 2013 (πριν από 4 χρόνια και 1 μέρα)

114 εμφανίσεις

Dynamic AOP

Advanced Software Tools Seminar

Spring
2005

Yossi Peery

Agenda


Static vs. Dynamic Aspects


JAC


Steamloom


Toskana

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

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)


Static Aspects
-

AspectJ

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
.

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)

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

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.

Dynamic Aspects
-

Tools


AOP Frameworks


JAC


JBoss AOP


AspectWerkz


Virtual Machine Support:


Steamloom


Prose


Kernel Code Splicing


TOSKANA

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, LIP
6
, CEDRIC
(French Research Labs)


Homepage


http://jac.objectweb.org/

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

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.

JAC


Aspect Component Example

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)

JAC


Pointcut experssions &
keywords

Pointcut type

Keyword/expression

Matching entity

Class

ALL

All the classes

<name>+

All the children classes of
name

<name>
-

All the parent classes of
name

Regexp for a classpath

Any class(es) matching

Object

ALL

All the instances

<rootName>path 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

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 object’s
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

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.


JAC


Dynamic Wrappers

JAC


A simple example

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

JAC


Dynamic Wrapping Example

JAC


Dynamic Wrapping Example

JAC


Library Aspects

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

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

dispatches

Wrappers

creates

Pointcuts

creates

calls

orders

Application
descriptor
(.jac)

reads

JAC.prop

reads

loads

Wrapable classes


translates

JAC
-

dynamic aspects

installation process

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


J
2
EE integration


XDoclet integration

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


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

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

Steamloom


Jikes RVM


Method initially not compiled


Lazy compilation stub


Compiled and installed on first use


Re
-
compiled (optimized) according to profiling data

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

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

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


Steamloom


Dynamic Aspects


Deployment of Instance
-
local aspects


TIB is cloned


VM_Method instance is cloned


Weaving performed on cloned instance

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

Steamloom


Simple Example

Steamloom


Simple Example

Steamloom


Simple Example

Steamloom
-

Performance

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

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

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

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

TOSKANA


Weaving

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.

TOSKANA


Weaving

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

TOSKANA
-

Implmenetation

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

Sources


Proceeding of the
2004
Dynamic Aspects Workshop
(DAW
04
)


“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