Keep Off the Grass Locking the Right Path for Atomicity Dave - - PowerPoint PPT Presentation

keep off the grass
SMART_READER_LITE
LIVE PREVIEW

Keep Off the Grass Locking the Right Path for Atomicity Dave - - PowerPoint PPT Presentation

Fundamentals Atomicity Keep Off the Grass Locking the Right Path for Atomicity Dave Cunningham Khilan Gudka Susan Eisenbach Imperial College London 07/03/2008 Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 1/34


slide-1
SLIDE 1

Fundamentals Atomicity

Keep Off the Grass

Locking the Right Path for Atomicity Dave Cunningham Khilan Gudka Susan Eisenbach

Imperial College London

07/03/2008

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 1/34

slide-2
SLIDE 2

Fundamentals Atomicity

Atomicity

In general...

◮ Semantics trivial to understand:

e, g ∗ v, g′ T ∪ {E[atomic e]}, g T ∪ {E[v]}, g′

◮ Naive implementation is inefficient ◮ Lots of research tries to interleave more threads... ◮ Deciding which threads can interleave is hard

atomic { Node x = new Node(); x.next = list.first; list.first = x; }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 1/34

slide-3
SLIDE 3

Fundamentals Atomicity

Comparison with Transactional Memory

There are two main approaches to allowing more threads:

◮ Transactional Memory

Disadvantages:

◮ IO, JNI, etc is very hard ◮ Performs badly under high contention ◮ Lots of runtime machinery

◮ Lock Inference

Disadvantages:

◮ Reflection, JNI, etc is very hard ◮ Worse granularity (common example: non-empty queue) ◮ Requires more compiler machinery than TM Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 2/34

slide-4
SLIDE 4

Fundamentals Atomicity

Related Work

Alternative ways of implementing atomic sections:

◮ Transactional Memory (more work than I can cite) ◮ Other lock inference approaches:

◮ Associating Synchronisation Constraints w/Data (POPL’05) ◮ Lock Inference for Atomic Sections (TRANSACT’06) ◮ Lock Allocation (POPL’07) ◮ Component-Based Lock Allocation (PACT’07) ◮ Inferring Locks for Atomic Sections (PLDI’08)

◮ Also, verification of programmer-implemented atomicity

◮ Cormac Flanagan et al (everywhere since 1999) ◮ “Autolocker” (POPL’06) ◮ Cunningham et al (VAMP’07) Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 3/34

slide-5
SLIDE 5

Fundamentals Lock Inference

Lock Inference

Inferred locks

◮ We try for at least the performance of manual locking ◮ Even if we are not as fast, we will at least be correct ◮ The accuracy of the inference determines the parallelism ◮ We avoid inferring locks for accesses to immutable data ◮ Knowing what objects are thread-local is also beneficial ◮ In theory, ownership types allow very good performance

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 4/34

slide-6
SLIDE 6

Fundamentals Lock Inference

Lock Discipline

◮ Usually require two-phase discipline

◮ Lock acquisitions precede lock releases ◮ All accesses nested within appropriate locks

◮ Example:

