Mem checking axiomatic SAT specifications of memory models Emina - - PowerPoint PPT Presentation

mem
SMART_READER_LITE
LIVE PREVIEW

Mem checking axiomatic SAT specifications of memory models Emina - - PowerPoint PPT Presentation

Mem checking axiomatic SAT specifications of memory models Emina Torlak Mandana Vaziri Julian Dolby MIT SAT/SMT Summer School June 16, 2011 Introduction x = 0, y = 0, y = 0 memory model contract between programmer r1 = x r2


slide-1
SLIDE 1

checking axiomatic specifications of memory models

Mem SAT

Emina Torlak · Mandana Vaziri · Julian Dolby

MIT SAT/SMT Summer School · June 16, 2011

slide-2
SLIDE 2

memory model

  • contract between programmer

and programming environment

  • specifies which writes can be

seen by a read

  • described (in)formally by a set of

axioms and litmus tests

  • hard to design and reason about

Introduction

2

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==r2==1? r1==r2==1?

slide-3
SLIDE 3

memory model

  • contract between programmer

and programming environment

  • specifies which writes can be

seen by a read

  • described (in)formally by a set of

axioms and litmus tests

  • hard to design and reason about

Introduction

On Validity of Program Transformations in the Java Memory Model 47
  • 5. For all reads r ∈ Ai − Ci−1 we have Wi(r) ≤hbi r.
  • 6. For all reads r ∈ Ci − Ci−1 we have W(r) ∈ Ci−1.
  • 7. If y ∈ Ci is an external action and x ≤hb y then x ∈ Ci.
The original definition of legality from [11,18] differs in rules 2 and 6, and adds rule 8:
  • 2. ≤hbi |Ci =≤hb |Ci.
  • 6. For all reads r ∈ Ci − Ci−1 we have W(r) ∈ Ci−1 and Wi(r) ∈ Ci−1.
  • 8. If x <sswi y ≤hbi z and z ∈ Ci − Ci−1, then x <swj y for all j ≥ i, where
<sswi is the transitive reduction of ≤hbi without any ≤poi edges, and the transitive reduction of ≤hbi is a minimum relation such that its transitive closure is ≤hbi. The reasons for weakening the rules are invalidity of reordering of independent statements, broken JMM causality tests 17–20 [21], and redundancy. For details, see [5,6]. For reasoning about validity of reordering, we define observable behaviours of executions and programs. Intuitively, a program P has an observable behaviour B if B is a subset of external actions of some execution of P, and B is downward closed on happens-before order (restricted to external actions). The JMM cap- tures non-termination as a behaviour in the definition of allowable behaviours. Definition 9. An execution A, P, ≤po, ≤so, W, V with happens-before order ≤hb has a set of observable behaviours O if for all x ∈ O we have y ≤hb x
  • r y ≤so x implies y ∈ O or T (y) = θinit. Moreover, there is no x ∈ O such that
T (x) = θinit. The allowable behaviours may contain a special external hang action if the ex- ecution does not terminate. We will use the notation Ext(A)) for all external actions of set A, i.e., Ext(A) = {a | K(a) = Ex}. Definition 10. A finite set of actions B is an allowable behaviour of a program P if either – There is a legal execution E of P with a set of observable behaviours O such that B = Ext(O), or B = Ext(O) ∪ {hang} and E is hung. – There is a set O such that B = Ext(O) ∪ {hang}, and for all n ≥ |O| there must be a legal execution E of P with set of actions A, and a set of actions O such that (i) O and O are observable behaviours of E, (ii) O ⊆ O ⊆ A, (iii) n ≤ |O|, and (iv) Ext(O) = Ext(O). B Proof We prove validity of irrelevant read elimination, elimination of redundant write before write, elimination of redundant read after write, and reordering of non- volatile memory accesses to different variables. 46
  • J. ˇ
Sevˇ c´ ık and D. Aspinall
  • 3. |t| > 0 implies πK(()t0) = St (start action first),
  • 4. πK(()ti) = Fin implies i = |t| − 1 (finish action last).
  • 5. θ = θinit implies ∀i. 1 ≤ i < |t| − 1 → ∃v. πK(()ti) = Wr(v) ∨ πK(()ti) =
Wrv(v) and πK(()t|t|−1) = Fin (initialisation thread only contains writes). The well-formedness of programs should not be hard to establish for any rea- sonable sequential language. The next definition places some sensible restriction on executions. Definition 7. We say that an execution A, P, ≤po, ≤so, W, V is well-formed if
  • 1. A is finite.
  • 2. ≤po restricted on actions of one thread is a total order, ≤po does not relate
actions of different threads.
  • 3. ≤so is total on synchronisation actions of A.
  • 4. ≤so is consistent with ≤po.
  • 5. W is properly typed: for every non-volatile read r ∈ A, W(r) is a non-volatile
write; for every volatile read r ∈ A, W(r) is a volatile write.
  • 6. Locking is proper: for all lock actions l ∈ A on monitors m and all threads θ
different from the thread of l, the number of locks in θ before l in ≤so is the same as the number of unlocks in θ before l in ≤so.
  • 7. Program order is intra-thread consistent: for each thread θ, the trace of θ in
E is sequentially valid for Pθ.
  • 8. ≤so is consistent with W: for every volatile read r of a variable v we have
W(r) ≤so r and for any volatile write w to v, either w ≤so W(r) or r ≤so w.
  • 9. ≤hb is consistent with W: for all reads r of v it holds that r ≤hb W(r) and
there is no intervening write w to v, i.e. if W(r) ≤hb w ≤hb r and w writes to v then W(r) = w.
  • 10. The initialisation thread θinit finishes before any other thread starts, i.e.,
∀a, b ∈ A. K(a) = Fin ∧ T (a) = θinit ∧ K(b) = St ∧ T (b) = θinit → a ≤so b. The following definition of legal execution constitutes the core of the Java Mem-
  • ry Model. In our work, we use a weakened version of the memory model that
we suggested in [5] and which permits more transformations than the original
  • version. In Tbl. 1, we label this version by ‘JMM-Alt’.
Definition 8. A well-formed execution A, P, ≤po, ≤so, W, V with happens be- fore order ≤hb is legal if there is a finite sequence of sets of actions Ci and well-formed executions Ei = Ai, P, ≤poi, ≤soi, Wi, Vi with happens-before ≤hbi and synchronises-with <swi such that C0 = ∅, Ci−1 ⊆ Ci for all i > 0, Ci = A, and for each i > 0 the following rules are satisfied:
  • 1. Ci ⊆ Ai.
  • 2. For all reads r ∈ Ci we have W(r) ≤hb r ⇐
⇒ W(r) ≤hbi r, and r ≤hbi W(r),
  • 3. Vi|Ci = V |Ci.
  • 4. Wi|Ci−1 = W|Ci−1.
On Validity of Program Transformations in the Java Memory Model 45 Definition 2. An execution E is a tuple E = A, P, ≤po, ≤so, W, V , where A ⊆ A is a set of actions; P is a program, represented as a thread-indexed set of memory traces; the partial order ≤po⊆ A × A is the program order, which is a union of total orders on actions of each thread; ≤so⊆ A×A is the synchronisation
  • rder, which is a total order on all synchronisation actions in A; V :: A ⇒V is
a value-written function that assigns a value to each write from A; W :: A ⇒A is a write-seen function that assigns a write to each read action from A, the W(r) denotes the write seen by r, i.e. the value read by r is V (W(r)). Definition 3. In an execution with synchronisation order ≤so, an action a synchronises-with an action b (written a <sw b) if a ≤so b and a and b sat- isfy one of the following conditions: – a is an unlock on monitor m and b is a lock on monitor m, – a is a volatile write to v and b is a volatile read from v. Definition 4. The happens-before order of an execution is the transitive closure
  • f the composition of its synchronises-with order and its program order, i.e.
≤hb= (<sw ∪ ≤po)+. To relate a (sequential) program to a sequence of actions performed by one thread we must define a notion of sequential validity. We consider single-thread programs as sets of sequences of pairs of an action kind and a value, which we call traces. A multi-thread program is a set of single-thread programs indexed by thread identifiers. Definition 5. Given an execution E = A, P, ≤po, ≤so, W, V , the action trace
  • f thread θ in E, denoted TrE(θ), is the list of actions of thread θ in the order
