sparse flow-sensitive pointer analysis for multithreaded ... · cgo 2016, march 15th, barcelona...

48
CGO 2016, March 15th, Barcelona Sparse Flow-Sensitive Pointer Analysis For Multithreaded Programs Yulei Sui , Peng Di and Jingling Xue School of Computer Science and Engineering The University of New South Wales 2052 Sydney Australia March 15, 2016 1/1

Upload: others

Post on 15-Oct-2020

9 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Sparse Flow-Sensitive Pointer AnalysisFor Multithreaded Programs

Yulei Sui, Peng Di and Jingling Xue

School of Computer Science and EngineeringThe University of New South Wales

2052 Sydney Australia

March 15, 2016

1 / 1

Page 2: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Contributions

• The first sparse flow-sensitive pointer analysis forunstructured multithreaded programs (C with Pthread)

• A series of static thread interference analyses byreasoning about fork/join, memory accesses, lock/unlockto generate value-flows among threads.

• Significantly faster than non-sparse algorithm and scalesto large size multithreaded Pthread programs with up to100KLOC.

2 / 1

Page 3: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Outline

• Background and Motivation• Our approach: FSAM• Evalution

2 / 1

Page 4: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Pointer Analysis

Pointer Analysis is to statically approximate runtime values of apointer

A fundamental enabling technology for many other programanalyses and optimisations.• Compiler optimisations (e.g., Auto-Vectorization)• Memory errors (e.g., Null pointer and use-after-free)• Concurrency bugs (e.g., Data race, dead lock detection)• Security (e.g., Control-flow integrity enforcement)• Accelerating dynamic analysis (e.g., MemSan, TSan)• ...

3 / 1

Page 5: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Pointer Analysis

Pointer Analysis is to statically approximate runtime values of apointer

A fundamental enabling technology for many other programanalyses and optimisations.• Compiler optimisations (e.g., Auto-Vectorization)• Memory errors (e.g., Null pointer and use-after-free)• Concurrency bugs (e.g., Data race, dead lock detection)• Security (e.g., Control-flow integrity enforcement)• Accelerating dynamic analysis (e.g., MemSan, TSan)• ...

3 / 1

Page 6: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Insensitive v.s. Flow-Sensitive AnalysisFlow-Insensitive Pointer Analysis:• Ignore program execution order• A single solution across whole program

Flow-Sensitive Pointer Analysis:• Respect program control-flow• A separate solution at each program point

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → a

a → b

Flow-sensitive Analysis

p → a

a → cp → a

a → cp → a q → c

4 / 1

Page 7: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Insensitive v.s. Flow-Sensitive AnalysisFlow-Insensitive Pointer Analysis:• Ignore program execution order• A single solution across whole program

Flow-Sensitive Pointer Analysis:• Respect program control-flow• A separate solution at each program point

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → a

a → b

Flow-sensitive Analysis

p → a

a → cp → a

a → cp → a q → c

4 / 1

Page 8: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Insensitive v.s. Flow-Sensitive AnalysisFlow-Insensitive Pointer Analysis:• Ignore program execution order• A single solution across whole program

Flow-Sensitive Pointer Analysis:• Respect program control-flow• A separate solution at each program point

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → a

a → b

Flow-sensitive Analysis

p → a

a → cp → a

a → cp → a q → c

4 / 1

Page 9: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Insensitive v.s. Flow-Sensitive AnalysisFlow-Insensitive Pointer Analysis:• Ignore program execution order• A single solution across whole program

Flow-Sensitive Pointer Analysis:• Respect program control-flow• A separate solution at each program point

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → a

a → b

Flow-sensitive Analysis

p → a

a → cp → a

a → cp → a q → c

4 / 1

Page 10: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Insensitive v.s. Flow-Sensitive AnalysisFlow-Insensitive Pointer Analysis:• Ignore program execution order• A single solution across whole program

