Memory Models and Language Semantics in Programming

hybrid static dynamic analysis for statically n.w
1 / 84
Embed
Share

Explore the challenges of defining reasonable semantics for programs with data races, the importance of stronger memory models, and the concepts of weak semantics and sequential consistency in programming languages.

  • Memory Models
  • Language Semantics
  • Weak Semantics
  • Sequential Consistency
  • Data Races

Uploaded on | 0 Views


Download Presentation

Please find below an Image/Link to download the presentation.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author. If you encounter any issues during the download, it is possible that the publisher has removed the file from their server.

You are allowed to download the files provided on this website for personal or commercial use, subject to the condition that they are used lawfully. All files are the property of their respective owners.

The content on the website is provided AS IS for your information and personal use only. It may not be sold, licensed, or shared on other websites without obtaining consent from the author.

E N D

Presentation Transcript


  1. Hybrid Static-Dynamic Analysis for Statically Bounded Region Serializability AritraSengupta, SwarnenduBiswas, MinjiaZhang, MichaelD.Bond and MilindKulkarni ASPLOS 2015, ISTANBUL, TURKEY

  2. Programming Language Semantics? Data Races C++ no guarantee of semantics catch-fire semantics Java provides weak semantics

  3. Weak Semantics A a = null; boolean init = false; T1 T2 a = new A(); init = true; if (init) a.field++;

  4. Weak Semantics No data dependence T1 T2 a = new A(); if (init) init = true; a.field++;

  5. Weak Semantics A a = null; boolean init = false; T1 T2 a = new A(); if (init) init = true; a.field++;

  6. Weak Semantics T1 T2 init = true; if (init) a.field++; a = new A();

  7. Weak Semantics Null dereference T1 T2 init = true; if (init) a.field++; a = new A();

  8. DRF0 Atomicity of synchronization-free regions for data-race-free programs Data races - no semantics C++, Java follow variants of DRF0 Adve and Hill, ISCA, 1990

  9. Need for Stronger Memory Models The inability to define reasonable semantics for programs with data races is not just a theoretical shortcoming, but a fundamental hole in the foundation of our languages and systems Give better semantics to programs with data races Stronger memory models Adve and Boehm, CACM, 2010

  10. Sequential Consistency (SC) Shared memory accesses interleave arbitrarily while each thread maintains program order

  11. Sequential Consistency DRF0 Sequential Consistency

  12. An Example Program Under SC int pos = 0 int [ ] buffer 0 0 T1 T2 buffer[pos++]= 5 buffer[pos++] = 6

  13. An Example Program Under SC int pos = 0 int [ ] buffer 0 0 T1 T2 t1 = pos buffer [t1] = 5 t1 = t1 + 1 pos = t1 t2 = pos buffer [t2] = 6 t2 = t2 + 1 pos = t2

  14. An Example Program Under SC int pos = 0 int [ ] buffer 0 0 T1 T2 t1 = pos buffer [t1] = 5 t1 = t1 + 1 t2 = pos Time buffer [t2] = 6 t2 = t2 + 1 pos = t2 pos = t1

  15. An Example Program Under SC int pos = 0 int [ ] buffer 0 0 T1 T2 t1 = pos buffer [t1] = 5 t1 = t1 + 1 t2 = pos Time pos = = 1 buffer buffer [t2] = 6 6 0 t2 = t2 + 1 pos = t2 pos = t1

  16. An Example Program Under SC int pos = 0 int [ ] buffer 0 0 T1 T2 pos = = 1 buffer buffer[pos++] = 6 buffer[pos++]= 5 6 0 pos = = 2 buffer buffer 6 5 5 6

  17. An Example Program Under SC int pos = 0 int [ ] buffer 0 0 T1 T2 pos = = 1 buffer buffer[pos++] = 6 buffer[pos++]= 5 6 0 SC execution

  18. Programmer Assumption Atomicity of high-level operations

  19. Can SC Eliminate Common Concurrency Bugs? ...programmers do not reason about correctness of parallel code in terms of interleavings of individual memory accesses SC does not prevent common concurrency bugs Data races dangerous even under SC Adve and Boehm, CACM 2010

  20. Run-time cost vs Strength Synchronization-free region serializability1 Run-time cost SC DRF0 Strength 1. Ouyang et al. ... and region serializability for all. In HotPar, 2013.

  21. Run-time cost vs Strength Synchronization-free region serializability1 Run-time cost SC DRF0 Strength 1. Ouyang et al. ... and region serializability for all. In HotPar, 2013.

  22. Run-time cost vs Strength Run-time cost Statically Bounded Region Serializability Strength

  23. Contribution EnfoRSer: An analysis to enforce SBRS practically Evaluation: Low run-time cost, eliminates real bugs Run-time cost Statically Bounded Region Serializability Strength

  24. New Memory Model: Statically Bounded Region Serializability (SBRS)

  25. Program Execution Behaviors Statically Bounded Region Serializability DRF0 SC

  26. Statically Bounded Region Serializability (SBRS) Synchronization operations Method calls Loop backedges acq(lock) methodCall() rel(lock)

  27. Statically Bounded Region Serializability (SBRS) acq(lock) methodCall() rel(lock)

  28. Statically Bounded Region Serializability (SBRS) Loop backedges Statically and dynamically bounded

  29. Under SBRS pos = 0 buffer 0 0 T1 T2 buffer[pos++]= 5 buffer[pos++] = 6

  30. Under SBRS pos = 0 buffer 0 0 T1 T2 t1 = pos buffer [t1] = 5 t1 = t1 + 1 pos = t1 t2 = pos buffer [t2] = 6 t2 = t2 + 1 pos = t2

  31. Under SBRS pos = 0 buffer 0 0 T1 T2 t1 = pos buffer [t1] = 5 t1 = t1 + 1 pos = t1 t1 = pos buffer [t1] = 6 t1 = t1 + 1 pos = t1 pos = = 2 buffer 5 6

  32. Under SBRS pos = 0 buffer 0 0 T1 T2 t1 = pos buffer [t1] = 6 t1 = t1 + 1 pos = t1 t1 = pos buffer [t1] = 5 t1 = t1 + 1 pos = t1 pos = = 2 buffer 6 5

  33. Bug Elimination x+= 42; read modify write if (o != null) {. . .= o.f; } check before use multi-variable operation buffer[pos++] = val;

  34. EnfoRSer: A Hybrid Static- Dynamic Analysis to Enforce SBRS

  35. EnfoRSer, an efficient enforcement of SBRS Compiler Transformations Runtime Enforcement Two-phase Locking

  36. Basic Mechanism Y = = X Y =

  37. Basic Mechanism Write lock Y = Read lock = X Y =

  38. Basic Mechanism Y = = X Y =

  39. Basic Mechanism Y = Program access = X Y =

  40. Basic Mechanism Y = Ownership transferred = X Y =

  41. Basic Mechanism X = = X Y =

  42. Basic Mechanism T1 T2 X = Y = = Y = X Conflict Z = Y =

  43. Basic Mechanism T1 T2 X = Y = = Y = X Deadlock Z = Y =

  44. Basic Mechanism T1 T2 Lightweight reader- writer locks2 Biased synchronization Lose ownership while acquiring locks X = Y = = Y = X Deadlock Z = Y = 2. Bond et al. Octet: Capturing and Controlling Cross-Thread Dependences Efficiently. In OOPSLA, 2013.

  45. Basic Mechanism T1 T2 Two-phase locking violated X = Y = = Y = X Ownership transferred Z = Y =

  46. Basic Mechanism T1 T2 X = Y = = Y = X Z = Y =

  47. Basic Mechanism Y = = X Locks acquired Y =

  48. Challenges in Basic Mechanism Stores executed Y = = X Y =

  49. EnfoRSer Atomicity Transformations Idempotent: Defer stores until all locks are acquired Speculation: Execute stores speculatively and roll back in case of a conflict

  50. Idempotent Transformation X = = Y X =

More Related Content