≤po. The trace of thread θ in E, written TrE(θ) is the list of action kinds and corresponding values obtained from the action trace (i.e., V (W(a)) if a is a read, V (a) otherwise). By writing t ≤ t we mean that t is a prefix of t, set(t) is the set of elements of the list t, ι(t, a) is an index i such that ti = a, or 0 if a / ∈ set(t). For an action kind-value pair p = k, v we will use the notation πK(p) for the action kind k and πV (p) for the value v. We say that a sequence s of action kind-value pairs is sequentially valid with respect to a program P if t ∈ P. A sequentially valid trace t is finished for P if there is no sequentially valid trace t > t. The operator + + stands for trace concatenation. To establish reasonable properties of concurrent programs we assume reason- able properties of the underlying sequential language: Definition 6. We say that program P is well-formed if sequential validity of trace t in P implies:
  • 1. any trace t ≤ t is sequentially valid (prefix closedness),
  • 2. if the last action of t is a read with value v, then the trace obtained from t
by replacing the value in the last action by v is also sequentially valid in P (final read value independence), A JMM Definitions The following definitions are mostly from [11,18]; however, we have weakened the definition of execution legality as suggested in [5]. We use letters θ for thread names, m for synchronisation monitor names, and v for variables (i.e., memory locations, in examples, x, y, v etc.). The abstract type V will denote values. The starting point is the notion of action. Definition 1. An action is a memory-related operation; it is modelled by an abstract type A with the following properties: (1) Each action belongs to one thread, we will denote it by T (a). (2) An action is one of the following action kinds: – volatile read of v, – volatile write to v, – normal read from v, – normal write to v, – lock on m, – unlock on m, – thread start, – thread finish, – external action. We denote the action kind of a by K(a), the action kinds will be abbreviated to Rdv(v), Wrv(v), Rd(v), Wr(v), L(m), U(m), St, Fin, Ex. An action kind also includes the associated variable or monitor. The volatile read, volatile write, lock, unlock, start, finish actions are called synchronisation actions. The JMM also defines thread spawn and join action kinds. We omit these for simplicity.

2

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==r2==1? r1==r2==1?

  • described (in)formally by a set of

axioms and litmus tests

slide-4
SLIDE 4

memory model

  • contract between programmer

and programming environment

  • specifies which writes can be

seen by a read

  • described (in)formally by a set of

axioms and litmus tests

  • hard to design and reason about

Introduction

On Validity of Program Transformations in the Java Memory Model 47
  • 5. For all reads r ∈ Ai − Ci−1 we have Wi(r) ≤hbi r.
  • 6. For all reads r ∈ Ci − Ci−1 we have W(r) ∈ Ci−1.
  • 7. If y ∈ Ci is an external action and x ≤hb y then x ∈ Ci.
The original definition of legality from [11,18] differs in rules 2 and 6, and adds rule 8:
  • 2. ≤hbi |Ci =≤hb |Ci.
  • 6. For all reads r ∈ Ci − Ci−1 we have W(r) ∈ Ci−1 and Wi(r) ∈ Ci−1.
  • 8. If x <sswi y ≤hbi z and z ∈ Ci − Ci−1, then x <swj y for all j ≥ i, where
<sswi is the transitive reduction of ≤hbi without any ≤poi edges, and the transitive reduction of ≤hbi is a minimum relation such that its transitive closure is ≤hbi. The reasons for weakening the rules are invalidity of reordering of independent statements, broken JMM causality tests 17–20 [21], and redundancy. For details, see [5,6]. For reasoning about validity of reordering, we define observable behaviours of executions and programs. Intuitively, a program P has an observable behaviour B if B is a subset of external actions of some execution of P, and B is downward closed on happens-before order (restricted to external actions). The JMM cap- tures non-termination as a behaviour in the definition of allowable behaviours. Definition 9. An execution A, P, ≤po, ≤so, W, V with happens-before order ≤hb has a set of observable behaviours O if for all x ∈ O we have y ≤hb x
  • r y ≤so x implies y ∈ O or T (y) = θinit. Moreover, there is no x ∈ O such that
T (x) = θinit. The allowable behaviours may contain a special external hang action if the ex- ecution does not terminate. We will use the notation Ext(A)) for all external actions of set A, i.e., Ext(A) = {a | K(a) = Ex}. Definition 10. A finite set of actions B is an allowable behaviour of a program P if either – There is a legal execution E of P with a set of observable behaviours O such that B = Ext(O), or B = Ext(O) ∪ {hang} and E is hung. – There is a set O such that B = Ext(O) ∪ {hang}, and for all n ≥ |O| there must be a legal execution E of P with set of actions A, and a set of actions O such that (i) O and O are observable behaviours of E, (ii) O ⊆ O ⊆ A, (iii) n ≤ |O|, and (iv) Ext(O) = Ext(O). B Proof We prove validity of irrelevant read elimination, elimination of redundant write before write, elimination of redundant read after write, and reordering of non- volatile memory accesses to different variables. 46
  • J. ˇ
Sevˇ c´ ık and D. Aspinall
  • 3. |t| > 0 implies πK(()t0) = St (start action first),
  • 4. πK(()ti) = Fin implies i = |t| − 1 (finish action last).
  • 5. θ = θinit implies ∀i. 1 ≤ i < |t| − 1 → ∃v. πK(()ti) = Wr(v) ∨ πK(()ti) =
Wrv(v) and πK(()t|t|−1) = Fin (initialisation thread only contains writes). The well-formedness of programs should not be hard to establish for any rea- sonable sequential language. The next definition places some sensible restriction on executions. Definition 7. We say that an execution A, P, ≤po, ≤so, W, V is well-formed if
  • 1. A is finite.
  • 2. ≤po restricted on actions of one thread is a total order, ≤po does not relate
actions of different threads.
  • 3. ≤so is total on synchronisation actions of A.
  • 4. ≤so is consistent with ≤po.
  • 5. W is properly typed: for every non-volatile read r ∈ A, W(r) is a non-volatile
write; for every volatile read r ∈ A, W(r) is a volatile write.
  • 6. Locking is proper: for all lock actions l ∈ A on monitors m and all threads θ
different from the thread of l, the number of locks in θ before l in ≤so is the same as the number of unlocks in θ before l in ≤so.
  • 7. Program order is intra-thread consistent: for each thread θ, the trace of θ in
E is sequentially valid for Pθ.
  • 8. ≤so is consistent with W: for every volatile read r of a variable v we have
W(r) ≤so r and for any volatile write w to v, either w ≤so W(r) or r ≤so w.
  • 9. ≤hb is consistent with W: for all reads r of v it holds that r ≤hb W(r) and
there is no intervening write w to v, i.e. if W(r) ≤hb w ≤hb r and w writes to v then W(r) = w.
  • 10. The initialisation thread θinit finishes before any other thread starts, i.e.,
∀a, b ∈ A. K(a) = Fin ∧ T (a) = θinit ∧ K(b) = St ∧ T (b) = θinit → a ≤so b. The following definition of legal execution constitutes the core of the Java Mem-
  • ry Model. In our work, we use a weakened version of the memory model that
we suggested in [5] and which permits more transformations than the original
  • version. In Tbl. 1, we label this version by ‘JMM-Alt’.
Definition 8. A well-formed execution A, P, ≤po, ≤so, W, V with happens be- fore order ≤hb is legal if there is a finite sequence of sets of actions Ci and well-formed executions Ei = Ai, P, ≤poi, ≤soi, Wi, Vi with happens-before ≤hbi and synchronises-with <swi such that C0 = ∅, Ci−1 ⊆ Ci for all i > 0, Ci = A, and for each i > 0 the following rules are satisfied:
  • 1. Ci ⊆ Ai.
  • 2. For all reads r ∈ Ci we have W(r) ≤hb r ⇐
⇒ W(r) ≤hbi r, and r ≤hbi W(r),
  • 3. Vi|Ci = V |Ci.
  • 4. Wi|Ci−1 = W|Ci−1.