Flow-Sensitive Pointer Analysis:• Respect program control-flow• A separate solution at each program point

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → aa → b, cq → b, c

Flow-Insensitive Analysis

p = & a

*p = & b

*p = & c

q = *p

p → a

a → b

Flow-sensitive Analysis

p → a

a → cp → a

a → cp → a q → c

4 / 1

Page 11: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Sparse Flow-Sensitive Analysis• Propagate points-to information only along pre-computed

def-use chains instead of control-flow

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dx → m m → d

q = *p

y = *xx → m y → dm → d

p → a a → c q → c

[a]

[a] [m]

Sparse flow-sensitive analysis(Hardekopf and Lin. - CGO’11) (Ye, Sui and Xue. - SAS ’14)

5 / 1

Page 12: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Sparse Flow-Sensitive Analysis• Propagate points-to information only along pre-computed

def-use chains instead of control-flow

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dx → m m → d

q = *p

y = *xx → m y → dm → d

p → a a → c q → c

[a]

[a] [m]

Sparse flow-sensitive analysis(Hardekopf and Lin. - CGO’11) (Ye, Sui and Xue. - SAS ’14)

5 / 1

Page 13: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Sparse Flow-Sensitive Analysis• Propagate points-to information only along pre-computed

def-use chains instead of control-flow

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dx → m m → d

q = *p

y = *xx → m y → dm → d

p → a a → c q → c

[a]

[a] [m]

Sparse flow-sensitive analysis(Hardekopf and Lin. - CGO’11) (Ye, Sui and Xue. - SAS ’14)

5 / 1

Page 14: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Sparse Flow-Sensitive Analysis• Propagate points-to information only along pre-computed

def-use chains instead of control-flow

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dp → a a → c x → m m → d

q = *p

y = *xp → a a → c x → m y → dm → d

p → a a → c x → m y → dm → d q → c

x → m

x → m

Data-flow-based flow-sensitive analysis

...p → a x → m

*p = & bp → a a → b

*p = & cp → a a → c

*x = & dx → m m → d

q = *p

y = *xx → m y → dm → d

p → a a → c q → c

[a]

[a] [m]

Sparse flow-sensitive analysis(Hardekopf and Lin. - CGO’11) (Ye, Sui and Xue. - SAS ’14)

5 / 1

Page 15: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Sensitivity Under Thread Interleaving

s1 : *p = & b

s2 : *p = & c

s3 : q = *p

Thread 1

[a]

[a]

s2 : *p = & c

s3 : q = *p

Thread 1

fork(t2, foo)

Thread 2

foo(){

s1 : *p = & b

}

Interleavingexecution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b[a]

[a]

Scenario 1:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

[a]

Scenario 2:

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

execution sequence : s2, s3, s1 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

Scenario 3:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(a) non-interference via join

join(t2)

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(b) non-interference via lock/unlock

lock(l)

unlock(l)

points-to of q: pt(q) = {c}

lock(l)

unlock(l)

6 / 1

Page 16: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Sensitivity Under Thread Interleaving

s1 : *p = & b

s2 : *p = & c

s3 : q = *p

Thread 1

[a]

[a]

s2 : *p = & c

s3 : q = *p

Thread 1

fork(t2, foo)

Thread 2

foo(){

s1 : *p = & b

}

Interleaving

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b[a]

[a]

Scenario 1:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

[a]

Scenario 2:

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

execution sequence : s2, s3, s1 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

Scenario 3:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(a) non-interference via join

join(t2)

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(b) non-interference via lock/unlock

lock(l)

unlock(l)

points-to of q: pt(q) = {c}

lock(l)

unlock(l)

6 / 1

Page 17: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Sensitivity Under Thread Interleaving

s1 : *p = & b

s2 : *p = & c

s3 : q = *p

Thread 1

[a]

[a]

s2 : *p = & c

s3 : q = *p

Thread 1

fork(t2, foo)

Thread 2

foo(){

s1 : *p = & b

}

