Title: CS294-32: Dynamic Partial Order Reduction
1CS294-32 Dynamic Partial Order Reduction
2Exponential Blowup
Computation tree for a single thread
Conditional statement
Computation tree for two threads
Scheduler choice thread switch
3Solution
- All paths in the tree are not important for
statement reachability - Many paths are equivalent to each other
- Prune equivalent paths gt Partial Order Reduction
- Generate inputs along with Partial Order Reduction
4Equivalent Paths
x0, y0
x0, y0
One partial order
Same partial order Different linear order gt
Different Path gt Equivalent Path
5Independent transitions
s
- B and R are independent transitions if
- they commute B R R B
- neither enables nor disables the other
- Example x 3 and y 2 are independent
6Existing Approaches
- Static Partial Order Reduction
- Valmari 91, Peled 93, Godefroid 96, SPIN model
checkerby Holzmann, Verisoft - Limitation
- Results in a large dependent relation
- Pointers -gt Whether two pointers point to the
same location is determined conservatively (May
point-to) - Results in over-approximation of the dependency
relation - Limited POR
7Example static partial-order reduction
Global Vars lock m int i1,i2 int x0 int
n100 char a
Thread 2 lock(m) i2 x unlock(m) for(
i2ltn i22) ai2 r
Thread 1 lock(m) i1 x unlock(m)
for( i1ltn i12) ai1 b
- Static analysis gives
- i1, i2 are thread-local
- x is protected by m
- but ai1 and ai2 may alias
- Static POR gives O(n2) explored states and
transitions - but only two possible terminating states
never alias (in practice)
8Dynamic partial-order reduction
- Static POR relies on static analysis
- to yield approximate information about run-time
behavior - pointers gt coarse information gt limited POR gt
path explosion - Dynamic POR
- while model checker executes the program,
- it sees exactly which threads access which
locations - use to simultaneously reduce the path space while
model-checking
9- Focus on Race-Detection and Flipping Algorithm
and Concolic Testing jCUTE - Race-Detection and Flipping Algorithm is a
simplified form of DPOR - Proof of correctness in the presence of inputs
and conditionals
10Event
- (t,l,a)
- If thread t executes the statement labeled l and
the access type is a - a 2 w,r,l,u,?
- An execution path ? is a sequence of events
11Sequential Relation
- e (t,l,a) and e (t,l,a)
- e C e
- e e', or
- tt and e appears before e' in ?, or
- t ? t, t created the thread t, and e appears
before e'' in ?, where e'' is the fork event on t
creating the thread t, or - there exists an event e'' in ? such that e C e''
and e'' C e'.
12Causal Relation (Happens-Before Relation)
- e (t,l,a) and e (t,l,a)
- e ¹ e
- e C e, or
- e appears before e' in ? and both access a shared
memory location m and one of the accesses is
update (write, lock acquire, release), or - there exists an event e'' in ? such that e ¹ e''
and e'' ¹ e'. - ¹ is a partial order relation
13Equivalent Paths
- Definition Two execution paths are equivalent if
they are linearizations of the same partial order - Proposition Exploration of one linear order of
each partial order is sufficient for statement
reachability
14Race Relation
- Not so strict definition (see paper for the
strict definition) - e (t,l,a) and e (t,l,a)
- e l e
- e ¹ e
- Not (e C e or e C e)
- There exists no e1 such that e ¹ e1 and e1 ¹ e
- Where e1 is not equal to e or e
- Events in race relation can be permuted by
changing schedule - What happens if we have locks? (see paper)
15DPOR (Race-detection and flipping) Example
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
16DPOR (Race-detection and flipping) Example
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
17DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
18DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
x 1
t1
y 2
Race
y 3
x 4
19DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
x 1
Backtrack Here
t1
y 2
Race
y 3
x 4
20DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
x 1
Backtrack Here
t1
y 2
Race
y 3
x 4
21DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
x 1
t1
y 3
x 4
y 2
22DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
t1
x 1
t1 ,t2
Race
y 3
x 4
Race
y 2
23DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
t1
x 1
Cannot Backtrack Here
t1 ,t2
Race
y 3
x 4
Race
y 2
24DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
Backtrack Here
t1
x 1
t1 ,t2
Race
y 3
x 4
Race
y 2
25DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
Backtrack Here
t1
x 1
Race
y 3
x 4
Race
y 2
26DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 3
t1
y 3
x 4
x 1
y 2
27DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 3
t1
y 3
t2
x 4
Race
x 1
y 2
28DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 3
t1
y 3
Backtrack Here
t2
x 4
Race
x 1
y 2
29DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 3
t1
y 3
Backtrack Here
t2
x 4
Race
x 1
y 2
30DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 4
t1
y 3
t2
x 1
y 2
x 4
31DPOR (Race-detection and flipping) Example
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 4
Cannot Backtrack Here
t1,t2
y 3
Cannot Backtrack Here
t1,t2
Race
x 1
y 2
Race
x 4
Done!
32DPOR (POPL 05) Example
Postponed
Persistent
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
x 1
t1
t2
y 2
Race
y 3
x 4
33DPOR (POPL 05) Example
Postponed
Persistent
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
t1
t2
x 1
t1 ,t2
t1 ,t2
y 3
x 4
y 2
34DPOR (POPL 05) Example
Postponed
Persistent
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 3
t1
t2
y 3
t2
t1
x 4
x 1
y 2
35DPOR (POPL 05) Example
Postponed
Persistent
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 4
t1,t2
t1,t2
y 3
t1,t2
t1,t2
x 1
y 2
x 4
36DPOR Problem
- Thread t1
- 1 x 1
- 2 x 2
- Thread t2
- 1 y 1
- 2 x 3
- DPOR (both approaches) explores all 6 execution
paths gt No reduction - Example in the POPL 05 paper has error
- Think about it
- Need Sleep Set to obtain reduction
37Sleep Set Example
38DPOR (Race-detection and flipping) Example
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
39DPOR (Race-detection and flipping) Example
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
40DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
41DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
x 1
t1
y 2
Race
y 3
x 4
42DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
x 1
Backtrack Here
t1
y 2
Race
y 3
x 4
43DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 1
x 1
Backtrack Here
t1
y 2
Race
y 3
x 4
44DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
x 1
t1
t1
y 3
t1
x 4
y 2
45DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
t1
x 1
t1
t1
Race
y 3
t1
X
x 4
Race
y 2
46DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
t1
x 1
Nothing to Backtrack Here
t1
t1
Race
y 3
t1
X
x 4
Race
y 2
47DPOR (Race-detection and flipping) Example
Delayed
Postponed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
Backtrack Here
t1
x 1
t1
t1
Race
y 3
t1
X
x 4
Race
y 2
48DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 2
Backtrack Here
t1
x 1
t1
Race
y 3
t1
X
x 4
Race
y 2
49DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 3
t1
t1
y 3
t1
x 4
x 1
y 2
50DPOR (Race-detection and flipping) Example
Postponed
Delayed
- Thread t1
- 1 x 1
- 2 y 2
- Thread t2
- 1 y 3
- 2 x 4
Execution 3
t1
t1
y 3
t1
x 4
Race
X
x 1
y 2
51jCUTE
- Key Observation Concolic execution is ideal for
testing concurrent programs with complex data
inputs - Use symbolic execution to generate new inputs
- Use concrete execution to perform partial order
reduction
?
52jCUTE
- Key Observation Concolic execution is ideal for
testing concurrent programs with complex data
inputs - Use symbolic execution to generate new inputs
- Use concrete execution to perform partial order
reduction - Explore Interesting thread schedules or total
orders - Where to perform context switches?
- How to perform context switches?
?
53jCUTE
- Key Observation Concolic execution is ideal for
testing concurrent programs with complex data
inputs - Use symbolic execution to generate new inputs
- Use concrete execution to perform partial order
reduction - Explore Interesting thread schedules or total
orders - Where to perform context switches?
- Detect data race and lock race
- How to perform context switches?
- Hijack the scheduler using semaphores
- Insert semaphores through instrumentation
?
54jCUTE Example
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
55jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
56jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
x ? 3, z ? 17
x ? 3, z ? z0
57jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 3, z ? 17
x ? 3, z ? z0
x ? 2, z ? 17
x ? 2, z ? z0
58jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 3, z ? 17
x ? 3, z ? z0
x ? 2, z ? 17
x ? 2, z ? z0
2z01!2
x ? 2, z ? 17
x ? 2, z ? z0
59jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 3, z ? 17
x ? 3, z ? z0
x ? 2, z ? 17
x ? 2, z ? z0
2z01!2
x ? 2, z ? 17
x ? 2, z ? z0
Backtrack Here Solve 2z012 No Solution
60jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 3, z ? 17
x ? 3, z ? z0
x ? 2, z ? 17
x ? 2, z ? z0
x ? 2, z ? 17
x ? 2, z ? z0
Backtrack Here
61jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
62jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 2, z ? 17
x ? 2, z ? z0
63jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 2, z ? 17
x ? 2, z ? z0
2z01!2
x ? 2, z ? 17
x ? 2, z ? z0
64jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 2, z ? 17
x ? 2, z ? z0
t2
2z01!2
x ? 2, z ? 17
x ? 2, z ? z0
x ? 3, z ? 17
x ? 3, z ? z0
65jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 2, z ? 17
x ? 2, z ? z0
t2
2z01!2
x ? 2, z ? 17
x ? 2, z ? z0
x ? 3, z ? 17
x ? 3, z ? z0
Backtrack Here Solve 2z012 No Solution
66jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 2, z ? 17
x ? 2, z ? z0
t2
x ? 2, z ? 17
x ? 2, z ? z0
x ? 3, z ? 17
x ? 3, z ? z0
Backtrack Here
67jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
t2
68jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1
x ? 2, z ? 17
x ? 2, z ? z0
t2
69jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1 ,t2
x ? 2, z ? 17
x ? 2, z ? z0
t2
x ? 3, z ? 17
x ? 3, z ? z0
70jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1 ,t2
x ? 2, z ? 17
x ? 2, z ? z0
t1 ,t2
x ? 3, z ? 17
x ? 3, z ? z0
2z01!3
x ? 3, z ? 17
x ? 3, z ? z0
71jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 17
x ? 0, z ? z0
t1 ,t2
x ? 2, z ? 17
x ? 2, z ? z0
t1 ,t2
x ? 3, z ? 17
x ? 3, z ? z0
2z01!3
x ? 3, z ? 17
x ? 3, z ? z0
Backtrack Here Solve 2z013 Solution z 1
72jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 1
x ? 0, z ? z0
t1 ,t2
t1 ,t2
73jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 1
x ? 0, z ? z0
t1 ,t2
x ? 2, z ? 1
x ? 2, z ? z0
t1 ,t2
x ? 3, z ? 1
x ? 3, z ? z0
2z013
x ? 3, z ? 1
x ? 3, z ? z0
74jCUTE Example
Concrete State
Symbolic State
Path Constraint Postponed Set
- z input()
- Thread t1
- 1 x 3
- Thread t2
- 1 x 2
- 2 if (2z 1 x)
- 3 ERROR
x ? 0, z ? 1
x ? 0, z ? z0
t1 ,t2
x ? 2, z ? 1
x ? 2, z ? z0
t1 ,t2
x ? 3, z ? 1
x ? 3, z ? z0
2z013
x ? 3, z ? 1
x ? 3, z ? z0
Nothing to Backtrack
75Race Detection
- Dynamic Vector Clock Algorithm FSE03,TACAS04
- Vector clock V Threads ! Nat
- Vi be vector clock for each thread ti.
- Vxa and Vxw vector clocks for each shared
variable x. - Algorithm
- if eik is a shared memory access, then
- Vii à Vii 1
- if eik is a read of a variable x then
- Vi à maxVi,Vxw
- Vxa à maxVxa,Vi
- if eik is a write of a variable x then
- Vxw à Vxa à Vi à maxVxa,Vi
Lemma For any two events e ¹ e iff Ve Ve
76Race Flipping Hijack Thread Scheduler
- Ensure that only one thread is executing
- Create a tester thread (tsched)
- Associate a semaphore sem(t) with each thread t
- Before any shared memory access by t
- release control to the tester thread
- V(sem(tsched)) P(sem(t))
- Tester thread schedules a thread t
- V(sem(t)) P(sem(tsched))
77jCUTE
- jCUTE can test multi-threaded Java programs
- URL
- http//osl.cs.uiuc.edu/ksen/cute/
- Next generation testing tools
- Combines Testing and Model-Checking
- jCUTE supports generation of JUnit test cases
- The tools also support replay of a buggy execution
78Sun Microsystems JDK 1.4 Library
- java.util package provides thread-safe
data-structure classes - LinkedList, ArrayList, HashSet, TeeMap, etc.
- Widely used
- Found previously undocumented concurrency related
problems - Data race, Infinite Loop, Uncaught Exceptions,
and Deadlocks
- List l1
- Collections.synchronizedList(new LinkedList())
- List l2
- Collections.synchronizedList(new LinkedList())
- l1.add(null)
- l2.add(null)
- // Create two threads
- // let thread 1 run
- l1.clear()
- // let thread 2 run
- l2.containsAll(l1)
79Sun Microsystems JDK 1.4 Library
Name Runtime in seconds of Paths of Threads Branch Coverage of Functions Tested of Bugs Found data races deadlocks infinite loops exceptions
Vector 5519 20000 5 76.38 16 1902
ArrayList 6811 20000 5 75.00 16 3903
LinkedList 4401 11523 5 82.05 15 3311
LinkedHashSet 7303 20000 5 67.39 20 3902
TreeSet 7333 20000 5 54.93 26 4902
HashSet 7449 20000 5 69.56 20 19902
80Honeywells DEOS real-time scheduling kernel
- Operating system developed for use in small
business aircraft - jCUTE found the subtle time-partitioning error in
lt 1 minute - Java Pathfinder from NASA Ames ran out of memory
on the original program - Had to test manually created abstraction
- Took 11 minutes to discover the same error in the
abstraction