master’s thesis defense: aspectual concepts

69
Master’s Thesis Defense: Aspectual Concepts John J. Sung

Upload: adrina

Post on 23-Jan-2016

55 views

Category:

Documents


0 download

DESCRIPTION

Master’s Thesis Defense: Aspectual Concepts. John J. Sung. J. DEMETER. DHMHTRA. AJ. (Demeter AspectJ). EMETERJ. AspectJ from PARC. Aspect-oriented tools referred to in this talk. Static Scattering and Tangling. aspect i is scattered across many classes (i = 1,2,3) - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Master’s Thesis Defense: Aspectual Concepts

Master’s Thesis Defense:Aspectual Concepts

John J. Sung

Page 2: Master’s Thesis Defense: Aspectual Concepts

AspectJ from PARC

AJJ

EMETERJ

(Demeter AspectJ)

Aspect-orientedtools referred to in this talk

Page 3: Master’s Thesis Defense: Aspectual Concepts

Static Scattering and Tangling• aspecti is scattered across many classes (i = 1,2,3)

• class X tangles aspects 1, 2 and 3

aspect1 aspect2 aspect3class A consistingof three aspects

classes foraspect1 classes for

aspect2

classes foraspect3

Class X

class diagram

Adding to classes

Page 4: Master’s Thesis Defense: Aspectual Concepts

Dynamic Scattering and Tanglingprogram executioninvolving three aspects (colors r b g)

program call tree(objectsexecuting method calls)

•Each aspect (colors) is scattered across many classes (shapes)•Class tangles all three aspects

At those calls the aspect enhances the behavior

classes

this(s)

target(t)f(..)

Enhancing callst.f(..);

Page 5: Master’s Thesis Defense: Aspectual Concepts

AspectJ DJ Kind Dynamic Dynamic

On What Dynamic call graph of base program

Dynamic call graph of a subcomputation of base program

When Pointcuts Signatures of visitor methods

What Before / around / after advice

Before / around / after visitor method body

subcomputation = join points related to traversing through the objectsguided by traversal specification and class graph.

Page 6: Master’s Thesis Defense: Aspectual Concepts

• Pointcut– set of execution points of

any method, …

– rich set of primitive pointcuts: this, target, call, … + set operations

– where to enhance

• Advice– how to enhance

• Visitor method sig.– set of execution points

of traversals

– specialized for traversals (nodes, edges)

– where to enhance

• Visitor method bodies– how to enhance

DJ AspectJ

From DJ to AspectJ

Page 7: Master’s Thesis Defense: Aspectual Concepts

Outline

• Motivation

• JPM and Demeter Concepts

• Demeter integrated with AspectJ (DAJ)

• DAJ Semantics/Syntax

• DAJ System Architecture

• Four Graph Model of Programs (4GMP)

• Conclusion

Page 8: Master’s Thesis Defense: Aspectual Concepts

Motivation

• Aspect Oriented Software Development Gaining Momentum– 1st International Conference on AOSD– AspectJ, DemeterJ, ConcernJ, HyperJ, etc.

• AOSD is Relatively Young– DemeterJ ~1989 – AspectJ ~1997

Karl J. Lieberherr:

Demeter C++ 1989

DemeterJ 1996

Karl J. Lieberherr:

Demeter C++ 1989

DemeterJ 1996

Page 9: Master’s Thesis Defense: Aspectual Concepts

Questions

• What are the fundamental concepts behind AOSD?

• How are these concepts related?• Can these concepts be mixed?

• What are the fundamental problems that software language features attempt to solve?

Karl J. Lieberherr:

How can these concepts be combined?

Karl J. Lieberherr:

How can these concepts be combined?

Page 10: Master’s Thesis Defense: Aspectual Concepts

Joinpoint Model (JPM)

• Fundamental Concepts– Joinpoint, Pointcut, Advice, Aspect,

Introduction– Concepts applied to call graph in AspectJ

– Building or Construction Metaphor

Karl J. Lieberherr:

Also to class graph : introductions

Karl J. Lieberherr:

Also to class graph : introductions

Page 11: Master’s Thesis Defense: Aspectual Concepts

Construction Metaphor

• Concepts in JPM create an image of constructed structures from building blocks

Karl J. Lieberherr:

Of structures constructed from building …

Karl J. Lieberherr:

Of structures constructed from building …

Page 12: Master’s Thesis Defense: Aspectual Concepts

AspectJ Abstraction of Programs