Interleaving

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b[a]

[a]

Scenario 1:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

[a]

Scenario 2:

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

execution sequence : s2, s3, s1 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

Scenario 3:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(a) non-interference via join

join(t2)

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(b) non-interference via lock/unlock

lock(l)

unlock(l)

points-to of q: pt(q) = {c}

lock(l)

unlock(l)

6 / 1

Page 18: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Sensitivity Under Thread Interleaving

s1 : *p = & b

s2 : *p = & c

s3 : q = *p

Thread 1

[a]

[a]

s2 : *p = & c

s3 : q = *p

Thread 1

fork(t2, foo)

Thread 2

foo(){

s1 : *p = & b

}

Interleavingexecution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b[a]

[a]

Scenario 1:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

[a]

Scenario 2:

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

execution sequence : s2, s3, s1 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

Scenario 3:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(a) non-interference via join

join(t2)

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(b) non-interference via lock/unlock

lock(l)

unlock(l)

points-to of q: pt(q) = {c}

lock(l)

unlock(l)

6 / 1

Page 19: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Sensitivity Under Thread Interleaving

s1 : *p = & b

s2 : *p = & c

s3 : q = *p

Thread 1

[a]

[a]

s2 : *p = & c

s3 : q = *p

Thread 1

fork(t2, foo)

Thread 2

foo(){

s1 : *p = & b

}

Interleavingexecution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b[a]

[a]

Scenario 1:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

[a]

Scenario 2:

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

execution sequence : s2, s3, s1 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

Scenario 3:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(a) non-interference via join

join(t2)

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(b) non-interference via lock/unlock

lock(l)

unlock(l)

points-to of q: pt(q) = {c}

lock(l)

unlock(l)

6 / 1

Page 20: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Flow-Sensitivity Under Thread Interleaving

s1 : *p = & b

s2 : *p = & c

s3 : q = *p

Thread 1

[a]

[a]

s2 : *p = & c

s3 : q = *p

Thread 1

fork(t2, foo)

Thread 2

foo(){

s1 : *p = & b

}

Interleavingexecution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b[a]

[a]

Scenario 1:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

[a]

Scenario 2:

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

execution sequence : s2, s3, s1 points-to of q : pt(q) = {c}

s2 : *p = & c

s3 : q = *p

Thread 1 Thread 2

s1 : *p = & b

[a]

Scenario 3:

execution sequence : s2, s1, s3 points-to of q : pt(q) = {b}

execution sequence : s1, s2, s3 points-to of q : pt(q) = {c}

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(a) non-interference via join

join(t2)

fork(t2, foo)

s2 : *p = & c s3 : q = *p

Thread 1 Thread 2

foo(){

s1 : *p = & b

}

(b) non-interference via lock/unlock

lock(l)

unlock(l)

points-to of q: pt(q) = {c}

lock(l)

unlock(l)

6 / 1

Page 21: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Outline

• Background and Motivation• Our approach: FSAM• Evalution

6 / 1

Page 22: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

FSAM: Sparse Flow-Sensitive Analysis ForMultithreaded Programs

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

7 / 1

Page 23: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

FSAM: Sparse Flow-Sensitive Analysis ForMultithreaded Programs

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

7 / 1

Page 24: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

FSAM: Sparse Flow-Sensitive Analysis ForMultithreaded Programs

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

7 / 1

Page 25: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

FSAM: Sparse Flow-Sensitive Analysis ForMultithreaded Programs

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

7 / 1

Page 26: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

FSAM: Sparse Flow-Sensitive Analysis ForMultithreaded Programs

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

Sparseflow-sensitive

resolution

Interleaving analysis

Value-flowanalysis Lock analysis

thread-oblivious def-usefork/join lock/unlock

MHP pairs

aliased pairs

flow-sensitive points-to

Pre-analysis memory accesses

thread-aware def-use

7 / 1

