CS 4536/CS 536 Homework 5: Garbage Collection

Due: Monday, October 5, 11:59pm via turnin (assignment name hwk5)
Collaboration Policy: Individual

The Assignment

In this assignment, you will implement a stop & copy garbage collector. As we have seen, garbage collection involves starting from a root set of references, which reside in local variables and stack frames, and searching for reachable values on the heap. We are providing support code that gives your collector access to a running Scheme program's root set. You just have to implement the memory allocator and the garbage-collection algorithm.

Write your garbage collector in the GC Collector Scheme language level. This language defines an interface to a program's stack and heap that you will use to implement garbage collection. Language-level docs

Your garbage collector must implement the following functions:

To help you write these functions, the GC Collector Scheme language defines an interface for the heap and the roots (the roots is the set of pointers into the heap from the stack):

Your collector should follow these error message conventions:

Testing your Garbage Collector

You may write programs that exercise your garbage collectors using the GC Mutator Scheme language. This language is a subset of Scheme that uses a garbage collector that you specify. The first line of a test program must be:

(allocator-setup "collector.ss" heap-size)

"collector.ss" must be the name of your collector's file. heap-size is the size of the heap your collector will use.

The remainder of the program is in a subset of Scheme with numbers, symbols, lists, etc. The primitives of the language (such as cons, first, rest) map directly to the procedures you define in your garbage collector.

Sample Code

To get you started, here are a sample mutator and a trivial collector that signals an error when the heap fills up. (this collector does signal an error with this mutator, if you don't increase the size of the heap.)

Notes


What to Turn In

Submit your collector as a file collector.ss (with your name at the top of it). Also submit at least 3 mutator-language files containing tests. Document each test with a comment describing what GC behavior the test is checking. Submit separate files, not a zip.


FAQ

get-root-set seems to return duplicate roots. Is this a bug in the support code? No, this is the intended behavior. Roots come from walking the stack, and several frames may refer to the same variable. Moreover, different variables may refer to the same heap location. You need to update all of them in your stop & copy collector.

It would be a lot easier if I could just make all objects consume the same amount of space. Would that be acceptable? No! We've been extremely easy-going in only making you handle two sizes. To reduce it to one size would make the problem trivial and unrealistic.