CONS should not CONS its arguments, or, a lazy alloc is a smart alloc

Lazy allocation is a model for allocating objects on the execution stack of a high-level language which does not create dangling references. Our model provides safe transportation into the heap for objects that may survive the deallocation of the surrounding stack frame. Space for objects that do not survive the deallocation of the surrounding stack frame is reclaimed without additional effort when the stack is popped. Lazy allocation thus performs a first-level garbage collection, and if the language supports garbage collection of the heap, then our model can reduce the amortized cost of allocation in such a heap by filtering out the short-lived objects that can be more efficiently managed in LIFO order. A run-time mechanism called result expectation further filters out unneeded results from functions called only for their effects. In a shared-memory multi-processor environment, this filtering reduces contention for the allocation and management of global memory.Our model performs simple local operations, and is therefore suitable for an interpreter or a hardware implementation. Its overheads for functional data are associated only with assignments, making lazy allocation attractive for mostly functional programming styles. Many existing stack allocation optimizations can be seen as instances of this generic model, in which some portion of these local operations have been optimized away through static analysis techniques.Important applications of our model include the efficient allocation of temporary data structures that are passed as arguments to anonymous procedures which may or may not use these data structures in a stack-like fashion. The most important of these objects are functional arguments (funargs), which require some run-time allocation to preserve the local environment. Since a funarg is sometimes returned as a first-class value, its lifetime can survive the stack frame in which it was created. Arguments which are evaluated in a lazy fashion (Scheme delays or "suspensions") are similarly handled. Variable-length argument "lists" themselves can be allocated in this fashion, allowing these objects to become "first-class". Finally, lazy allocation correctly handles the allocation of a Scheme control stack, allowing Scheme continuations to become first-class values.

[1]  Andrew W. Appel,et al.  A Standard ML compiler , 1987, FPCA.

[2]  Daniel G. Bobrow,et al.  Common lisp object system specification , 1988, SIGP.

[3]  Henry Lieberman,et al.  A real-time garbage collector based on the lifetimes of objects , 1983, CACM.

[4]  Microcomputer Standards Subcommittee IEEE standard for the Scheme programming language , 1991 .

[5]  Gerald Jay Sussman,et al.  Design of LISP-based Processors, or SCHEME: A Dielectric LISP, or Finite Memories Considered Harmful, or LAMBDA: The Ultimate Opcode , 1979 .

[6]  William D. Clinger,et al.  Implementation strategies for continuations , 1988, LFP '88.

[7]  Henry G. Baker,et al.  Unify and conquer , 1990, LISP and Functional Programming.

[8]  David A. Fisher,et al.  Bounded Workspace Garbage Collection in an Address-Order Preserving List Processing Environment , 1974, Information Processing Letters.

[9]  Norman P. Jouppi,et al.  Improving direct-mapped cache performance by the addition of a small fully-associative cache and prefetch buffers , 1990, [1990] Proceedings. The 17th Annual International Symposium on Computer Architecture.

[10]  Brian Randall,et al.  ALGOL 60 implementation , 1964 .

[11]  Fred Mellender,et al.  Optimizing Smalltalk Message Performance , 1989, Object-Oriented Concepts, Databases, and Applications.

[12]  David H. D. Warren,et al.  Applied logic : its use and implementation as a programming tool , 1978 .

[13]  David Ungar Generation scavenging: a nondisruptive high performance storage reclamation algorithm , 1984 .

[14]  John McCarthy,et al.  LISP 1.5 Programmer's Manual , 1962 .

[15]  Thomas P. Murtagh,et al.  Lifetime analysis of dynamically allocated objects , 1988, POPL '88.

[16]  John B. Johnston,et al.  The contour model of block structured processes , 1971, SIGP.

[17]  Arthur Evans,et al.  The BCPL Reference Manual , 1974 .

[18]  Guy L. Steele,et al.  C, a reference manual , 1984 .

[19]  David Alex Lamb,et al.  An Ada code generator for VAX 11/780 with Unix , 1980, SIGPLAN '80.

[20]  Guy L. Steele,et al.  A compiler for scheme (a study in compiler optimization) , 1978 .

[21]  Antoni Kreczmar,et al.  Programmed Deallocation Without Dangling Reference , 1984, Inf. Process. Lett..

[22]  Andrew W. Appel,et al.  Simple generational garbage collection and fast allocation , 1989, Softw. Pract. Exp..

[23]  Eiichi Goto,et al.  Genetic Order and Compactifying Garbage Collectors , 1978, Inf. Process. Lett..

