A direct approach to control-flow sensitive region-based memory management

Region-based memory management can be used to control dynamic memory allocations and deallocations safely and efficiently. Existing (direct-style) region systems that statically guarantee region safety---no dereferencing of dangling pointers---are based on refinements of Tofte and Talpin's seminal work on region inference for managing heap memory in stacks of regions.We present a unified Floyd-Hoare Logic inspired region type system for reasoning about and inferring region-based memory management, using a sublanguage of imperative region commands. Our system expresses and performs control-sensitive region management without requiring a stack discipline for allocating and deallocating regions. Furthermore, it captures storage mode analysis and late allocation/early deallocation analysis in a single, expressive, unified logical framework. Explicit region aliasing in combination with reference-counted regions provides flexible, context-sensitive early memory deallocation and simultaneously dispenses with the need for an integrated region alias analysis.In this paper we present the design of our region type system, illustrate its practical expressiveness, compare it to existing region analyses, demonstrate how this eliminates the need for previously required source code rewritings for good memory performance, and describe automatic inference of region commands that give consistently better (or at least equally good) memory performance as existing inference techniques.

[1]  David Walker,et al.  Typed memory management via static capabilities , 2000, TOPL.

[2]  David K. Gifford,et al.  Integrating functional and imperative programming , 1986, LFP '86.

[3]  Amr Sabry,et al.  Monadic encapsulation in ML , 1999, ICFP '99.

[4]  Alexander Aiken,et al.  Better static memory management: improving region-based analysis of higher-order languages , 1995, PLDI '95.

[5]  Philip Wadler,et al.  The marriage of effects and monads , 1998, ICFP '98.

[6]  Mads Tofte,et al.  Region-based Memory Management , 1997, Inf. Comput..

[7]  Douglas T. Ross The AED free storage package , 1967, CACM.

[8]  John Hughes,et al.  Recursion and dynamic data-structures in bounded space: towards embedded ML programming , 1999, ICFP '99.

[9]  Robert E. Strom,et al.  Typestate: A programming language concept for enhancing software reliability , 1986, IEEE Transactions on Software Engineering.

[10]  Martin Elsman,et al.  Programming with regions in the ML Kit , 1997 .

[11]  Lars Birkedal,et al.  From region inference to von Neumann machines via region representation inference , 1996, POPL '96.

[12]  Mads Tofte,et al.  Implementation of the typed call-by-value λ-calculus using a stack of regions , 1994, POPL '94.

[13]  David Walker,et al.  Typed memory management in a calculus of capabilities , 1999, POPL '99.

[14]  David R. Hanson Fast allocation and deallocation of memory based on object lifetimes , 1990, Softw. Pract. Exp..

[15]  Pierre Jouvelot,et al.  Polymorphic type, region and effect inference , 1992, Journal of Functional Programming.