1 / 26

Validating Library Usage Interactively

Validating Library Usage Interactively. William Harris , Guoliang Jin, Shan Lu, and Somesh Jha. Outline. Motivation Problem definition Technique and experiments. Motivation. Developers Often Optimize Library Usage.

cecily
Download Presentation

Validating Library Usage Interactively

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. Validating Library Usage Interactively • William Harris, Guoliang Jin, Shan Lu, and Somesh Jha

  2. Outline • Motivation • Problem definition • Technique and experiments • Motivation

  3. Developers Often Optimize Library Usage In a previous study (Understanding and Detecting Real-World Performance Bugs, Jin et. al., PLDI ’12), of 109 bug patches: 42 caused by "an inefficient function call sequence composed of efficient individual functions"

  4. Developers Often Optimize Library Usage In a previous study (Understanding and Detecting Real-World Performance Bugs, Jin et. al., PLDI ’12), of 109 bug patches: 34 caused by "calling functions that conduct unnecessary work given the calling context"

  5. Developers Often Optimize Library Usage Concisely In a previous study (Understanding and Detecting Real-World Performance Bugs, Jin et. al., PLDI ’12), of 109 bug patches: 42 contained ≤ 5 lines of code,and median size was 8 lines

  6. The Case for Verification • Opportunities to improve practice: optimizations... • are discussed extensively • validated by testing only • Why its feasible: optimizations... • use a clean interface • are small Why its hard: optimizations implicitly rely onsubtle library properties

  7. Mozilla Bug # 409961 ∀ x, y, z. AddAddressToList[arg2](x, y) = AddAddressToList[arg2](z, y) Original Optimized DbList dbnewList; Card card; for (pos=1;pos<=numAddrs;pos++) card = CreateCard(user(pos)); dbnewList = DbList(); AddAddrToList(dbnewList,card); return card; DbList dbnewList Card card; for (pos=1;pos<=numAddrs;pos++) card = CreateCard(user(pos)); AddAddrToList(dbnewList,card); return card; ; dbnewList = DbList();

  8. MySQL Bug # 38769 ∀ x. snap_count(x) < 256 ∀ x, y. snap_count(x) ≤ y ⇒ at(x, y) = NULL Original Optimized snap_count(info) for (n=0; n< ;++n){ Snapshot_info* i = at(info, n); if (!i) continue; process_snapshot(i); } for (n=0; n < 256; ++n) { Snapshot_info* i = at(info, n); if (!i) continue; process_snapshot(i); } 256

  9. Bug # 34464 Apache len(“”) = 0 ∀ x, y. len(x) > len(y) ⇒ ¬is_sub(x, y) ∀ x, y, z. ¬is_sub(x, y) ⇒ is_sub(app(x, z), y) ⇔ is_sub(sub(app(x, z), len(app(x, z)) - len(y)), y) Original Optimized int pos := -len(s); string sb := “”; string sb := “”; while (!is_sub(sb, s)) { app(sb, get()); } return sb; pos < 0 || while ( !is_sub( s)) { sb, sub( pos), app(sb, get()); } return sb; • pos := len(sb) - len(s);

  10. Outline • Motivation • Problem definition • Technique and experiments • Problem definition

  11. Apache Bug #34464 Org. ≈ Opt assuming ∀ x, y. len(x) > len(y) ⇒ ¬is_sub(x, y) ... chklibs Org. Opt. ∀ x, y. len(x) > len(y) ⇒ ¬is_sub(x, y) ∀ x, y. is_sub(x, y) ... string sb := “”; int pos = -len(s); while (pos < 0 || !is_sub(sub(sb, pos), s)){ app(sb, get()); pos := len(sb) - len(s); } return sb; string sb := “”; while (!is_sub(sb, s)) { app(sb, get()); } return sb; Invalid Valid User

  12. Requirements chklibs • Relative soundness • Queries on properties of the library only • Non-redundant queries

  13. Non-redundant queries Inputs string sb := “”; int pos = -len(s); while (pos < 0 !is_sub(sub(sb, pos), s)) { app(sb, get()); pos := len(sb) - len(s); } return sb; string sb := “”; while (!is_sub(sb, s)) { app(sb, get()); } return sb; chklibs ∀ x, y. len(x) > len(y) ⇒ is_sub(x, y) ∀ x, y. is_sub(x, y) Invalid User

  14. Queries on properties of the library only Inputs string sb := “”; int pos = -len(s); while (pos < 0 !is_sub(sub(sb, pos), s)) { app(sb, get()); pos := len(sb) - len(s); } return sb; string sb := “”; while (!is_sub(sb, s)) { app(sb, get()); } return sb; chklibs ∀ x, y. len(x) > len(y) ⇒ ¬is_sub(x, y) pos=len(sb) -len(s) User

  15. Why involve the user? • Libraries may be difficult to analyze • Do small optimizations contain specificationsof big callees?

  16. Outline • Technique and experiments • Motivation • Problem definition • Technique

  17. Technique • Based on known translation-validation algorithm (Necula, PLDI ’00) • Key difference: simultaneously find formula in simulation relation and supporting library property over predicates in post

  18. L0’: string sb := “”; int pos = -len(s); L1’: while (pos < 0 || !is_sub(sub(sb, pos), s)){ app(sb, get()); pos := len(sb) - len(s); } L2’: return sb; L0: string sb := “”; L1: while (!is_sub(sb, s)) { app(sb, get()); } L2: return sb; chklibs User

  19. TP chklibs s = s’ L0’: string sb := “”; int pos = -len(s); L1’: while (pos < 0 || !is_sub(sub(sb, pos), s)){ app(sb, get()); pos := len(sb) - len(s); } L2’: return sb; L0: string sb := “”; L1: while (!is_sub(sb, s)) { app(sb, get()); } L2: return sb; sb=sb’ φ φ sb = sb’ post[ ]( ) L1→L2 L1’→L2’ ⇒ sb = sb’ sb=sb’ Invalid validated Lib. property: True User

  20. Lib.-Abd. TP TP chklibs s = s’ L0’: string sb := “”; int pos = -len(s); L1’: while (pos < 0 || !is_sub(sub(sb, pos), s)){ app(sb, get()); pos := len(sb) - len(s); } L2’: return sb; L0: string sb := “”; L1: while (!is_sub(sb, s)) { app(sb, get()); } L2: return sb; sb=sb’ sb = sb’ post[ ]( ) L1→L2 L1’→L2’ ⇒ sb = sb’ sb=sb’ ∀x, y. find(x, y) validated Lib. property: True User

  21. Experimental Highlights • Ran tool on 11 performance-bug patches from Apache, Mozilla, and MySQL • On average, found supporting conditions • in < 1 second • with < 10 queries (0 - 7 invalid)

  22. Thanksfor your attention!

  23. Questions? Org. ≈ Opt assuming ∀ x, y. len(x) > len(y) ⇒ ¬is_sub(x, y) ... string sb := “”; int pos = -len(s); while (pos < 0 || !is_sub(sub(sb, pos), s)){ app(sb, get()); pos := len(sb) - len(s); } return sb; string sb := “”; while (!is_sub(sb, s)) { app(sb, get()); } return sb; chklibs ∀ x, y. len(x) > len(y) ⇒ ¬is_sub(x, y) ∀ x, y. is_sub(x, y) ... Invalid Valid User

  24. Extra Slides

  25. Apache Bug # 19101 ∀ x, y. size(at[arg0](x, y)) = size(x) Original Optimized vector<BuildListener> ls = getBuildListeners(); for (i=0; i < size(ls); i++) { BuildListener l = at(ls, i); l.startTask(); } vector<BuildListener> ls = getBuildListeners(); int sz = ; sz for (i=0; i < ; i++) { BuildListener l = at(ls, i); l.startTask(); } size(ls)

  26. Non-redundant string sb := “”; int pos = -len(s); while (pos < 0 !find(sub(sb, pos), s)) { app(sb, get()); pos := len(sb) - len(s); } return sb; string sb := “”; while (!find(sb, s)) { app(sb, get()); } return sb; chklibs ∀ x, y, z. len(app(x, y)) > len(z) ⇒ ¬ find(x, z) ∀ x, y, z. ¬find(app(x, y), z) ⇒ ¬ find(x, z) ∀ x, y. len(x) > len(y) ⇒ ¬find(x, y) Valid Valid User

More Related