Homework 4: a garbage collector for C

In this homework, we build a basic, conservative garbage collector for C programs. Starting from the set of root pointers present in the stack and global variables, we traverse the “object graph” (in the case of malloc, a chunk graph) to find all chunks reachable from the root. These are marked using the third lowest order bit in the size field of each chunk.

As of the release of this assignment, we have not covered the concepts related to garbage collection in class; to start on this homework, take a look at section 9.10, and 9.10.2 specifically. The week 7 lab will help with getting started on the assignment as well.

The skeleton code in the public git repository provides supporting code for finding the limits of the global variable area in memory, as well as for the stack and heap areas. It also demonstrates very basic marking and sweeping. Your task is to complete the garbage collector, so that it frees all garbage, and leaves every other chunk intact. To compile the template, type make, and run it with ./hw4.

Performance requirements

For full points, your program should pass all tests in main.c - that is, it should free all inaccessible memory. At present, these are not coded as actual tests, they simply output the heap size and number of free and in-use chunks. Nevertheless, your program should produce the correct values.

Runtime performance is not a major goal for this homework. However if your program is taking more than 2 seconds, you almost certainly did something wrong.

Turn-in instructions

You can start the assignment via this invite link: [expired] and turn it in via gradescope as with other homework assignments. You should only make changes to hw4.c. The turnin will be activated at a later date.

Due date

This homework is due Friday, November 2, at 11:59:59 PM.