Hostname: page-component-cd9895bd7-dk4vv Total loading time: 0 Render date: 2024-12-23T10:53:08.176Z Has data issue: false hasContentIssue false

Region-based memory management for Mercury programs

Published online by Cambridge University Press:  29 May 2012

QUAN PHAN
Affiliation:
Department of Computer Science, Katholieke Universiteit Leuven Celestijnenlaan, 200A, B-3001 Leuven, Belgium (e-mail: [email protected], [email protected])
GERDA JANSSENS
Affiliation:
Department of Computer Science, Katholieke Universiteit Leuven Celestijnenlaan, 200A, B-3001 Leuven, Belgium (e-mail: [email protected], [email protected])
ZOLTAN SOMOGYI
Affiliation:
National ICT Australia and Department of Computer Science and Software Engineering, The University of Melbourne, Victoria, 3010, Australia (e-mail: [email protected])

Abstract

Region-based memory management (RBMM) is a form of compile time memory management, well-known from the world of functional programming. In this paper we describe our work on implementing RBMM for the logic programming language Mercury. One interesting point about Mercury is that it is designed with strong type, mode, and determinism systems. These systems not only provide Mercury programmers with several direct software engineering benefits, such as self-documenting code and clear program logic, but also give language implementors a large amount of information that is useful for program analyses. In this work, we make use of this information to develop program analyses that determine the distribution of data into regions and transform Mercury programs by inserting into them the necessary region operations. We prove the correctness of our program analyses and transformation. To execute annotated programs, we have implemented runtime support that tackles the two main challenges posed by backtracking. First, backtracking can require regions removed during forward execution to be “resurrected”; and second, any memory allocated during computation that has been backtracked over must be recovered promptly without waiting for the regions involved to come to the end of their life. We describe in detail our solution of both these problems. We study in detail how our RBMM system performs on a selection of benchmark programs, including some well-known difficult cases for RBMM. Even with these difficult cases, our RBMM-enabled Mercury system obtains clearly faster runtimes for 15 out of 18 benchmarks compared to the base Mercury system with its Boehm runtime garbage collector, with an average runtime speedup of 24%, and an average reduction in memory requirements of 95%. In fact, our system achieves optimal memory consumption in some programs.

Type
Regular Papers
Copyright
Copyright © Cambridge University Press 2012 

Access options

Get access to the full version of this content by using one of the access options below. (Log in options will check for institutional or personal access. Content may require purchase if you do not have access.)

References