On Validity of Program Transformations in the Java Memory Model 45 Definition 2. An execution E is a tuple E = A, P, ≤po, ≤so, W, V , where A ⊆ A is a set of actions; P is a program, represented as a thread-indexed set of memory traces; the partial order ≤po⊆ A × A is the program order, which is a union of total orders on actions of each thread; ≤so⊆ A×A is the synchronisation
  • rder, which is a total order on all synchronisation actions in A; V :: A ⇒V is
a value-written function that assigns a value to each write from A; W :: A ⇒A is a write-seen function that assigns a write to each read action from A, the W(r) denotes the write seen by r, i.e. the value read by r is V (W(r)). Definition 3. In an execution with synchronisation order ≤so, an action a synchronises-with an action b (written a <sw b) if a ≤so b and a and b sat- isfy one of the following conditions: – a is an unlock on monitor m and b is a lock on monitor m, – a is a volatile write to v and b is a volatile read from v. Definition 4. The happens-before order of an execution is the transitive closure
  • f the composition of its synchronises-with order and its program order, i.e.
≤hb= (<sw ∪ ≤po)+. To relate a (sequential) program to a sequence of actions performed by one thread we must define a notion of sequential validity. We consider single-thread programs as sets of sequences of pairs of an action kind and a value, which we call traces. A multi-thread program is a set of single-thread programs indexed by thread identifiers. Definition 5. Given an execution E = A, P, ≤po, ≤so, W, V , the action trace
  • f thread θ in E, denoted TrE(θ), is the list of actions of thread θ in the order
≤po. The trace of thread θ in E, written TrE(θ) is the list of action kinds and corresponding values obtained from the action trace (i.e., V (W(a)) if a is a read, V (a) otherwise). By writing t ≤ t we mean that t is a prefix of t, set(t) is the set of elements of the list t, ι(t, a) is an index i such that ti = a, or 0 if a / ∈ set(t). For an action kind-value pair p = k, v we will use the notation πK(p) for the action kind k and πV (p) for the value v. We say that a sequence s of action kind-value pairs is sequentially valid with respect to a program P if t ∈ P. A sequentially valid trace t is finished for P if there is no sequentially valid trace t > t. The operator + + stands for trace concatenation. To establish reasonable properties of concurrent programs we assume reason- able properties of the underlying sequential language: Definition 6. We say that program P is well-formed if sequential validity of trace t in P implies:
  • 1. any trace t ≤ t is sequentially valid (prefix closedness),
  • 2. if the last action of t is a read with value v, then the trace obtained from t
by replacing the value in the last action by v is also sequentially valid in P (final read value independence), A JMM Definitions The following definitions are mostly from [11,18]; however, we have weakened the definition of execution legality as suggested in [5]. We use letters θ for thread names, m for synchronisation monitor names, and v for variables (i.e., memory locations, in examples, x, y, v etc.). The abstract type V will denote values. The starting point is the notion of action. Definition 1. An action is a memory-related operation; it is modelled by an abstract type A with the following properties: (1) Each action belongs to one thread, we will denote it by T (a). (2) An action is one of the following action kinds: – volatile read of v, – volatile write to v, – normal read from v, – normal write to v, – lock on m, – unlock on m, – thread start, – thread finish, – external action. We denote the action kind of a by K(a), the action kinds will be abbreviated to Rdv(v), Wrv(v), Rd(v), Wr(v), L(m), U(m), St, Fin, Ex. An action kind also includes the associated variable or monitor. The volatile read, volatile write, lock, unlock, start, finish actions are called synchronisation actions. The JMM also defines thread spawn and join action kinds. We omit these for simplicity.

2

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==r2==1? r1==r2==1?

  • described (in)formally by a set of

axioms and litmus tests

  • hard to design and reason about
slide-5
SLIDE 5

MemSAT overview

3

memory model litmus test

finitization parameters

legality witness proof of illegality

MemSAT Mem

slide-6
SLIDE 6

MemSAT overview

3

memory model

finitization parameters

legality witness proof of illegality P

annotated java program with one

  • r more assertions

MemSAT Mem

slide-7
SLIDE 7

MemSAT overview

3 finitization parameters

legality witness proof of illegality M P

annotated java program with one

  • r more assertions

set of constraints in relational logic

MemSAT Mem

slide-8
SLIDE 8

MemSAT overview

3 finitization parameters

legality witness proof of illegality M P

annotated java program with one

  • r more assertions

set of constraints in relational logic

  • translate P to relational logic
  • combine result with M
  • solve combined constraints

F(P, M)

MemSAT

slide-9
SLIDE 9

MemSAT overview

3 finitization parameters

legality witness proof of illegality M P

annotated java program with one

  • r more assertions

set of constraints in relational logic

  • translate P to relational logic
  • combine result with M
  • solve combined constraints

kodkod

F(P, M)

slide-10
SLIDE 10

MemSAT overview

3 finitization parameters

proof of illegality M P model(F(P, M))

annotated java program with one

  • r more assertions

set of constraints in relational logic model (solution) of the legality formula sat

  • translate P to relational logic
  • combine result with M
  • solve combined constraints

kodkod

F(P, M)

slide-11
SLIDE 11

MemSAT overview

3 finitization parameters

M P model(F(P, M)) mincore(F(P, M))

annotated java program with one

  • r more assertions

set of constraints in relational logic minimal unsatisfiable core of the legality formula model (solution) of the legality formula sat unsat

  • translate P to relational logic
  • combine result with M
  • solve combined constraints

kodkod

F(P, M)

slide-12
SLIDE 12

Specifying a litmus test

4

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==r2==1? r1==r2==1?

public class Test0 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } }

  • control flow
  • synchronize
  • method calls
  • field and array accesses
  • assertions
slide-13
SLIDE 13

Specifying a memory model

5

constants variables relational logic

slide-14
SLIDE 14

Specifying a memory model

5

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,)

slide-15
SLIDE 15

Specifying a memory model

5

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order
slide-16
SLIDE 16

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

Specifying a memory model

5

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order
slide-17
SLIDE 17

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

Specifying a memory model

5

t2 t1 t0

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order
slide-18
SLIDE 18

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

Specifying a memory model

5

t2 t1 t0

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

to = { 〈t0, t1〉, 〈t0, t2〉 }

slide-19
SLIDE 19

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

Specifying a memory model

5

t2 t1 t0

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

relational variables capture runtime properties of a program

  • A, set of all executed actions
  • W, maps reads to seen writes
  • V, maps writes to written values
  • l, maps reads/writes to locations
  • m, maps locks/unlocks to monitors

to = { 〈t0, t1〉, 〈t0, t2〉 }

slide-20
SLIDE 20

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

a00: start a01: write(x, 0) a02: write(y, 0) a03: end

Specifying a memory model

5

t2 t1

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

relational variables capture runtime properties of a program

  • A, set of all executed actions
  • W, maps reads to seen writes
  • V, maps writes to written values
  • l, maps reads/writes to locations
  • m, maps locks/unlocks to monitors

to = { 〈t0, t1〉, 〈t0, t2〉 }

slide-21
SLIDE 21

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

a00: start a01: write(x, 0) a02: write(y, 0) a03: end

Specifying a memory model

5

t2

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

relational variables capture runtime properties of a program

  • A, set of all executed actions
  • W, maps reads to seen writes
  • V, maps writes to written values
  • l, maps reads/writes to locations
  • m, maps locks/unlocks to monitors

to = { 〈t0, t1〉, 〈t0, t2〉 } a10: start a11: read(x, 0) a12: write(y, 1) a13: end

slide-22
SLIDE 22

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

a00: start a01: write(x, 0) a02: write(y, 0) a03: end

Specifying a memory model

5

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

relational variables capture runtime properties of a program

  • A, set of all executed actions
  • W, maps reads to seen writes
  • V, maps writes to written values
  • l, maps reads/writes to locations
  • m, maps locks/unlocks to monitors

to = { 〈t0, t1〉, 〈t0, t2〉 } a20: start a21: read(y, 1) a22: write(x, 1) a23: end a10: start a11: read(x, 0) a12: write(y, 1) a13: end

