Next: , Previous: Heap and relocatable areas, Up: Memory management


4.3 The Garbage Collector

ECL uses a conservative garbage collection technique for collecting the C stack and a type accurate technique for areas containing Lisp objects. Scanning conservatively the C stack, looking for potential pointers to Lisp objects, ensures that no live Lisp objects get collected, even if they are passed to external procedures in C or some other language. This approach greatly simplifies integration of Lisp and C code, since it is not necessary to protect Lisp object form collection when a foreign function is invoked.

The garbage collector of ECL has three levels according to what it collects:

  1. cells
  2. cells and relocatable blocks
  3. cells, relocatable blocks and contiguous blocks.

In levels 2 and 3, the relocatable area is shifted to the higher address space to reserve an appropriate number of pages in the hole.

For each type class, ECL keeps a free list of unused cells, and when the free list is exhausted, a new page is allocated, or the garbage collector is invoked, depending on whether the maximum number of pages for that class have been allocated or not.

The garbage collector does not compact the heap. That is, cells and contiguous blocks are never moved to another place. Moreover, once a page is allocated for a particular type class or for contiguous blocks, that page will never be freed for other classes, even if the entire page becomes garbage.

On the other hand, the relocatable area is compacted during level 2 and level 3 of garbage collection. A relocatable block is really relocatable.

The garbage collector is automatically invoked in one of the following situations. The number in the parentheses indicates the level of garbage collection that is performed.

  1. The free list of a certain type class is exhausted after the maximum number of pages have been allocated for that type class (1).
  2. The hole is exhausted (2).
  3. The relocatable area is exhausted after the maximum number of pages have been allocated for the relocatable area (2).
  4. The contiguous blocks are exhausted after the maximum number of pages have been allocated for contiguous blocks (3).

The garbage collector is also invoked by the following ECL specific function.

— Function: system gc x

The garbage collector is invoked with the level specified by x. If x is (), the garbage collector is invoked for level 1 garbage collection. If x is T, it is invoked for level 3 garbage collection. Otherwise, it is invoked for level 2 garbage collection. If sys:*gc-verbose* is non-(), then it print messages at the start and end of each garbage collection.

— Variable: *gc-verbose*[system] This variable controls whether to print messages

at the start and end of each garbage collection. If sys:*gc-verbose* is (), gc fore goes printing any messages. The default value is T.