Aspect-Oriented Software Development (Advanced Object-Oriented Systems) COM 3362 Fall 2002 Homework 4 ========== Note: AOOS = /home/lieber/.www/com3362/w02/ = http://www.ccs.neu.edu/home/lieber/com3362/w02/ Due date: Feb. 5 Acknowledgements: Homework first implemented and tested by Pengcheng Wu. PART 1: Caching: An Optimization Aspect Consider the program in directory $AOOS/hw/4/container which implements a container checking problem in a recursive style. (An iterative solution some of you have seen in COM 3360 is in: /proj/demeter/lieber/courses/com1205-w02/hw/3/onlyDJ-capacity-with-stack) In the recursive solution the traversal methods return a value and the traversal results of the subtraversal are combined at each node. PART 1a: You implement a caching aspect as follows: Cache the value of the sum for each container and the number of violations. If the same container is checked again and there has been no change, we can reuse the cached values. Modify the weights of some of the Item-objects and invalidate the appropriate cached values. Recheck the container and make sure that the result is still correct. Can the caching aspect (an optimization aspect) be written so that no change is needed to the base program? The answer is positive. PART 1b: Is the given program in $AOOS/container free of caching issues? Not completely! To invalidate the cached values you need the capability to go up the containment hierarchy. If you don't cache, you don't need those back pointers. Rewrite $AOOS/container with a back pointer aspect and use it together with your caching aspect. This will make your base program cleaner and the back pointer aspect can also be used for other purposes than caching. PART 1c: Explore the design space for the caching aspect. You can either use a Hashtable or you can store the values directly in the Container-objects. Implement both versions in AspectJ. PART 1d: From all the above programs that you have developed choose the one that you consider as the best solution and focus on using abstract aspects that are reusable in other contexts. Discuss the reusability of your abstract aspects. PART 2: Graph connections: proposed by John Sung In AspectJ and Demeter we work with static/dynamic call graphs and class/object graphs. How are the static/dynamic call graphs and class/object graphs related during an execution of a program? Discuss the various connections between these graphs. PART 3: Planning to extend AspectJ PART 3a: Translate the following to AspectJ and test the aspect with a concrete Java program having classes A,R,S,B and at least one extra class between A and R and S and B. aspect SimulateTraversal { int count = 0; // introductions of traversal methods // traversal t = from a1:A through ->R,x,S to b1:B UNKNOWN1 // pointcuts // visiting node A pointcut visiting_A(A a1) : call(UNKNOWN2) // should be traversal(t) && target(a1); // visiting node B pointcut visiting_B(B b1) : call(UNKNOWN3) && target(b1); // crossing edge named x from R to S pointcut crossing_x(R r1, S s1) : call(UNKOWN4) // should be crossing(x) && this(r1) && target(s1); // transporting A-object down to B-object pointcut AandB(A a1, B b1): cflow(visiting_A(a1)) && visiting_B(b1); // advice before (A a1) : visiting_A(a1) {print(a1);} before (A a1, B b1) : AandB(a1, b1) {print(b1); print(a1); count++;} after (A a1) : visiting_A(a1) {print(count);} } PART 3b: Implement the aspect SimulateTraversal without cflow. PART 3c: Propose a better grammar for writing aspects involving traversals. Consider new pointcut designators traversal(t) and crossing(e) where t is a traversal name and e is the name of a field. It should be possible to do things like: traversal(t) && get(Signature): to capture all field accesses during a traversal. traversal(t) && cflow(call(* f(..))): all join points in the traversal reachable from a call of f. Consider the DJ tool, alpha version, developed by Pengcheng Wu. http://www.ccs.neu.edu/home/lieber/com1205/w01/materials/html/alpha.html DJ expresses sets of join points in traversals. Describe how you would simulate those pointcuts in AspectJ using the new traversal(t) and crossing(e) pointcuts.