slide-23
SLIDE 23

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

a00: start a01: write(x, 0) a02: write(y, 0) a03: end

Specifying a memory model

5

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

relational variables capture runtime properties of a program

  • A, set of all executed actions
  • W, maps reads to seen writes
  • V, maps writes to written values
  • l, maps reads/writes to locations
  • m, maps locks/unlocks to monitors

to = { 〈t0, t1〉, 〈t0, t2〉 } A = { 〈a00〉, 〈a01〉, ..., 〈a23〉 } a20: start a21: read(y, 1) a22: write(x, 1) a23: end a10: start a11: read(x, 0) a12: write(y, 1) a13: end

slide-24
SLIDE 24

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

a00: start a01: write(x, 0) a02: write(y, 0) a03: end

Specifying a memory model

5

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

relational variables capture runtime properties of a program

  • A, set of all executed actions
  • W, maps reads to seen writes
  • V, maps writes to written values
  • l, maps reads/writes to locations
  • m, maps locks/unlocks to monitors

to = { 〈t0, t1〉, 〈t0, t2〉 } A = { 〈a00〉, 〈a01〉, ..., 〈a23〉 } W = { 〈a11, a01〉, 〈a21, a12〉 } a20: start a21: read(y, 1) a22: write(x, 1) a23: end a10: start a11: read(x, 0) a12: write(y, 1) a13: end

slide-25
SLIDE 25

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

a00: start a01: write(x, 0) a02: write(y, 0) a03: end

Specifying a memory model

5

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

relational variables capture runtime properties of a program

  • A, set of all executed actions
  • W, maps reads to seen writes
  • V, maps writes to written values
  • l, maps reads/writes to locations
  • m, maps locks/unlocks to monitors

to = { 〈t0, t1〉, 〈t0, t2〉 } A = { 〈a00〉, 〈a01〉, ..., 〈a23〉 } W = { 〈a11, a01〉, 〈a21, a12〉 } V = { 〈a01, 0〉, 〈a02, 0〉, 〈a12, 1〉, 〈a22, 1〉 } a20: start a21: read(y, 1) a22: write(x, 1) a23: end a10: start a11: read(x, 0) a12: write(y, 1) a13: end

slide-26
SLIDE 26

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

a00: start a01: write(x, 0) a02: write(y, 0) a03: end

Specifying a memory model

5

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

relational variables capture runtime properties of a program

  • A, set of all executed actions
  • W, maps reads to seen writes
  • V, maps writes to written values
  • l, maps reads/writes to locations
  • m, maps locks/unlocks to monitors

to = { 〈t0, t1〉, 〈t0, t2〉 } A = { 〈a00〉, 〈a01〉, ..., 〈a23〉 } W = { 〈a11, a01〉, 〈a21, a12〉 } V = { 〈a01, 0〉, 〈a02, 0〉, 〈a12, 1〉, 〈a22, 1〉 } l = { 〈a01, x〉, 〈a02, y〉, ..., 〈a22, x〉 } a20: start a21: read(y, 1) a22: write(x, 1) a23: end a10: start a11: read(x, 0) a12: write(y, 1) a13: end

slide-27
SLIDE 27

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1

a00: start a01: write(x, 0) a02: write(y, 0) a03: end

Specifying a memory model

5

constants variables relational logic

first order logic (∀, ∃, ∧, ∨, ¬ ) relational algebra (., ∪, ∩, ∕, ×, ⊆) bitvector arithmetic (+, -, *, /,) relational constants capture static properties of a program

  • co, control flow
  • to, thread order

relational variables capture runtime properties of a program

  • A, set of all executed actions
  • W, maps reads to seen writes
  • V, maps writes to written values
  • l, maps reads/writes to locations
  • m, maps locks/unlocks to monitors

to = { 〈t0, t1〉, 〈t0, t2〉 } A = { 〈a00〉, 〈a01〉, ..., 〈a23〉 } W = { 〈a11, a01〉, 〈a21, a12〉 } V = { 〈a01, 0〉, 〈a02, 0〉, 〈a12, 1〉, 〈a22, 1〉 } l = { 〈a01, x〉, 〈a02, y〉, ..., 〈a22, x〉 } m = { } a20: start a21: read(y, 1) a22: write(x, 1) a23: end a10: start a11: read(x, 0) a12: write(y, 1) a13: end

slide-28
SLIDE 28
  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

Example: sequential consistency

6

all statements appear to execute in a total

  • rder that agrees with the program text

interleaved semantics

Execution order is total, antisymmetric, and transitive. It respects the control flow and thread order. Reads cannot see out of order writes. No write interferes between a read and the write seen by that read.

slide-29
SLIDE 29
  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

Example: sequential consistency

6

all statements appear to execute in a total

  • rder that agrees with the program text

interleaved semantics

antisymmetric, and transitive. It respects the control flow and thread order. Reads cannot see out of order writes. No write interferes between a read and the write seen by that read. Execution order is total,

slide-30
SLIDE 30
  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

Example: sequential consistency

6

all statements appear to execute in a total

  • rder that agrees with the program text

interleaved semantics

transitive. It respects the control flow and thread order. Reads cannot see out of order writes. No write interferes between a read and the write seen by that read. Execution order is total, antisymmetric, and

slide-31
SLIDE 31
  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

Example: sequential consistency

6

all statements appear to execute in a total

  • rder that agrees with the program text

interleaved semantics

It respects the control flow and thread order. Reads cannot see out of order writes. No write interferes between a read and the write seen by that read. Execution order is total, antisymmetric, and transitive.

slide-32
SLIDE 32
  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

Example: sequential consistency

6

all statements appear to execute in a total

  • rder that agrees with the program text

interleaved semantics

thread order. Reads cannot see out of order writes. No write interferes between a read and the write seen by that read. Execution order is total, antisymmetric, and transitive. It respects the control flow and

slide-33
SLIDE 33
  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

Example: sequential consistency

6

all statements appear to execute in a total

  • rder that agrees with the program text

interleaved semantics

Reads cannot see out of order writes. No write interferes between a read and the write seen by that read. Execution order is total, antisymmetric, and transitive. It respects the control flow and thread order.

slide-34
SLIDE 34
  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

Example: sequential consistency

6

all statements appear to execute in a total

  • rder that agrees with the program text

interleaved semantics

No write interferes between a read and the write seen by that read. Execution order is total, antisymmetric, and transitive. It respects the control flow and thread order. Reads cannot see out of order writes.

slide-35
SLIDE 35
  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

Example: sequential consistency

6

all statements appear to execute in a total

  • rder that agrees with the program text

interleaved semantics

Execution order is total, antisymmetric, and transitive. It respects the control flow and thread order. Reads cannot see out of order writes. No write interferes between a read and the write seen by that read.

slide-36
SLIDE 36

A A2, W2, V2, l2, m2, po2, so2, sw2, hb2

E2

Ak, Wk, Vk, lk, mk, pok, sok, swk, hbk

Ek

A, W, V, l, m, po, so, sw, hb

E

Example: Java memory model

7

  • 1. ∀ i: [1..k] | Ci ⊆ Ai
  • 2. ∀ i: [1..k], r: Ci ∩ Read | (hb[W[r], r] ⇔

hbi[W[r], r]) ∧ ¬ hbi[r, W[r]]

  • 3. ∀ i: [1..k] | Ci ◁ Vi = Ci ◁ V
  • 4. ∀ i: [1..k] | Ci-1 ◁ Wi = Ci-1 ◁ W
  • 5. ∀ i: [1..k], r: (Ai ⧵ Ci) ∩ Read | hbi[Wi[r], r]
  • 6. ∀ i: [1..k], r: (Ci ⧵ Ci-1) ∩ Read | Wi[r] ⊆ Ci-1
  • 7. ∀ i: [1..k], y: Ci , x: Ai | (y ⊆ Special ∧

hb[x, y]) ⇒ x ⊆ Ci-1 an execution is legal if it can be derived by committing and executing actions in a sequence of speculative executions

committing semantics

A1, W1, V1, l1, m1, po1, so1, sw1, hb1

