Fine-Grained Generic Aspects Tobias Rho, Gnter Kniesel, Malte - - PowerPoint PPT Presentation

fine grained generic aspects
SMART_READER_LITE
LIVE PREVIEW

Fine-Grained Generic Aspects Tobias Rho, Gnter Kniesel, Malte - - PowerPoint PPT Presentation

Fine-Grained Generic Aspects Tobias Rho, Gnter Kniesel, Malte Appeltauer Dept. of Computer Science III University of Bonn FOAL Workshop Overview Motivation LogicAJ 2 Examples Related Work Conclusion Universitt Bonn


slide-1
SLIDE 1

Fine-Grained Generic Aspects

Tobias Rho, Günter Kniesel, Malte Appeltauer

  • Dept. of Computer Science III

University of Bonn FOAL Workshop

slide-2
SLIDE 2

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [2]

Overview

  • Motivation
  • LogicAJ 2
  • Examples
  • Related Work
  • Conclusion
slide-3
SLIDE 3

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [3]

  • Restricted set of join points

pointcuts just on the interface level (classes, methods, fields)

call, execution, set, get ...

fine-grained ?

e.g. loops ?

Limitations of Common Aspect Languages

parallizable!

class Foo{ private int myField; public void foo(){ myField = 42; if(Bar.A < 4711){ myField = 1; } else{ myField = 0; } } public int bar(){ foo(); return myField; } public void m(int[] a, int[] b) { for(int i = 0;i< a.length;i++) { a[i] = 2*i; b[i] = i*i; } } ... final Vector v = new Vector(); List list = new ArrayList(); final int range= (a.length-0)/THREADS; for(int i = 0; i< THREADS; i++){ final int finalThreads = i; Thread thread = new Thread(){ public void run(){ int newLb = lb+range*finalThreads; int newUB = newLB + range; if(newUB >= ub) newUB = ub; for(int i = newLB;i< newUB;i++) { a[i] = 2*i; b[i] = i*i; } }.run(); list.add(thread); ...

aspect

call

statement

for(int i = 0;i< a.length;i++) { a[i] = 2*i; b[i] = i*i; }

slide-4
SLIDE 4

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [4]

Limitations of Common Aspect Languages

  • Restricted set of join points

pointcuts just on the interface level (classes, methods, fields)

call, execution, set, get ...

fine-grained ?

class Foo{ private int myField; public void foo(){ myField = 42; if(Bar.A < 4711){ myField = 1; } else{ myField = 0; } public int bar(){ foo(); return myField; } public void (int[] a, int[] b) { for(int i = 0;i< a.length;i++) { a[i] = 2*i; b[i] = i*i; } }

AOP Test Coverage?

slide-5
SLIDE 5

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [5]

Find Bad Smells

class Foo{ public int getValue(){ if(this instanceof A) return 42; if(this instanceof B) return 4711; else return 0; }…

Bad Smell!

Compile-time warning : „Use Polymorphism!“

aspect

myField.methFromKnownClass(). methFromUnknownClass();

Compile-time warning : „Violates the Law of Demeter!“

aspect

  • Compile-time check for bad smells

Bad Smell!

? ?

slide-6
SLIDE 6

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [6]

LogicAJ 2

A fine-grained generic aspect language

slide-7
SLIDE 7

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [7]

Fine-grained pointcuts

  • Fine-grained pointcuts

select all syntactically distinguishable join points

statements, expressions, declarations

  • Minimal language core

minimal number of pointcuts simple, easy to learn language based on code patterns

stmt(code) expr(code) decl(code) pointcut fooBarCalls(): expr(foo() ) || expr(bar() );

slide-8
SLIDE 8

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [8]

Extensible

  • Extensible

build high-level pointcuts by composition

logic operations and recursion

e.g. static AspectJ pointcut semantics loops, condition pointcuts

  • Patterns?

Placeholders necessary! Example task: Select all getter methods

First try: use wildcards

pointcut getter(): decl( public int get*() { * return *; });

slide-9
SLIDE 9

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [9]

Use Logic Meta-Variables instead of Wildcards

  • Transition from wildcards to meta-variables

pointcut getter(): decl( public int get*() { * return *; }); pointcut getter(?fname) : decl( public int ?getter() { ??stmts return ?fname; }) && concat("get", ?fname, ?getter);

slide-10
SLIDE 10

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [10]

Logic Meta-Variables

Syntax: ?lmv Here: used to bind syntactically complete syntax elements

statements, expressions, declarations, (type) identifier

Special meta-variables for lists: ??llmv

pointcut getter(?fname) : decl( public int ?getter() { ??stmts return ?fname; }) && concat("get", ?fname, ?getter); identifier arbitrary number of statements auxiliary predicates for string and list

  • perations
slide-11
SLIDE 11

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [11]

Relations between pointcuts

  • Additional pointcut: setter
  • New contract: For every setter there is a getter method in

the same class

pointcut setter(?fname): decl( public void ?setter(int ?param) { ??stmtbefore this.?fname = ?param; ??stmtafter }) && concat("set", ?fname, ?setter); pointcut inconsistentGetterSetter(): setter(?fname) && !getter(?fname);

How do we express a relationship between selected join points?

INSUFFICIENT

slide-12
SLIDE 12

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [12]

Explicit join point variables

  • Primitive pointcuts bind join points to meta-variables

stmt(?jp, code) expr(?jp, code) decl(?jp, code)

slide-13
SLIDE 13

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [13]

Explicit join point variables

