Nothing Special   »   [go: up one dir, main page]

skip to main content
10.1145/3453483.3454032acmconferencesArticle/Chapter ViewAbstractPublication PagespldiConference Proceedingsconference-collections
research-article

Perceus: garbage free reference counting with reuse

Published: 18 June 2021 Publication History

Abstract

We introduce Perceus, an algorithm for precise reference counting with reuse and specialization. Starting from a functional core language with explicit control-flow, Perceus emits precise reference counting instructions such that (cycle-free) programs are _garbage free_, where only live references are retained. This enables further optimizations, like reuse analysis that allows for guaranteed in-place updates at runtime. This in turn enables a novel programming paradigm that we call _functional but in-place_ (FBIP). Much like tail-call optimization enables writing loops with regular function calls, reuse analysis enables writing in-place mutating algorithms in a purely functional way. We give a novel formalization of reference counting in a linear resource calculus, and prove that Perceus is sound and garbage free. We show evidence that Perceus, as implemented in Koka, has good performance and is competitive with other state-of-the-art memory collectors.

References

[1]
Koka repository. 2019. URL https://github.com/koka-lang/koka.
[2]
Erik Barendsen and Sjaak Smetsers. Uniqueness typing for functional languages with graph rewriting semantics. Mathematical Structures in Computer Science, 6 (6): 579–612, 1996.
[3]
Jeffrey M. Barth. Shifting garbage collection overhead to compile time. Technical Report UCB/ERL M524, EECS Department, University of California, Berkeley, Jun 1975. URL http://www2.eecs.berkeley.edu/Pubs/TechRpts/1975/29109.html.
[4]
Jean-Philippe Bernardy, Mathieu Boespflug, Ryan R. Newton, Simon Peyton Jones, and Arnaud Spiwack. Linear haskell: Practical linearity in a higher-order polymorphic language. Proc. ACM Program. Lang., 2 (POPL), December 2017.
[5]
Jawahar Chirimar, Carl A. Gunter, and Jon G. Riecke. Reference counting as a computational interpretation of linear logic. Journal of Functional Programming, 6: 6–2, 1996.
[6]
Jiho Choi, Thomas Shull, and Josep Torrellas. Biased reference counting: Minimizing atomic operations in garbage collection. In Proceedings of the 27th International Conference on Parallel Architectures and Compilation Techniques, PACT ’18, 2018.
[7]
George E Collins. A method for overlapping and erasure of lists. Communications of the ACM, 3 (12): 655–657, 1960.
[8]
Edsko de Vries, Rinus Plasmeijer, and David M. Abrahamson. Uniqueness typing simplified. In Olaf Chitil, Zoltán Horváth, and Viktória Zsók, editors, Implementation and Application of Functional Languages (IFL’08), pages 201–218. Springer, 2008. ISBN 978-3-540-85373-2.
[9]
David L. Detlefs, Paul A. Martin, Mark Moir, and Guy L. Steele Jr. Lock-free reference counting. In in Proceedings of the 20th Annual ACM Symposium on Principles of Distributed Computing, pages 190–199, 2001.
[10]
L. Peter Deutsch and Daniel G. Bobrow. An efficient, incremental, automatic garbage collector. Communications of the ACM, 19 (9): 522–526, September 1976. ISSN 0001-0782.
[11]
Damien Doligez and Xavier Leroy. A concurrent, generational garbage collector for a multithreaded implementation of ML. In Proceedings of the 20th ACM Symposium on Principles of Programming Languages (POPL), pages 113–123. ACM press, January 1993.
[12]
Gaspard Férey and Natarajan Shankar. Code generation using a formal model of reference counting. In Sanjai Rayadurgam and Oksana Tkachuk, editors, NASA Formal Methods, pages 150–165. Springer International Publishing, 2016. ISBN 978-3-319-40648-0.
[13]
Free Software Foundation, Silicon Graphics, and Hewlett–Packard Company. Internal red-black tree implemention for ßtl::map". URL https://code.woboq.org/gcc/libstdc++-v3/src/c++98/tree.cc.html.
[14]
Matt Gallagher. Reference counted releases in Swift. Blog post, December 2016. URL https://www.cocoawithlove.com/blog/resources-releases-reentrancy.html.
[15]
A. Gidenstam, M. Papatriantafilou, H. Sundell, and P. Tsigas. Efficient and reliable lock-free memory reclamation based on reference counting. In 8th International Symposium on Parallel Architectures,Algorithms and Networks (ISPAN’05), 2005.
[16]
Clemens Grelck and Kai Trojahner. Implicit memory management for SAC. In 6th International Workshop on Implementation and Application of Functional Languages (IFL’04), September 2004.
[17]
Leo J Guibas and Robert Sedgewick. A dichromatic framework for balanced trees. In 19th Annual Symposium on Foundations of Computer Science (sfcs 1978), pages 8–21. IEEE, 1978.
[18]
Carl A. Gunter, Didier Rémy, and Jon G. Riecke. A generalization of exceptions and control in ml-like languages. In Proceedings of the Seventh International Conference on Functional Programming Languages and Computer Architecture, FPCA ’95, page 12–23. ACM, 1995. ISBN 0897917197.
[19]
Paul Hudak and Adrienne Bloss. The aggregate update problem in functional programming systems. In Proceedings of the 12th ACM SIGACT-SIGPLAN Symposium on Principles of Programming Languages, POPL ’85, page 300–314. ACM, 1985. ISBN 0897911474.
[20]
Gérard P. Huet. The zipper. Journal of Functional Programming, 7 (5): 549–554, 1997.
[21]
Apple Inc. The Swift guide: Error handling. 2017. URL https://docs.swift.org/swift-book/LanguageGuide/ErrorHandling.html.
[22]
Donald E. Knuth. The Art of Computer Programming, Volume 1 (3rd Ed.): Fundamental Algorithms. Addison Wesley Longman Publishing Co., Inc., 1997. ISBN 0201896834.
[23]
Daan Leijen. Koka: Programming with row polymorphic effect types. In MSFP’14, 5th workshop on Mathematically Structured Functional Programming, 2014.
[24]
Daan Leijen. Algebraic effects for functional programming. Technical Report MSR-TR-2016-29, Microsoft Research technical report, August 2016. Extended version of Leijen:algeff.
[25]
Daan Leijen. Type directed compilation of row-typed algebraic effects. In Proceedings of the 44th ACM SIGPLAN Symposium on Principles of Programming Languages (POPL’17), pages 486–499, January 2017. ISBN 978-1-4503-4660-3.
[26]
Daan Leijen. Structured asynchrony with algebraic effects. In Proceedings of the 2nd ACM SIGPLAN International Workshop on Type-Driven Development, TyDe 2017, pages 16–29, 2017. ISBN 978-1-4503-5183-6.
[27]
Daan Leijen, Zorn Ben, and Leo de Moura. Mimalloc: Free list sharding in action. Programming Languages and Systems, 11893, 2019. APLAS’19.
[28]
Yossi Levanoni and Erez Petrank. An on-the-fly reference-counting garbage collector for java. ACM Trans. Program. Lang. Syst., 28 (1): 1–69, January 2006. ISSN 0164-0925.
[29]
Prabhaker Mateti and Ravi Manghirmalani. Morris’ tree traversal algorithm reconsidered. Science of Computer Programming, 11 (1): 29–43, 1988. ISSN 0167-6423.
[30]
Conor McBride. The derivative of a regular type is its type of one-hole contexts, 2001. URL http://strictlypositive.org/diff.pdf. (Extended Abstract).
[31]
John McCarthy. Recursive functions of symbolic expressions and their computation by machine, part i. Communications of the ACM, 3 (4): 184–195, 1960.
[32]
J. McGraw, S. Skedzielewski, S. Allan, D. Grit, R. Oldehoeft, J. Glauert, I. Dobes, and P. Hohensee. SISAL: streams and iteration in a single-assignment language. language reference manual, version 1. 1. Technical Report LLL/M-146, ON: DE83016576, Lawrence Livermore National Lab., CA, USA, 7 1983.
[33]
Maged M. Michael. Hazard pointers: Safe memory reclamation for lock-free objects. IEEE Trans. Parallel Distrib. Syst., 15 (6): 491–504, June 2004.
[34]
Yaron Minsky, Anil Madhavapeddy, and Jason Hickey. Real World OCaml: Functional programming for the masses. 2012. ISBN 978-1449323912. URL https://dev.realworldocaml.org.
[35]
Joseph M. Morris. Traversing binary trees simply and cheaply. Information Processing Letters, 9 (5): 197 – 200, 1979.
[36]
Chris Okasaki. Purely Functional Data Structures. Colombia University, June 1999. ISBN 9780521663502.
[37]
Chris Okasaki. Red-black trees in a functional setting. Journal of Functional Programming, 9 (4): 471–477, 1999.
[38]
Simon L. Peyton Jones and André L. M. Santos. A transformation-based optimiser for haskell. Science of Computer Programming, 32 (1): 3 – 47, 1998.
[39]
Gordon D. Plotkin and John Power. Algebraic operations and generic effects. Applied Categorical Structures, 11 (1): 69–94, 2003.
[40]
Gordon D. Plotkin and Matija Pretnar. Handling algebraic effects. volume 9, 2013.
[41]
Alex Reinking, Ningning Xie, Leonardo de Moura, and Daan Leijen. Perceus: Garbage free reference counting with reuse. Technical Report MSR-TR-2020-42, Microsoft Research, November 2020.
[42]
Sven-Bodo Scholz. Single Assignment C: Efficient support for high-level array operations in a functional setting. Journal of Functional Programming, 13 (6): 1005–1059, November 2003.
[43]
Wolfram Schulte. Deriving residual reference count garbage collectors. In Manuel Hermenegildo and Jaan Penjam, editors, Programming Language Implementation and Logic Programming (PLILP), pages 102–116, Berlin, Heidelberg, 1994. Springer Berlin Heidelberg. ISBN 978-3-540-48695-4.
[44]
Herb S. Sutter. Zero-overhead deterministic exceptions: Throwing values. C++ open-std proposal P0709 R2, 10 2018.
[45]
David N. Turner and Phillip Wadler. Operational interpretations of linear logic. (227): 231–248, 1999.
[46]
Sebastian Ullrich and Leonardo de Moura. Counting immutable beans – reference counting optimized for purely functional programming. In Proceedings of the 31st symposium on Implementation and Application of Functional Languages (IFL’19), September 2019.
[47]
David Ungar, David Grove, and Hubertus Franke. Dynamic atomicity: Optimizing swift memory management. In Proceedings of the 13th ACM SIGPLAN International Symposium on on Dynamic Languages, DLS 2017, page 15–26, 2017.
[48]
Phillip Wadler. Linear types can change the world! In Programming Concepts and Methods, 1990.
[49]
Andrew K. Wright and Matthias Felleisen. A syntactic approach to type soundness. Inf. Comput., 115 (1): 38–94, November 1994.
[50]
Ningning Xie and Daan Leijen. Effect handlers in Haskell, evidently. In Proceedings of the 2020 ACM SIGPLAN Symposium on Haskell, Haskell’20, August 2020.
[51]
Ningning Xie and Daan Leijen. Generalized evidence passing for effect handlers. Technical Report MSR-TR-2021-5, Microsoft Research, March 2021.
[52]
Ningning Xie, Jonathan Brachthäuser, Phillip Schuster, Daniel Hillerström, and Daan Leijen. Effect handlers, evidently. In Proceedings of the 25th ACM SIGPLAN International Conference on Functional Programming (ICFP’2020), ICFP ’20, August 2020.
[53]
Danil Yarantsev. Orc - nim’s cycle collector. October 2020. URL https://nim-lang.org/blog/2020/10/15/introduction-to-arc-orc-in-nim.html.

