Code Generation Using a Formal Model of Reference Counting
Reference counting is a popular technique for memory management. It tracks the number of active references to a data object during the execution of a program. Reference counting allows the memory used by a data object to be freed when there are no active references to it. We develop the metatheory of reference counting by presenting an abstract model for a functional language with arrays. The model is captured by an intermediate language and its operational semantics, defined both with and without reference counting. These two semantics are shown to correspond by means of a bisimulation. The reference counting implementation allows singly referenced data objects to be updated in place, i.e., without copying. The main motivation for our model of reference counting is in soundly translating programs from a high-level functional language, in our case, an executable fragment of the PVS specification language, to efficient code with a compact footprint in a small subset of a low-level imperative language like C.
An earlier version of the intermediate language used here was developed by the second author in collaboration with Basile Clement (École Normal Supérieure, Paris) and Simon Halfon (École Normal Supérieure, Cachan). We thank them for many illuminating conversations on topics related to this paper. We thank Greg Morrisett (Cornell University), Sam Owre (SRI), Bruno Dutertre (SRI), Andrew Tolmach (Portland State University), Jean-Christophe Filliâtre (LRI Université Paris-Sud), John Launchbury (DARPA I20), Robin Larrieu (École Polytechnique), and the anonymous referees for their helpful suggestions and useful feedback.
- 1.Boehm, H.-J., Weiser, M.: Garbage collection in an uncooperative environment. Softw.: Pract. Exp. 18(9), 807–820 (1988)Google Scholar
- 5.Felleisen, N.: On the expressive power of programming languages. In: Jones, N. (ed.) ESOP 1990. LNCS, vol. 432, pp. 35–75. Springer, Heidelberg (1990)Google Scholar
- 6.Flanagan, C., Sabry, A., Duba, B.F., Felleisen, M.: The essence of compiling with continuations (with retrospective). In: McKinley, K.S. (ed.) Best of PLDI, pp. 502–514. ACM (1993)Google Scholar
- 7.Hudak, P.: A semantic model of reference counting and its abstraction (detailed summary). In: Proceedings of 1986 ACM Conference on LISP and Functional Programming, pp. 351–363. ACM, August 1986Google Scholar
- 9.Harold, J.: McBeth: On the reference counter method. Commun. ACM 6(9), 575 (1963)Google Scholar
- 12.Wilson, P.R.: Uniprocessor garbage collection techniques. In: Proceedings of International Workshop on Memory Management, IWMM 1992, St. Malo, France, pp. 1–42, 17–19 September 1992Google Scholar