E1 ⇝

…⇝…

slide-37
SLIDE 37

A A1 A2, W2, V2, l2, m2, po2, so2, sw2, hb2

E2

Ak, Wk, Vk, lk, mk, pok, sok, swk, hbk

Ek

A, W, V, l, m, po, so, sw, hb

E

Example: Java memory model

7

  • 1. ∀ i: [1..k] | Ci ⊆ Ai
  • 2. ∀ i: [1..k], r: Ci ∩ Read | (hb[W[r], r] ⇔

hbi[W[r], r]) ∧ ¬ hbi[r, W[r]]

  • 3. ∀ i: [1..k] | Ci ◁ Vi = Ci ◁ V
  • 4. ∀ i: [1..k] | Ci-1 ◁ Wi = Ci-1 ◁ W
  • 5. ∀ i: [1..k], r: (Ai ⧵ Ci) ∩ Read | hbi[Wi[r], r]
  • 6. ∀ i: [1..k], r: (Ci ⧵ Ci-1) ∩ Read | Wi[r] ⊆ Ci-1
  • 7. ∀ i: [1..k], y: Ci , x: Ai | (y ⊆ Special ∧

hb[x, y]) ⇒ x ⊆ Ci-1 an execution is legal if it can be derived by committing and executing actions in a sequence of speculative executions

committing semantics

A1, W1, V1, l1, m1, po1, so1, sw1, hb1

E1 ⇝

…⇝…

initial execution: reads can only see writes that happen-before them

slide-38
SLIDE 38

A C1 A1 A2, W2, V2, l2, m2, po2, so2, sw2, hb2

E2

Ak, Wk, Vk, lk, mk, pok, sok, swk, hbk

Ek

A, W, V, l, m, po, so, sw, hb

E

Example: Java memory model

7

  • 1. ∀ i: [1..k] | Ci ⊆ Ai
  • 2. ∀ i: [1..k], r: Ci ∩ Read | (hb[W[r], r] ⇔

hbi[W[r], r]) ∧ ¬ hbi[r, W[r]]

  • 3. ∀ i: [1..k] | Ci ◁ Vi = Ci ◁ V
  • 4. ∀ i: [1..k] | Ci-1 ◁ Wi = Ci-1 ◁ W
  • 5. ∀ i: [1..k], r: (Ai ⧵ Ci) ∩ Read | hbi[Wi[r], r]
  • 6. ∀ i: [1..k], r: (Ci ⧵ Ci-1) ∩ Read | Wi[r] ⊆ Ci-1
  • 7. ∀ i: [1..k], y: Ci , x: Ai | (y ⊆ Special ∧

hb[x, y]) ⇒ x ⊆ Ci-1 an execution is legal if it can be derived by committing and executing actions in a sequence of speculative executions

committing semantics

A1, W1, V1, l1, m1, po1, so1, sw1, hb1

E1 ⇝

…⇝…

initial execution: reads can only see writes that happen-before them

slide-39
SLIDE 39

A C1 A2, W2, V2, l2, m2, po2, so2, sw2, hb2

E2

Ak, Wk, Vk, lk, mk, pok, sok, swk, hbk

Ek

A, W, V, l, m, po, so, sw, hb

E

Example: Java memory model

7

  • 1. ∀ i: [1..k] | Ci ⊆ Ai
  • 2. ∀ i: [1..k], r: Ci ∩ Read | (hb[W[r], r] ⇔

hbi[W[r], r]) ∧ ¬ hbi[r, W[r]]

  • 3. ∀ i: [1..k] | Ci ◁ Vi = Ci ◁ V
  • 4. ∀ i: [1..k] | Ci-1 ◁ Wi = Ci-1 ◁ W
  • 5. ∀ i: [1..k], r: (Ai ⧵ Ci) ∩ Read | hbi[Wi[r], r]
  • 6. ∀ i: [1..k], r: (Ci ⧵ Ci-1) ∩ Read | Wi[r] ⊆ Ci-1
  • 7. ∀ i: [1..k], y: Ci , x: Ai | (y ⊆ Special ∧

hb[x, y]) ⇒ x ⊆ Ci-1 an execution is legal if it can be derived by committing and executing actions in a sequence of speculative executions

committing semantics

A1, W1, V1, l1, m1, po1, so1, sw1, hb1

E1 ⇝

…⇝…

ith execution: committed reads can see committed writes; other reads must see writes that happen- before them

A2

slide-40
SLIDE 40

C2 A C1 A2, W2, V2, l2, m2, po2, so2, sw2, hb2

E2

Ak, Wk, Vk, lk, mk, pok, sok, swk, hbk

Ek

A, W, V, l, m, po, so, sw, hb

E

Example: Java memory model

7

  • 1. ∀ i: [1..k] | Ci ⊆ Ai
  • 2. ∀ i: [1..k], r: Ci ∩ Read | (hb[W[r], r] ⇔

hbi[W[r], r]) ∧ ¬ hbi[r, W[r]]

  • 3. ∀ i: [1..k] | Ci ◁ Vi = Ci ◁ V
  • 4. ∀ i: [1..k] | Ci-1 ◁ Wi = Ci-1 ◁ W
  • 5. ∀ i: [1..k], r: (Ai ⧵ Ci) ∩ Read | hbi[Wi[r], r]
  • 6. ∀ i: [1..k], r: (Ci ⧵ Ci-1) ∩ Read | Wi[r] ⊆ Ci-1
  • 7. ∀ i: [1..k], y: Ci , x: Ai | (y ⊆ Special ∧

hb[x, y]) ⇒ x ⊆ Ci-1 an execution is legal if it can be derived by committing and executing actions in a sequence of speculative executions

committing semantics

A1, W1, V1, l1, m1, po1, so1, sw1, hb1

E1 ⇝

…⇝…

ith execution: committed reads can see committed writes; other reads must see writes that happen- before them

A2

slide-41
SLIDE 41

C2 A C1 A2, W2, V2, l2, m2, po2, so2, sw2, hb2

E2

Ak, Wk, Vk, lk, mk, pok, sok, swk, hbk

Ek

A, W, V, l, m, po, so, sw, hb

E

Example: Java memory model

7

  • 1. ∀ i: [1..k] | Ci ⊆ Ai
  • 2. ∀ i: [1..k], r: Ci ∩ Read | (hb[W[r], r] ⇔

hbi[W[r], r]) ∧ ¬ hbi[r, W[r]]

  • 3. ∀ i: [1..k] | Ci ◁ Vi = Ci ◁ V
  • 4. ∀ i: [1..k] | Ci-1 ◁ Wi = Ci-1 ◁ W
  • 5. ∀ i: [1..k], r: (Ai ⧵ Ci) ∩ Read | hbi[Wi[r], r]
  • 6. ∀ i: [1..k], r: (Ci ⧵ Ci-1) ∩ Read | Wi[r] ⊆ Ci-1
  • 7. ∀ i: [1..k], y: Ci , x: Ai | (y ⊆ Special ∧

hb[x, y]) ⇒ x ⊆ Ci-1 an execution is legal if it can be derived by committing and executing actions in a sequence of speculative executions

committing semantics

A1, W1, V1, l1, m1, po1, so1, sw1, hb1

E1 ⇝

…⇝…

ith execution: committed reads can see committed writes; other reads must see writes that happen- before them

Ak

slide-42
SLIDE 42

C2 A C1

… Ck

A2, W2, V2, l2, m2, po2, so2, sw2, hb2

E2

Ak, Wk, Vk, lk, mk, pok, sok, swk, hbk

Ek

A, W, V, l, m, po, so, sw, hb

E

Example: Java memory model