Cited By

View all
  • (2024)Realistic Realizability: Specifying ABIs You Can Count OnProceedings of the ACM on Programming Languages10.1145/36897558:OOPSLA2(1249-1278)Online publication date: 8-Oct-2024
  • (2024)Oxidizing OCaml with Modal Memory ManagementProceedings of the ACM on Programming Languages10.1145/36746428:ICFP(485-514)Online publication date: 15-Aug-2024
  • (2024)Snapshottable StoresProceedings of the ACM on Programming Languages10.1145/36746378:ICFP(338-369)Online publication date: 15-Aug-2024
  • Show More Cited By

Recommendations

Comments

Please enable JavaScript to view thecomments powered by Disqus.

Information & Contributors

Information

Published In

cover image ACM Conferences
PLDI 2021: Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation
June 2021
1341 pages
ISBN:9781450383912
DOI:10.1145/3453483
This work is licensed under a Creative Commons Attribution International 4.0 License.

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 18 June 2021

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Algebraic Effects
  2. Handlers
  3. Reference Counting

Qualifiers

  • Research-article

Conference

PLDI '21
Sponsor:

Acceptance Rates

Overall Acceptance Rate 406 of 2,067 submissions, 20%

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • Downloads (Last 12 months)172
  • Downloads (Last 6 weeks)13
