47
1 Expressiveness and Complexity of Crosscut Languages Karl Lieberherr, Jeffrey Palm and Ravi Sundaram Northeastern University FOAL 2005 presentation

Expressiveness and Complexity of Crosscut Languages

  • Upload
    garret

  • View
    48

  • Download
    0

Embed Size (px)

DESCRIPTION

Expressiveness and Complexity of Crosscut Languages. Karl Lieberherr, Jeffrey Palm and Ravi Sundaram Northeastern University FOAL 2005 presentation. Goal. Crosscut Languages are important in AOP Study them abstractly using expressions on graphs: lower bounds and upper bounds - PowerPoint PPT Presentation

Citation preview

Page 1: Expressiveness and Complexity of Crosscut Languages

1

Expressiveness and Complexity of Crosscut Languages

Karl Lieberherr, Jeffrey Palm and Ravi Sundaram

Northeastern UniversityFOAL 2005 presentation

Page 2: Expressiveness and Complexity of Crosscut Languages

2

Goal

• Crosscut Languages are important in AOP• Study them abstractly using expressions

on graphs: lower bounds and upper bounds• Assumption: know entire program or class

graph• Of interest to: AOSD language designers

and tool builders and mathematicians.

Page 3: Expressiveness and Complexity of Crosscut Languages

3

Regular Expressions on Graphs• Questions: Given G and reg. exp. r:

– Is there a path in G satisfying r? (SAT)– Do all paths in G that satisfy r contain n in G?

(ALWAYS)– Is there a path in G that starts with e and satisfies r?

(FIRST)• Questions: Given G and reg. exps r1 and r2:

– Is the set of paths in G satisfying r1 a subset of the set of paths satisfying r2? (IMPL)

• What has this to do with AOSD?

ALL PROBLEMSARE POLYNOMIAL

Generalizes regular expressions on strings:sentences must be node paths in graphs. Work by Tarjan and Mendelzon.

Page 4: Expressiveness and Complexity of Crosscut Languages

4

Enhanced Regular Expressions

• ERE = regular expressions (primitive, concatenation, union, star) with – complement/negation– nodes and edges

Page 5: Expressiveness and Complexity of Crosscut Languages

5

Canonical Crosscut Language

Enhanced Regular Expressions

AspectJ Pointcuts Traversal Strategies subset of XPath

Page 6: Expressiveness and Complexity of Crosscut Languages

6

Some PARC-Northeastern History about Crosscut Languages:

Enhanced Regular Expressions (ERE)>From [email protected] Thu Aug 31 13:33:57 1995 >To [email protected] (cc to Gregor, Crista and Jens Palsberg et al.)Subject: Re: Boolean and Regular We seem to be converging, but I still think that enhanced regular

expressions can express all of the operators. Here is the enhanced regular expression language from a while back:

Atomic expressions: A The empty traversal at class Alnk A link of type lnk ("any" is a special case of any link type)

For combining expressions, the usual regular expression crowd: . concatenation \cap intersection \cup union * repetition not negation

Page 7: Expressiveness and Complexity of Crosscut Languages

7

Same message continued:Demeter in ERE

[A,B] A.any*.B through edges any*.lnk.any* bypassing edges not(any*.lnk.any*) through vertices any*.A.any* bypassing vertices not(any*.A.any*) d1 join d2 [d1].[d2] d1 merge d2 [d1] \cup [d2] d1 intersect d2 [d1] \cap [d2] not d1 not([d1])

Page 8: Expressiveness and Complexity of Crosscut Languages

8

Enhanced Regular Expressions on Graphs

• Questions: Given G and reg. exp. r:– Is there a path in G satisfying r? (SAT)– Do all paths in G that satisfy r contain n in G?

(ALWAYS)– Is there a path in G that starts with e and satisfies r?

(FIRST) • Questions: Given G and reg. exps. r1 and r2:

– Is the set of paths in G satisfying r1 a subset of the set of paths satisfying r2? (IMPL)

