32
1 Software Engineering Laboratory, Department of Computer Science, Graduate School of Information Science and Technology, Osaka University 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

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

  • Upload
    raleigh

  • View
    51

  • Download
    0

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

Citation preview

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

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

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

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

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

Overview

Aspect-Oriented ProgrammingAOP’s advantage and disadvantagesDifficulties in debugging AOP program

Proposed MethodProgram Slicing extended for AOPLoop Detection based on Call Graph

(not included in this presentation)

ImplementationEvaluationConclusion

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

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

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 aspectWhen a concern is changed, programmers modify one aspect instead of related classes.

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

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

AspectJ, an AOP extension for Java

AspectJ: an AOP extension for JavaAn 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.

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

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

Simple Example of Aspectaspect 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”);

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

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

Advantages of AOP

AOP improves:Maintainability

Programmers change one aspect instead of multiple classses.

ReusabilityProgrammers can reuse classes and aspects independently.

– Reuse classes without aspect, or– Reuse aspects for other classes

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

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

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

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

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

Our Approach

Debugging Supportesp. fault localization (investigation) task

Extending Program Slicing for AOPProgram Slicing is a technique to aid fault localization.

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

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

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;

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

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

Slice Calculation ProcessPhase 1: Extraction of dependence relations

Data: assignment referenceControl: conditional statement controlled block

Phase 2: Construction of Program Dependence Graph

node: a statement.edge: a dependence relation

Phase 3: Traversal of PDGtraversal backward from a nodecorresponding 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 DependenceGraph

slice criterion

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

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

DC-Slicing for OOPDC-Slicing:

a slicing method combining static and dynamic information.control dependence relations static analysisdata dependence relations dynamic analysis

Dynamic information is used fordata dependence analysis

to distinguish object instances

method call analysisto solve polymorhpic method calls

Size and Cost:Size: Dynamic Slice < DC-slice < Static SliceCost: Static Slice < DC-slice < Dynamic Slice

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

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

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 GraphAdvice Call Vertex and Advice Execution Edge

A vertex is inserted into the place of the statement which calls an adviceAn edge connected to an advice body

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

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

Control Flow Modified by Aspect

a.foo();

a.foo();

after: call(A.foo()) {...}

around: call(A.foo()) {...}

the part ofaround advice

proceed

after advice call

the rest part of the around advice

a path withoutproceed

A method call statement

Advices executed for each method call

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

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

Dynamic Elements in AOP

Dynamic Pointcut: if, cflowif(expr): When expr is true, the advice is executed.

cflow(PCD): all events reached from PCDcflow( 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.

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

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

ImplementationSlicing tool as an Eclipse plug-in

Environment: Eclipse 2.1 + AspectJ 1.0.6Integrated 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.

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

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

Screenshot

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

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

ExperimentDebugging 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 EclipseDebugging a Java program using Eclipse. (PRE1)A lecture for AspectJWrite an AspectJ program using Eclipse. (PRE2)Debugging a AspectJ program using Eclipse. (DEBUG)

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

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

Debugged ProgramAn AspectJ Program “Eval Expression”

Input: an expression represented by a graph.An evaluation = graph traversalOutput: (* (+ 2 3) (+ 2 3) ) = 25

5 classes (Graph nodes) and 4 aspects, 340 LOCLoop 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.

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

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

A fragment of program slicepublic aspect CachingAspect {

// member of this Aspectstatic private Set workers = new HashSet();

// add a member to Worker classprivate 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 finishedafter(): first_work_call() {

for (Iterator it = workers.iterator(); it.hasNext(); ) {Worker w = (Worker)it.next();w.isAlreadyCalculated = false;

}workers.clear();

}}

When a node is alreadyvisited, 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 becauseflags do not affect the output.

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

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

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) 150 186 200

2 (with a slice) 200 210 190

Average Working Time (Unit: Minutes)

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

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

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.

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

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

ConclusionDebugging Support for AOP

Key Idea: Advice Execution == Method CallLoop Detection using Call GraphApplication of Program Slicing

Program Slicing indicates dependence relations changed by aspectsis effective to localize a fault.

Future WorkVisualization of Inter-aspect relations for large-scale software Combining other technique to fix a fault, e.g. impact analysis

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

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

Any questions/comments ?

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

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

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.

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

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

Overview of Aspects Relation

Two aspects included in the program slice.Print and Cleanup are dominated by Caching

Caching

LoopDetectCleanup

Print

included in the Slicejoin point:visit a node

②around call

visitmethod body

③proceedrecursivecall①

before,after ④after

⑤after

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

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

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

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

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

Experiment 1: Applying tool

Apply program slicingto 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

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

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

Evaluation

Program slicing reduces complexityAspects 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)

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

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

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

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

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

Analysis Cost

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

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

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

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

Dynamic Analysis Aspect

We implement dynamic analysis using AspectJ.

Dynamic analysis aspectrecords 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).

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

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

Call Graph Example

Aspect

Class

call

凡例

An inifnite loop