1 / 62

Slicing Java Programs that Throw and Catch Exceptions

Slicing Java Programs that Throw and Catch Exceptions. Matthew Allen Susan Horwitz University of Wisconsin-Madison PEPM 2003 San Diego, CA June 7, 2003. Motivation. Exceptions: Important error-handling technique BUT: Current program-slicing algorithms don’t handle exceptions Goal:

nenet
Télécharger la présentation

Slicing Java Programs that Throw and Catch Exceptions

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. Slicing Java Programs thatThrow 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) { • 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

  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--; • } • } 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--; • } • } 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. 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 while (y > 0) x = x * y enter foo CFGPDGSDG F T call fact enter fact F T x = 1 F T y-- exit

  20. 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 while (y > 0) x = x * y enter foo y = y_in CFGPDGSDG F T y_in = y call fact x = x_out y = y_out enter fact y = y_in F T x = 1 F T y-- x_out = x y_out = y exit

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

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

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

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

  25. static void foo() { fact(); print(x); print(y); } static void fact() throws NegEx { x = 1; while (y > 0) { x = x * y; y--; } } enter foo call fact call fact y = y_in enter foo print(x) y = y_out y_in = y y_in = y y_out=y x_out=x x = x_out enter fact enter fact x = x * y y = y_in y=y_in y_out=y y=y_in while (y > 0) y-- x = 1 while (y > 0) y-- CFGPDGSDG print(y) y = y_out 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 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--; • } • } 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() while (y>0) normal exit NegEx exit x=x*y y-- Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

  29. enter foo catch (NegEx e) if(y<0) throw new NegEx() NegEx exit 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

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

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

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

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

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

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

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

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

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

  40. enter foo try y = y_in call fact normal return catch (NegEx e) print (“no error”) print (“error”) x_out = x y_out = y exit • static void foo() { • try { • fact(); • print(“no error”); • } • catch (NegEx e) { • print(“error”); • } • } F T normal NegEx F F T T 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 try x=x_out call fact normal return catch (NegEx e) enter fact x=1 if(y<0) throw new NegEx() while (y>0) normal exit x_out=x x=1 NegEx exit x=x*y y-- x=x*y y=y_in y_in=y y=y_out x=x_out print(x) print(x) y=y_in x_out=x y_out=y Slicing Java Programs that Throw and Catch Exceptions – Allen / Horwitz

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

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

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

  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

More Related