[24]  Alfred V. Aho,et al.  Nested Stack Automata , 1969, Journal of the ACM.

[25]  Rodney A. Brooks,et al.  Trading data space for reduced time and code space in real-time garbage collection on stock hardware , 1984, LFP '84.

[26]  Olivier Danvy Memory allocation and higher-order functions , 1987, PLDI.

[27]  Michael J. Fischer,et al.  Lambda-calculus schemata , 1993, LISP Symb. Comput..

[28]  Rodney A. Brooks,et al.  An optimizing compiler for lexically scoped LISP , 1982, SIGPLAN '82.

[29]  Guy L. Steele,et al.  Fast arithmetic in MacLISP , 1977 .

[30]  David M. Ungar,et al.  Generation Scavenging: A non-disruptive high performance storage reclamation algorithm , 1984, SDE 1.

[31]  Daniel M. Berry Block structure (Extended Abstract): Retention or deletion? , 1971, STOC '71.

[32]  Robert Hieb,et al.  A variable-arity procedural interface , 1988, LFP '88.

[33]  S. L. Graham,et al.  List Processing in Real Time on a Serial Computer , 1978 .

[34]  J. Eliot B. Moss Managing stack frames in Smalltalk , 1987, PLDI.

[35]  Robert G. Wedig,et al.  A performance analysis of automatically managed top of stack buffers , 1987, ISCA '87.

[36]  Christian Queinnec Dynamic extent objects , 1988, LIPO.

[37]  Richard D. Greenblatt,et al.  A LISP machine , 1974, CAW '80.

[38]  David A. Moon,et al.  Garbage collection in a large LISP system , 1984, LFP '84.

[39]  D. H. Bartley,et al.  Revised4 report on the algorithmic language scheme , 1991, LIPO.

[40]  Daniel P. Friedman,et al.  The one-bit reference count , 1977 .

[41]  Hans-Juergen Boehm,et al.  Implementing RUSSELL , 1986, SIGPLAN '86.

[42]  Drew McDermott,et al.  An efficient environment allocation scheme in an interpreter for a lexically-scoped LISP , 1980, LISP Conference.

[43]  Henry G. Baker,et al.  Shallow binding in Lisp 1.5 , 1978, CACM.

[44]  Jeffrey M. Barth Shifting garbage collection overhead to compile time , 1977, CACM.

[45]  Robert Hieb,et al.  Representing control in the presence of first-class continuations , 1990, PLDI '90.

[46]  Mary Lou Soffa,et al.  An optimistic implementation of the stack-heap , 1985, J. Syst. Softw..

[47]  Peter Boehler Bishop,et al.  Computer systems with a very large address space and garbage collection , 1977 .

[48]  Jr. Guy L. Steele,et al.  Rabbit: A Compiler for Scheme , 1978 .

[49]  Erik Sandewall A proposed solution to the FUNARG problem , 1971, SIGS.

[50]  Ken Kennedy,et al.  Garbage collection and other optimizations , 1988 .

[51]  Paul Hudak,et al.  ORBIT: an optimizing compiler for scheme , 1986, SIGPLAN '86.

[52]  Richard M. Stallman Phantom Stacks: If You Look Too Hard, They Aren't There , 1980 .

[53]  Joel Moses The function of FUNCTION in LISP or why the FUNARG problem should be called the environment problem , 1970, SIGS.

[54]  Daniel P. Friedman,et al.  CONS Should Not Evaluate its Arguments , 1976, ICALP.

[55]  R. K. Dybvig Three implementation models for scheme , 1987 .

[56]  Steven J. Harrington Space Efficient Copying Storage Recovery , 1981, Comput. J..

[57]  Daniel G. Bobrow,et al.  A model and stack implementation of multiple environments , 1973, CACM.

[58]  Benjamin Goldberg,et al.  Higher Order Escape Analysis: Optimizing Stack Allocation in Functional Program Implementations , 1990, ESOP.

[59]  Andrew W. Appel,et al.  Garbage Collection can be Faster than Stack Allocation , 1987, Inf. Process. Lett..

[60]  Paul N. Hilfinger,et al.  SOAR: Smalltalk Without Bytecodes , 1986, OOPSLA.

[61]  Won Kim,et al.  Object-Oriented Concepts, Databases, and Applications , 1989 .

[62]  S. Tucker Taft,et al.  Portable and efficient dynamic storage management in Ada , 1987, SIGAda '87.

[63]  David H. Bartley,et al.  The implementation of PC Scheme , 1986, LFP '86.