Call Graph Pointcuts+ + Advices=>

Program

Page 13: Master’s Thesis Defense: Aspectual Concepts

AspectJ Abstraction of Programs

foo(){x = 0;if (x < 0) throw KException;}

barint x;

b1.foo();

c1

within(bar)

aspect

before() : within(bar) {}

Page 14: Master’s Thesis Defense: Aspectual Concepts

Another View

Java Program

AspectJ

Advice

pointcut advice body

join point

Page 15: Master’s Thesis Defense: Aspectual Concepts

Demeter

• Fundamental Concepts– Class Graph, Strategy, Visitor, Advice– Concepts applied to data structures, i.e. class

graph– Journey Metaphor

Page 16: Master’s Thesis Defense: Aspectual Concepts

Journey Metaphor

• Concepts in Demeter create an image of a person on a journey

Page 17: Master’s Thesis Defense: Aspectual Concepts

Demeter Abstraction of Programs

Class Graph StrategyGraph

+ +VisitorAdvices

=>

Program

Page 18: Master’s Thesis Defense: Aspectual Concepts

Demeter Abstraction of Programs

=>before(..)

after(..)

before(..)

ClassGraph

StrategyGraph

TraversalGraph

VisitorAdvices

Page 19: Master’s Thesis Defense: Aspectual Concepts

Mixing Concepts

• Application of JPM on Demeter– Class graph is built of classes and edges– Joinpoints become the points along traversals– Advices are executed at these joinpoints

Page 20: Master’s Thesis Defense: Aspectual Concepts

Mixing Concepts

• Application of Demeter on JPM– CPU is the global visitor– Advice with a pointcut are Demeter advices for

the global visitor– Visitor is traversing the Dynamic Call Graph

Karl J. Lieberherr:

Advices with a …

Karl J. Lieberherr:

Advices with a …

Karl J. Lieberherr:

This continues to be non-convincing.

Karl J. Lieberherr:

This continues to be non-convincing.

Page 21: Master’s Thesis Defense: Aspectual Concepts

Demeter AspectJ (DAJ)

• Uses AspectJ as the backend compiler• Uses DJ to generate Class Graph, Traversal

Graph• Generates the AspectJ implementation of

the traversal• Defines a traversal specification language• Implemented using DemeterJ• Application of JPM on Demeter

Page 22: Master’s Thesis Defense: Aspectual Concepts

Traversal Specification Language

• Designed to have similar syntax to DJ and AspectJ

• Allows users to specify Class Graph, Traversal, and Visitor

• Generates AspectJ implementation of traversals

Page 23: Master’s Thesis Defense: Aspectual Concepts

Class Graph Specification

• Default Class Graph

– ClassGraph cgvar;

• Class Graph Slice

– ClassGraph cgvar = new ClassGraph(cg, “strategy”);

Page 24: Master’s Thesis Defense: Aspectual Concepts

Visitor Specification

• Uses Java Reflection to obtain method signatures

• Recognized methods are– around, before, after, start, finish, returnValue

• Visitor Declaration– Visitor visitorClass;

Page 25: Master’s Thesis Defense: Aspectual Concepts

Traversal Specification• Default Traversal Specification

– declare traversal tvar : “strategy”;

• Traversal with Class Graph

– declare traversal tvar(cgvar) : “strategy”;

• Traversal with Visitor

– declare traversal tvar(cgvar, visitorvar) : “strategy”;

Page 26: Master’s Thesis Defense: Aspectual Concepts

Aspect Specification

aspect aspectName {

class graph declarations;

traversal declarations;

visitor declarations;

}

Page 27: Master’s Thesis Defense: Aspectual Concepts

What DAJ Generates

• For each default and class graph slice traversal– method void tvar() for the source node of the traversal

strategy

• For each traversal with visitor– method void tvar() for the source node of the traversal

strategy– method void tvar(visitorClass) for the source node of

the traversal strategy– Appropriate AspectJ Advices for each advice in

visitorClass

Page 28: Master’s Thesis Defense: Aspectual Concepts

A Simple Basket Exampleclass Basket { Basket(Fruit _f, Pencil _p) { f = _f; p = _p; } Basket(Fruit _f, Fruit _f2, Pencil _p) { f = _f; f2 = _f2; p = _p; } Fruit f, f2; Pencil p;}class Fruit { Fruit(Weight _w) { w = _w; } Weight w;}class Orange extends Fruit { Orange(Color _c) { super(null); c=_c;} Orange(Color _c, Weight _w) { super(_w); c = _c;} Color c;}class Pencil {}class Color { Color(String _s) { s = _s;} String s;}class Weight{ Weight(int _i) { i = _i;} int i; int get_i() { return i; }}

