Presentation is loading. Please wait.

Presentation is loading. Please wait.

Slicing Java Programs that Throw and Catch Exceptions

Similar presentations


Presentation on theme: "Slicing Java Programs that Throw and Catch Exceptions"— Presentation transcript:

1 Slicing Java Programs that Throw and Catch Exceptions
Matthew Allen Susan Horwitz University of Wisconsin-Madison PEPM 2003 San Diego, CA June 7, 2003

2 Motivation Exceptions: Important error-handling technique BUT:
Current program-slicing algorithms don’t handle exceptions Goal: Extend System Dependence Graph (SDG) based slicing to support exceptions Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

3 Outline Motivation Program Slicing Slicing with the SDG
Extending SDG-Based Slicing to Handle Exceptions Related Work Conclusions Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

4 Program Slicing A slice from a component S is the set of components that might affect: Whether or how often S executes The value of a variable used at S Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

5 Slicing Example int x, y; void foo() { fact(); print(x); print(y); }
void fact() { x = 1; while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

6 Slicing Example int x, y; void foo() { fact(); print(x);
print(y);  slice from here } void fact() { x = 1; while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

7 Slicing Example int x, y; void foo() { fact(); print(x);
print(y);  slice from here } void fact() { x = 1; while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

8 Slicing Programs with Exceptions
Exceptions can affect: Whether or how often a statement executes Value of a variable used at a statement Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

9 Example: when/how often stmt executes
void foo() { try { fact(); print(“no error”); } catch (NegEx e) { print(“error”); void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

10 Example: when/how often stmt executes
void foo() { try { fact(); print(“no error”); } catch (NegEx e) { print(“error”);  Slice from here void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

11 Example: when/how often stmt executes
void foo() { try { fact(); print(“no error”); } catch (NegEx e) { print(“error”);  Slice from here void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

12 Exception affects value of variable
void foo() { try { fact(); print(x); } catch (NegEx e) { void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

13 Exception affects value of variable
void foo() { try { fact(); print(x); } catch (NegEx e) { print(x);  Slice from here void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

14 Exception affects value of variable
void foo() { try { fact(); print(x); } catch (NegEx e) { print(x);  Slice from here void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Componenets that affect WHETHER the print executes Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

15 Exception affects value of variable
void foo() { try { fact(); print(x); } catch (NegEx e) { print(x);  Slice from here void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Componenets that affectVALUE printed Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

16 Exception affects value of variable
void foo() { try { fact(); print(x);  Slice from here } catch (NegEx e) { print(x); void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

17 Exception affects value of variable
void foo() { try { fact(); print(x);  Slice from here } catch (NegEx e) { print(x); void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

18 Outline Motivation Program Slicing
Slicing with the SDG (no exceptions) Extending SDG-Based Slicing to Handle Exceptions Related Work Conclusions Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

19 CFGPDGSDG F T static void foo() { fact(); print(x); print(y); }
enter foo CFGPDGSDG F T call fact static void foo() { fact(); print(x); print(y); } static void fact() throws NegEx { x = 1; while (y > 0) { x = x * y; y--; print(x) print(y) exit foo enter fact F T x = 1 while (y > 0) F T x = x * y y-- exit

20 CFGPDGSDG F T static void foo() { fact(); print(x); print(y); }
enter foo y = y_in CFGPDGSDG F T y_in = y call fact x = x_out y = y_out static void foo() { fact(); print(x); print(y); } static void fact() throws NegEx { x = 1; while (y > 0) { x = x * y; y--; print(x) print(y) exit foo enter fact y = y_in F T x = 1 Better explanation of parameter in/out; then go to PDG: almost same set of nodes: no exit, param-passing nodes become separate nodes while (y > 0) F T x = x * y y-- x_out = x y_out = y exit

21 CFGPDGSDG enter foo y = y_in call fact print(x) print(y)
static void foo() { fact(); print(x); print(y); } static void fact() throws NegEx { x = 1; while (y > 0) { x = x * y; y--; y_in = y x = x_out y = y_out enter fact Nodes only control-dep edges Data dep edges y=y_in x = 1 while (y > 0) x_out=x y_out=y x = x * y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

22 CFGPDGSDG enter foo y = y_in call fact print(x) print(y)
static void foo() { fact(); print(x); print(y); } static void fact() throws NegEx { x = 1; while (y > 0) { x = x * y; y--; y_in = y x = x_out y = y_out enter fact Why add the interproc edges, not just what is added; more about summary edges y=y_in x = 1 while (y > 0) x_out=x y_out=y x = x * y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

23 CFGPDGSDG enter foo y = y_in call fact print(x) print(y)
static void foo() { fact(); print(x); print(y); } static void fact() throws NegEx { x = 1; while (y > 0) { x = x * y; y--; y_in = y x = x_out y = y_out enter fact Make source of slices bold y=y_in x = 1 while (y > 0) x_out=x y_out=y x = x * y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

24 CFGPDGSDG enter foo call fact y_in = y y = y_out y = y_in enter foo
print(x) print(y) static void foo() { fact(); print(x); print(y); } static void fact() throws NegEx { x = 1; while (y > 0) { x = x * y; y--; y_in = y x = x_out y = y_out enter fact Make source of slices bold y=y_in x = 1 while (y > 0) x_out=x y_out=y x = x * y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

25 CFGPDGSDG enter foo call fact y_in = y y = y_out y = y_in enter foo
print(x) print(y) static void foo() { fact(); print(x); print(y); } static void fact() throws NegEx { x = 1; while (y > 0) { x = x * y; y--; y_in = y x = x_out y = y_out enter fact while (y > 0) y-- y=y_in y_out=y enter fact Make source of slices bold y=y_in x = 1 while (y > 0) x_out=x y_out=y x = x * y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

26 Outline Motivation Program Slicing Slicing with the SDG
Extending SDG-Based Slicing to Handle Exceptions Related Work Conclusions Emphasize new work starts here Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

27 Example Revisited static void foo() { try { fact(); print(“no error”);
} catch (NegEx e) { print(“error”);  Slice from here static void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx (); while (y > 0) { x = x * y; y--; Throw is in slice only if there is a CONTROL-dep path in the SDG Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

28 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y
x=x_out y=y_out print (“no error”) print (“error”) enter fact y=y_in x=1 if(y<0) x_out=x y_out=y throw new NegEx() Start by explaining new nodes that give us the path for exceptional/normal return while (y>0) normal exit NegEx exit x=x*y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

29 enter foo y=y_in try call fact normal return catch (NegEx e) catch
y_in=y x=x_out y=y_out NegEx exit print (“no error”) print (“error”) enter fact y=y_in x=1 if(y<0) if(y<0) x_out=x y_out=y throw new NegEx() throw new NegEx() Start by explaining new nodes that give us the path for exceptional/normal return while (y>0) normal exit NegEx exit x=x*y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

30 static void fact() throws NegEx { x = 1; if (y < 0)
throw new NegEx (); while (y > 0) { x = x * y; y--; } Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

31 static void fact() throws NegEx { x = 1; if (y < 0)
enter fact y = y_in F T x=1 static void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx (); while (y > 0) { x = x * y; y--; } if(y<0) F T throw new NegEx() while (y>0) F T x=x*y For fact, issue is how to represent the throw, and the fact that method could exit via exception Or normally; for foo, the issue is that the call to fact may return normally or via an exception y-- x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

32 static void fact() { x = 1; if (y < 0) throw new NegEx ();
enter fact y = y_in F T x=1 static void fact() { x = 1; if (y < 0) throw new NegEx (); while (y > 0) { x = x * y; y--; } if(y<0) F T throw new NegEx() NegEx exit while (y>0) F T x=x*y y-- x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

33 static void fact() { x = 1; if (y < 0) throw new NegEx ();
enter fact y = y_in F T x=1 static void fact() { x = 1; if (y < 0) throw new NegEx (); while (y > 0) { x = x * y; y--; } if(y<0) F T throw new NegEx() NegEx exit while (y>0) F T x=x*y y-- normal exit x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

34 static void fact() { x = 1; if (y < 0) throw new NegEx ();
enter fact y = y_in F T x=1 static void fact() { x = 1; if (y < 0) throw new NegEx (); while (y > 0) { x = x * y; y--; } if(y<0) F T throw new NegEx() F T NegEx exit while (y>0) F T x=x*y Stress that throw must be a )pseudo) predicate because only preds are sources of control-dep edges y-- normal exit x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

35 static void fact() { x = 1; if (y < 0) throw new NegEx ();
enter fact y = y_in F T x=1 static void fact() { x = 1; if (y < 0) throw new NegEx (); while (y > 0) { x = x * y; y--; } if(y<0) F T throw new NegEx() F T NegEx exit while (y>0) F T x=x*y Omit this slide? y-- normal exit x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

36 static void foo() { try { fact(); print(“no error”); }
enter foo static void foo() { try { fact(); print(“no error”); } catch (NegEx e) { print(“error”); try y = y_in call fact catch (NegEx e) print (“no error”) print (“error”) x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

37 static void foo() { try { fact(); print(“no error”); }
enter foo static void foo() { try { fact(); print(“no error”); } catch (NegEx e) { print(“error”); try y = y_in call fact normal NegEx normal return catch (NegEx e) print (“no error”) print (“error”) x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

38 static void foo() { try { fact(); print(“no error”); }
enter foo static void foo() { try { fact(); print(“no error”); } catch (NegEx e) { print(“error”); try y = y_in call fact normal NegEx normal return catch (NegEx e) F F T T print (“no error”) print (“error”) x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

39 static void foo() { try { fact(); print(“no error”); }
enter foo static void foo() { try { fact(); print(“no error”); } catch (NegEx e) { print(“error”); try F T y = y_in call fact normal NegEx normal return catch (NegEx e) F F T T print (“no error”) print (“error”) x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

40 static void foo() { try { fact(); print(“no error”); }
enter foo static void foo() { try { fact(); print(“no error”); } catch (NegEx e) { print(“error”); try F T y = y_in call fact normal NegEx normal return catch (NegEx e) F F T T print (“no error”) print (“error”) x_out = x y_out = y exit Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

41 Example revisited static void foo() { try { fact(); print(x); }
catch (NegEx e) { print(x);  Slice from here static void fact() { x = 1; if (y < 0) throw new NegEx (); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

42 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y
x=x_out x=x_out y=y_out x_out=x print(x) print(x) enter fact y=y_in x=1 x=1 if(y<0) x_out=x y_out=y x=x*y throw new NegEx() while (y>0) normal exit NegEx exit x=x*y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

43 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y x=x_out y=y_out print(x) x=x_out y=y_out print(x) enter fact y=y_in x=1 if(y<0) throw new NegEx() while (y>0) normal exit NegEx exit x=x*y y-- y_out=y x_out=x y_out=y x_out=x

44 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y x=x_out y=y_out print(x) x=x_out x=x_out y=y_out print(x) enter fact x_out=x y=y_in x=1 x=1 if(y<0) throw new NegEx() while (y>0) normal exit NegEx exit x=x*y y-- y_out=y x_out=x y_out=y x_out=x

45 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y
x=x_out y=y_out print(x) x=x_out y=y_out print(x) enter fact y=y_in x=1 if(y<0) throw new NegEx() Show path is now correct not whole slice while (y>0) normal exit NegEx exit x=x*y y-- y_out=y x_out=x y_out=y x_out=x

46 Other Issues finally clauses Unchecked exceptions See paper!
Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

47 Outline Motivation Program Slicing Slicing with the SDG
Extending SDG-Based Slicing to Handle Exceptions Related Work Conclusions Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

48 Related Work [Sinha / Harrold / Rothermel 1999]
Addresses slicing programs with exceptions. Some similar aspects . Problems: Does not correctly represent interprocedural control dependences when length of call chain from try to throw is greater than 1. Does not address data dependences. [Sinha / Harrold 1998, 2000] Addresses handling finally clauses. See paper. Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

49 Conclusions Slicing is an important operation.
Slicing Java programs is an area of current interest. Contribution: Extend SDG-based Slicing: To correctly handle exceptions. Changes only to CFG. Same slicing algorithm! Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

50 Example: when/how often stmt executes
void foo() { try { fact(); print(“no error”);  Slice from here } catch (NegEx e) { print(“error”); void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

51 Example: when/how often stmt executes
void foo() { try { fact(); print(“no error”);  Slice from here } catch (NegEx e) { print(“error”); void fact() throws NegEx { x = 1; if (y < 0) throw new NegEx(); while (y > 0) { x = x * y; y--; Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

52 CFGPDGSDG control dependence T data dependence F T
enter foo y = y_in data dependence CFGPDGSDG F T y_in = y call fact x = x_out y = y_out static void foo() { fact(); print(x); print(y); } static void fact() { x = 1; while (y > 0) { x = x * y; y--; print(x) print(y) exit foo enter fact y = y_in F T x = 1 while (y > 0) F T x = x * y y-- x_out = x y_out = y exit

53 CFGPDGSDG control dependence T data dependence static void foo() {
enter foo y = y_in data dependence CFGPDGSDG y_in = y call fact x = x_out y = y_out static void foo() { fact(); print(x); print(y); } static void fact() { x = 1; while (y > 0) { x = x * y; y--; print(x) print(y) exit foo enter fact y = y_in x = 1 Data dep: def-use edges, computed using standard reaching-defs analysis while (y > 0) x = x * y y-- x_out = x y_out = y exit

54 CFGPDGSDG enter foo y = y_in call fact print(x) print(y)
static void foo() { fact(); print(x); print(y); } static void fact() { x = 1; while (y > 0) { x = x * y; y--; y_in = y x = x_out y = y_out enter fact y=y_in x = 1 while (y > 0) x_out=x y_out=y x = x * y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

55 CFGPDGSDG enter foo y = y_in call fact print(x) print(y)
static void foo() { fact(); print(x); print(y); } static void fact() { x = 1; while (y > 0) { x = x * y; y--; y_in = y x = x_out y = y_out enter fact y=y_in x = 1 while (y > 0) x_out=x y_out=y x = x * y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

56 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y
x=x_out y=y_out print (“no error”) print (“error”) enter fact y=y_in x=1 if(y<0) x_out=x y_out=y throw new NegEx() Start by explaining new nodes that give us the path for exceptional/normal return while (y>0) normal exit NegEx exit x=x*y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

57 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y
x=x_out y=y_out print (“no error”) print (“error”) enter fact y=y_in x=1 if(y<0) x_out=x y_out=y throw new NegEx() while (y>0) normal exit NegEx exit x=x*y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

58 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y
x=x_out y=y_out print (“no error”) print (“error”) enter fact y=y_in x=1 if(y<0) x_out=x y_out=y throw new NegEx() Either say something about this graph, or omit it while (y>0) normal exit NegEx exit x=x*y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

59 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y
x=x_out y=y_out print(x) print(x) enter fact y=y_in x=1 if(y<0) x_out=x y_out=y throw new NegEx() while (y>0) normal exit NegEx exit x=x*y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

60 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y
x=x_out y=y_out print(x) print(x) enter fact y=y_in x=1 if(y<0) x_out=x y_out=y throw new NegEx() Animate – a step at a time of the improtant part of the slice, end with BOTH edges back from the x_out=x in fact Just show bad path not rest of slice while (y>0) normal exit NegEx exit x=x*y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

61 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y x=x_out y=y_out print(x) x=x_out y=y_out print(x) enter fact y=y_in x=1 if(y<0) throw new NegEx() while (y>0) normal exit NegEx exit x=x*y y-- y_out=y x_out=x y_out=y x_out=x

62 enter foo y=y_in try call fact normal return catch (NegEx e) y_in=y x=x_out y=y_out print(x) x=x_out y=y_out print(x) enter fact y=y_in x=1 if(y<0) throw new NegEx() while (y>0) normal exit NegEx exit x=x*y y-- y_out=y x_out=x y_out=y x_out=x


Download ppt "Slicing Java Programs that Throw and Catch Exceptions"

Similar presentations


Ads by Google