Page 27: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Context-Sensitive Abstract ThreadsAn abstract thread t refers to a call of pthread create() at acontext-sensitive fork site during the analysis.

void main(){

for(i=0;i<10;i++){ fork(t[i], foo) }

}

t is multi-forked thread

void main(){

foo(); foo();

}

void foo(){

fork(t1, bar);}

cs1:cs2:

cs3:

t1 refers to fork siteunder context [1,3]

t1 and t1' are context-sensitive threads

t1' refers to fork siteunder context [2,3]

void main(){

for(i=0;i<10;i++){ fork(t[i], foo) }

}

t is multi-forked thread

void main(){

foo(); foo();

}

void foo(){

fork(t1, bar);}

cs1:cs2:

cs3:

t1 refers to fork siteunder context [1,3]

t1 and t1' are context-sensitive threads

t1' refers to fork siteunder context [2,3]

A thread t always refers to a context-sensitive fork site, i.e., aunique runtime thread unless t ∈M is multi-forked, in whichcase, t may represent more than one runtime thread.

8 / 1

Page 28: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Context-Sensitive Abstract ThreadsAn abstract thread t refers to a call of pthread create() at acontext-sensitive fork site during the analysis.

void main(){

for(i=0;i<10;i++){ fork(t[i], foo) }

}

t is multi-forked thread

void main(){

foo(); foo();

}

void foo(){

fork(t1, bar);}

cs1:cs2:

cs3:

t1 refers to fork siteunder context [1,3]

t1 and t1' are context-sensitive threads

t1' refers to fork siteunder context [2,3]

void main(){

for(i=0;i<10;i++){ fork(t[i], foo) }

}

t is multi-forked thread

void main(){

foo(); foo();

}

void foo(){

fork(t1, bar);}

cs1:cs2:

cs3:

t1 refers to fork siteunder context [1,3]

t1 and t1' are context-sensitive threads

t1' refers to fork siteunder context [2,3]

A thread t always refers to a context-sensitive fork site, i.e., aunique runtime thread unless t ∈M is multi-forked, in whichcase, t may represent more than one runtime thread.

8 / 1

Page 29: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Thread-Aware Value-FlowsA thread-aware def-use is added if a pair of statements (t , c, s)and (t ′, c′, s′)

• (1) may access same memory using pre-computed results.• (2) may happen in parallel

s : ∗p = s′ : = ∗q or ∗q =(t , c, s) ‖ (t ′, c′, s′) o ∈ Alias(∗p, ∗q)

so

↪−→ s′

t t'