• Ok, related to Demeter but how does AspectJ come in?

ALL PROBLEMSBECOME NP-COMPLETE

Page 9: Expressiveness and Complexity of Crosscut Languages

9

Page 10: Expressiveness and Complexity of Crosscut Languages

10

My responseFrom lieber Thu Aug 31 13:51:57 1995From: Karl Lieberherr <lieber>To: [email protected], [email protected]: Re: Boolean and RegularCc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]

Hi John:

yes, we agree. The operators of what I called Boolean algebra operatorsare just as well counted as regular expression operators.

I like your integration; have to think more about how expressive it is.

-- Karl CLAIM: ERE are the foundation for crosscut languages

Page 11: Expressiveness and Complexity of Crosscut Languages

11

Using ERE for AspectJ

AspectJk (a primitive)cflow(k)&&||!

EREmain any* kmain any* k any* \cap\cup!

Page 12: Expressiveness and Complexity of Crosscut Languages

12

We continue the study of crosscut languages

• and show that AspectJ pointcuts are equivalent to Demeter strategies and vice versa if you abstract from the unimportant details.

• we show the correspondence by direct translations in both directions.

Page 13: Expressiveness and Complexity of Crosscut Languages

13

Examples first

• Show two programs and their graph abstractions

Page 14: Expressiveness and Complexity of Crosscut Languages

14

