25
1 X-ASB: A Framework for Implementing Extensible AOPL Naoyasu Ubayashi (Kyushu Institute of Technology) Hidehiko Masuhara (University of Tokyo) Tetsuo Tamai (University of Tokyo) March 18, 2004 IPSJ SIG-PRO

X-ASB: A Framework for Implementing Extensible AOPL

  • Upload
    dagmar

  • View
    19

  • Download
    0

Embed Size (px)

DESCRIPTION

IPSJ SIG-PRO. X-ASB: A Framework for Implementing Extensible AOPL. Naoyasu Ubayashi(Kyushu Institute of Technology) Hidehiko Masuhara(University of Tokyo) Tetsuo Tamai(University of Tokyo) March 18, 2004. Overview. Motivation --Issues on implementing AOPL Masuhara & Kiczales Model - PowerPoint PPT Presentation

Citation preview

Page 1: X-ASB: A Framework for Implementing Extensible AOPL

1

X-ASB:A Framework forImplementing Extensible AOPL

Naoyasu Ubayashi (Kyushu Institute of Technology)Hidehiko Masuhara (University of Tokyo)Tetsuo Tamai (University of Tokyo)

March 18, 2004

IPSJ SIG-PRO

Page 2: X-ASB: A Framework for Implementing Extensible AOPL

2

Overview

1. Motivation --Issues on implementing AOPL

2. Masuhara & Kiczales Model3. X-ASB: A framework for extending AOPL4. Towards reflection5. Related work6. Conclusion

Page 3: X-ASB: A Framework for Implementing Extensible AOPL

3

1. Motivation

Issues on implementing AOPL

Page 4: X-ASB: A Framework for Implementing Extensible AOPL

4

What is the essence of AOP ?

consists of the join points a means of identifying the join points (pointcut) a means of raising effects at the join points (advice)

JPM (Join Point Model) !

AspectJ?HyperJ?

Demeter?

Page 5: X-ASB: A Framework for Implementing Extensible AOPL

5

However …

Each of current AOP languages is based on a few fixed set of join point models.

Many different join point models have been proposed, and they are still evolving so that they could better modularize various crosscutting concerns.

There are crosscutting concerns that may not be modularized with current join point models.

Page 6: X-ASB: A Framework for Implementing Extensible AOPL

6

Example

aspect DisplayUpdating { pointcut move(FigureElement figElt): target(figElt) && (call(void FigureElement.moveBy(int, int)) || call(void Line.set*(Point)) || call(void Point.set*(int)))

after(FigureElement fe) returning:move(fe){ Display.update(fe); }}