  • Primitive pointcuts bind the join points to a meta-variable

pointcut getter(?jp, ?fname): decl(?jp, public int ?getter() { ??stmts return ?fname; }) && concat("get", ?fname, ?getter); pointcut setter(?jp): … pointcut inconsistentGetterSetter(): setter(?setter, ?fname) && !getter(?getter ,?fname);

How do we express a relationship between meta- variables?

STILL INSUFFICIENT

How do we ensure they are defined in the same class?

slide-14
SLIDE 14

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [14]

Finally …

  • Use attributes to relate to meta-variable context

pointcut getter(?jp): decl(?jp public int ?getter() { ??stmts return ?fname; }) && concat(get, ?fname, ?getter); pointcut setter(?jp): … pointcut inconsistentGetterSetter(): setter(?setter, ?fname) && !(getter(?getter, ?fname) && equals(?getter::parent, ?setter::parent));

slide-15
SLIDE 15

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [15]

Logic Meta-Variable Attributes

  • Meta-variable attributes provide context information

Syntax:

  • parent

The enclosing element

  • ref

Resolved referenced declaration

  • type

Resolved Java type of an element bound to a LMV ( syntactic sugar, inferable via the ref attribute )

?lmv::<attr>

slide-16
SLIDE 16

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [16]

Generalized Aspect Construct

( introduce | before | after | around ) <name>(<jp id>, <optional parameters>) : <pointcut description> { ( <class template> | <method introduction> | <field introduction> | <advice body> ) }

  • Syntax

explicit join point meta-variable

slide-17
SLIDE 17

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [17]

LogicAJ 2 Summary

  • Fine-grained aspect language
  • Minimal set of basic pointcuts as a language core
  • Uniform genericity
  • Extensible

build high-level pointcuts by composition

logic operations and recursion

e.g. static AspectJ pointcut semantics loops, condition pointcuts

slide-18
SLIDE 18

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [18]

Constructing higher-level pointcuts

slide-19
SLIDE 19

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [19]

pointcut call(?jp,??mods,?declType,?returnType,?name,??parTypes): expr(?jp, ?name(??args) ) && decl(?jp::ref, ??mods ?returnType ?name(??par){??stmts} ) && equals(?declType, ?jp::ref::parent::type) && parameterTypes(??parTypes,??par);

Named Pointcut Examples

  • AspectJ call pointcut

select call expression and bind ?name to the method name and the LMV list variable ??args to the arguments list

slide-20
SLIDE 20

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [20]

pointcut call(?jp,??mods,?declType,?returnType,?name,??parTypes): expr(?jp, ?name(??args) ) && decl(?jp::ref, ??mods ?returnType ?name(??par){??stmts} ) && equals(?declType, ?jp::ref::parent::type) && parameterTypes(??parTypes,??par);

Named Pointcut Examples

  • AspectJ call pointcut

select the syntax elements of the referenced method ?jp::ref

slide-21
SLIDE 21

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [21]

after log(?jp): call(?jp, [public], ?ret, ClassX, ?m, [int] ) { System.out.println("called method" + ?m); }

Using named pointcuts: Free Code Patterns

  • Free Code patterns

pointcut call(?jp,??mods,?declType,?returnType,?name,??parTypes): …

The call pointcut can easily be extended to support patterns.

slide-22
SLIDE 22

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [22]

For-loop pointcut

  • For-loop

pointcut forLoop(?jp,index, ?lb, ?ub, ?incr, ?statements): stmt( for(?jp, type ?index = ?lb; ?index < ?ub; ?incr) { ??statements } );

slide-23
SLIDE 23

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [23]

For-loop pointcut

  • Using the For-loop pointcut

?range::type around(): forLoop(?range, ?lb , ?ub, ?incr, ??statements) { < .. > int newLb = < .. > int newUb = < .. > for(?range::type ?range = newLb;?range < newUb; ?incr) { ??statements } < .. > }

slide-24
SLIDE 24

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [24]

forLoop(?index, int, ?ub(), 0, ??statements)

Free Code Patterns

int ?ub() m(int i)

class C

for int i <

init cond

block

body

i++

step

int i m() int

free source patterns bind meta-variables

slide-25
SLIDE 25

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [25]

Related Work

  • concrete solutions to a subset of join points

EOS (Hridesh Rajan et al.)

conditionals and loop pointcuts

LoopsAJ (B. Harbulot et al.)

loop pointcut, byte code analysis

  • Extensible Compiler

abc Compiler (de Moor et al.)

aspect compiler framework every part of the compiler is open to extension still, for all extensions compiler knowledge is necessary

  • JaTS

language for pattern based transformations of Java programs code patterns describe program parts on which transformations should take place transformation specification is described with another pattern both parts can be linked by the use of meta-variables, which substitute syntactic elements at the interface level of a base-program

slide-26
SLIDE 26

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [26]

Conclusion

  • fine-grained genericity for aspect languages
  • base-language code patterns with meta-variables
  • minimal set of fine-grained pointcuts
  • express dependencies between multiple join points
  • define arbitrary kinds of pointcuts that previously required

specific language extensions

slide-27
SLIDE 27

Universität Bonn – Institute for Computer Science III FOAL'06, Fine-grained generic Aspects, Tobias Rho, Günter Kniesel, Malte Appeltauer [27]

Questions?

?

?