1 / 32

Debugging Support for Aspect-Oriented Program Using Program Slicing and Call Graph

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. Overview. Aspect-Oriented Programming AOP’s advantage and disadvantages

raleigh
Download Presentation

Debugging Support for Aspect-Oriented Program Using Program Slicing and Call Graph

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. 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. 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. 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. 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. 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. when a method is executed, logger.logs(v) is called. A.foo(int v) A.foo(int v) Logger.logs(“A.foo”); Logging Aspect Logging Class B.foo(int v) B.foo(int v) Logger.logs(“C.foo”); C.foo(int v) C.foo(int v)

  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. 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. Our Approach • Debugging Support • esp. fault localization (investigation) task • Extending Program Slicing for AOP • Program Slicing is a technique to aid fault localization.

  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. 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; a slice based on slice criteria(6, b)

  10. Data Dependence 1: a = 1; 2: c = 4; 3: b = a; a Control Dependence 4: if (a < 1) { 5: b = a; 6: } Program Dependence Graph 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 slice criterion

  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. 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. Control Flow Modified by Aspect A method call statement the part of around advice a.foo(); proceed a path without proceed a.foo(); Advices executed for each method call after advice call after: call(A.foo()) {...} the rest part of the around advice around: call(A.foo()) {...}

  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. 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. Screenshot

  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. 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. 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. When a node is skipped, Print Aspect’s advice is also skipped. Reset flags after evaluation Excluded because flags do not affect the output.

  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. Average Working Time (Unit: Minutes)

  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. 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. Any questions/comments ?

  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. Overview of Aspects Relation • Two aspects included in the program slice. • Print and Cleanup are dominated by Caching included in the Slice join point: visit a node ②around call Caching recursive call ① before, after ③proceed ⑤after visit method body ④after Cleanup LoopDetect Print

  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. 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. 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. A calculated slice: void f1() { x = f2();  : } int f2() { return doSomething(); } int f3() { return doSomething2(); } aspect redirectMethodCall { int around(): call(f2) { return f3(); } } Modified Dependence Relation void f1() { x = f2();  : } int f2() { return doSomething(); } int f3() { return doSomething2(); } aspect redirectMethodCall { int around(): call(f2) { return f3(); } } A developer tracks: An advice replaces a method call

  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. 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. Call Graph Example 凡例 Aspect Class call An inifnite loop

More Related