class Company { static ClassGraph cg = new ClassGraph(); // class structure Double sumSalaries() { String s =''from Company to Salary''; // traversal strategy Visitor v = new Visitor(){ // adaptive visitor private double sum; public void start() { sum = 0.0;} public void before(Salary host) { sum += host.getValue();} public Object getReturnValue() { return new Double(sum);} }; return (Double)cg.traverse(this, s, v); } // ... rest of Company definition ...}

AspectJ Demeter

drastically different

Page 7: X-ASB: A Framework for Implementing Extensible AOPL

7

Extensible AOPLs are needed!

We propose a framework for implementing extensible AOPLs in which different JPMs can be provided as its extension.

computational reflection for AOP

Our Final Goal

Initial Result -- Common implementation model for JPMs

Page 8: X-ASB: A Framework for Implementing Extensible AOPL

8

2. Masuhara & Kiczales Model

Page 9: X-ASB: A Framework for Implementing Extensible AOPL

9

Weaving process

parses source code, and creates an internal data structure including an AST (Abstract Syntax Tree) in AspectJ, an object graph in Demeter, and so forth.

analyzes the internal data structure, creates a join point, checks if the join point satisfies conditions specified by pointcut designators, and execute advice if these conditions are true.

Page 10: X-ASB: A Framework for Implementing Extensible AOPL

10

Masuhara & Kiczales model (1)

M & K (Masuhara & Kiczales) Model [ECOOP 2003]

common framework for modeling different join point modelsincluding PA (pointcuts and advice as in), TRAV (traversal specifications as in Demeter), COMPOSITOR (class hierarchy composition as in Hyper/J), OC (open classes as in AspectJ), and QB (query-based browsing as in JQuery)

Page 11: X-ASB: A Framework for Implementing Extensible AOPL

11

Masuhara & Kiczales model (2)<X, XJP, A, AID, AEFF, B, BID, BEFF, META>

B - program

X - computationor programXJP-

join point

IDA -

means of

identifyingID

BIDB

EFFA

EFFA

EFF B -

mea

ns o

f

effe

ctingEFF B -

mea

ns o

f

effe

cting

META -weaving

parameter

Page 12: X-ASB: A Framework for Implementing Extensible AOPL

12

3. X-ASB:A framework for extending AOPL

Page 13: X-ASB: A Framework for Implementing Extensible AOPL

13

Framework layer for implementing weaver

Common implementation for all kinds of J PMs(currently provided by X-ASB)

FrameworkLevel 1

Toolkit for implementingPA- like J PMS

Toolkit for implementingTRAV- like J PMS

...

PA- likeWeaver

FrameworkLevel 2

PA+TRAV- like

Weaver...TRAV- like

Weaver

CommonComponents

Page 14: X-ASB: A Framework for Implementing Extensible AOPL

14

X-ASB overview

Development process1. define kinds of join points2. define kinds of pointcuts3. define a body of a weaver define computation at pointcuts

Commonimplementation

computation-at- jpregister-one- jp register-one-pcd

pointcut-matches

eval-program

generator

register- jp register-pcd

lookup-A- ID

lookup-B- ID

effect-A

effect-B

lookup- jp-generator

evaluatorjp

Programmingprotocol

1

1-1 1-2

2

2-12-2

3

4

4-1

4-2

4-3

5

6 7 8

base languageinterpreter

call

input / output

(define computation-at-jp (lambda (jp param) (let* ((A-ID (lookup-A-ID jp param)) (B-ID (lookup-B-ID jp param))) (effect-B B-ID jp (lambda () (effect-A A-ID jp param)) param))))

Page 15: X-ASB: A Framework for Implementing Extensible AOPL

15

PA weaver & TRAV weaver

eval-program

generator

register- jp

register-pcd

lookup-A- ID

lookup-B- ID

effect-A

effect-B

evaluator

1. generate an AST2. walk the AST

[generate-call- jp]

[call-pcd?]

lookup method

lookup advice

execute method

execute advice

walk

call-method(join point)

computation-at- jp

AST

eval-program

generator

register- jp

register-pcd

lookup-A- ID

lookup-B- ID

effect-A

effect-B

evaluator

1. generate an object graph2. walk the object graph

[generate- trav- jp]

[trav-pcd?]

dummy

lookup visitor

dummy

execute visitormethod

walk

arrival at anode

(join point)

computation-at- jp

ObjectGraph

Page 16: X-ASB: A Framework for Implementing Extensible AOPL

16

Advantage- modular JPM extension -

Hot spots for adding new kinds of join points and pointcut constructs are better modularized in comparison with the original ASB implementation. (encapsulated in the code region for the framework adaptation)

In ASB, the code for adding them is scattered in several code regions.

Page 17: X-ASB: A Framework for Implementing Extensible AOPL

17

4. Towards reflection

--- Future work ---

Page 18: X-ASB: A Framework for Implementing Extensible AOPL

18

Reflective features of X-ASB

(class sample-protocol-error-detection object (method int m1 () (...)) (method int m2 () (...)) (method int m2 () (...)) (after (calling-sequence (not (list 'm1 'm2 'm3))) (write 'invalid-calling-sequence) (newline)))

(class sample-calling-sequence object (method void register-user-defined-pcd () (meta register-one-pcd 'calling-sequence-pcd-check? 'calling-sequence-pcd-handler) (super register-user-defined-pcd))

(method boolean calling-sequence-pcd-check? ((pcd p)(jp j)) ...) (method void calling-sequence-pcd-handler ((pcd p)(jp j)) ...))

extendPA weaver

Page 19: X-ASB: A Framework for Implementing Extensible AOPL

19

A big problem

Although JPMs such as COMPOSITOR need compile-time weaving, JPMs such as TRAV need run-time weaving. PA can be implemented by either of them.

We must integrate compile-time weaving and run-time weaving into a single interpreter.

Page 20: X-ASB: A Framework for Implementing Extensible AOPL

20

Multi-stageweaving

Source program(J PM 1)

Source program(J PM 2)

Generator (Source-> J P structure)

J P structure (AST, etc.)

J P structure walker

Pointcutevaluator

Advice executor

Compile- timeweaving

Compile- timeweaving

J P structure

Generator (J Pstructure -> Source)

Source program(J PM n)

Run- time weaving

Results

Base Interpreter

Generator (Source-> J P structure)

J P structure

J P structurewalker

Pointcutevaluator

Advice executor

Generator (Source-> J P structure)

J P structure

J P structurewalker

Pointcutevaluator

Advice executor

(J PM n+1) (J PM m)

apply J PM by specifyingexecution scope

Page 21: X-ASB: A Framework for Implementing Extensible AOPL

21

Example

;; PA(class sample-fact user-defined-jpm (method int main () (send this fact 6)) (method int fact ((int n)) (if (< n 1) 1 (* n (send this fact (- n 1))))) (method void write-after () ...) ;pointcut & advice (pcd 'pa 'call-fact '(call fact)) (advice 'pa 'call-fact '(after 'write-after)))

;; COMPOSITOR(class foo object (method void init () (super init)) (method void test () (write 'foo) (newline)))

(class bar object (method void init () (super init)) (method void test () (write 'bar) (newline)))

(class main user-defined-jpm (method void main () (send (new foo) test))

;pointcut & advice for compositor (pcd 'compositor 'merge-foo-and-bar '(foo NL bar NL)) (advice 'compositor 'merge-foo-and-bar 'merge-by-name))

(jpm 'pa 'static)(jpm 'trav 'dynamic)(jpm 'compositor 'static)(jpm-precedence 'compositor 'pa 'trav)

Page 22: X-ASB: A Framework for Implementing Extensible AOPL

22

5. Related Work

Page 23: X-ASB: A Framework for Implementing Extensible AOPL

23

Related Work

XAspect CME (Concern Manipulation Environment) Josh

Page 24: X-ASB: A Framework for Implementing Extensible AOPL

24

6. Conclusion

Page 25: X-ASB: A Framework for Implementing Extensible AOPL

25

Summary

We proposed X-ASB, a framework for implementing extensible AOPLs.

The framework exposes programming interfaces for adding new kinds of JPMs.

Clarifying programming interfaces for extending JPMs is an important milestone towards computational reflection for AOP.