7

  • 1. ∀ i: [1..k] | Ci ⊆ Ai
  • 2. ∀ i: [1..k], r: Ci ∩ Read | (hb[W[r], r] ⇔

hbi[W[r], r]) ∧ ¬ hbi[r, W[r]]

  • 3. ∀ i: [1..k] | Ci ◁ Vi = Ci ◁ V
  • 4. ∀ i: [1..k] | Ci-1 ◁ Wi = Ci-1 ◁ W
  • 5. ∀ i: [1..k], r: (Ai ⧵ Ci) ∩ Read | hbi[Wi[r], r]
  • 6. ∀ i: [1..k], r: (Ci ⧵ Ci-1) ∩ Read | Wi[r] ⊆ Ci-1
  • 7. ∀ i: [1..k], y: Ci , x: Ai | (y ⊆ Special ∧

hb[x, y]) ⇒ x ⊆ Ci-1 an execution is legal if it can be derived by committing and executing actions in a sequence of speculative executions

committing semantics

A1, W1, V1, l1, m1, po1, so1, sw1, hb1

E1 ⇝

…⇝…

ith execution: committed reads can see committed writes; other reads must see writes that happen- before them

Ak

slide-43
SLIDE 43

C2 A C1

… Ck

A2, W2, V2, l2, m2, po2, so2, sw2, hb2

E2

Ak, Wk, Vk, lk, mk, pok, sok, swk, hbk

Ek

A, W, V, l, m, po, so, sw, hb

E

Example: Java memory model

7

  • 1. ∀ i: [1..k] | Ci ⊆ Ai
  • 2. ∀ i: [1..k], r: Ci ∩ Read | (hb[W[r], r] ⇔

hbi[W[r], r]) ∧ ¬ hbi[r, W[r]]

  • 3. ∀ i: [1..k] | Ci ◁ Vi = Ci ◁ V
  • 4. ∀ i: [1..k] | Ci-1 ◁ Wi = Ci-1 ◁ W
  • 5. ∀ i: [1..k], r: (Ai ⧵ Ci) ∩ Read | hbi[Wi[r], r]
  • 6. ∀ i: [1..k], r: (Ci ⧵ Ci-1) ∩ Read | Wi[r] ⊆ Ci-1
  • 7. ∀ i: [1..k], y: Ci , x: Ai | (y ⊆ Special ∧

hb[x, y]) ⇒ x ⊆ Ci-1 an execution is legal if it can be derived by committing and executing actions in a sequence of speculative executions

committing semantics

A1, W1, V1, l1, m1, po1, so1, sw1, hb1

E1 ⇝

…⇝…

slide-44
SLIDE 44

Witness of legality (model)

8

a00: start a01: write(x, 0) a02: write(y, 0) a03: end a10: start a11: read(x, 0) a12: write(y, 1) a13: end a20: start a21: read(y, 0) a22: write(x, 1) a23: end W1 hb1

C1 E1

x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==r2==1? r1==r2==1?

JMM

witness: an execution of the program that satisfies both the assertions and the memory model constraints.

C2 E2

a00: start a01: write(x, 0) a02: write(y, 0) a03: end a10: start a11: read(x, 0) a12: write(y, 1) a13: end a20: start a21: read(y, 0) a22: write(x, 1) a23: end W2 hb2

E

a00: start a01: write(x, 0) a02: write(y, 0) a03: end a10: start a11: read(x, 1) a12: write(y, 1) a13: end a20: start a21: read(y, 1) a22: write(x, 1) a23: end W hb

slide-45
SLIDE 45

Proof of illegality (minimal core)

9

SC

minimal core: an unsatisfiable subset of the program and memory model constraints that becomes satisfiable if one of its members is removed x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==1 && r1==1 && r2==1?

V[a01] = 0 V[a02] = 0 V[W[a11]] = 1 V[W[a21]] = 1 ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i] ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k] ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j] ∀ k: A ∩ Read | ¬ ord[k, W[k]]

  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

slide-46
SLIDE 46

Proof of illegality (minimal core)

9

SC

minimal core: an unsatisfiable subset of the program and memory model constraints that becomes satisfiable if one of its members is removed x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==1 && r1==1 && r2==1?

V[a01] = 0 V[a02] = 0 V[W[a11]] = 1 V[W[a21]] = 1 ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i] ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k] ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j] ∀ k: A ∩ Read | ¬ ord[k, W[k]] aij represents the action (if any) performed by the jth statement of the ith thread

  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

slide-47
SLIDE 47

Proof of illegality (minimal core)

9

SC

minimal core: an unsatisfiable subset of the program and memory model constraints that becomes satisfiable if one of its members is removed x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==1 && r1==1 && r2==1?

V[a01] = 0 V[a02] = 0 V[W[a11]] = 1 V[W[a21]] = 1 ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i] ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k] ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j] ∀ k: A ∩ Read | ¬ ord[k, W[k]]

  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

slide-48
SLIDE 48

Proof of illegality (minimal core)

9

SC

minimal core: an unsatisfiable subset of the program and memory model constraints that becomes satisfiable if one of its members is removed x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==1 && r1==1 && r2==1?

V[a01] = 0 V[a02] = 0 V[W[a11]] = 1 V[W[a21]] = 1 ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i] ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k] ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j] ∀ k: A ∩ Read | ¬ ord[k, W[k]]

  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

slide-49
SLIDE 49

Proof of illegality (minimal core)

9

SC

minimal core: an unsatisfiable subset of the program and memory model constraints that becomes satisfiable if one of its members is removed x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==1 && r1==1 && r2==1?

V[a01] = 0 V[a02] = 0 V[W[a11]] = 1 V[W[a21]] = 1 ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i] ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k] ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j] ∀ k: A ∩ Read | ¬ ord[k, W[k]] a01: write(x, 1) a02: write(y, 0) a11: read(x, 1) a12: write(y, 1) a21: read(y, 1) a22: write(x, 1)

  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

x = 1,

slide-50
SLIDE 50

Proof of illegality (minimal core)

9

SC

minimal core: an unsatisfiable subset of the program and memory model constraints that becomes satisfiable if one of its members is removed x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==1 && r1==1 && r2==1?

V[a01] = 0 V[a02] = 0 V[W[a11]] = 1 V[W[a21]] = 1 ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i] ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k] ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j] ∀ k: A ∩ Read | ¬ ord[k, W[k]] a01: write(x, 1) a02: write(y, 0) a11: read(x, 1) a12: write(y, 1) a21: read(y, 1) a22: write(x, 1)

  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

a01: write(x, 0) a02: write(y, 0) a11: read(x, 0) a12: write(y, 1) a21: read(y, 1) a22: write(x, 1)

slide-51
SLIDE 51

Proof of illegality (minimal core)

9

SC

minimal core: an unsatisfiable subset of the program and memory model constraints that becomes satisfiable if one of its members is removed x = 0, y = 0, y = 0 r1 = x r2 = y y = 1 x = 1 r1==1 && r1==1 && r2==1?

V[a01] = 0 V[a02] = 0 V[W[a11]] = 1 V[W[a21]] = 1 ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i] ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k] ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j] ∀ k: A ∩ Read | ¬ ord[k, W[k]] a01: write(x, 1) a02: write(y, 0) a11: read(x, 1) a12: write(y, 1) a21: read(y, 1) a22: write(x, 1)

  • 1. ∀ i, j: A | i ≠ j ⇒ ord[i, j] ∨ ord[j, i]
  • 2. ∀ i, j: A | ord[i, j] ⇒ ¬ord[j, i]
  • 3. ∀ i, j, k: A | (ord[i, j] ∧ ord[j, k]) ⇒ ord[i, k]
  • 4. ∀ i, j: A | (t[i] = t[j] ∧ co+[i, j]) ⇒ ord[i, j]
  • 5. ∀ i, j: A | (t[i] ≠ t[j] ∧ to+[t[i], t[j]]) ⇒ ord[i, j]
  • 6. ∀ k: A ∩ Read | ¬ ord[k, W[k]]
  • 7. ∀ k: A ∩ Read, j: A ∩ Write |

¬ ( l[k] = l[j] ∧ ord[W[k], j] ∧ ord[j, k] )

a01: write(x, 0) a02: write(y, 0) a11: read(x, 0) a12: write(y, 1) a21: read(y, 1) a22: write(x, 1) a01: write(x, 0) a02: write(y, 0) a12: write(y, 1) a21: read(y, 1) a22: write(x, 1) a11: read(x, 1)

slide-52
SLIDE 52

Approach

10

Memory model Program preprocessor translator constraint assembler bounds assembler solver

