Presentation is loading. Please wait.

Presentation is loading. Please wait.

Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Debugging Support.

Similar presentations


Presentation on theme: "Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Debugging Support."— Presentation transcript:

1 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Debugging Support for Aspect-Oriented Program Using Program Slicing and Call Graph Takashi Ishio, Shinji Kusumoto, Katsuro Inoue Osaka University {t-isio, kusumoto, inoue}@ist.osaka-u.ac.jp

2 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 2 Overview Aspect-Oriented Programming AOP’s advantage and disadvantages Difficulties in debugging AOP program Proposed Method Program Slicing extended for AOP Loop Detection based on Call Graph (not included in this presentation) Implementation Evaluation Conclusion

3 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 3 Aspect-Oriented Programming Key Idea: Separation of crosscutting concerns In OOP, programmers cannot encapsulate crosscutting concerns: logging, error handling, transactions, security,... Code for object interaction is scattered to related classes. It is hard to manage scattered code. In AOP: A crosscutting concern == An aspect When a concern is changed, programmers modify one aspect instead of related classes.

4 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 4 AspectJ, an AOP extension for Java AspectJ: an AOP extension for Java An aspect is defined as a set of advices. Advice: a procedure + a condition when the procedure is executed. A condition = before or after specific events, or instead of the events (around). Around advice uses proceed keyword to execute the original event. Events are specified by Pointcut Designators (PCDs) including: –Method Call and Execution –Field Assignment and Reference –Exception Handling A procedure is written in plain Java with thisJoinPoint object representing the event information.

5 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 5 Simple Example of Aspect aspect LoggingExample { after(): execution(void *.foo(int)) { Logger.logs(thisJoinPoint.getSignature()); } } An advice knows when the advice is executed. Call statements in classes are removed. C.foo(int v) B.foo(int v) A.foo(int v) Logging Class Logging Aspect C.foo(int v) B.foo(int v) A.foo(int v) Logger.logs(“A.foo”); when a method is executed, logger.logs(v) is called. Logger.logs(“C.foo”);

6 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 6 Advantages of AOP AOP improves: Maintainability Programmers change one aspect instead of multiple classses. Reusability Programmers can reuse classes and aspects independently. –Reuse classes without aspect, or –Reuse aspects for other classes

7 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 7 Disadvantages of AOP AOP is useful, but... several drawbacks exist. Fault localization is difficult since: A programmer needs to investigate related classes and aspects to understand the system behavior. When a class is affected by several aspects, the result is hard to predict. e.g. Logging + Transaction  ??? A transaction process is logged, or Logging is transactional, or... ? The result depends on the definition of aspects, or compiler/interpreter implementation

8 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 8 Our Approach Debugging Support esp. fault localization (investigation) task Extending Program Slicing for AOP Program Slicing is a technique to aid fault localization.

9 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 9 Program Slicing Program Slicing extracts a slice of codes, which affects the value of a specific variable. Program Slicing excludes unrelated codes to aid fault localization. a slice based on slice criteria ( 6, b ) 1: a = 5; 2: b = a + a; 3: if (b > 0) { 4: c = a; 5: } 6: d = b; 1: a = 5; 2: b = a + a; 3: if (b > 0) { 4: c = a; 5: } 6: d = b;

10 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 10 Slice Calculation Process Phase 1: Extraction of dependence relations Data: assignment  reference Control: conditional statement  controlled block Phase 2: Construction of Program Dependence Graph node: a statement. edge: a dependence relation Phase 3: Traversal of PDG traversal backward from a node corresponding a slice criterion 1: a = 1; 2: c = 4; 3: b = a; 1: a = 1; 2: c = 4; 3: b = a; a Data Dependence 4: if (a < 1) { 5: b = a; 6: } 4: if (a < 1) { 5: b = a; 6: } Control Dependence Program Dependence Graph slice criterion