[o](t,c,s) (t',c',s')

s:*p= ... s': ...=*q

(t,c,s) || (t',c',s')

9 / 1

Page 30: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Context-sensitive Thread Interleaving Analysis

(t1, c1, s1) ‖ (t2, c2, s2) holds if:{t2 ∈ I(t1, c1, s1) ∧ t1 ∈ I(t2, c2, s2) if t1 6= t2t1 ∈M otherwise

where I(t , c, s): denotes a set of interleaved threads may run inparallel with s in thread t under calling context c,M is the set of multi-forked threads.

10 / 1

Page 31: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Interleaving Analysis

Computing I(t , c, s) is formalized as a forward data-flowproblem (V ,u,F ).• V : the set of all thread interleaving facts.• u: meet operator (∪).• F : V → V transfer functions associated with each node in

an ICFG.

11 / 1

Page 32: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Interleaving Analysis Rule

[I-DESCENDANT]t

(c,fki )−−−→ t ′ (t , c, fki)→ (t , c, `) (c′, `′) = Entry(St ′)

{t ′} ⊆ I(t , c, `) {t} ⊆ I(t ′, c′, `′)

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

[I-JOIN]t

(c,jni )←−−− t ′

I(t , c, jni) = I(t , c, jni)\{t ′}[I-CALL]

(t , c, `)calli−−→ (t , c′, `′) c′ = c.push(i)I(t , c, `) ⊆ I(t , c′, `′)

[I-INTRA](t , c, `)→ (t , c, `′)I(t , c, `) ⊆ I(t , c, `′) [I-RET]

(t , c, `)reti−−→ (t , c′, `′) i = c.peek() c′ = c.pop()

I(t , c, `) ⊆ I(t , c′, `′)

12 / 1

Page 33: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Interleaving Analysis Rule

[I-DESCENDANT]t

(c,fki )−−−→ t ′ (t , c, fki)→ (t , c, `) (c′, `′) = Entry(St ′)

{t ′} ⊆ I(t , c, `) {t} ⊆ I(t ′, c′, `′)

t t'

fork

I(t,c,s) = {t'} I(t',c',s')={t}s s'

(t,c,s) || (t',c',s')

[I-JOIN]t

(c,jni )←−−− t ′

I(t , c, jni) = I(t , c, jni)\{t ′}

fork

I(t,c,s) = {t'} I(t',c',s')={t}s s'

join

s1I(t,c,s1) = { }

(t,c,s) || (t',c',s') (t',c',s') || (t,c,s1)

t t'

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

forkI(t,c,s)={}s

join

s'I(t',c',s')={}fork

join

t0 tt'

(t,c,s) || (t',c',s')

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

(t,c,s) || (t',c',s')

forkI(t,c,s)={t'}s

join

s'I(t',c',s')={t}fork

join

t0 tt'

13 / 1

Page 34: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Interleaving Analysis Rule

[I-DESCENDANT]t

(c,fki )−−−→ t ′ (t , c, fki)→ (t , c, `) (c′, `′) = Entry(St ′)

{t ′} ⊆ I(t , c, `) {t} ⊆ I(t ′, c′, `′)

t t'

fork

I(t,c,s) = {t'} I(t',c',s')={t}s s'

(t,c,s) || (t',c',s')

[I-JOIN]t

(c,jni )←−−− t ′

I(t , c, jni) = I(t , c, jni)\{t ′}

fork

I(t,c,s) = {t'} I(t',c',s')={t}s s'

join

s1I(t,c,s1) = { }

(t,c,s) || (t',c',s') (t',c',s') || (t,c,s1)

t t'

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

forkI(t,c,s)={}s

join

s'I(t',c',s')={}fork

join

t0 tt'

(t,c,s) || (t',c',s')

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

(t,c,s) || (t',c',s')

forkI(t,c,s)={t'}s

join

s'I(t',c',s')={t}fork

join

t0 tt'

13 / 1

Page 35: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Interleaving Analysis Rule

[I-DESCENDANT]t

(c,fki )−−−→ t ′ (t , c, fki)→ (t , c, `) (c′, `′) = Entry(St ′)

{t ′} ⊆ I(t , c, `) {t} ⊆ I(t ′, c′, `′)

t t'

fork

I(t,c,s) = {t'} I(t',c',s')={t}s s'

(t,c,s) || (t',c',s')

[I-JOIN]t

(c,jni )←−−− t ′

I(t , c, jni) = I(t , c, jni)\{t ′}

fork

I(t,c,s) = {t'} I(t',c',s')={t}s s'

join

s1I(t,c,s1) = { }

(t,c,s) || (t',c',s') (t',c',s') || (t,c,s1)

t t'

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

forkI(t,c,s)={}s

join

s'I(t',c',s')={}fork

join

t0 tt'

(t,c,s) || (t',c',s')

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

(t,c,s) || (t',c',s')

forkI(t,c,s)={t'}s

join

s'I(t',c',s')={t}fork

join

t0 tt'

13 / 1

Page 36: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Interleaving Analysis Rule

[I-DESCENDANT]t

(c,fki )−−−→ t ′ (t , c, fki)→ (t , c, `) (c′, `′) = Entry(St ′)

{t ′} ⊆ I(t , c, `) {t} ⊆ I(t ′, c′, `′)

t t'

fork

I(t,c,s) = {t'} I(t',c',s')={t}s s'

(t,c,s) || (t',c',s')

[I-JOIN]t

(c,jni )←−−− t ′

I(t , c, jni) = I(t , c, jni)\{t ′}

fork

I(t,c,s) = {t'} I(t',c',s')={t}s s'

join

s1I(t,c,s1) = { }

(t,c,s) || (t',c',s') (t',c',s') || (t,c,s1)

t t'

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

forkI(t,c,s)={}s

join

s'I(t',c',s')={}fork

join

t0 tt'

(t,c,s) || (t',c',s')

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

(t,c,s) || (t',c',s')

forkI(t,c,s)={t'}s

join

s'I(t',c',s')={t}fork

join

t0 tt'

13 / 1

Page 37: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Interleaving Analysis Rule

[I-DESCENDANT]t

(c,fki )−−−→ t ′ (t , c, fki)→ (t , c, `) (c′, `′) = Entry(St ′)

{t ′} ⊆ I(t , c, `) {t} ⊆ I(t ′, c′, `′)

[I-SIBLING]t ./ t ′ (c, `) = Entry(St) (c′, `′) = Entry(St ′) t 6� t ′ ∧ t ′ 6� t

{t} ⊆ I(t ′, c′, `′) {t ′} ⊆ I(t , c, `)

[I-JOIN]t

(c,jni )←−−− t ′

I(t , c, jni) = I(t , c, jni)\{t ′}[I-CALL]

(t , c, `)calli−−→ (t , c′, `′) c′ = c.push(i)I(t , c, `) ⊆ I(t , c′, `′)

[I-INTRA](t , c, `)→ (t , c, `′)I(t , c, `) ⊆ I(t , c, `′) [I-RET]

(t , c, `)reti−−→ (t , c′, `′) i = c.peek() c′ = c.pop()

I(t , c, `) ⊆ I(t , c′, `′)

14 / 1

Page 38: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Lock Analysis

Statements from different mutex regions are interference-free ifthese regions are protected by a common lock.

s1

T1 T2

s3

s4s2

fork(t2, foo)

s1 : *p = & c

s2 : *p = & d

Thread 1 Thread 2

foo(){

s4 : q = *p

}

s3 : *p = & e

[a][a]

[a]

fork

[a]

main(){

}

[a]

15 / 1

Page 39: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Lock Analysis

Statements from different mutex regions are interference-free ifthese regions are protected by a common lock.

s1

T1 T2

s3

sp!1 sp!2

s4Xs2

fork(t2, foo)

s1 : *p = & c

s2 : *p = & d

Thread 1 Thread 2

foo(){

s4 : q = *p

}

s3 : *p = & e

[a][a]

[a]

fork

[a]

main(){

}

lock(l)

unlock(l)

lock(l)

unlock(l)

16 / 1

Page 40: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Outline

• Background and Motivation• Our approach: FSAM• Evalution

16 / 1

Page 41: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Evaluation• Implementation:

• On top of our previous open-source tool SVF(http://unsw-corg.github.io/SVF/) (CC ’16)

• Around 4,000 LOC core source code• Field-sensitivity: each field instance of a struct is treated as

a separate object, arrays are considered monolithic.• On-the-fly call graph construction.

• Methodology• FSAM v.s. NONSPARSE iterative flow-sensitive analysis

following RR algorithm1

• Benchmarks:• Two largest C benchmarks from Phoenix-2.0• Five largest C benchmarks from Parsec-3.0• Three open-source applications

• Machine setup:• Ubuntu Linux 3.11 Intel Xeon Quad Core, 3.7GHZ, 64GB

1Radu Rugina and Martin Rinard, Pointer Analysis for Multithreaded ProgramsPLDI ’99

17 / 1

Page 42: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Evaluation• Implementation:

• On top of our previous open-source tool SVF(http://unsw-corg.github.io/SVF/) (CC ’16)

• Around 4,000 LOC core source code• Field-sensitivity: each field instance of a struct is treated as

a separate object, arrays are considered monolithic.• On-the-fly call graph construction.

• Methodology• FSAM v.s. NONSPARSE iterative flow-sensitive analysis

following RR algorithm1

• Benchmarks:• Two largest C benchmarks from Phoenix-2.0• Five largest C benchmarks from Parsec-3.0• Three open-source applications

• Machine setup:• Ubuntu Linux 3.11 Intel Xeon Quad Core, 3.7GHZ, 64GB

1Radu Rugina and Martin Rinard, Pointer Analysis for Multithreaded ProgramsPLDI ’99

17 / 1

Page 43: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Evaluation• Implementation:

• On top of our previous open-source tool SVF(http://unsw-corg.github.io/SVF/) (CC ’16)

• Around 4,000 LOC core source code• Field-sensitivity: each field instance of a struct is treated as

a separate object, arrays are considered monolithic.• On-the-fly call graph construction.

• Methodology• FSAM v.s. NONSPARSE iterative flow-sensitive analysis

following RR algorithm1

• Benchmarks:• Two largest C benchmarks from Phoenix-2.0• Five largest C benchmarks from Parsec-3.0• Three open-source applications

• Machine setup:• Ubuntu Linux 3.11 Intel Xeon Quad Core, 3.7GHZ, 64GB

1Radu Rugina and Martin Rinard, Pointer Analysis for Multithreaded ProgramsPLDI ’99

17 / 1

Page 44: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Benchmarks

Table: Program statistics.

Benchmark Description LOCword count Word counter based on map-reduce 6330kmeans Iterative clustering of 3-D points 6008radiosity Graphics 12781automount Manage autofs mount points 13170ferret Content similarity search server 15735bodytrack Body tracking of a person 19063httpd server Http server 52616mt daapd Multi-threaded DAAP Daemon 57102raytrace Real-time raytracing 84373x264 Media processing 113481Total 380,659

RR only evaluated their analysis with benchmarks with up to 4500 lines of Cilk code.18 / 1

Page 45: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Analysis Time and Memory Usage

Table: Analysis time and memory usage.

Program Time (Secs) Memory (MB)FSAM NONSPARSE FSAM NONSPARSE

word count 3.04 17.40 13.79 53.76kmeans 2.50 18.19 18.27 53.19radiosity 6.77 29.29 38.65 95.00automount 8.66 83.82 27.56 364.67ferret 13.49 87.10 52.14 934.57bodytrack 128.80 2809.89 313.66 12410.16httpd server 191.22 2079.43 55.78 6578.46mt daapd 90.67 2667.55 37.92 3403.26raytrace 284.61 OOT 135.06 OOTx264 531.55 OOT 129.58 OOT

FSAM is 12x faster and uses 28x less memory.19 / 1

Page 46: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Impact of FSAM’s three thread interferenceanalysis

Figure: Impact of FSAM’s three thread interference analysis phaseson the performance of flow-sensitive points-to resolution.

20 / 1

Page 47: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Conclusion

• The first sparse flow-sensitive pointer analysis forunstructured multithreaded programs (C with Pthread)

• A series of context-sensitive thread interference analysesby reasoning about fork/join, memory accesses,lock/unlock.

• Significantly faster than non-sparse algorithm and scalesto large size multithreaded Pthread programs with up to100KLOC.

Consist

ent *Complete *

Well D

ocumented*Easyt

oR

euse* *

Evaluated

*CGO*

Art ifact *

AEC Open source and publicly available online:

http://www.cse.unsw.edu.au/~corg/fsam/

21 / 1

Page 48: Sparse Flow-Sensitive Pointer Analysis For Multithreaded ... · CGO 2016, March 15th, Barcelona Pointer Analysis Pointer Analysis is to statically approximate runtime values of a

CGO 2016, March 15th, Barcelona

Thanks!

Q & A

21 / 1