4 (´ 2 2 4 ´ 1 1 4 ´ 3 ` 1 2 2 4 ` 2 3 ` 3) 4

◮ Known that two phase locking ⇒ atomicity, due to Lipton (POPL’75) ◮ Everyone else uses two-phase

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 5/34

slide-7
SLIDE 7

Our Approach Examples (State)

Example 1 - Single Access

Source Target atomic { x = this.f } lock(this); x = this.f; unlock(this);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 6/34

slide-8
SLIDE 8

Our Approach Examples (State)

Example 1 - Single Access

Source Target atomic { x = this.f } // if f is final // or this is thread-local x = this.f;

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 6/34

slide-9
SLIDE 9

Our Approach Examples (State)

Example 1 - Single Access

Source Target atomic { x = this.f } // if f is final // or this is thread-local x = this.f; Henceforth, everything is non-final and shared between threads.

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 6/34

slide-10
SLIDE 10

Our Approach Examples (State)

Example 2

Source Target atomic { this.f = 42; x.f = 20; } lock(this); this.f = 42; lock(x); unlock(this); x.f = 20; unlock(x);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 7/34

slide-11
SLIDE 11

Our Approach Examples (State)

Example 2

Source Target atomic { this.f = 42; x.f = 20; } while (true) { lock(this); if (lock(x)) { break; // yes, continue } else { unlock(this); } // no, try again } this.f = 42; unlock(this); x.f = 20; unlock(x);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 7/34

slide-12
SLIDE 12

Our Approach Examples (State)

Example 2

Source Target atomic { this.f = 42; x.f = 20; } while (true) { lock(this); if (x==null || lock(x)) { break; // yes, continue } else { unlock(this); } // no, try again } this.f = 42; unlock(this); x.f = 20; unlock(x);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 7/34

slide-13
SLIDE 13

Our Approach Examples (State)

Example 2

Source Target atomic { this.f = 42; x.f = 20; } // from now on, assume: // - deadlock free // - NPE free // - CCE free lock(this,x); this.f = 42; unlock(this); x.f = 20; unlock(x);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 7/34

slide-14
SLIDE 14

Our Approach Examples (State)

Pause For Thought on Deadlock...

◮ We cannot insert locks that may deadlock ◮ The programmer cannot recover the situation ◮ Related work avoids deadlock by using ordering locks statically... ◮ ... but this seriously hurts granularity ◮ Our rollback strategy should have better granularity ◮ In our experience, rollback is actually very rare ◮ Overhead should be minimal ◮ All lock acquisitions moved to top, this might hurt granularity a bit ◮ No transaction log required

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 8/34

slide-15
SLIDE 15

Our Approach Examples (State)

Example 3 - Assign

Source Target atomic { x = this; x.f = 42; } lock(x); x = this; x.f = 42; unlock(x);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 9/34

slide-16
SLIDE 16

Our Approach Examples (State)

Example 3 - Assign

Source Target atomic { x = this; x.f = 42; } lock(this); x = this; x.f = 42; unlock(this);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 9/34

slide-17
SLIDE 17

Our Approach Examples (State)

Example 4 - Load

Source Target atomic { x = this.g; x.f = 42; } lock(this,this.g); x = this.g unlock(this); x.f = 42; unlock(x);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 10/34

slide-18
SLIDE 18

Our Approach Examples (State)

Example 5 - Construction

Source Target atomic { x = new C; x.f = 42; } x = new C; x.f = 42; atomic { x = null; x.f = 42; } x = null; x.f = 42;

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 11/34

slide-19
SLIDE 19

Our Approach Examples (State)

Example 6 - Readers/Writers

Many threads may read concurrently. Source Target atomic { x.f = 10; y = x.g; } lockw(x); x.f = 10; lockr(x); unlockw(x); y = x.g; unlockr(x);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 12/34

slide-20
SLIDE 20

Our Approach Examples (State)

Example 7 - Store

Source Target atomic { x.g = this; y = x.g; y.f = 42; } lockw(x,this); x.g = this; lockr(x); unlockw(x); y = x.g; unlockr(x); y.f = 42; unlockw(y);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 13/34

slide-21
SLIDE 21

Our Approach Examples (State)

How Does This Work?

Backwards program analysis propogates locks to start of block Source CFG Target atomic { x.g = this; y = x.g; y.f = 42; }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 14/34

slide-22
SLIDE 22

Our Approach Examples (State)

How Does This Work?

Backwards program analysis propogates locks to start of block Source CFG Target atomic { x.g = this; y = x.g; y.f = 42; }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 14/34

slide-23
SLIDE 23

Our Approach Examples (State)

How Does This Work?

Backwards program analysis propogates locks to start of block Source CFG Target atomic { x.g = this; y = x.g; y.f = 42; }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 14/34

slide-24
SLIDE 24

Our Approach Examples (State)

How Does This Work?

Backwards program analysis propogates locks to start of block Source CFG Target atomic { x.g = this; y = x.g; y.f = 42; }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 14/34

slide-25
SLIDE 25

Our Approach Examples (State)

How Does This Work?

Backwards program analysis propogates locks to start of block Source CFG Target atomic { x.g = this; y = x.g; y.f = 42; } lockw(x,this); x.g = this; lockr(x); unlockw(x); //lockw(x.g); //unlockw(this); y = x.g; //lockw(y); //unlockw(x.g); unlockr(x); y.f = 42; unlockw(y);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 14/34

slide-26
SLIDE 26

Our Approach Examples (Control Flow and Arrays)

Example8 - If

Source Target atomic { if (b) { vehicle = car; } else { vehicle = van; } vehicle.fuel = 42; } lock(car,van); if (b) { unlock(van); vehicle = car; } else { unlock(car); vehicle = van; } vehicle.fuel = 42; unlock(vehicle);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 15/34

slide-27
SLIDE 27

Our Approach Examples (Control Flow and Arrays)

Example 9 - While

class Node { Node n; int f; } atomic { while (x.n) { x = x.n; } x.f = 42; } //lock(x, x.n, x.n.n, ...); while (x.n) { x = x.n; } x.f = 42;

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 16/34

slide-28
SLIDE 28

Our Approach Examples (Control Flow and Arrays)

Example 9 - While

class Node { Node n; int f; } atomic { while (x.n) { x = x.n; } x.f = 42; } lock(Node); while (x.n) { x = x.n; } lock(x); unlock(Node); x.f = 42; unlock(x);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 16/34

slide-29
SLIDE 29

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-30
SLIDE 30

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-31
SLIDE 31

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-32
SLIDE 32

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-33
SLIDE 33

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-34
SLIDE 34

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-35
SLIDE 35

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-36
SLIDE 36

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } } Analysis doesn’t terminate :(

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-37
SLIDE 37

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } } How do we solve this?

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-38
SLIDE 38

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } } First, number the CFG nodes...

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-39
SLIDE 39

Our Approach Examples (Control Flow and Arrays)

How does it work?

atomic { while (x.n) { x = x.n; } } First, number the CFG nodes...

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 17/34

slide-40
SLIDE 40

Our Approach Examples (Control Flow and Arrays)

Nondeterministic Finite Automata

Recap:

◮ Propogating sets of “paths” through the graph. ◮ (This is a static characterisation of a set of objects.) ◮ We cannot represent an infinite set of paths: {x, x.n, x.n.n, . . .} ◮ Use regular expressions? {x.n∗} (sadly, hard to mechanise...) ◮ Use nondeterministic finite automata?

NFAs easily represent infinite sets of locks: More formally, a set of edges (doubles and triples): {x → 1, 1 →n 1} We constrain the set of automata nodes to the set of CFG nodes!

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 18/34

slide-41
SLIDE 41

Our Approach Examples (Control Flow and Arrays)

How does it work?

NFAs avoid the infinite loop: atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 19/34

slide-42
SLIDE 42

Our Approach Examples (Control Flow and Arrays)

How does it work?

NFAs avoid the infinite loop: atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 19/34

slide-43
SLIDE 43

Our Approach Examples (Control Flow and Arrays)

How does it work?

NFAs avoid the infinite loop: atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 19/34

slide-44
SLIDE 44

Our Approach Examples (Control Flow and Arrays)

How does it work?

NFAs avoid the infinite loop: atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 19/34

slide-45
SLIDE 45

Our Approach Examples (Control Flow and Arrays)

How does it work?

NFAs avoid the infinite loop: atomic { while (x.n) { x = x.n; } }

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 19/34

slide-46
SLIDE 46

Our Approach Examples (Control Flow and Arrays)

How does it work?

NFAs avoid the infinite loop: atomic { while (x.n) { x = x.n; } } Analysis now terminates.

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 19/34

slide-47
SLIDE 47

Our Approach Examples (Control Flow and Arrays)

How Do We Lock an NFA?

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 20/34

slide-48
SLIDE 48

Our Approach Examples (Control Flow and Arrays)

How Do We Lock an NFA?

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 20/34

slide-49
SLIDE 49

Our Approach Examples (Control Flow and Arrays)

How Do We Lock an NFA?

lockr(Node); while (...) { x = x.n; } unlockr(Node);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 20/34

slide-50
SLIDE 50

Our Approach Transfer Functions

The Transfer Functions

Addition function introduces new accesses into the CFG Translation function translates NFAs to compensate for state change

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 21/34

slide-51
SLIDE 51

Our Approach Transfer Functions

Addition function

(introduces new accesses into the CFG) a[x = y]n = ∅ a[x = null]n = ∅ a[x = new]n = ∅ a[x = y.f ]n = {y → n} a[x.f = y]n = {x → n}

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 22/34

slide-52
SLIDE 52

Our Approach Transfer Functions

Translation Function (1)

A standard kill/gen function t[x = y]n(G) = G \ {x → n′|x → n′ ∈ G} ∪{y → n′|x → n′ ∈ G} t[x = null]n(G) = G \ {x → n′|x → n′ ∈ G} t[x = new]n(G) = G \ {x → n′|x → n′ ∈ G}

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 23/34

slide-53
SLIDE 53

Our Approach Transfer Functions

Translation Function (2)

t[x = y.f ]n(G) = G \ {x → n′|x → n′ ∈ G} ∪ {n →f n′|x → n′ ∈ G} t[x.f = y]n(G) = G \ {n′ →f _|x → n′ ∈ G, (∄z = x : z → n′ ∈ G), (∄n′′′ : n′′′ →_ n′ ∈ G)} ∪ {y → n′|_ →f n′ ∈ G}

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 24/34

slide-54
SLIDE 54

Soundness Fundamentals

What Should we Prove?

Already known that two-phase locking = ⇒ atomicity. Therefore sufficient to show we are two-phase.

◮ Clearly the acquires precede the releases ◮ Locking a class can be thought of as locking every instance ◮ We are locking everything in the NFA.

We need to prove the NFA inferred by the analysis represents the accesses actually performed by the code...

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 25/34

slide-55
SLIDE 55

Soundness Fundamentals

Soundness?

Let’s invent some notation for the ideas:

◮ h, σ is the initial heap, stack ◮ P ⊢ h, σ, n, A

∗ means an incomplete execution from CFG node n can access the set of addresses A

◮ X maps every CFG node n to an NFA G ◮ P ⊢ X means that X is the fixed point of the analysis of CFG P

Soundness: P ⊢ h, σ, n,

A

∗ P ⊢ X X(n) = G      = ⇒ A ⊆ G? Not quite, but almost...

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 26/34

slide-56
SLIDE 56

Soundness Assignments

Assigning Meaning to NFAs

Recall the earlier NFA: (let’s call it G)

◮ G is a static repepresention of a set of objects ◮ When combined with a h, σ, it resolves into a set of objects ◮ We must formalise this...

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 27/34

slide-57
SLIDE 57

Soundness Assignments

Assignments ϕ

An assignment ϕ maps a consistent set of addresses to each node in G. (with respect to the h, σ) G = {x → 1, 1 →next 1} We say h, σ ⊢ G : ϕ if ϕ is consistent with h, σ, G Example: If σ(x) = a1 h(a1)(next) = a2 h(a2)(next) = a1 h(a3)(next) = a3 ϕ(1) = {a1, a2} then h, σ ⊢ G : ϕ

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 28/34

slide-58
SLIDE 58

Soundness Assignments

Assignments ϕ

An assignment ϕ maps a consistent set of addresses to each node in G. (with respect to the h, σ) G = {x → 1, 1 →next 1} We say h, σ ⊢ G : ϕ if ϕ is consistent with h, σ, G Example: If σ(x) = a1 h(a1)(next) = a2 h(a2)(next) = a1 h(a3)(next) = a3 ϕ′(1) = {a1, a2, a3} then h, σ ⊢ G : ϕ′

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 28/34

slide-59
SLIDE 59

Soundness Assignments

Assignments ϕ

An assignment ϕ maps a consistent set of addresses to each node in G. (with respect to the h, σ) G = {x → 1, 1 →next 1} We say h, σ ⊢ G : ϕ if ϕ is consistent with h, σ, G Example: If σ(x) = a1 h(a1)(next) = a2 h(a2)(next) = a1 h(a3)(next) = a3 ϕ′(1) = {a1, a2, a3} then h, σ ⊢ G : ϕ′ x → n ∈ G ⇒ σ(x) ∈ ϕ(n) n →f n′ ∈ G ⇒ {h(a)(f )|a ∈ ϕ(n)} ⊆ ϕ(n′) h, σ ⊢ G : ϕ

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 28/34

slide-60
SLIDE 60

Soundness Assignments

Assignments ϕ

An assignment ϕ maps a consistent set of addresses to each node in G. (with respect to the h, σ) G = {x → 1, 1 →next 1} We say h, σ ⊢ G : ϕ if ϕ is consistent with h, σ, G Example: If σ(x) = a1 h(a1)(next) = a2 h(a2)(next) = a1 h(a3)(next) = a3 ϕ′(1) = {a1, a2, a3} then h, σ ⊢ G : ϕ′ x → n ∈ G ⇒ σ(x) ∈ ϕ(n) n →f n′ ∈ G ⇒ {h(a)(f )|a ∈ ϕ(n)} ⊆ ϕ(n′) h, σ ⊢ G : ϕ squash(ϕ) gets the addresses from ϕ

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 28/34

slide-61
SLIDE 61

Soundness Semantics

Operational Semantics

We need to know what addresses are accessed by a block of code. A big step operational semantics will suffice for this. We can define it on the CFG to keep it simple. P ⊢ h, σ, n

{}

∗ P(n) = [x = y.f , n′] σ(y) = a P ⊢ h, σ[x → h(a)(f )], n′

A

∗ P ⊢ h, σ, n

{a}∪A

∗ P(n) = [x = y, n′] P ⊢ h, σ[x → σ(y)], n′

A

∗ P ⊢ h, σ, n

A

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 29/34

slide-62
SLIDE 62

Soundness Soundness Theorem

Soundness?

Now we can define soundness properly:

◮ h, σ is the initial heap, stack ◮ P ⊢ h, σ, n, A

∗ means an incomplete execution from CFG node n can access the set of addresses A

◮ X maps every CFG node n to an NFA G ◮ P ⊢ X means that X is the fixed point of the analysis of CFG P ◮ ϕ is the addresses represented by the static G.

Soundness: P ⊢ h, σ, n,

A

∗ P ⊢ X X(n) = G h, σ ⊢ G : ϕ          = ⇒ A ⊆ squash(ϕ)

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 30/34

slide-63
SLIDE 63

Soundness Isabelle

Soundness!

Proved with Isabelle/HOL.

◮ Mostly just sets (with a few lists too) ◮ Definitions are exactly as presented except for:

◮ Explicit quantifiers where they are needed ◮ Explicit handling of null, and the undefinedness of partial functions ◮ A few concessions so we could use primitive recursion: ◮ Convenient to make A a list of “addr option” ◮ Convenient to store set of constructed objects C

◮ Induction over structure of A ◮ ∼ 940 lines (including definitions) ◮ ∼ 30 seconds for proofgeneral to verify on an early P4 ◮ The 2 big theorems were 443 and 75 steps ◮ Proof assistants are cool!

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 31/34

slide-64
SLIDE 64

Finishing Off

Conclusions

Implemented atomic sections using lock inference:

◮ Two-phase discipline ◮ Locks are multi-granularity, read/write, reentrant, deadlock-free ◮ Unlock as early as possible for better granularity ◮ Implemented for a subset of Java in custom interpreter ◮ Currently implementing for full Java using soot

Further work:

◮ Better precision (ownership types?) ◮ Better runtime performance ◮ Better compiletime performance (JIT possible?) ◮ Nested atomicity would be nice ◮ Thread-local type system

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 32/34

slide-65
SLIDE 65

Finishing Off

Questions

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 33/34

slide-66
SLIDE 66

Finishing Off

Balancing Example

Source CFG Target atomic { if (b) { x.f = x; } else { x.f = y; } t = x.f; t.f = null; } lockw(x,y); if (b) { unlockw(y); x.f = x; lockr(x); } else { x.f = y; lockr(x); unlockw(x); } t = x.f; unlockr(x); t.f = null; unlockw(t);

Dave Cunningham, Khilan Gudka, Susan Eisenbach Keep Off the Grass 34/34