Outline Motivation Analysis Of Accessed Objects Conclusion Implementing Atomicity with Locks Dave Cunningham April 4, 2006 Dave Cunningham Implementing Atomicity with Locks 1/16
Outline Motivation Analysis Of Accessed Objects Conclusion Motivation The Problem A New Solution Example Analysis Of Accessed Objects Examples Formalism Correctness Termination Conclusion Conclusion Future work Dave Cunningham Implementing Atomicity with Locks 2/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Atomic Section Future concurrent programming languages may include the atomic section. atomic { account.balance := account.balance - amount; log.append("withdrew ..."); } Dave Cunningham Implementing Atomicity with Locks 3/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Atomic Section Future concurrent programming languages may include the atomic section. atomic { account.balance := account.balance - amount; log.append("withdrew ..."); } ◮ Efficient implementations must understand interference . Dave Cunningham Implementing Atomicity with Locks 3/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Atomic Section Future concurrent programming languages may include the atomic section. atomic { account.balance := account.balance - amount; log.append("withdrew ..."); } ◮ Efficient implementations must understand interference . ◮ What objects are accessed by atomic code? Dave Cunningham Implementing Atomicity with Locks 3/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Two Approaches Transactions : Log object accesses at runtime. ◮ Concurrent logs with non-empty intersection ⇒ interference. ◮ Interference avoided by undoing (or not committing) code. ◮ Atomic code re-executed. Dave Cunningham Implementing Atomicity with Locks 4/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Two Approaches Transactions : Log object accesses at runtime. ◮ Concurrent logs with non-empty intersection ⇒ interference. ◮ Interference avoided by undoing (or not committing) code. ◮ Atomic code re-executed. Alternative : Statically infer what objects may be accessed ◮ Prevent interference using synchronisation. ◮ Dataflow analysis may be inaccurate (arbitrary pointers). ◮ But programmers already do this in their heads. . . Dave Cunningham Implementing Atomicity with Locks 4/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Two Approaches Transactions : Log object accesses at runtime. ◮ Concurrent logs with non-empty intersection ⇒ interference. ◮ Interference avoided by undoing (or not committing) code. ◮ Atomic code re-executed. Alternative : Statically infer what objects may be accessed ◮ Prevent interference using synchronisation. ◮ Dataflow analysis may be inaccurate (arbitrary pointers). ◮ But programmers already do this in their heads. . . (Like Ethernet vs Token Ring) Dave Cunningham Implementing Atomicity with Locks 4/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Interference Prevention account.balance := account.balance - amount; log.append("withdrew ..."); Dave Cunningham Implementing Atomicity with Locks 5/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Interference Prevention synchronized (account,log) { account.balance := account.balance - amount; log.append("withdrew ..."); } Dave Cunningham Implementing Atomicity with Locks 5/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Interference Prevention synchronized (account,log) { account.balance := account.balance - amount; log.append("withdrew ..."); } Static Inference returns { account , log } Dynamic Evaluate { account , log } to find out what to lock. Dave Cunningham Implementing Atomicity with Locks 5/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Interference Prevention synchronized (account,log) { account.balance := account.balance - amount; log.append("withdrew ..."); } Static Inference returns { account , log } Dynamic Evaluate { account , log } to find out what to lock. What should the analysis return in general? Dave Cunningham Implementing Atomicity with Locks 5/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Interference Prevention synchronized (account,log) { account.balance := account.balance - amount; log.append("withdrew ..."); } Static Inference returns { account , log } Dynamic Evaluate { account , log } to find out what to lock. What should the analysis return in general? ◮ Variables? Dave Cunningham Implementing Atomicity with Locks 5/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Interference Prevention synchronized (account,log) { account.balance := account.balance - amount; log.append("withdrew ..."); } Static Inference returns { account , log } Dynamic Evaluate { account , log } to find out what to lock. What should the analysis return in general? ◮ Variables? ◮ Arbitrary expressions? Dave Cunningham Implementing Atomicity with Locks 5/16
Outline The Problem Motivation A New Solution Analysis Of Accessed Objects Example Conclusion Interference Prevention synchronized (account,log) { account.balance := account.balance - amount; log.append("withdrew ..."); } Static Inference returns { account , log } Dynamic Evaluate { account , log } to find out what to lock. What should the analysis return in general? ◮ Variables? ◮ Arbitrary expressions? Paths : sequences of field lookups: ◮ me.brother.girlfriend.car ◮ list.first.next.next.next Dave Cunningham Implementing Atomicity with Locks 5/16
Outline Examples Motivation Formalism Analysis Of Accessed Objects Correctness Conclusion Termination Examples (1) L ( e ) e { me , me.brother.car.fuel := 100; me.brother , me.brother.car } if (goodWeather) { this.clothing := drawer.hat; { this , } else { drawer , this.clothing := cloakroom.umbrella; cloakroom } } Dave Cunningham Implementing Atomicity with Locks 6/16
Outline Examples Motivation Formalism Analysis Of Accessed Objects Correctness Conclusion Termination Examples (2) L ( e ) e { me , me.car := you.car; you , me.car.fuel := 100; you.car } { me , you , me.car := you.car; you.car , dave.car.fuel := 100; dave , dave.car } Dave Cunningham Implementing Atomicity with Locks 7/16
Outline Examples Motivation Formalism Analysis Of Accessed Objects Correctness Conclusion Termination Definition of L Intuition: L ( e ) ≈ “objects that may be accessed by e ” Dave Cunningham Implementing Atomicity with Locks 8/16
Outline Examples Motivation Formalism Analysis Of Accessed Objects Correctness Conclusion Termination Definition of L Intuition: L ( e ) ≈ “objects that may be accessed by e ” (in terms of paths through the initial heap ) Dave Cunningham Implementing Atomicity with Locks 8/16
Outline Examples Motivation Formalism Analysis Of Accessed Objects Correctness Conclusion Termination Definition of L Intuition: L ( e ) ≈ “objects that may be accessed by e ” (in terms of paths through the initial heap ) Definition: L ( x ) = ∅ Dave Cunningham Implementing Atomicity with Locks 8/16
Outline Examples Motivation Formalism Analysis Of Accessed Objects Correctness Conclusion Termination Definition of L Intuition: L ( e ) ≈ “objects that may be accessed by e ” (in terms of paths through the initial heap ) Definition: L ( x ) = ∅ L ( if q e 1 e 2 ) = L ( q ) ∪ ( L ( e 1 ) ∪ L ( e 2 )) Dave Cunningham Implementing Atomicity with Locks 8/16
Outline Examples Motivation Formalism Analysis Of Accessed Objects Correctness Conclusion Termination Definition of L Intuition: L ( e ) ≈ “objects that may be accessed by e ” (in terms of paths through the initial heap ) Definition: L ( x ) = ∅ L ( if q e 1 e 2 ) = L ( q ) ∪ ( L ( e 1 ) ∪ L ( e 2 )) L ( q . f ) = L ( q ) ∪ { q } L ( q . f := r ) = L ( q ) ∪ L ( r ) ∪ { q } Dave Cunningham Implementing Atomicity with Locks 8/16
Outline Examples Motivation Formalism Analysis Of Accessed Objects Correctness Conclusion Termination Definition of L Intuition: L ( e ) ≈ “objects that may be accessed by e ” (in terms of paths through the initial heap ) Definition: L ( x ) = ∅ L ( if q e 1 e 2 ) = L ( q ) ∪ ( L ( e 1 ) ∪ L ( e 2 )) L ( q . f ) = L ( q ) ∪ { q } L ( q . f := r ) = L ( q ) ∪ L ( r ) ∪ { q } L ( e 1 ; e 2 ) = L ( e 1 ) ∪ T e 1 ( L ( e 2 )) Dave Cunningham Implementing Atomicity with Locks 8/16
Outline Examples Motivation Formalism Analysis Of Accessed Objects Correctness Conclusion Termination Definition of T Intuition: T e ( P ′ ) ≈ “ P ′ translated with respect to the side-effects of e ” Dave Cunningham Implementing Atomicity with Locks 9/16
Recommend
More recommend