Docsity

Context-sensitive Correlation Analysis for Detecting Races in Concurrent Programming - Pro, Study notes of Computer Science

Partial preview of the text

Download Context-sensitive Correlation Analysis for Detecting Races in Concurrent Programming - Pro and more Study notes Computer Science in PDF only on Docsity!

C

ONTEXT

- SENSITIVE

C

ORRELATION

A

NALYSIS FOR

R

ACE

D

ETECTION

Polyvios Pratikakis

Jeff FosterMichael Hicks

University of Maryland, College Park

Context-sensitive Correlation Analysis for Detecting Races – p.1/

Data Races

Race: two threads access memory without synchronizationand at least one is a write Famous problems caused by races:

August 14th 2004, Northeastern Blackout 1985-1987, Therac-25 medical accelerator Programs with races are difficult to understand

Context-sensitive Correlation Analysis for Detecting Races – p.2/

A way to prevent races^ Formally:

Shared locations

ρ, locks

Correlation

 :

Lock

is correlated with pointer

ρ^ if-f

is held while

ρ^ is

accessed Consistent correlation

:

Location

ρ^ is

always

correlated with lock

Assert that every shared location

ρ^ is

consistently correlated

with a lock

Context-sensitive Correlation Analysis for Detecting Races – p.4/

LOCKSMITH

: static correlation inference

ρ^ and

are static approximations of run-time values Sound, conservative Alias analysis:

Context-sensitive, flow-insensitive May-alias for locations

ρ, must-alias for locks

Correlation

 inference

Every access creates a

 constraint

Infer all other

 relations by closing the constraints

Consistent correlation

Verify consistent correlation for every shared

ρ, or report a

contradiction (race)

Context-sensitive Correlation Analysis for Detecting Races – p.5/

Type Based Analysis

Annotate types with labels:

pthread_mutex_t



pthread_mutex_t





 ρ

Create constraints among labels to capture data flow andcorrelation

Dereferencing

ρ^ while

is held:



Aliasing

ρ^ to

 ρ :

  ρ

Aliasing

to

 : 



Solve constraints to close the relation



Verify

consistent correlation

of every shared

ρ^ with a single

lock

for all dereferences of

Context-sensitive Correlation Analysis for Detecting Races – p.7/

Correlation^ pthread

mutex

t^

L^

=^

int

x;

&x:

int*

void

munge(pthread

mutex

t^

*l,

int

*^

p)

pthread

mutex

lock(l);

*p^

=^ 3;

pthread

mutex

unlock(l);

munge(&L1,

&x);

Context-sensitive Correlation Analysis for Detecting Races – p.8/

Correlation^ pthread

mutex

 t  1

L^

=^

int

x;

&x:

int*

ρ x



void

munge(pthread

mutex

 t  *l,

int

*^

 ρ p)

pthread

mutex

lock(l);

*p^

=^ 3;

pthread

mutex

unlock(l);

munge(&L1,

&x);

ρ x

1

munge Context-sensitive Correlation Analysis for Detecting Races – p.9/

Correlation^ pthread

mutex

 t  1

L^

=^

int

x;

&x:

int*

ρ x



void

munge(pthread

mutex

 t  *l,

int

*^

 ρ p)

pthread

mutex

lock(l);

*p^

=^ 3;

pthread

mutex

unlock(l);

munge(&L1,

&x);

ρ x

1

munge Context-sensitive Correlation Analysis for Detecting Races – p.9/

Correlation^ pthread

mutex

 t  1

L^

=^

int

x;

&x:

int*

ρ x



void

munge(pthread

mutex

 t  *l,

int

*^

 ρ p)

pthread

mutex

lock(l);

*p^

=^ 3;

pthread

mutex

unlock(l);

munge(&L1,

&x);

ρ x

1

munge

  Context-sensitive Correlation Analysis for Detecting Races – p.9/

Context Sensitivity^ pthread

mutex

 t  1

L^

=^

  2

L^

=^

int

x,

y,

z;

ρ

 , x

 ρ y

 ,^

 ρ z

void

munge(pthread

mutex

 t  *l,

int

*^

 ρ p)

pthread

mutex

lock(l);

*p^

=^ 3;

pthread

mutex

unlock(l);

munge

(&L1,

&x);

munge

(&L2,

&y);

munge

(&L2,

&z);

ρ x^

ρ y^

ρ z

1

2

munge

 Context-sensitive Correlation Analysis for Detecting Races – p.10/

Context Sensitivity^ pthread

mutex

 t  1

L^

=^

  2

L^

=^

int

x,

y,

z;

ρ

 , x

 ρ y

 ,^

 ρ z

void

munge(pthread

mutex

 t  *l,

int

*^

 ρ p)

pthread

mutex

lock(l);

*p^

=^ 3;

pthread

mutex

unlock(l);

munge

(&L1,

&x);

munge

(&L2,

&y);

munge

(&L2,

&z);

ρ x^

ρ y^

ρ z

1

2

munge

 ^ Context-sensitive Correlation Analysis for Detecting Races – p.10/

Context Sensitivity^ pthread

mutex

 t  1

L^

=^

  2

L^

=^

int

x,

y,

z;

ρ

 , x

 ρ y

 ,^

 ρ z

void

munge(pthread

mutex

 t  *l,

int

*^

 ρ p)

pthread

mutex

lock(l);

*p^

=^ 3;

pthread

mutex

unlock(l);

munge

(&L1,

&x);

munge

(&L2,

&y);

munge

(&L2,

&z);

ρ x^

ρ y^

ρ z

1

2

munge

 ^ Context-sensitive Correlation Analysis for Detecting Races – p.10/

Context Sensitivity^ pthread

mutex

 t  1

L^

=^

  2

L^

=^

int

x,

y,

z;

ρ

 , x

 ρ y

 ,^

 ρ z

void

munge(pthread

mutex

 t  *l,

int

*^

 ρ p)

pthread

mutex

lock(l);

*p^

=^ 3;

pthread

mutex

unlock(l);

munge

(&L1,

&x);

munge

(&L2,

&y);

munge

(&L2,

&z);

ρ x^

ρ y^

ρ z

1

2

munge

 

  Context-sensitive Correlation Analysis for Detecting Races – p.10/

Context Sensitivity^ pthread

mutex

 t  1

L^

=^

  2

L^

=^

int

x,

y,

z;

ρ

 , x

 ρ y

 ,^

 ρ z

void

munge(pthread

mutex

 t  *l,

int

*^

 ρ p)

pthread

mutex

lock(l);

*p^

=^ 3;

pthread

mutex

unlock(l);

munge

1 (&L1, &x); munge

2 (&L2, &y); munge

3 (&L2, &z);

ρ x^

ρ y^

ρ z

1

2

munge



^1

  1 1

^1

^1

Context-sensitive Correlation Analysis for Detecting Races – p.10/