Validating library usage interactively
This presentation is the property of its rightful owner.
Sponsored Links
1 / 26

Validating Library Usage Interactively PowerPoint PPT Presentation


  • 88 Views
  • Uploaded on
  • Presentation posted in: General

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.

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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -

Presentation Transcript


Validating library usage interactively

Validating Library Usage Interactively

  • William Harris, Guoliang Jin, Shan Lu, and Somesh Jha


Outline

Outline

  • Motivation

  • Problem definition

  • Technique and experiments

  • Motivation


Developers often optimize library usage

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"


Developers often optimize library usage1

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"


Developers often optimize library usage2

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


Validating library usage interactively

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


Validating library usage interactively

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();


Validating library usage interactively

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


Validating library usage interactively

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);


Outline1

Outline

  • Motivation

  • Problem definition

  • Technique and experiments

  • Problem definition


Validating library usage interactively

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


Requirements

Requirements

chklibs

  • Relative soundness

  • Queries on properties of the library only

  • Non-redundant queries


Validating library usage interactively

  • 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


Validating library usage interactively

  • 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


Why involve the user

Why involve the user?

  • Libraries may be difficult to analyze

  • Do small optimizations contain specificationsof big callees?


Outline2

Outline

  • Technique and experiments

  • Motivation

  • Problem definition

  • Technique


Technique

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


Validating library usage interactively

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


Validating library usage interactively

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


Validating library usage interactively

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


Experimental highlights

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)


Thanks for your attention

Thanksfor your attention!


Validating library usage interactively

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


Extra slides

Extra Slides


Validating library usage interactively

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)


Validating library usage interactively

  • 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


  • Login