Page 29: Master’s Thesis Defense: Aspectual Concepts

A Simple Basket Example

Basket

FruitPencil

p f, f2

Orange

Weight Color

w c

String

sint i

Page 30: Master’s Thesis Defense: Aspectual Concepts

BasketVisitorclass BasketVisitor { int total;

public void start() {total = 0;

}

public int returnValue() {return total;

} void before(Weight w) {

total += w.get_i(); }}

Page 31: Master’s Thesis Defense: Aspectual Concepts

Basket Traversalaspect BasketTraversal {

ClassGraph default;

ClassGraph myClassGraph =

new ClassGraph(default, "from Basket to *");

Visitor BasketVisitor;

declare traversal t1(myClassGraph,BasketVisitor) :

"from Basket to Weight";

declare traversal t2(myClassGraph,BasketVisitor) :

"from Basket via Orange to Weight";

}

Page 32: Master’s Thesis Defense: Aspectual Concepts

Basket Mainclass BasketMain { static public void main(String args[]) throws Exception {

Basket b = new Basket(new Orange(new Color("orange"), new Weight(5)),

new Fruit( new Weight(10)), new Pencil() );

BasketVisitor bv = new BasketVisitor();b.t1(bv);int totalWeight = bv.returnValue();System.out.println("Total weight of basket = " + totalWeight);

b.t2(bv);

totalWeight = bv.returnValue();System.out.println("Total weight2 of basket = " + totalWeight);

}}

Karl J. Lieberherr:

Visitor object generation not automatic. More flexibility this way.

Karl J. Lieberherr:

Visitor object generation not automatic. More flexibility this way.

Page 33: Master’s Thesis Defense: Aspectual Concepts

Generated Code for Visitor