class Example { // AspectJ program public static void main(String[] s) {x1(); nx1();} static void x1() { x2(); nx2(); } static void x2() { x3(); nx3(); } static void x3() { target(); } static void nx1() { x2(); nx2(); } static void nx2() { x3(); nx3(); } static void nx3() { target(); } static void target() {}}aspect Aspect { pointcut p1(): cflow(call (void x1())) || cflow(call (void nx2())) || cflow(call (void x3())); pointcut p2() : cflow(call (void nx1())) || cflow(call (void x2())); pointcut p3() : cflow(call (void x1())); pointcut p4() : cflow(call (void nx3())); pointcut all(): p1() && p2() && p3() && p4(); before(): all() && !within(Aspect) { System.out.println(thisJoinPoint); }}

x1

main

nx1

x2 nx2

x3 nx3

targetmain x1 x2 x3 target nx3 target…

Meta graph=Call graph

Instance treeCall tree

Selected by all()

Page 15: Expressiveness and Complexity of Crosscut Languages

15

class Main { // Java Program with DJ X1 x1; Nx1 nx1; public static void main(String[] s) { ClassGraph cg = new ClassGraph(); Main m = new Main(); cg.traverse(m, // m is the complete tree with 8 leaves "intersect(" + // union is expressed by concatenation of edges "{source: Main -> X1 X1 -> target: Target " + "source: Main ->Nx2 Nx2 -> target: Target " + "Main -> X3 X3 -> Target}," + "{source: Main -> Nx1 Nx1 -> target: Target " + "Main -> X2 X2 -> Target}," + "{source:Main -> X1 X1 -> target: Target}," + "{source:Main -> Nx3 Nx3 -> target: Target})", new Visitor(){ public void start (){System.out.println(" start traversal");} public void finish (){System.out.println(" finish traversal");} void before (Target host){System.out.print(host + ' ');} void before (Nx3 host) {System.out.print(host + ' ');} void before (X2 host) {System.out.print(host + ' ');} void before (X1 host) {System.out.print(host + ' ');} });}}class X1 { X2 x2; Nx2 nx2; } class Nx1 { X2 x2; Nx2 nx2; }class X2 { X3 x3; Nx3 nx3; } class Nx2 { X3 x3; Nx3 nx3; }class X3 { Target t; } class Nx3 { Target t; }class Target {}

X1

Main

Nx1

X2 Nx2

X3 Nx3

TargetMain X1 X2 X3 Target Nx3 Target…

Meta graph=Class graph

Instance treeObject tree

Selected by strategy

Page 16: Expressiveness and Complexity of Crosscut Languages

16

Crosscut Language SAJ

S ::= a set of nodesk | set of nodes having label kflow(S) | set of nodes reachable from SS | S | unionS & S | intersection!S complement

base language

Page 17: Expressiveness and Complexity of Crosscut Languages

17

Crosscut language SD

D ::= a set of paths[A,B] | paths from A to BD . D | concatenation of pathsD | D | union of pathsD & D | intersection of paths!D complement of paths

base language

Page 18: Expressiveness and Complexity of Crosscut Languages

18

Instance Tree

J is called an instance tree of graph G, if J is a tree, Root(J)=Start(G) and for each edge e=(u,v) in E(J), there is an edge e’ = (u’, v’) in G so that Label(u)=Label(u’) and Label(v)=Label(v’). J is a rooted tree with edges directed away from the root. (think of Label = Class)

Page 19: Expressiveness and Complexity of Crosscut Languages

19

Expressions on GraphsExpressions on Instances

• Questions: Given graph G and r: Exists J sat G:– Is there a path in J satisfying r?– For a given node m in G: Do all paths in J that satisfy r

contain a node n in J with Label(n) = m?– Is there a path in J that starts with e and satisfies r?

• Questions: Given G and r1 and r2: Exists J sat G:– Is the set of paths in J satisfying r1 a subset of the set

of paths satisfying r2?

push down to instances

Page 20: Expressiveness and Complexity of Crosscut Languages

20

Expressions on instances

• Questions: Given graph G, r and instance J satisfying G:– Determine the set of edges e from Root(J) so

that there is a path in J starting with e and satisfying r?

Page 21: Expressiveness and Complexity of Crosscut Languages

21

Connections between SAJ and SD

SAJ• selects set of nodes

in tree (but there is a unique path from root to each node)

• set expression flavor

SD• selects set of paths in

tree• regular expression

flavor

Page 22: Expressiveness and Complexity of Crosscut Languages

22

Equivalence of node sets and path sets

In a rooted tree, such as an instance tree, there is a one-to-one correspondence between nodes, and, paths from the root, because there is a unique path from the root to each node.

We say a set of paths P is equivalent to a set of nodes N if for each n in N there is a path p in P that starts at the root and ends at n and similarly for each p in P it is the case that p starts at the root and ends in a node n in N.

Page 23: Expressiveness and Complexity of Crosscut Languages

23

Theorem 1

• A selector expression in SD (SAJ) can be transformed into an expression in SAJ (SD) in polynomial-time, such that for all meta graphs and instance trees the set of paths (nodes) selected by the SD (SAJ) selector is equivalent to the set of nodes (paths) selected by the SAJ (SD) selector.

Page 24: Expressiveness and Complexity of Crosscut Languages

24

Proof: T: SD to SAJ

SDT([A,B])T(D1.D2)T(D1 | D2)T(D1 & D2)!D

SAJflow(A) & Bflow(T(D1)) & T(D2)T(D1) | T(D2)T(D1) & T(D2)!T(D)

Page 25: Expressiveness and Complexity of Crosscut Languages

25

Proof

SAJT(k)

SDStart(G)

Page 26: Expressiveness and Complexity of Crosscut Languages

26

class Example { // AspectJ program public static void main(String[] s) {x1(); nx1();} static void x1() {if (false) x2(); nx2(); } static void x2() { if (false) x3(); nx3(); } static void x3() { if (false) target(); } static void nx1() {if (false) x2(); nx2(); } static void nx2() {if (false) x3(); nx3(); } static void nx3() {if (false) target(); } static void target() {}}aspect Aspect { pointcut p1(): cflow(call (void x1())) || cflow(call (void nx2())) || cflow(call (void x3())); pointcut p2() : cflow(call (void nx1())) || cflow(call (void x2())); pointcut p3() : cflow(call (void x1())); pointcut p4() : cflow(call (void nx3())); pointcut all(): p1() && p2() && p3() && p4(); before(): all() && !within(Aspect) { System.out.println(thisJoinPoint); }}

x1

main

nx1

x2 nx2

x3 nx3

targetmain x1 x2 x3 target nx3 target…

Meta graph

Instance tree

Selected by all()

APPROXIMATION

Page 27: Expressiveness and Complexity of Crosscut Languages

27

Computational Properties

• Select-Sat: Given a selector p and a meta graph G, is there an instance tree for G for which p selects a non-empty set of nodes.

• X/Y/Z– X is a problem, e.g., Select-Sat– Z is a language, e.g. SAJ or SD– Y is one of -,&,! representing a version of Z.

• X/-/Z base language of Z. • X/&/Z is base language of Z plus intersection. • X/!/Z is base language of Z plus negation.

Page 28: Expressiveness and Complexity of Crosscut Languages

28

Approximation and Computational Properties

• Not Select-Sat: Given a selector p and a meta graph G, for all instance trees for G selector p selects an empty set of nodes, i.e. p is useless.

• If Not Select-Sat(p,G)/*/SAJ holds then also for the original Java program the selector p (pointcut) is useless.

Page 29: Expressiveness and Complexity of Crosscut Languages

29

Same results for 5 problems

• We don’t know yet how to unify all the proofs.

• So we prove the results separately.

Page 30: Expressiveness and Complexity of Crosscut Languages

30

Results (Problem)

Problem SD SAJ

- P P

& NP-complete NP-complete

! NP-complete NP-complete

Page 31: Expressiveness and Complexity of Crosscut Languages

31

Results (Problem)

• Results(Select-Sat)• Results(Not Select-Impl)• Results(Select-First)• Results(Not Select-Always)• Results(Not Select-Never)

Page 32: Expressiveness and Complexity of Crosscut Languages

32

Select-Sat

• Select-Sat/&/SAJ is NP-complete• This is unexpected because we have only

primitive pointcuts (e.g., call), cflow, union and intersection. Looks like Satisfiability of a monotone Boolean expression which is polynomial.

Page 33: Expressiveness and Complexity of Crosscut Languages

33

Page 34: Expressiveness and Complexity of Crosscut Languages

34

An idea by Gregor

• add a new primitive pointcut to AspectJ: traversal(D).

• cflow(call (void class(traversal({A->B})). foo())) && this(B)– in the cflow of a call to void foo() of a class

between A and B and the currently executing object is of class B.

Page 35: Expressiveness and Complexity of Crosscut Languages

35

Combining SAJ and SD

• Extend SD with [A,*]: all nodes reachable from A

• Replace in SAJ: flow(S) by nodes(D)• Can simulate flow(S): use [X,*] for each X

in S and take the union.

Page 36: Expressiveness and Complexity of Crosscut Languages

36

Crosscut Language SAJ/SD

S ::= a set of nodesk | set of nodes having label knodes(D) | set of nodes selected by D in SDS | S | unionS & S | intersection!S complement

SAJ/SD seems interesting. Have both capabilities of AspectJ pointcutsand Demeter traversals.This is basically what Gregor Kiczales suggested a few years ago:he called ittraversal(D), instead of nodes(D).

Page 37: Expressiveness and Complexity of Crosscut Languages

37

Crosscut language SD

D ::= a set of paths[A,B] | paths from A to BD . D | concatenation of pathsD | D | union of pathsD & D | intersection of paths!D complement of paths

Page 38: Expressiveness and Complexity of Crosscut Languages

38

Mathematics for AOP

string graph/instance tree

class graph/instance tree

reg. exp. Kleene Mendelzon (SIAM Comp. 95, no instance trees)

Palsberg/Xiao/Lieberherr (TOPLAS 95)

e. reg. exp Kleene PARC/Northeastern (summer 95)Palsberg/Patt-Shamir/ Lieberherr (96)

Palsberg/Patt-Shamir/Lieberherr (96)Palm/Sundaram/ Lieberherr (04)

strategy graph

? Patt-Shamir/ Orleans/Lieberherr (97,05)

Patt-Shamir/ Orleans/Lieberherr (97, 05)Wand/Lieberherr (01)

Page 39: Expressiveness and Complexity of Crosscut Languages

39

SAT: is there a path in G satisfying r?

graph G/instance tree

class graph G/instance tree

reg. exp. r Mendelzon (SIAM J. Comp. 95, no instance trees): polynomial

Palsberg/Xiao/Lieberherr (TOPLAS 95): polynomial (special case)

e. reg. expr

PARC/Northeastern (summer 95)Palm/Sundaram/ Lieberherr (04): NP-complete

Palm/Sundaram/ Lieberherr (04): NP-complete

strategy graph r

Patt-Shamir/ Orleans/Lieberherr (97,05): polynomial

Patt-Shamir/ Orleans/Lieberherr (97, 05): polynomial

Page 40: Expressiveness and Complexity of Crosscut Languages

40

SAT: is there a path in G satisfying r?

graph G/instance tree

class graph G/instance tree

reg. exp. r Mendelzon (SIAM J. Comp. 95, no instance trees): polynomial

Palsberg/Xiao/Lieberherr (TOPLAS 95): polynomial (special case)

e. reg. expr

PARC/Northeastern (summer 95)Palm/Sundaram/ Lieberherr (04): NP-complete

Palm/Sundaram/ Lieberherr (04): NP-complete

strategy graph r

Patt-Shamir/ Orleans/Lieberherr (97,05): polynomial

Patt-Shamir/ Orleans/Lieberherr (97, 05): polynomial

Page 41: Expressiveness and Complexity of Crosscut Languages

41

SAT: is there a path in G satisfying r?

graph Greg. exp. poly.e. reg. exp. NPC (add negation)strat. graph poly.e. strat. graph NPC (add intersection/negation)SAJ (AspectJ) NPCSD (Demeter) NPCSAJ-base poly. (without intersection)SD-base poly. (without intersection)

results identical for class graphs

Page 42: Expressiveness and Complexity of Crosscut Languages

42

Abbreviations

Language Abbreviationregular exp. REenhanced regular exp. EREstrategy graph SGenhanced strategy graph ESGSAJ (AspectJ) SAJSD (Demeter) SDSAJ-base SAJBSD-base SDB

Page 43: Expressiveness and Complexity of Crosscut Languages

43

Polynomial Translations

• We want to know which languages are fundamental. We conjecture that all languages can be translated in polynomial time into ERE. Maybe we also need ESG?

• The translations must preserve the meaning: – same set of nodes or – same set of paths or – set of paths corresponding to a set of nodes or – set of nodes corresponding to a set of paths.

Page 44: Expressiveness and Complexity of Crosscut Languages

44

Motivation for polynomial translations

• If a large number of languages can be translated efficiently to ERE, we only need an efficient implementation for ERE.

• Currently the AP Library uses SG with intersection. If we would add complement, the AP Library would use ESG.

Page 45: Expressiveness and Complexity of Crosscut Languages

45

Polynomial Translations ( any mistakes?)

RE ERE SG ESG SAJ SD SAJB SDB

RE Y Y Y N NERE NN NSG YESG NN NSAJ Y Y Y N NSD Y Y Y N NSAJB Y Y Y Y YSDB Y Y Y Y NN

translate row to column N: no, unless P=NP; NN: no

Page 46: Expressiveness and Complexity of Crosscut Languages

46

Discussion

• some results are trivial: an RE sentence is trivially an ERE sentence.

• an ERE sentence can not be translated in polynomial time to an RE sentence because negation cannot be simulated by union et al.

• An SAJ sentence cannot be translated to an SDB sentence in polynomial time because otherwise P=NP (consider SAT).

Page 47: Expressiveness and Complexity of Crosscut Languages

47

Assignments

• We want to fill in all 64 entries and have a proof for them. This is a good opportunity for a beginning PhD student.

• Yuantai: please can you do the upper triangle.

• Jingsong: please can you do the lower triangle.