1 / 24

For John

For John. DAJ (temporary name for AspectJ with traversals). planned to be added to AspectJ provides an efficient implementation of traversals using the AP library we have also added traversals to Java but implementation is very slow (using reflection)

trista
Télécharger la présentation

For John

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. For John

  2. DAJ (temporary name for AspectJ with traversals) • planned to be added to AspectJ • provides an efficient implementation of traversals using the AP library • we have also added traversals to Java but implementation is very slow (using reflection) • AspectJ + traversals > Java + traversals because AspectJ > Java

  3. Adding Demeter Traversals to AspectJ • Because the AspectJ join point model is a generalization of Demeter’s join point model, we can use the AspectJ pointcuts to express the traversal pointcuts for visitors. • declare ClassGraph • declare TraversalGraph • declare Behavior

  4. Traversal(t) pointcut • picks out all join points between the start and the end of the traversal that are needed for the traversal only, i.e. the node visits and the edge visits.

  5. Traversal Syntax Example aspect MyTraversal { ClassGraph defaultCG = new ClassGraph(); ClassGraph cg1 = new ClassGraph(defaultCG, “from CompoundFile to * bypassing ->*,tail,*”); declare traversal t1: “from CompoundFile to SimpleFile”; declare traversal t2(cg1): “from CompoundFile to *”; }

  6. Traversal Syntax Example aspect MyTraversal { declare visitors : VisitorInterface1; ClassGraph defaultCG = new ClassGraph(); ClassGraph cg1 = new ClassGraph(defaultCG, “from CompoundFile to * bypassing ->*,tail,*”); declare traversal t1(defaultCG): “from CompoundFile to SimpleFile”; declare traversal t2(cg1, VisitorInterface1): “from CompoundFile to *”; }

  7. Generate pointcuts / advice interface VisitorInterface1 { void before(Object host); void after(B host); void after(C source, D target); void around(A host); void start(); void finish(); }

  8. used = from EquationSystem via -> *,rhs,* to Variable M1: Equation System EquationSystem equations Equation_List Ident * lhs Equation Variable Numerical rhs Simple args Expression_List Expression S T * op Add Compound D B

  9. before_rhs < before ! Motivation for edge advice for each used variable v print the largest expression that contains v class LargestVisitor { Expression exp; void before_rhs(Object s, Expression t){ exp = t; }; void before(Variable v) { System.out.println(exp, v) } } from EquationSystem via -> *,rhs,* to Variable

  10. around < before ! from EquationSystem to Variable Motivation for edge advice class MarkVariableVisitor { boolean through_lhs; … void before(Variable v) { if (through_lhs) { … } else if (through_rhs) { … } }; void around_lhs(Subtraversal t){ through_lhs = true; t.proceed(); through_lhs = false; }; … } for each variable print whether it is used or defined

  11. Self-Contained Example • Java classes • Traversal file • Use traversal defined

  12. Basket Example Basket f p Pencil Fruit Orange w c Weight Color int i s String

  13. BasketMain.java class Weight{ Weight(int _i) { i = _i;} int i; int get_i() { return i; } } class Pencil {} class Color { Color(String _s) { s = _s;} String s; } class Basket { Basket(Fruit _f, Pencil _p) { f = _f; p = _p; } Fruit f; 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; }

  14. BasketMain.java class BasketMain { static public void main(String args[]) throws Exception { Basket b = new Basket( new Orange( new Color("orange"), new Weight(5)), new Pencil()); int totalWeight = b.totalWeight(); System.out.println("Total weight of basket = " + totalWeight); }}

  15. Traversals • Count the total weight within the basket • Traversal Strategy: “From Basket to Weight” • Visitor: Add up all the values within Weight

  16. Basket Example Traversal Graph Basket f p Pencil Fruit Orange w c Weight Color int i s String

  17. Two versions • define visitor using • AspectJ pointcuts and advice • Java visitor class complete with initialization, finalization and return value processing

  18. BasketTraversal.trv // traversals for basket aspect BasketTraversal { declare ClassGraph default; declare ClassGraph myClassGraph : default, "from Basket to * bypassing {->*,*,java.lang.String }"); declare traversal t2(myClassGraph) : "from Basket to Weight"; declare TraversalGraph t2 : myClassGraph, "from Basket to Weight"; }

  19. generated: BasketTraversal.java public aspect BasketTraversal { // traversal t2 : {source: Basket -> target: Weight} with { } public void Basket.t2(){ if (f != null) t2_crossing_f(); } public void Basket.t2_crossing_f() { f.t2();} public void Fruit.t2(){ if (w != null) t2_crossing_w(); } public void Fruit.t2_crossing_w() { w.t2();} public void Weight.t2(){ } public void Orange.t2(){ super.t2(); } pointcut pointcut_t2() : call(public void t2*()); before () : pointcut_t2 () { System.out.println(thisJoinPoint); } } // BasketTraversal for testing traversal code

  20. BasketMainCount.java // the aspect for counting the total weight of the basket aspect BasketMainCount { static int returnVal; int Basket.totalWeight() { returnVal = 0; t2(); return returnVal; } pointcut t2WeightPC(Weight weight) : call(* *t2*()) && target(weight); before(Weight weight) : t2WeightPC(weight) { returnVal += weight.get_i(); } }

  21. “visitor in Java” version BasketTraversal.trv // traversals for basket aspect BasketTraversal { declare ClassGraph default; declare ClassGraph myClassGraph : default, "from Basket to * bypassing {->*,*,java.lang.String }"); declare traversal Integer t2(myClassGraph, SumVis) : "from Basket to Weight"; }

  22. !!!!!!!!!!!!!!! Better “visitor in Java” version BasketTraversal.trv // traversals for basket aspect BasketTraversal { declare ClassGraph default; declare ClassGraph myClassGraph : default, "from Basket to * bypassing {->*,*,java.lang.String }"); declare TraversalGraph tg : myClassGraph, “from A to B”; // tg() declare Behavior void b1 : tg, Vis; //b1() declare Behavior Integer summing : myCg, “from A to B”, Vis; //b2() declare traversal Integer t2(myClassGraph, SumVis) : "from Basket to Weight"; }

  23. BasketMainCount.java // the aspect for counting the total weight of the basket aspect BasketMainCount { int Basket.totalWeight() { Integer retVal = summing(); return retVal.intValue(); } class SumVis { int retVal = 0; void before (Weight w) {retVal += weight.get_i();} Object returnVal() {return new Integer(retVal);} }

  24. Stub Java Files CreateClassGraph.java AspectJ Compiler Class Files Traversal Implementation and User Class Files Traversal Implementation Java Files AspectJ Compiler JVM Compilation Process Detail Traversal Files DAJ AspectJ Files

More Related