Reflects downloads up to 18 Feb 2025

Other Metrics

Citations

Cited By

View all
  • (2024)Realistic Realizability: Specifying ABIs You Can Count OnProceedings of the ACM on Programming Languages10.1145/36897558:OOPSLA2(1249-1278)Online publication date: 8-Oct-2024
  • (2024)Oxidizing OCaml with Modal Memory ManagementProceedings of the ACM on Programming Languages10.1145/36746428:ICFP(485-514)Online publication date: 15-Aug-2024
  • (2024)Snapshottable StoresProceedings of the ACM on Programming Languages10.1145/36746378:ICFP(338-369)Online publication date: 15-Aug-2024
  • (2024)The Sparse Synchronous Model on Real HardwareACM Transactions on Embedded Computing Systems10.1145/357292023:5(1-30)Online publication date: 14-Aug-2024
  • (2024)A Fast Wait-Free Solution to Read-Reclaim Races in Reference CountingEuro-Par 2024: Parallel Processing10.1007/978-3-031-69583-4_8(103-118)Online publication date: 26-Aug-2024
  • (2023)FP²: Fully in-Place Functional ProgrammingProceedings of the ACM on Programming Languages10.1145/36078407:ICFP(275-304)Online publication date: 31-Aug-2023
  • (2023)Tail Recursion Modulo Context: An Equational ApproachProceedings of the ACM on Programming Languages10.1145/35712337:POPL(1152-1181)Online publication date: 11-Jan-2023
  • (2023)A Quantitative Performance Benchmark of Different Navigation Patterns and User Interface Design Frameworks for an Enhanced iOS Experience2023 8th International Conference on Computer Science and Engineering (UBMK)10.1109/UBMK59864.2023.10286664(195-200)Online publication date: 13-Sep-2023
  • (2022)First-class names for effect handlersProceedings of the ACM on Programming Languages10.1145/35632896:OOPSLA2(30-59)Online publication date: 31-Oct-2022
  • (2022)Reference counting with frame limited reuseProceedings of the ACM on Programming Languages10.1145/35476346:ICFP(357-380)Online publication date: 31-Aug-2022
  • Show More Cited By

View Options

Login options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Figures

Tables

Media

Share

Share

Share this Publication link

Share on social media