skip to main content
research-article
Open Access
Artifacts Evaluated & Functional / v1.1

Retrofitting parallelism onto OCaml

Published:03 August 2020Publication History
Skip Abstract Section

Abstract

OCaml is an industrial-strength, multi-paradigm programming language, widely used in industry and academia. OCaml is also one of the few modern managed system programming languages to lack support for shared memory parallel programming. This paper describes the design, a full-fledged implementation and evaluation of a mostly-concurrent garbage collector (GC) for the multicore extension of the OCaml programming language. Given that we propose to add parallelism to a widely used programming language with millions of lines of existing code, we face the challenge of maintaining backwards compatibility--not just in terms of the language features but also the performance of single-threaded code running with the new GC. To this end, the paper presents a series of novel techniques and demonstrates that the new GC strikes a balance between performance and feature backwards compatibility for sequential programs and scales admirably on modern multicore processors.

Skip Supplemental Material Section

Supplemental Material

Presentation at ICFP '20

References

  1. Todd A. Anderson. 2010. Optimizations in a Private Nursery-Based Garbage Collector. In Proceedings of the 2010 International Symposium on Memory Management (Toronto, Ontario, Canada) ( ISMM '10). Association for Computing Machinery, New York, NY, USA, 21-30. https://doi.org/10.1145/1806651.1806655 Google ScholarGoogle ScholarDigital LibraryDigital Library
  2. Andrew W Appel. 1990. A runtime system. Lisp and Symbolic Computation 3, 4 ( 1990 ), 343-380.Google ScholarGoogle Scholar
  3. Sven Auhagen, Lars Bergstrom, Matthew Fluet, and John Reppy. 2011. Garbage Collection for Multicore NUMA Machines. In Proceedings of the 2011 ACM SIGPLAN Workshop on Memory Systems Performance and Correctness (San Jose, California) ( MSPC '11). Association for Computing Machinery, New York, NY, USA, 51-57. https://doi.org/10.1145/1988915.1988929 Google ScholarGoogle ScholarDigital LibraryDigital Library
  4. François Bobot. 2014. Ephemerons meet OCaml GC. In OCaml Users and Developers Workshop.Google ScholarGoogle Scholar
  5. Sivaramakrishnan Krishnamoorthy Chandrasekaran, Daan Leijen, Matija Pretnar, and Tom Schrijvers. 2018. Algebraic Efect Handlers go Mainstream (Dagstuhl Seminar 18172). Dagstuhl Reports 8, 4 ( 2018 ), 104-125. https://doi.org/10.4230/ DagRep.8.4. 104 Google ScholarGoogle ScholarCross RefCross Ref
  6. Clif Click, Gil Tene, and Michael Wolf. 2005. The Pauseless GC Algorithm. In Proceedings of the 1st ACM/USENIX International Conference on Virtual Execution Environments (Chicago, IL, USA) ( VEE '05). Association for Computing Machinery, New York, NY, USA, 46-56. https://doi.org/10.1145/1064979.1064988 Google ScholarGoogle ScholarDigital LibraryDigital Library
  7. Edsger W Dijkstra, Leslie Lamport, Alain J. Martin, Carel S. Scholten, and Elisabeth FM Stefens. 1978. On-the-fly garbage collection: An exercise in cooperation. Commun. ACM 21, 11 ( 1978 ), 966-975.Google ScholarGoogle Scholar
  8. Stephen Dolan, Spiros Eliopoulos, Daniel Hillerström, Anil Madhavapeddy, KC Sivaramakrishnan, and Leo White. 2018a. Concurrent System Programming with Efect Handlers. In Trends in Functional Programming, Meng Wang and Scott Owens (Eds.). Springer International Publishing, Cham, 98-117.Google ScholarGoogle Scholar
  9. Stephen Dolan, KC Sivaramakrishnan, and Anil Madhavapeddy. 2018b. Bounding Data Races in Space and Time. In Proceedings of the 39th ACM SIGPLAN Conference on Programming Language Design and Implementation (Philadelphia, PA, USA) ( PLDI 2018 ). Association for Computing Machinery, New York, NY, USA, 242-255. https://doi.org/10.1145/ 3192366.3192421 Google ScholarGoogle ScholarDigital LibraryDigital Library
  10. Damien Doligez. 1989. Réalisation d'un glaneur de cellules de Lang et Dupont à générations. Memoire de DEA, Universite Paris VII ( 1989 ).Google ScholarGoogle Scholar
  11. Damien Doligez. 2019. A new allocator for OCaml. http://gallium.inria.fr/~scherer/doc/chameau-sur-le-plateau/2019-10-08-damien-doligez-major-allocator.orgGoogle ScholarGoogle Scholar
  12. Damien Doligez and Xavier Leroy. 1993. A Concurrent, Generational Garbage Collector for a Multithreaded Implementation of ML. In Proceedings of the 20th ACM SIGPLAN-SIGACT Symposium on Principles of Programming Languages (Charleston, South Carolina, USA) ( POPL '93). Association for Computing Machinery, New York, NY, USA, 113-123. https://doi.org/ 10.1145/158511.158611 Google ScholarGoogle ScholarDigital LibraryDigital Library
  13. Tamar Domani, Gal Goldshtein, Elliot K. Kolodner, Ethan Lewis, Erez Petrank, and Dafna Sheinwald. 2002. Thread-Local Heaps for Java. In Proceedings of the 3rd International Symposium on Memory Management (Berlin, Germany) ( ISMM '02). Association for Computing Machinery, New York, NY, USA, 76-87. https://doi.org/10.1145/512429.512439 Google ScholarGoogle ScholarDigital LibraryDigital Library
  14. Marc Feeley. 1993. Polling Eficiently on Stock Hardware. In Proceedings of the Conference on Functional Programming Languages and Computer Architecture (Copenhagen, Denmark) ( FPCA '93). Association for Computing Machinery, New York, NY, USA, 179-187. https://doi.org/10.1145/165180.165205 Google ScholarGoogle ScholarDigital LibraryDigital Library
  15. Christine H. Flood, Roman Kennke, Andrew Dinn, Andrew Haley, and Roland Westrelin. 2016. Shenandoah: An Open-Source Concurrent Compacting Garbage Collector for OpenJDK. In Proceedings of the 13th International Conference on Principles and Practices of Programming on the Java Platform: Virtual Machines, Languages, and Tools (Lugano, Switzerland) ( PPPJ '16). Association for Computing Machinery, New York, NY, USA, Article 13, 9 pages. https://doi.org/10.1145/2972206.2972210 Google ScholarGoogle ScholarDigital LibraryDigital Library
  16. Matthew Fluet, Mike Rainey, John Reppy, and Adam Shaw. 2010. Implicitly Threaded Parallelism in Manticore. J. Funct. Program. 20, 5-6 ( Nov. 2010 ), 537-576. https://doi.org/10.1017/S0956796810000201 Google ScholarGoogle ScholarDigital LibraryDigital Library
  17. Ben Gamari and Laura Dietz. 2020. Alligator Collector: A Latency-Optimized Garbage Collector for Functional Programming Languages. In Proceedings of the 2020 ACM SIGPLAN International Symposium on Memory Management (London, UK) (ISMM 2020 ). Association for Computing Machinery, New York, NY, USA, 87âĂŞ99. https://doi.org/10.1145/3381898. 3397214 Google ScholarGoogle ScholarDigital LibraryDigital Library
  18. Peter Gammie, Antony L. Hosking, and Kai Engelhardt. 2015. Relaxing Safely: Verified on-the-Fly Garbage Collection for X86-TSO. In Proceedings of the 36th ACM SIGPLAN Conference on Programming Language Design and Implementation (Portland, OR, USA) ( PLDI '15). Association for Computing Machinery, New York, NY, USA, 99-109. https://doi.org/10. 1145/2737924.2738006 Google ScholarGoogle ScholarDigital LibraryDigital Library
  19. GoWriteBarrier 2015. Go Write Barrier. https://golang.org/src/runtime/mbarrier.goGoogle ScholarGoogle Scholar
  20. David Gries. 1977. An Exercise in Proving Parallel Programs Correct. Commun. ACM 20, 12 (Dec. 1977 ), 921-930. https://doi.org/10.1145/359897.359903 Google ScholarGoogle ScholarDigital LibraryDigital Library
  21. Adrien Guatto, Sam Westrick, Ram Raghunathan, Umut Acar, and Matthew Fluet. 2018. Hierarchical Memory Management for Mutable State. In Proceedings of the 23rd ACM SIGPLAN Symposium on Principles and Practice of Parallel Programming (Vienna, Austria) ( PPoPP '18). Association for Computing Machinery, New York, NY, USA, 81-93. https://doi.org/10. 1145/3178487.3178494 Google ScholarGoogle ScholarDigital LibraryDigital Library
  22. Barry Hayes. 1997. Ephemerons: A New Finalization Mechanism. In Proceedings of the 12th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (Atlanta, Georgia, USA) ( OOPSLA '97). Association for Computing Machinery, New York, NY, USA, 176-183. https://doi.org/10.1145/263698.263733 Google ScholarGoogle ScholarDigital LibraryDigital Library
  23. Gerard J. Holzmann. 1997. The Model Checker SPIN. IEEE Trans. Softw. Eng. 23, 5 (May 1997 ), 279-295. https://doi.org/10. 1109/32.588521 Google ScholarGoogle ScholarDigital LibraryDigital Library
  24. Lorenz Huelsbergen and Phil Winterbottom. 1998. Very Concurrent Mark-&-Sweep Garbage Collection without Fine-Grain Synchronization. In Proceedings of the 1st International Symposium on Memory Management (Vancouver, British Columbia, Canada) ( ISMM '98). Association for Computing Machinery, New York, NY, USA, 166-175. https://doi.org/10.1145/ 286860.286878 Google ScholarGoogle ScholarDigital LibraryDigital Library
  25. Richard Jones, Antony Hosking, and Eliot Moss. 2011. The Garbage Collection Handbook: The Art of Automatic Memory Management (1st ed.). Chapman & Hall/CRC.Google ScholarGoogle Scholar
  26. Xavier Leroy. 1990. The ZINC experiment : an economical implementation of the ML language. Technical Report RT-0117. INRIA. 100 pages. https://hal.inria.fr/inria-00070049Google ScholarGoogle Scholar
  27. Anil Madhavapeddy, Richard Mortier, Charalampos Rotsos, David Scott, Balraj Singh, Thomas Gazagnaire, Steven Smith, Steven Hand, and Jon Crowcroft. 2013. Unikernels: Library Operating Systems for the Cloud. In Proceedings of the Eighteenth International Conference on Architectural Support for Programming Languages and Operating Systems (Houston, Texas, USA) ( ASPLOS '13). Association for Computing Machinery, New York, NY, USA, 461-472. https://doi.org/10.1145/ 2451116.2451167 Google ScholarGoogle ScholarDigital LibraryDigital Library
  28. Simon Marlow and Simon Peyton Jones. 2011. Multicore Garbage Collection with Local Heaps. In Proceedings of the International Symposium on Memory Management (San Jose, California, USA) ( ISMM '11). Association for Computing Machinery, New York, NY, USA, 21-32. https://doi.org/10.1145/1993478.1993482 Google ScholarGoogle ScholarDigital LibraryDigital Library
  29. Simon Marlow, Simon Peyton Jones, and Satnam Singh. 2009. Runtime Support for Multicore Haskell. In Proceedings of the 14th ACM SIGPLAN International Conference on Functional Programming (Edinburgh, Scotland) (ICFP '09). Association for Computing Machinery, New York, NY, USA, 65-78. https://doi.org/10.1145/1596550.1596563 Google ScholarGoogle ScholarDigital LibraryDigital Library
  30. Yaron Minsky, Anil Madhavapeddy, and Jason Hickey. 2013. Real World OCaml-Functional Programming for the Masses. O'Reilly. http://shop.oreilly.com/product/0636920024743.do#tab_04_2Google ScholarGoogle Scholar
  31. OCamlCAPI 2019. Interfacing C with OCaml. https://caml.inria.fr/pub/docs/manual-ocaml/intfc.htmlGoogle ScholarGoogle Scholar
  32. Ram Raghunathan, Stefan K. Muller, Umut A. Acar, and Guy Blelloch. 2016. Hierarchical Memory Management for Parallel Programs. In Proceedings of the 21st ACM SIGPLAN International Conference on Functional Programming (Nara, Japan) (ICFP 2016 ). Association for Computing Machinery, New York, NY, USA, 392-406. https://doi.org/10.1145/2951913.2951935 Google ScholarGoogle ScholarDigital LibraryDigital Library
  33. ReasonML 2019. ReasonML : A new syntax and toolchain for OCaml. https://reasonml.github.io/Google ScholarGoogle Scholar
  34. John H. Reppy. 1993. Concurrent ML : Design, Application and Semantics. In Functional Programming, Concurrency, Simulation and Automated Reasoning: International Lecture Series 1991-1992, McMaster University, Hamilton, Ontario, Canada. Springer-Verlag, Berlin, Heidelberg, 165-198.Google ScholarGoogle Scholar
  35. Scott Schneider, Christos D. Antonopoulos, and Dimitrios S. Nikolopoulos. 2006. Scalable Locality-Conscious Multithreaded Memory Allocation. In Proceedings of the 5th International Symposium on Memory Management (Ottawa, Ontario, Canada) ( ISMM '06). Association for Computing Machinery, New York, NY, USA, 84-94. https://doi.org/10.1145/1133956.1133968 Google ScholarGoogle ScholarDigital LibraryDigital Library
  36. KC Sivaramakrishnan, Stephen Dolan, Leo White, Sadiq Jafer, Tom Kelly, Anmol Sahoo, Sudha Parimala, Atul Dhiman, and Anil Madhavapeddy. 2020. Retrofitting Parallelism onto OCaml. ArXiv abs/ 2004.11663 ( 2020 ). https://arxiv.org/abs/ 2004. 11663Google ScholarGoogle Scholar
  37. KC Sivaramakrishnan, Lukasz Ziarek, and Suresh Jagannathan. 2012. Eliminating Read Barriers through Procrastination and Cleanliness. In Proceedings of the 2012 International Symposium on Memory Management (Beijing, China) ( ISMM '12). Association for Computing Machinery, New York, NY, USA, 49-60. https://doi.org/10.1145/2258996.2259005 Google ScholarGoogle ScholarDigital LibraryDigital Library
  38. KC Sivaramakrishnan, Lukasz Ziarek, and Suresh Jagannathan. 2014. MultiMLton: A multicore-aware runtime for standard ML. J. Funct. Program. 24, 6 ( 2014 ), 613-674. https://doi.org/10.1017/S0956796814000161 Google ScholarGoogle ScholarCross RefCross Ref
  39. Daniel Dominic Sleator and Robert Endre Tarjan. 1985. Self-Adjusting Binary Search Trees. J. ACM 32, 3 ( July 1985 ), 652-686. https://doi.org/10.1145/3828.3835 Google ScholarGoogle ScholarDigital LibraryDigital Library
  40. Thomas A. Standish. 1980. Data Structure Techniques. Addison-Wesley Longman Publishing Co., Inc., USA.Google ScholarGoogle Scholar
  41. Guy Lewis Steele Jr. 1977. Data Representations in PDP-10 MacLISP. Technical Report. Massauchusetts Institute of Technology Cambridge Artificial Intelligence Laboratory.Google ScholarGoogle Scholar
  42. James Swaine, Kevin Tew, Peter Dinda, Robert Bruce Findler, and Matthew Flatt. 2010. Back to the Futures: Incremental Parallelization of Existing Sequential Runtime Systems. In Proceedings of the ACM International Conference on Object Oriented Programming Systems Languages and Applications (Reno/Tahoe, Nevada, USA) ( OOPSLA '10). Association for Computing Machinery, New York, NY, USA, 583-597. https://doi.org/10.1145/1869459.1869507 Google ScholarGoogle ScholarDigital LibraryDigital Library
  43. Gil Tene, Balaji Iyengar, and Michael Wolf. 2011. C4: The Continuously Concurrent Compacting Collector. SIGPLAN Not. 46, 11 ( June 2011 ), 79-88. https://doi.org/10.1145/2076022.1993491 Google ScholarGoogle ScholarDigital LibraryDigital Library
  44. Kevin Tew, James Swaine, Matthew Flatt, Robert Bruce Findler, and Peter Dinda [email protected]. 2011. Places: Adding Message-Passing Parallelism to Racket. In Proceedings of the 7th Symposium on Dynamic Languages (Portland, Oregon, USA) ( DLS '11). Association for Computing Machinery, New York, NY, USA, 85-96. https://doi.org/10.1145/ 2047849.2047860 Google ScholarGoogle ScholarDigital LibraryDigital Library
  45. Katsuhiro Ueno and Atsushi Ohori. 2016. A Fully Concurrent Garbage Collector for Functional Programs on Multicore Processors. SIGPLAN Not. 51, 9 (Sept. 2016 ), 421-433. https://doi.org/10.1145/3022670.2951944 Google ScholarGoogle ScholarDigital LibraryDigital Library
  46. Martin T Vechev, David F Bacon, Perry Cheng, and David Grove. 2005. Derivation and evaluation of concurrent collectors. In European Conference on Object-Oriented Programming. Springer, 577-601.Google ScholarGoogle ScholarDigital LibraryDigital Library
  47. Sam Westrick, Rohan Yadav, Matthew Fluet, and Umut A. Acar. 2019. Disentanglement in Nested-Parallel Programs. Proc. ACM Program. Lang. 4, POPL, Article 47 ( Dec. 2019 ), 32 pages. https://doi.org/10.1145/3371115 Google ScholarGoogle ScholarDigital LibraryDigital Library
  48. T. Yuasa. 1990. Real-Time Garbage Collection on General-Purpose Machines. J. Syst. Softw. 11, 3 (March 1990 ), 181-198. https://doi.org/10.1016/ 0164-1212 ( 90 ) 90084-Y Google ScholarGoogle ScholarDigital LibraryDigital Library

Index Terms

  1. Retrofitting parallelism onto OCaml

    Recommendations

    Comments

    Login options

    Check if you have access through your login credentials or your institution to get full access on this article.

    Sign in

    Full Access

    PDF Format

    View or Download as a PDF file.

    PDF

    eReader

    View online with eReader.

    eReader
    About Cookies On This Site

    We use cookies to ensure that we give you the best experience on our website.

    Learn more

    Got it!