finitization parameters

slide-53
SLIDE 53

Approach

10

Memory model Program preprocessor translator constraint assembler bounds assembler solver I(P)

finitize P and convert it to an intermediate form finitization parameters

slide-54
SLIDE 54

Approach

10

Memory model Program preprocessor translator constraint assembler bounds assembler solver I(P) R(P)

finitize P and convert it to an intermediate form translate I(P) to a relational representation finitization parameters

slide-55
SLIDE 55

Approach

10

Memory model Program preprocessor translator constraint assembler bounds assembler solver I(P) R(P) F(P, M)

finitize P and convert it to an intermediate form translate I(P) to a relational representation combine R(P) and M into the legality formula finitization parameters

slide-56
SLIDE 56

compute a set of bounds on the search space

Approach

10

Memory model Program preprocessor translator constraint assembler bounds assembler solver I(P) R(P) F(P, M) B(P, M)

finitize P and convert it to an intermediate form translate I(P) to a relational representation combine R(P) and M into the legality formula finitization parameters

slide-57
SLIDE 57

Approach

10

Memory model Program preprocessor translator constraint assembler bounds assembler

finitization parameters kodkod + MiniSat

WALA

MemSAT

contributions

efficiency m

  • d

u l a r i t y

slide-58
SLIDE 58

public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } } public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } }

Preprocessing

11

I(P)

finitize P and convert it to an intermediate form

slide-59
SLIDE 59

public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } } public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } }

Preprocessing

11

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

slide-60
SLIDE 60

public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } } public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } }

Preprocessing

11

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

control flow thread order

slide-61
SLIDE 61

public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } } public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } }

Preprocessing

11

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true

slide-62
SLIDE 62

public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } } public class Test1 { static int x = 0; static int y = 0; @thread public static void thread1() { final int r1 = x; if (r1 != 0) y = r1; else y = 1; assert r1==1; } @thread public static void thread2() { final int r2 = y; x = 1; assert r2==1; } }

Preprocessing

11

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

slide-63
SLIDE 63

Translation

12 translate I(P) to a relational representation

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

R(P)

slide-64
SLIDE 64

s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

Translation

12

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

slide-65
SLIDE 65

s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

Translation

12

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14} maps reads, writes, locks, and unlocks to relations representing locations that are accessed

slide-66
SLIDE 66

s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

Translation

12

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14} maps reads, writes, locks, and unlocks to relations representing locations that are accessed relational constants that represent fields: x = {<x>} and y = {<y>}

slide-67
SLIDE 67

s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

Translation

12

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14} maps writes and asserts to relational encodings of the values written or asserted

slide-68
SLIDE 68

s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

Translation

12

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14} maps writes and asserts to relational encodings of the values written or asserted relational variable that acts as a placeholder for the value read into r1

slide-69
SLIDE 69

s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

Translation

12

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14} maps statements to formulas that encode their guards

slide-70
SLIDE 70

s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

Translation

12

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

slide-71
SLIDE 71

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

F(P, M)

construct the legality formula for R(P) and M

Constraint assembly

13 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

slide-72
SLIDE 72

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly

13 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

slide-73
SLIDE 73

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly

13 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ The witness execution E respects the sequential semantics of P

slide-74
SLIDE 74

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly

13 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ The witness execution E respects the sequential semantics of P E executes and satisfies the assertions in P

slide-75
SLIDE 75

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly

13 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ The witness execution E respects the sequential semantics of P Each speculative execution Ei respects the sequential semantics of P E executes and satisfies the assertions in P

slide-76
SLIDE 76

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly

13 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ The witness execution E respects the sequential semantics of P E and all Ei respect the memory model constraints Each speculative execution Ei respects the sequential semantics of P E executes and satisfies the assertions in P

slide-77
SLIDE 77

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly

13 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

slide-78
SLIDE 78

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: Fα(R(P), E)

14 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors

slide-79
SLIDE 79

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: Fα(R(P), E)

14 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24 relational variable aij represents the action performed if E executes the statement ij

slide-80
SLIDE 80

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: Fα(R(P), E)

14 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a21]] V[W[a11]]

slide-81
SLIDE 81

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: Fα(R(P), E)

14 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤

V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a21]] V[W[a11]] V[W[a11]]

slide-82
SLIDE 82

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: F(R(P), E)

15 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a11]]

(|a13| = 1 ⇔ V[W[a11]] ≠ Bits(0)) ∧ (a13 ∩ a00) = ∅ ∧…∧ (a13 ∩ a24) = ∅ ∧ V[a13] = V[W[a11]] A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors |a13| ≤ 1 ∧ l[a13] = y ∧ 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end

V[W[a21]]

slide-83
SLIDE 83

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: F(R(P), E)

15 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a11]]

⋀s∈P F(s, R(P), E) ∧

A = a00 ∪…∪ a24 ∧ V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

(|a13| = 1 ⇔ V[W[a11]] ≠ Bits(0)) ∧ (a13 ∩ a00) = ∅ ∧…∧ (a13 ∩ a24) = ∅ ∧ V[a13] = V[W[a11]] A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors |a13| ≤ 1 ∧ l[a13] = y ∧ 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end

V[W[a21]]

slide-84
SLIDE 84

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: F(R(P), E)

15 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a11]]

⋀s∈P F(s, R(P), E) ∧

A = a00 ∪…∪ a24 ∧ V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

  • 0 or 1 action performed
  • action performed iff the

guard is true

  • no other statement

performs the same action

  • action location is valid
  • action value is valid

(|a13| = 1 ⇔ V[W[a11]] ≠ Bits(0)) ∧ (a13 ∩ a00) = ∅ ∧…∧ (a13 ∩ a24) = ∅ ∧ V[a13] = V[W[a11]] A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors |a13| ≤ 1 ∧ l[a13] = y ∧ 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end

V[W[a21]]

slide-85
SLIDE 85

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: F(R(P), E)

15 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a11]]

⋀s∈P F(s, R(P), E) ∧

A = a00 ∪…∪ a24 ∧ V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

  • 0 or 1 action performed
  • action performed iff the

guard is true

  • no other statement

performs the same action

  • action location is valid
  • action value is valid

(|a13| = 1 ⇔ V[W[a11]] ≠ Bits(0)) ∧ (a13 ∩ a00) = ∅ ∧…∧ (a13 ∩ a24) = ∅ ∧ V[a13] = V[W[a11]] A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors |a13| ≤ 1 ∧ l[a13] = y ∧ 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end

V[W[a21]] V[W[a11]]

slide-86
SLIDE 86

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: F(R(P), E)

15 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a11]]

⋀s∈P F(s, R(P), E) ∧

A = a00 ∪…∪ a24 ∧ V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

  • action performed iff the

guard is true

  • no other statement

performs the same action

  • action location is valid
  • action value is valid

(|a13| = 1 ⇔ V[W[a11]] ≠ Bits(0)) ∧ (a13 ∩ a00) = ∅ ∧…∧ (a13 ∩ a24) = ∅ ∧ V[a13] = V[W[a11]] A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors |a13| ≤ 1 ∧ l[a13] = y ∧ 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end

V[W[a21]] V[W[a11]]

slide-87
SLIDE 87

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: F(R(P), E)

15 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a11]]

⋀s∈P F(s, R(P), E) ∧

A = a00 ∪…∪ a24 ∧ V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

  • no other statement

performs the same action

  • action location is valid
  • action value is valid

(|a13| = 1 ⇔ V[W[a11]] ≠ Bits(0)) ∧ (a13 ∩ a00) = ∅ ∧…∧ (a13 ∩ a24) = ∅ ∧ V[a13] = V[W[a11]] A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors |a13| ≤ 1 ∧ l[a13] = y ∧ 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end

V[W[a21]] V[W[a11]]

slide-88
SLIDE 88

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: F(R(P), E)

15 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a11]]

⋀s∈P F(s, R(P), E) ∧

A = a00 ∪…∪ a24 ∧ V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

  • action location is valid
  • action value is valid