11 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 11 DC-Slicing for OOP DC-Slicing: a slicing method combining static and dynamic information. control dependence relations  static analysis data dependence relations  dynamic analysis Dynamic information is used for data dependence analysis to distinguish object instances method call analysis to solve polymorhpic method calls Size and Cost: Size: Dynamic Slice < DC-slice < Static Slice Cost: Static Slice < DC-slice < Dynamic Slice

12 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 12 DC-Slicing Extended for AOP Basic Idea: Advice Execution is similar to Method Call An advice is executed when a condition is satisfied.  A statement which satisfies a condition calls the advice. AspectJ Developement Tools plug-in indicates an advice execution as a marker. Extending PDG and Call Graph Advice Call Vertex and Advice Execution Edge A vertex is inserted into the place of the statement which calls an advice An edge connected to an advice body

13 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 13 Control Flow Modified by Aspect a.foo(); after: call(A.foo()) {...} around: call(A.foo()) {...} the part of around advice proceed after advice call the rest part of the around advice a path without proceed A method call statement Advices executed for each method call

14 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 14 Dynamic Elements in AOP Dynamic Pointcut: if, cflow if(expr): When expr is true, the advice is executed. cflow(PCD): all events reached from PCD cflow( execution(C.foo() ) ) == all events during C.foo() is executing. Converted to an advice call with “may be executed” control dependence relation. We use dynamic information to resolve dynamic pointcut.

15 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 15 Implementation Slicing tool as an Eclipse plug-in Environment: Eclipse 2.1 + AspectJ 1.0.6 Integrated Function: PDG construction –[Compile]-[Rebuild All] constructs PDG –A call graph is also constructed. –A method call loop including advices is recorded as “infinite loop candidates”. Slice Calculation –is started by a button of a tool bar –calculates a slice and indicates a slice on the text editor. Dynamic Analysis is not integerated to IDE. Dynamic analysis code is also inserted using AspectJ. A programmer need to execute a program once.

16 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 16 Screenshot

17 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 17 Experiment Debugging Experiment We have 12 students debug an AspectJ program. All students have used Java, but not AspectJ. devided into two groups; a group working with a program slice, another without the slice Environment: Eclipse 2.1 + AspectJ Development Tools Procedure: A lecture for using Eclipse Debugging a Java program using Eclipse. (PRE1) A lecture for AspectJ Write an AspectJ program using Eclipse. (PRE2) Debugging a AspectJ program using Eclipse. (DEBUG)

18 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 18 Debugged Program An AspectJ Program “Eval Expression” Input: an expression represented by a graph. An evaluation = graph traversal Output: (* (+ 2 3) (+ 2 3) ) = 25 5 classes (Graph nodes) and 4 aspects, 340 LOC Loop Detection, Caching, Print, Cleanup The program contains a bug. Print Aspect generates a String representation of a graph. But the generated string is incorrect in several test cases. Gives test cases to all students. Gives a program slice to one group (6 students). The variable contains the output is specified as a slice criterion.