Aiken, A., Fähndrich, M. and Levien, R. 1995. Better static memory management: Improving region-based analysis of higher-order languages. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, La Jolla, CA, USA, 174185.Google Scholar
Aspinall, D., Hofmann, M. and Konečný, M. 2008. A type system with usage aspects. The Journal of Functional Programming 18, 2, 141178.Google Scholar
Baker, H. G. 1990. Unify and conquer. In Proceedings of the ACM Conference on LISP and Functional Programming, Nice, France, 218226.CrossRefGoogle Scholar
Birkedal, L., Tofte, M. and Vejlstrup, M. 1996. From region inference to von Neumann machines via region representation inference. In Proceedings of the 23rd ACM SIGPLAN Symposium on Principles of Programming Languages, St. Petersburg Beach, FL, USA, 171183.Google Scholar
Boehm, H. and Weiser, M. 1988. Garbage collection in an uncooperative environment. Software – Practice and Experience 18, 807820.CrossRefGoogle Scholar
Bueno, F., Garcia de la Banda, M., Hermenegildo, M., Marriott, K., Puebla, G. and Stuckey, P. July 2001. A model for inter-module analysis and optimizing compilation. In Proceedings of the Tenth International Workshop on Logic-Based Program Synthesis and Transformation Paphos, Cyprus, 86102.Google Scholar
Chase, D. R., Wegman, M. and Zadeck, F. K. 1990. Analysis of pointers and structures. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, White Plains, NY, USA, 296310.Google Scholar
Cherem, S. and Rugina, R. 2004. Region analysis and transformation for Java programs. In Proceedings of the Fourth International Symposium on Memory Management, Vancouver, BC, Canada, 8596.Google Scholar
Chin, W., Craciun, F., Qin, S. and Rinard, M. 2004. Region inference for an object-oriented language. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, Washington DC, USA, 243254.Google Scholar
Gay, D. and Aiken, A. 1998. Memory management with explicit regions. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, Montreal, Canada, 313323.Google Scholar
Grossman, D., Morrisett, G., Jim, T., Hicks, M., Wang, Y. and Cheney, J. 2002. Region-based memory management in Cyclone. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, Berlin, Germany, 282293.Google Scholar
Hallenberg, N., Elsman, M. and Tofte, M. 2002. Combining region inference and garbage collection. In Proceedings of the ACM SIGPLAN Conference on Programming Language Design and Implementation, Berlin, Germany, 141152.Google Scholar
Henderson, F. J. 2002. Accurate garbage collection in an uncooperative environment. In Proceedings of the Third International Symposium on Memory Management, Berlin, Germany, 150156.Google Scholar
Henglein, F., Makholm, H. and Niss, H. 2001. A direct approach to control-flow sensitive region-based memory management. In Proceedings of the Symposium on Principles and Practice of Declarative Programming, Firenze, Italy, 175186.Google Scholar
Makholm, H. 2000a. A region-based memory manager for Prolog. In Proceedings of the Second International Symposium on Memory Management, Minneapolis, MN, USA, 2534.Google Scholar
Makholm, H. 2000b. Region-Based Memory Management in Prolog. MS thesis, University of Copenhagen, Copenhagen, Denmark.Google Scholar
Makholm, H. and Sagonas, K. 2002. On enabling the WAM with region support. In Proceedings of the 18th International Conference on Logic Programming. Copenhagen, Denmark, 163178.Google Scholar
Mazur, N. 2004. Compile-time Garbage Collection for the Declarative Language Mercury. PhD thesis, Department of Computer Science, Katholieke Universiteit Leuven, Belgium.Google Scholar
Mazur, N., Janssens, G. and Bruynooghe, M. 2000. A module-based analysis for memory reuse in Mercury. In Proceedings of First International Conference on Computational Logic, London, UK, 12551269.Google Scholar
Mazur, N., Ross, P., Janssens, G. and Bruynooghe, M. 2001. Practical aspects for a working compile time garbage collection system for Mercury. In Proceedings of the 17th International Conference on Logic Programming, Paphos, Cyprus, 105119.Google Scholar
Mercury team 2009. The Mercury Programming Language Reference Manual. Accessed 3 December 2009. URL: http://www.cs.mu.oz.au/research/mercury/information/doc-latest/mercury_ref.Google Scholar
Nielson, F., Nielson, H. R. and Hankin, C. 1999. The Principles of Program Analysis. Springer, New York.CrossRefGoogle Scholar
Phan, Q. and Janssens, G. 2007. Static region analysis for Mercury. In Proceedings of the 23rd International Conference on Logic Programming, Porto, Portugal, 317332.Google Scholar
Phan, Q. and Janssens, G. 2009. Path-sensitive region analysis for Mercury programs. In Proceedings of the 11th ACM SIGPLAN Symposium on Principles and Practice of Declarative Programming, Coimbra, Portugal, 161169.Google Scholar
Phan, Q., Somogyi, Z. and Janssens, G. 2008. Runtime support for region-based memory management in Mercury. In Proceedings of the Seventh International Symposium on Memory Management, Tucson, AZ, USA, 6170.Google Scholar
Somogyi, Z., Henderson, F. and Conway, T. 1996. The execution algorithm of Mercury, an efficient purely declarative logic programming language. Journal of Logic Programming 29, 1–3, 1764.CrossRefGoogle Scholar
Somogyi, Z. and Sagonas, K. 2006. Tabling in Mercury: Design and implementation. In Proceedings of the Eighth International Symposium on Practical Aspects of Declarative languages, Charleston, SC, USA, 150167.Google Scholar
Steensgaard, B. 1996. Points-to analysis in almost linear time. In Proceedings of the 23rd ACM SIGPLAN Symposium on Principles of Programming Languages, St. Petersburg Beach, FL, USA, 3241.Google Scholar
Tofte, M., Birkedal, L., Elsman, M. and Hallenberg, N. 2004. A retrospective on region-based memory management. Higher-Order and Symbolic Computation 17, 245265.CrossRefGoogle Scholar
Tofte, M., Birkedal, L., Elsman, M., Hallenberg, N., Olesen, T. and Sestoft, P. 2006. Programming with Regions in the MLKit. Accessed 3 December 2009. URL: http://www.it.edu/research/mlkit/dist/mlkit-4.3.0.pdf.Google Scholar
Tofte, M. and Talpin, J.-P. 1997. Region-based memory management. Information and Computation. 132, 2, 109176.Google Scholar