Two-pass Heap Profiling: a Matter of Life and Death Colin Runciman and Niklas Röjemo Department of Computer Science, University of York, Heslington, York, YO1 5DD, UK (e-mail: {colin,rojemo}@cs.york.ac.uk) Abstract. A heap profile is a chart showing the contents of heap mem- ory throughout a computation. Contents are depicted abstractly by show- ing how much space is occupied by memory cells in each of several classes. A good heap profiler can use a variety of attributes of memory cells to define a classification. Effective profiling usually involves a combination of attributes. The ideal profiler gives full support for combination in two ways. First, a section of the heap of interest to the programmer can be specified by constraining the values of any combination of cell attributes. Secondly, no matter what attributes are used to specify such a section, a heap profile can be obtained for that section only, and any other at- tribute can be used to define the classification. Achieving this ideal is not simple for some combinations of attributes. A heap profile is derived by interpolation of a series of censuses of heap contents at different stages. The obvious way to obtain census data is to traverse the live heap at intervals throughout the computation. This is fine for static attributes (eg. What type of value does this memory cell represent?), and for dynamic attributes that can be determined for each cell by examining the heap at any given moment (eg. From which function closures can this cell be reached?). But some attributes of cells can only be determined retrospectively by post-mortem inspection as a cell is over- written or garbage-collected (eg. Is this cell ever used again?). Now we see the problem: if a profiler supports both live and post-mortem attributes, how can we implement the ideal of unrestricted combinations? That is the problem we solve in this paper. We give techniques for profiling a heap section specified in terms of both live and post-mortem attributes. We show how to generate live-attribute profiles of a section of the heap specified using post-mortem attributes, and vice versa.