19 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 19 A fragment of program slice public aspect CachingAspect { // member of this Aspect static private Set workers = new HashSet(); // add a member to Worker class private boolean Worker.isAlreadyCalculated = false; pointcut work_call() : call(void Worker.work()); pointcut first_work_call() : work_call() && !cflowbelow(work_call()); void around(): work_call() { Worker w = (Worker)thisJoinPoint.getTarget(); if (w.isAlreadyCalculated) return; else { proceed(); w.isAlreadyCalculated = true; workers.add(w); } // clear the flag when calculation process is finished after(): first_work_call() { for (Iterator it = workers.iterator(); it.hasNext(); ) { Worker w = (Worker)it.next(); w.isAlreadyCalculated = false; } workers.clear(); } When a node is already visited, return the value of the node. Otherwise, visit the node and set a “visited” flag. Reset flags after evaluation When a node is skipped, Print Aspect’s advice is also skipped. Excluded because flags do not affect the output.

20 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 20 Result Effectiveness is evaluated based on working time. Program slicing is used only “DEBUG” task. Students working with a program slice completed DEBUG task faster than students without a slice. However, the effectiveness is not statistically confirmed. Group PRE1 (Java) PRE2 (AspectJ) DEBUG (AspectJ) 1 (without a slice)150186200 2 (with a slice)200210190 Average Working Time (Unit: Minutes)

21 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 21 Discussion From an interview to the students: A program slice is useful to investigate the problem. A slice is a good starting point to read a program. A slice is used to reduce the scope of investigation. “unrelated aspects” is very useful information. A program slice is not useful to fix a problem. A programmer must investigate the influence of the modification to fix a problem. Changes of classes and aspects may affect other aspects.  Other methods such as impact analysis should be combined to support bug-fixing task.

22 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 22 Conclusion Debugging Support for AOP Key Idea: Advice Execution == Method Call Loop Detection using Call Graph Application of Program Slicing Program Slicing indicates dependence relations changed by aspects is effective to localize a fault. Future Work Visualization of Inter-aspect relations for large-scale software Combining other technique to fix a fault, e.g. impact analysis

23 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 23 Any questions/comments ?

24 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 24 Applicability Our program slicing extension is based on Join Point Model. Dynamic slicing for Java byte-code is also applicable. However, join point shadows are embedded into the byte code. It is hard to untangle byte-code without aspect information.

25 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 25 Overview of Aspects Relation Two aspects included in the program slice. Print and Cleanup are dominated by Caching Caching LoopDetect Cleanup Print included in the Slice join point: visit a node ② around call visit method body ③ proceed recursive call ① before, after ④ after ⑤ after

26 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 26 Collected Data Students submitted: What causes a problem How to fix a problem Modified Source Code Time requried to complete the work Thought about Program Slicing

27 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 27 Experiment 1: Applying tool Apply program slicing to 5 AspectJ design pattern implementation. Evaluate analysis cost Target: 5 Design Pattern implementation in AspectJ Observer, ChainOfResponsibility,... Average size: about 500 lines of code Test: Execute a sample code, and calculates a slice specify a output variable as a slice criterion. Comparation to AJDT’s marker

28 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 28 Evaluation Program slicing reduces complexity Aspects added dependence relations. tracking by hands is costly since relations crosscutting many modules (files). Slice can indicates a lost of dependence relations. A statement skipped by an aspect (e.g. around advice)

29 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 29 Modified Dependence Relation void f1() { x = f2(); : } int f2() { return doSomething(); } int f3() { return doSomething2(); } aspect redirectMethodCall { int around(): call(f2) { return f3(); } void f1() { x = f2(); : } int f2() { return doSomething(); } int f3() { return doSomething2(); } aspect redirectMethodCall { int around(): call(f2) { return f3(); } A calculated slice: A developer tracks: An advice replaces a method call

30 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 30 Analysis Cost Time Static analysis = a traversal to AST generated by compiler. Dynamic analysis: executes a program with dynamic analysis. The performance depends on a target program and a test case. about 2 times longer than normal execution on the average. Memory The analysis cost depends on a number of join points affected by aspects. Analyze 10000 LOC Java Code  20MB + 1000 LOC Aspect Logging All Events  100MB required ! Too many method calls, executions, field set and get are extracted.

31 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 31 Dynamic Analysis Aspect We implement dynamic analysis using AspectJ. Dynamic analysis aspect records a position of the assignment statement when a new value is assigned to a field, extracts a dynamic data dependence relation when the field is referred, collects method-call information for each thread (multi- threading), collects information when an exception is thrown and which handling clause caught the exception (exception- handling).

32 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 32 Call Graph Example Aspect Class call 凡例 An inifnite loop


Download ppt "Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 1 Debugging Support."

Similar presentations


Ads by Google