(|a13| = 1 ⇔ V[W[a11]] ≠ Bits(0)) ∧ (a13 ∩ a00) = ∅ ∧…∧ (a13 ∩ a24) = ∅ ∧ V[a13] = V[W[a11]] A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors |a13| ≤ 1 ∧ l[a13] = y ∧ 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end

V[W[a21]] V[W[a11]]

slide-89
SLIDE 89

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: F(R(P), E)

15 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a11]]

⋀s∈P F(s, R(P), E) ∧

A = a00 ∪…∪ a24 ∧ V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

  • action value is valid

(|a13| = 1 ⇔ V[W[a11]] ≠ Bits(0)) ∧ (a13 ∩ a00) = ∅ ∧…∧ (a13 ∩ a24) = ∅ ∧ V[a13] = V[W[a11]] A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors |a13| ≤ 1 ∧ l[a13] = y ∧ 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end

V[W[a21]] V[W[a11]]

slide-90
SLIDE 90

F(R(P), E) ∧ Fα(R(P), E) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek) V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

Constraint assembly: F(R(P), E)

15 s Loc Val Guard 00 ⊤ 01 x Bits(0) ⊤ 02 y Bits(0) ⊤ 03 ⊤ 10 ⊤ 11 x ⊤ 12 ⊤ 13 y r1 r1≠Bits(0) 14 y Bits(1) r1=Bits(0) 15 r1=Bits(1) ⊤ 16 ⊤ 20 ⊤ 21 y ⊤ 22 x Bits(1) ⊤ 23 r2=Bits(1) ⊤ 24 ⊤ a00 a01 a02 a03 a10 a11 a13 a14 a16 a20 a21 a22 a24

V[W[a11]]

⋀s∈P F(s, R(P), E) ∧

A = a00 ∪…∪ a24 ∧ V[W[a11]]=Bits(1) ∧ V[W[a21]]=Bits(1) ∧

⋀1≤i≤k F(R(P), Ei) ∧

M(E, E1, …, Ek)

(|a13| = 1 ⇔ V[W[a11]] ≠ Bits(0)) ∧ (a13 ∩ a00) = ∅ ∧…∧ (a13 ∩ a24) = ∅ ∧ V[a13] = V[W[a11]] A set of all executed actions W maps reads to seen writes V maps writes to written values l maps writes to written values m maps locks/unlocks to monitors |a13| ≤ 1 ∧ l[a13] = y ∧ 00 start 01 write(x, 0) 02 write(y, 0) 03 end 10 start 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 14 write(y, 1) 15 assert(r1==1) 16 end 20 start 21 r2=read(y) 22 write(x, 1) 23 assert(r2==1) 24 end

V[W[a21]] V[W[a11]]

slide-91
SLIDE 91

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

Bounds assembly

16

F(P, M)

compute a set of bounds on the search space

B(P, M)

slide-92
SLIDE 92

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

Bounds assembly

16

F(P, M)

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24

slide-93
SLIDE 93

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

Bounds assembly: universe

17

F(P, M)

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24 finite universe of symbolic values from which the model, if any, is drawn

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

slide-94
SLIDE 94

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

Bounds assembly: universe

17

F(P, M)

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24 finite universe of symbolic values from which the model, if any, is drawn primitives fields

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

slide-95
SLIDE 95

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

Bounds assembly: universe

17

F(P, M)

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24 finite universe of symbolic values from which the model, if any, is drawn a00 a01 a02 a03 a20 a21 a22 a24 a10 a11 a13 a16 primitives fields actions

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

slide-96
SLIDE 96

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

18

F(P, M)

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24 a00 a01 a02 a03 a20 a21 a22 a24 a10 a11 a13 a16

Bounds assembly: lower/upper bounds

upper and lower bound on the value

  • f each relation that

appears in F(P, M)

slide-97
SLIDE 97

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

18

F(P, M)

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24 a00 a01 a02 a03 a20 a21 a22 a24 a10 a11 a13 a16

Bounds assembly: lower/upper bounds

upper and lower bound on the value

  • f each relation that

appears in F(P, M)

slide-98
SLIDE 98

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

18

F(P, M)

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24 a00 a01 a02 a03 a20 a21 a22 a24 a10 a11 a13 a16

Bounds assembly: lower/upper bounds

<a00>, <a01>, <a02>, <a03>, <a10>, <a11>, <a13>, <a16>, <a20>, <a21>, <a22>, <a24>

{ }

upper and lower bound on the value

  • f each relation that

appears in F(P, M)

slide-99
SLIDE 99

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

18

F(P, M)

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24 a00 a01 a02 a03 a20 a21 a22 a24 a10 a11 a13 a16

Bounds assembly: lower/upper bounds

<a00>, <a01>, <a02>, <a03>, <a10>, <a11>, <a13>, <a16>, <a20>, <a21>, <a22>, <a24>

{ }

<a00>, <a01>, <a02>, <a03>, <a10>, <a11>, <a16>, <a20>, <a21>, <a22>, <a24>

{ }

upper and lower bound on the value

  • f each relation that

appears in F(P, M)

slide-100
SLIDE 100

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

18

F(P, M)

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24 a00 a01 a02 a03 a20 a21 a22 a24 a10 a11 a13 a16

Bounds assembly: lower/upper bounds

<a00>, <a01>, <a02>, <a03>, <a10>, <a11>, <a13>, <a16>, <a20>, <a21>, <a22>, <a24>

{ }

<a00>, <a01>, <a02>, <a03>, <a10>, <a11>, <a16>, <a20>, <a21>, <a22>, <a24>

{ } {

<a11, a01>, <a11, a22>, <a21, a02>, <a21, a13>}

upper and lower bound on the value

  • f each relation that

appears in F(P, M)

slide-101
SLIDE 101

00 start 01 write(x, 0) 02 write(y, 0) 03 end 21 r2=read(y) 22 write(x, 1) 24 end 20 start 23 assert(r2==1) 11 r1=read(x) 12 branch(r1!=0) 13 write(y, r1) 16 end 15 assert(r1==1) 14 write(y, 1) T F 10 start

s guard 13 r1!=0 14 r1==0 * true s maySee 11 {01, 22} 21 {02, 13, 14}

{…} ⊆ A ⊆ {…} {…} ⊆ V ⊆ {…} {…} ⊆ W ⊆ {…} {…} ⊆ l ⊆ {…} {…} ⊆ m ⊆ {…}

18

F(P, M)

  • 8, 1, 2, 4, x, y,

a00, a01, a02, a03, a10, a11, a13, a16, a20, a21, a22, a24 a00 a01 a02 a03 a20 a21 a22 a24 a10 a11 a13 a16

Bounds assembly: lower/upper bounds

<a00>, <a01>, <a02>, <a03>, <a10>, <a11>, <a13>, <a16>, <a20>, <a21>, <a22>, <a24>

{ }

<a00>, <a01>, <a02>, <a03>, <a10>, <a11>, <a16>, <a20>, <a21>, <a22>, <a24>

{ } {

<a11, a01>, <a11, a22>, <a21, a02>, <a21, a13>}

upper and lower bound on the value

  • f each relation that

appears in F(P, M)

slide-102
SLIDE 102

Results (highlights)

19

10 20 30 40 50 60 70 80 90 100 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20

2 1 1 2 1 56 13 2 3 2 2 2 2 2 2 2 2 2 2 2 2 2 2 2 1 96 35 2 4 2 2 2 2 2 2 3 2 2 2 2

MemSAT performance on JMM causality tests

analysis time (sec) JMM test

Original JMM

  • validates 17 & 18 (Sevcik’08 ✘)
  • violates 19 & 20 (Aspinall’07 ✔)

Revised JMM

  • overconstrained as given; fixed it
  • now validates all tests (Aspinall’07 ✔)
slide-103
SLIDE 103

Conclusion

Practical checker for axiomatic specifications of memory models

  • first tool to directly handle the current JMM
  • first tool to provide minimal cores

Prior work (highlights)

  • CheckFence hardcodes the memory model
  • Nemos accepts simple axiomatic specs but no cores
  • JMM checkers (e.g. OpMM) use operational approximations

Future work

  • extend MemSAT to handle hardware memory models

20

MemSAT