Using Escape Analysis in Dynamic Data Race Detection

  • Slides: 18
Download presentation
Using Escape Analysis in Dynamic Data Race Detection Emma Harrington `15 Williams College Emma.

Using Escape Analysis in Dynamic Data Race Detection Emma Harrington `15 Williams College Emma. Harrington@williams. edu

 • Multithreaded programs can utilize multiple cores. • But at the cost of

• Multithreaded programs can utilize multiple cores. • But at the cost of greater programming complexity.

Multithreaded programming can be awkward… Some resources should never be used simultaneously. Thread interference

Multithreaded programming can be awkward… Some resources should never be used simultaneously. Thread interference occurs when two threads access a shared resource without proper coordination.

Multithreaded programming can be awkward… Race Condition = two concurrent unsynchronized accesses with at

Multithreaded programming can be awkward… Race Condition = two concurrent unsynchronized accesses with at least one write Thread 1 … t 1 = bal; bal = t 1 + 10; … Thread 2 … t 2 = bal; bal = t 2 - 10; … Thread 1 Thread 2 t 1 = bal = t 1 + 10 t 2 = bal bal = t 2 - 10

Locks prevent interference. Programmers use mutual exclusion locks to protect shared resources in multithreaded

Locks prevent interference. Programmers use mutual exclusion locks to protect shared resources in multithreaded environments.

We can use locks to prevent race conditions Thread 1 … acq(m); t 1

We can use locks to prevent race conditions Thread 1 … acq(m); t 1 = bal; bal = t 1 + 10; rel(m); … Thread 2 … acq(m); t 2 = bal; bal = t 2 – 10; rel(m); … Thread 1 Thread 2 acq(m) t 1 = bal = t 1 + 10 rel(m) acq(m) t 2 = bal = t 2 - 10 rel(m)

It’s easy to forget a lock and leave a resource unprotected. Thread 1 …

It’s easy to forget a lock and leave a resource unprotected. Thread 1 … t 1 = bal; bal = t 1 + 10; … Thread 1 Thread 2 t 1 = bal acq(m) t 2 = bal Thread 2 … acq(m); t 2 = bal; bal = t 2 – 10; rel(m); … bal = t 1 + 10 bal = t 2 - 10 rel(m)

Dynamic Race Detection Goal: • Identify race conditions automatically Method: • Monitor program as

Dynamic Race Detection Goal: • Identify race conditions automatically Method: • Monitor program as it runs. • Check that conflicting memory accesses are ordered by synchronization. • Uses Lamport HB relation. • Can be efficiently represented in VCs [DJIT+][Fast. Track]. Thread A Thread B x = 0 rel(m) acq(m) . . . ta Da x = 2 ce a R x = 1

How do dynamic race detectors work? Thread 1 Thread 2 acq(m) t 1 =

How do dynamic race detectors work? Thread 1 Thread 2 acq(m) t 1 = bal = t 1 + 10 rel(m) acq(m) t 2 = bal = t 2 - 10 rel(m)

How do dynamic race detectors work? Thread 1 Thread 2 t 1 = bal

How do dynamic race detectors work? Thread 1 Thread 2 t 1 = bal t 2 = bal = t 1 + 10 bal = t 2 - 10 No ordering of these writes.

When there are many sensitive resources and many accesses, checking can be expensive (~10

When there are many sensitive resources and many accesses, checking can be expensive (~10 x).

Dynamic Escape Analysis Teller ATM Bank Account Name … Balance Name Balance

Dynamic Escape Analysis Teller ATM Bank Account Name … Balance Name Balance

Dynamic Escape Analysis Algorithm • Objects are either shared or local • Local objects

Dynamic Escape Analysis Algorithm • Objects are either shared or local • Local objects are accessible from one thread. • Shared objects are accessible from multiple threads. • Storing a reference to a thread local object in a shared object makes it and all objects reachable from it shared.

Q: How common are local objects and accesses? A: 0% 20% 40% 60% 80%

Q: How common are local objects and accesses? A: 0% 20% 40% 60% 80% 100% 120% crypt lufact moldyn montecarlo 2 mtrt 2 sparsemm series sor raytracer 2 tsp hedc 2 elevator philo • In a suite of 11 multithreaded Java benchmarks, about 40% of accesses are local and can be safely ignored by dynamic race detectors. • I wrote my dynamic escape analysis tool for the Road. Runner Testing Framework [Flanagan and Freund 2010].

Q: Does eliminating checks on local accesses speed Fast. Track [Flanagan and Freund 2009]

Q: Does eliminating checks on local accesses speed Fast. Track [Flanagan and Freund 2009] Dynamic Escape Analysis 5, 00 4, 50 4, 00 3, 50 3, 00 2, 50 2, 00 1, 50 1, 00 0, 50 crypt tsp sor series sparsemm mtrt montecarlo moldyn lufact 0, 00 raytracer (Run time / Fast. Track Run Time) A: up race detection?

Q: By adding a static escape analysis, can we improve these results? A: Fast.

Q: By adding a static escape analysis, can we improve these results? A: Fast. Track [Flanagan and Freund 2009] Dynamic Escape Analysis Static and Dynamic Escape Analysis 4, 50 4, 00 3, 50 3, 00 2, 50 2, 00 1, 50 1, 00 0, 50 crypt tsp sor series sparsemm mtrt montecarlo moldyn lufact 0, 00 raytracer (Run time / Fast. Track Run Time) 5, 00 For the static escape analysis, I used IBM’s WALA thread-local analysis that identifies classes where every instance is only accessible from its creating thread.

Contributions • Race detectors spend a significant amount of time checking accesses to thread-local

Contributions • Race detectors spend a significant amount of time checking accesses to thread-local data that are inherently race free. • Dynamic escape analysis identifies accesses that race detectors can ignore. • Dynamic escape analysis can be augmented with static information to improve performance.

Future Work • Use extra cores or the GPU to reduce the overhead by

Future Work • Use extra cores or the GPU to reduce the overhead by offloading the heap traversal required by dynamic escape analysis. • Build into the garbage collector, which already efficiently traverses the heap.