public aspect BasketTraversal { static BasketVisitor t1_visitor; public void Basket.t1(BasketVisitor v) { t1_visitor=v; t1_visitor.start(); t1(); } before(Weight host) :

call(public void t1*()) && target(host) { t1_visitor.before(host); } void Basket.t1() { t1_copy0(); }

Karl J. Lieberherr:

What is this?

Karl J. Lieberherr:

What is this?

Page 34: Master’s Thesis Defense: Aspectual Concepts

Basket Class Graph

Basket

FruitPencil

p f, f2

Orange

Weight Color

w c

String

sint i

Page 35: Master’s Thesis Defense: Aspectual Concepts

Generated Code for Traversal // traversal t1 : {source: Basket -> target: Weight} with { } public void Basket.t1_copy0(){ if (f != null) t1_copy0_crossing_f(); if (f2 != null) t1_copy0_crossing_f2(); } public void Basket.t1_copy0_crossing_f() { f.t1_copy0();} public void Basket.t1_copy0_crossing_f2() { f2.t1_copy0();} public void Fruit.t1_copy0(){ if (w != null) t1_copy0_crossing_w(); } public void Fruit.t1_copy0_crossing_w() { w.t1_copy0();} public void Weight.t1_copy0(){ } public void Orange.t1_copy0(){ super.t1_copy0(); } pointcut pointcut_t1() : call(public void t1*()); before () : pointcut_t1 () { System.out.println(thisJoinPoint); }

Page 36: Master’s Thesis Defense: Aspectual Concepts

System Architecture

• DAJ Main– Parses command line arguments– Manages the DAJ code generation phases

• Stub Generation– Generates stubs for traversal methods

• Traversal Generation Compilation– Compiles using ajc the stubs, user code, and

CreateClassGraph.java

Karl J. Lieberherr:

How are stubs different from traversals?

Karl J. Lieberherr:

How are stubs different from traversals?

Page 37: Master’s Thesis Defense: Aspectual Concepts

System Architecture

• Traversal Generation– Uses DJ, Java Reflection, and DemeterJ to

generate AspectJ traversal code

• Traversal Compilation– Compiles the generated traversal code with user

code

Page 38: Master’s Thesis Defense: Aspectual Concepts

System ArchitectureStub Generation

Traversal Generation Compilation

Traversal Generation

Traversal Compilation

DAJMain

methodcall

shell

shell

shell

Karl J. Lieberherr:

Do not mention shell scripts

Karl J. Lieberherr:

Do not mention shell scripts

Page 39: Master’s Thesis Defense: Aspectual Concepts

DAJ Process

Stub Generation

Traversal Files

Generated Stubs

Traversal Generation Compilation

Class Files

Class Files

Traversal Generation

Traversal Compilation

UserCode

CreateClassGraph.javaTraversalImplementation

Karl J. Lieberherr:

CreateClassGraph.java is provided by DAJ

Very confusing naming

What information is generated by each box: input files and output files and who provides them

Karl J. Lieberherr:

CreateClassGraph.java is provided by DAJ

Very confusing naming

What information is generated by each box: input files and output files and who provides them

Page 40: Master’s Thesis Defense: Aspectual Concepts

Future Improvements

• http://www.ccs.neu.edu/research/demeter/DAJ• Two syntax supported

– DJ/Java like style– AspectJ’s declare syntax

• Handle Collections– Traversal through Java Collections

• Handle interfaces– Traversal “correctly” for interfaces

Karl J. Lieberherr:

Correctly??

Karl J. Lieberherr:

Correctly??

Page 41: Master’s Thesis Defense: Aspectual Concepts

Four Graph Model of Programs

• Merging of graphs in Demeter and JPM

• Model for creating relationships between different features

• AOP feature analysis

• Only a proposal and needs lots of work

Page 42: Master’s Thesis Defense: Aspectual Concepts

4GMP

Compile-Time Runtime

Data Structures

Algorithm

ProgramProgram

Class GraphClass Graph Object GraphObject Graph

Static Call Graph

Static Call Graph Dynamic Call

Graph

Dynamic Call Graph

ExecutableExecutable ProcessProcess

Page 43: Master’s Thesis Defense: Aspectual Concepts

Compile-Time vs. Run-Time

• Compile-time graphs specify all possible run-time graphs

• The computer system combines the compile-time graph with input to generate the run-time graph

• In a way, the compile-time graph has factored out the commonalities within the run-time graph

• Factorizational Concern

Page 44: Master’s Thesis Defense: Aspectual Concepts

Factorizational Concern

Input

Specification

Processor Output

Page 45: Master’s Thesis Defense: Aspectual Concepts

Factorizational Concern

+

Page 46: Master’s Thesis Defense: Aspectual Concepts

Factorizational Concern Examples

• Functions that are used multiple times

• Inherited methods and data members

• Parser generation for DemeterJ

• Wildcards for pointcut designators in AspectJ

• Traversal generation in DAJ

Page 47: Master’s Thesis Defense: Aspectual Concepts

Data Structure vs. Algorithm

• One of many ways of slicing up a program– data flow / control flow– Layering– Modules

• It does not change the amount of code that one has to write

• Large programs are a fact of life and it needs to be organized in some way

• Organizational Concern

Page 48: Master’s Thesis Defense: Aspectual Concepts

Organizational Concern

Page 49: Master’s Thesis Defense: Aspectual Concepts

Organizational Concern Examples

• Functions that are called only once

• Non-inherited methods and data members

• Open classes in DemeterJ

• Introductions in AspectJ

Page 50: Master’s Thesis Defense: Aspectual Concepts

Factorizational/Organizational Concerns

• Most programming language features have both characteristics depending on their uses

• Both are needed to cope with the problem of programs growing ever larger

Page 51: Master’s Thesis Defense: Aspectual Concepts

Concern Relationship Diagram

• We may approximate relationships between features and the graphs in 4GMP

Page 52: Master’s Thesis Defense: Aspectual Concepts

Concern Relationship Diagram

Class GraphClass Graph Object GraphObject Graph

Static Call Graph

Static Call Graph

Dynamic Call Graph

Dynamic Call Graph

FC

FC

OC OC

Concern RelationshipFC = Factorizational Concern

OC = Organizational Concern

Page 53: Master’s Thesis Defense: Aspectual Concepts

AspectJ CRD

Class GraphClass Graph Object Graph

Object Graph

Static Call Graph

Static Call Graph

Dynamic Call Graph

Dynamic Call Graph

FC

FC

OC OC

FC = Factorizational Concern

OC = Organizational Concern

Introduction

Pointcut

Join Point

Aspect

Advice

SP = Specification Feature

SP

SP

SP

SP

FC

OC

OC

OC

OC

OC

SP

FC

Page 54: Master’s Thesis Defense: Aspectual Concepts

DemeterJ CRD

Class GraphClass Graph Object GraphObject Graph

Static Call Graph

Static Call Graph

Dynamic Call Graph

Dynamic Call Graph

FC

FC

OC OC

FC = Factorizational Concern

OC = Organizational Concern

FC

StrategyGraph

Class Dictionary

TraversalGraph

Visitor

Advice

OC

FC

FC

OC

FC

FC

Page 55: Master’s Thesis Defense: Aspectual Concepts

Ideal CRD

FeatureFC

FeatureFC

Feature

OC

Feature

OC

Page 56: Master’s Thesis Defense: Aspectual Concepts

Ideal CRD

FeatureFC

FeatureFC

Feature

OCOC

Page 57: Master’s Thesis Defense: Aspectual Concepts

What Good Are CRDs?

• CRD is a higher level feature map

• Allows designers to see imbalance of concerns

• Designers can fix these imbalances with appropriate features that address appropriate concerns

• Programming Feature Analysis!

Page 58: Master’s Thesis Defense: Aspectual Concepts

DemeterJ Feature Analysis

• CRD has many FC relations

• Possibly add features with OC relations to Class Dictionary, Strategy Graph, Traversal Graph

Page 59: Master’s Thesis Defense: Aspectual Concepts

DemeterJ CRD

Class GraphClass Graph Object GraphObject Graph

Static Call Graph

Static Call Graph

Dynamic Call Graph

Dynamic Call Graph

FC

FC

OC OC

FC = Factorizational Concern

OC = Organizational Concern

FC

StrategyGraph

Class Dictionary

TraversalGraph

Visitor

Advice

OC

FC

FC

OC

FC

OC

Page 60: Master’s Thesis Defense: Aspectual Concepts

AspectJ Feature Analysis

• CRD has many OC relations

• Possibly add features with FC relations to Aspect and Introductions

Page 61: Master’s Thesis Defense: Aspectual Concepts

AspectJ CRD

Class GraphClass Graph Object Graph

Object Graph

Static Call Graph

Static Call Graph

Dynamic Call Graph

Dynamic Call Graph

FC

FC

OC OC

FC = Factorizational Concern

OC = Organizational Concern

Introduction

Pointcut

Join Point

Aspect

Advice

SP = Specification Feature

SP

SP

SP

SP

FC

OC

OC

OC

OC

OC

SP

FC

Page 62: Master’s Thesis Defense: Aspectual Concepts

Problems With CRDs

• In what scope should one create CRDs?– Should AspectJ and DemeterJ CRDs account

for features in Java?

• Most features have FC and OC– How do I deal with these features?

Page 63: Master’s Thesis Defense: Aspectual Concepts

Other Types of Concerns

• Interface Concerns– When two entities within a program need to

communicate

– Abstract classes in OOP

– Interfaces in Java

• Specification Concerns– Things that programmers want to specify or reference

– Java reflections

– AspectJ joinpoints

Page 64: Master’s Thesis Defense: Aspectual Concepts

Questions

• What are the fundamental concepts behind AOSD in Demeter and AspectJ?

• How are these concepts related?

• Can these concepts be mixed?

• What are the fundamental problems that software language features attempt to solve?

Page 65: Master’s Thesis Defense: Aspectual Concepts

Conclusions

• Metaphors used in Demeter and JPM– Construction and Journey Metaphors– Usage of one or the other depends on the users

and application– Can describe each other– Mixable

Page 66: Master’s Thesis Defense: Aspectual Concepts

Conclusions

• DAJ– Mixing Demeter with AspectJ concepts– Uses DJ, DemeterJ and AspectJ– www.ccs.neu.edu/research/demeter/DAJ

Page 67: Master’s Thesis Defense: Aspectual Concepts

Conclusions

• Four Graph Model of Programs– Merges graphs in Demeter and AspectJ– Factorizational/Organizational Concerns– Concern Relationship Diagram– Programming Feature Analysis– Needs lots of work!

Page 68: Master’s Thesis Defense: Aspectual Concepts

Future Direction

• Try mixing other tools– ComposeJ, HyperJ, etc.

• Feature analysis of other tools and concepts

• Investigate other types of concerns

• Relationship between concerns relationships in features with HCI and SE

Page 69: Master’s Thesis Defense: Aspectual Concepts

References

• www.ccs.neu.edu/research/demeter/DAJ• www.ccs.neu.edu/research/demeter/DemeterJava• www.ccs.neu.edu/research/demeter/DJ• www.aspectj.org