1 / 37

A Slicing Method for Object-Oriented Programs Using Lightweight Dynamic Information

This paper introduces a slicing method for object-oriented programs that uses lightweight dynamic information to extract program slices. The method is evaluated and compared to other slicing methods, showing its effectiveness. The paper also discusses future work and potential applications of program slicing.

Télécharger la présentation

A Slicing Method for Object-Oriented Programs Using Lightweight Dynamic Information

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. A Slicing Method forObject-Oriented ProgramsUsingLightweight Dynamic Information Fumiaki OHATA, Kouya HIROSE, Masato FUJII and Katsuro INOUE Osaka University, JAPAN

  2. Contents • Program Slice • Dependence-Cache (DC) Slice • Object-Oriented Dependence-Cache (OODC) Slice • Implementation • Evaluation • Summary and Future Work

  3. Contents (1/6) • Program Slice • Dependence-Cache (DC) Slice • Object-Oriented Dependence-Cache (OODC) Slice • Implementation • Evaluation • Summary and Future Work

  4. Program Slice (Slice) • Subprogram which affects the value of slicing criterion <s, v> in p s : Statement v : Variable p : Program • Applications • Program understanding • Program debugging • …

  5. 1: scanf("%d", &a); 2: scanf("%d", &b); 3: max = a; 4: min = b; 5: if (a > b) { 6: max = b; 7: min = a; 8: } 9: printf("%d", max); - Correct program - - Incorrect program - 1:scanf("%d", &a); 2: scanf("%d", &b); 3: max = a; 4: min = b; 5: if (a < b) { 6: max = b; 7: min = a; 8: } 9: printf("%d", max); 1:scanf("%d", &a); 2: scanf("%d", &b); 3: max = a; 4: min = b; 5: if (a > b) { 6: max = b; 7: min = a; 8: } 9: printf("%d", max); Slice for <9, max> Application Example [Program Debugging] • Slice is effective on fault localization process. • The slice for <9, max> indicates the statements that might cause the unexpected value of max at line 9, so that we have only to focus on them.

  6. Computation Process Phase 1 : Defined and referred variables extraction Phase 2 : Dependence analysis • Data dependence (DD) analysis • Control dependence (CD) analysis Phase 3 : Program dependence graph (PDG) construction Phase 4 : Slice extraction using PDG traversal

  7. Data Dependence (DD) Analysis Extract DD relations between two statements • DD relation represents data-flow through variable. 1: a = 3; 2: b = 2; 3: scanf("%d", &c); 4: if ( c == 0 ) 5: d = a; 6: else 7: d = a + 1; 8: e = a + b; 9: printf("%d", d); 10: printf("%d", e); d d

  8. Control Dependence (CD) Analysis Extract CD relations between two statements • CD relation represents control-flow from conditional expression to conditional predicate or from method invocation to method definition. 1: a = 3; 2: b = 2; 3: scanf("%d", &c); 4: if ( c == 0 ) 5: d = a; 6: else 7: d = a + 1; 8: e = a + b; 9: printf("%d", d); 10: printf("%d", e);

  9. Static Slice • Scope : all possible execution paths • Target : source code • Execution : not required • Dependence analysis • DD : static • CD : static • Advantage • Small analysis cost • Disadvantage • Imprecise analysis results 1: a = 3; 2: b = 2; 3: scanf("%d", &c); 4: if ( c == 0 ) 5: d = a; 6: else 7: d = a + 1; 8: e = a + b; 9: printf("%d", d); 10: printf("%d", e); d d Slice for <9, d>

  10. Dynamic Slice • Scope : single execution path • Target : execution trace • Execution : required • Dependence analysis • DD : dynamic • CD : dynamic • Advantage • Precise analysis results • Disadvantage • Large analysis cost - input ‘0’ for c - 1: a = 3; 2: b = 2; 3: scanf("%d", &c); 4: if ( c == 0 ) 5: d = a; 6: else 7: d = a + 1; 8: e = a + b; 9: printf("%d", d); 10: printf("%d", e); d d

  11. Contents (2/6) • Program Slice • Dependence-Cache (DC) Slice • Object-Oriented Dependence-Cache (OODC) Slice • Implementation • Evaluation • Summary and Future Work

  12. Problems • Static slice has two problems, • array indexes problem : it is difficult for us to determine the values of array indices, and • pointer alias problem : it is difficult for us to determine the destination of pointer variables, so that extracted DD relations are imprecise. • Dynamic slice can resolve these problems; however, it requires large analysis cost.

  13. Dependence-Cache (DC) Slice • Scope : single execution path • Target : source code • Execution : required • Dependence analysis • DD : dynamic • CD : static • Advantage • More precise analysis results than static slice • Smaller analysis cost than dynamic slice - input ‘0’ for c - 1: a = 3; 2: b = 2; 3: scanf("%d", &c); 4: if ( c == 0 ) 5: d = a; 6: else 7: d = a + 1; 8: e = a + b; 9: printf("%d", d); 10: printf("%d", e);

  14. Dynamic DD Analysis • DD relation DD(s, t, v) exists when the following conditions are all satisfied: • statement s defines variable v, and • statement t refers v, and • at least one execution path from s to t without re-defining v exists. Dynamic analysis • On program execution, we have only to trace the most-recently defined statement for each variable using cache.

  15. Cache • Cache(v) : statement that defined variable v most-recently. • Operations for caches Before program execution, • For each variable v, Cache(v)  . On program execution, • For each statement s, - when v is defined, Cache(v) s. - when v is referred, we extract DD relation “DD(Cache(v), s, v)”.

  16. Comparison withStatic Slice & Dynamic Slice¶ • Analysis precision (slice size) : Static slice  DC slice  Dynamic slice • Analysis cost (memory space & computation time) : Static slice < DC slice « Dynamic slice ¶Ashida, Y., Ohata, F. and Inoue, K. : “Slicing Methods Using Static and Dynamic Information”, Proceedings of the 6th Asia Pacific Software Engineering Conference, 344-350, 1999.

  17. Contents (3/6) • Program Slice • Dependence-Cache (DC) Slice • Object-Oriented Dependence-Cache (OODC) Slice • Implementation • Evaluation • Summary and Future Work

  18. Object-Oriented DC (OODC) Slice • Extended DC slice for Object-Oriented (OO) programs • OO languages have concepts which procedural languages do not have. • Class, Object (Instance) • Inheritance, Class hierarchy, Method overriding • Dynamic binding : based on the reference-type of the object, an appropriate overriding method is selected and invoked.

  19. Analysis Policy Character 1 : object is a collection of attributes and methods that operate them. Character 2 : dynamic binding feature exists; however, static analysis can not handle it sufficiently. Policy 1 : when a variable is created, the corresponding cache is also created. Policy 2 : we use dynamic CD analysis for method invocation.

  20. Dynamic CD analysis for Method Invocation • CD relation CD(s, t) about method invocation exists when the following conditions are all satisfied: • statement t is a method definition, and • statement s calls t. Dynamic analysis • On program execution, we have only to watch the execution trace from a method invocation to a method definition.

  21. Contents (4/6) • Program Slice • Dependence-Cache (DC) Slice • Object-Oriented Dependence-Cache (OODC) Slice • Implementation • Evaluation • Summary and Future Work

  22. Program Slicing Criterion GUI (Graphical User Interface) Preprocessor Program + Analysis Code [Source] Slice Java Compiler Slicer Program + Analysis Code [Bytecode] Java Virtual Machine PDG Analysis Libraries Implementation • DC Slicing System for Java • Analysis libraries • GUI • Developing environment • JDK1.3.0_01 • JavaCC2.0

  23. Analysis Libraries • 10,000 lines • Analysis method : preprocessor style • Preprocessor loads target program p, and generate program p’ that contains p and the code to analyze p dynamically. • Easily development • Easily optimization using JIT or JavaVM

  24. Example [Preprocessed Code] - Original code - - Preprocessed code - • For each statement s, • when variable v is referred, we insert ref(v, s) before s. • when v is defined, we insert def(v, s) before s. 1 : int a = 10; 2 : int b = 20; 3 : int c; 4 : c = a + b; 5 : printf(“%d\n”, c); 0 : initPDG(); 1’: def(a, 1); 1 : int a = 10; 2’: def(b, 2); 2 : int b = 20; 3’: def(c, 3); 3 : int c; 4’: ref(a, 4); 4’: ref(b, 4); 4’: def(c, 4); 4 : c = a + b; 5’: ref(c, 5); 5 : printf(“%d\n”, c); Developed Preprocessor

  25. GUI • 3,000 lines • Features • Program editing • Slice computation

  26. Contents (5/6) • Program Slice • Dependence-Cache (DC) Slice • Object-Oriented Dependence-Cache (OODC) Slice • Implementation • Evaluation • Summary and Future Work

  27. Metrics Values (1/2) • Sample programs • Analysis precision (slice size) [lines]

  28. Metrics Values (2/2) • Analysis cost • Computation cost (execution time) [ms] T1 : original code, T2 : preprocessed code (original code + analysis code) • Space cost (memory use on execution) [KByte]

  29. Evaluation • Analysis precision • Slice size : 30-60% of Static slice • Static slice  DC slice  Dynamic slice¶ • Analysis cost • Additional cost for dynamic DD analysis and dynamic CD analysis for method invocation is not so large. - Computation cost : 4.2 - Space cost : 1.2 ¶Ashida, Y., Ohata, F. and Inoue, K. : “Slicing Methods Using Static and Dynamic Information”, Proceedings of the 6th Asia Pacific Software Engineering Conference, 344-350, 1999.

  30. Contents (6/6) • Program Slice • Dependence-Cache (DC) Slice • Object-Oriented Dependence-Cache (OODC) Slice • Implementation • Evaluation • Summary and Future Work

  31. Summary • Classification of slicing methods • OODC slice • An intermediate slice between static slice and dynamic slice for OO programs • Dynamic DD analysis • Dynamic CD analysis for method invocation • Static CD analysis (except method invocation) • Implementation (DC Slicing System for Java) • Evaluation (Experimentation using sample Java programs)

  32. Future Work • Application of dynamic CD analysis to other dynamically determined elements in Java • Exception • Thread • Experimental comparison with other slicing methods on analysis cost • Application of OODC slice to large programs • JavaVM-based (interpreter style) DC Slicing System for Java (now developing)

  33. End.

  34. Data dependence (DD) relation 16: sum = a + b + c; 17: x = (float) sum / 3.0; sum Example [Phase 2] (DD Analysis) 1: #include <stdio.h> 2: 3: float absolute(float x) 4: { 5: if(x < 0) { 6: x = -1 * x; 7: } 8: return x; 9: } 10: 11: float ave(int a, int b, int c) 12: { 13: int sum; 14: float x; 15: 16: sum = a + b + c; 17: x = (float) sum / 3.0; 18: x = absolute(x); 19: return x; 20: } 21: 22: int main(void) 23: { 24: int a, b, c; 25: float x; 26: 27: printf("Input a b c ?"); 28: scanf("%d %d %d", &a, &b, &c); 29: 30: x = ave(a, b, c); 31: printf("Ave = %9.3f\n", x); 32: return 0; 33: }

  35. Control dependence (CD) relation [intra-method] Control dependence (CD) relation [inter-method] 3: float absolute(float x) 4: { 5: if(x < 0) { 6: x = -1 * x; 7: } 8: return x; 9: } 5: if (x < 0) { 6: x = -1 * x; 7: } call return 11: float ave(int a, int b, int c) 12: { 18: x = absolute(x); 20: } Example [Phase 2] (CD Analysis) 1: #include <stdio.h> 2: 3: float absolute(float x) 4: { 5: if(x < 0) { 6: x = -1 * x; 7: } 8: return x; 9: } 10: 11: float ave(int a, int b, int c) 12: { 13: int sum; 14: float x; 15: 16: sum = a + b + c; 17: x = (float) sum / 3.0; 18: x = absolute(x); 19: return x; 20: } 21: 22: int main(void) 23: { 24: int a, b, c; 25: float x; 26: 27: printf("Input a b c ?"); 28: scanf("%d %d %d", &a, &b, &c); 29: 30: x = ave(a, b, c); 31: printf("Ave = %9.3f\n", x); 32: return 0; 33: }

  36. 28 11 3 a b c x a b c 16 30 5 sum x x 17 31 6 x x 27 18 8 x DD 19 CD Example [Phase 3] 1: #include <stdio.h> 2: 3: float absolute(float x) 4: { 5: if(x < 0) { 6: x = -1 * x; 7: } 8: return x; 9: } 10: 11: float ave(int a, int b, int c) 12: { 13: int sum; 14: float x; 15: 16: sum = a + b + c; 17: x = (float) sum / 3.0; 18: x = absolute(x); 19: return x; 20: } 21: 22: int main(void) 23: { 24: int a, b, c; 25: float x; 26: 27: printf("Input a b c ?"); 28: scanf("%d %d %d", &a, &b, &c); 29: 30: x = ave(a, b, c); 31: printf("Ave = %9.3f\n", x); 32: return 0; 33: } • Node : statement or conditional expression • Edge : dependence relation between two nodes

  37. 28 11 3 a b c x a b c 16 30 5 sum x x x 17 31 6 x x 27 18 8 x 19 Example [Phase 4] (Slice for <30, x>) 1: #include <stdio.h> 2: 3: float absolute(float x) 4: { 5: if(x < 0) { 6: x = -1 * x; 7: } 8: return x; 9: } 10: 11: float ave(int a, int b, int c) 12: { 13: int sum; 14: float x; 15: 16: sum = a + b + c; 17: x = (float) sum / 3.0; 18: x = absolute(x); 19: return x; 20: } 21: 22: int main(void) 23: { 24: int a, b, c; 25: float x; 26: 27: printf("Input a b c ?"); 28: scanf("%d %d %d", &a, &b, &c); 29: 30: x = ave(a, b, c); 31: printf("Ave = %9.3f\n", x); 32: return 0; 33: } • We start PDG traversal from the slicing criterion node in reverse order. • The corresponding statements to the reachable nodes form the slice.

More Related