This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: CS2400, Fall 2010 GC Lab: Writing a Garbage Collecting Storage Allocator 1 Introduction In this lab you will be writing a garbage collector for a hypothetical programming language. Garbage collection is described in § 9.10 of the textbook; it’s used in many languages such as Java, C#, and so on. Our implementation is designed for a computer with a 32-bit address space – i.e. one where the the size of a pointer is four bytes. 2 Logistics You may work in a group of up to two people. Any clarifications and revisions to the assignment will be posted on the course Moodle. 3 Hand Out Instructions Download the gclab-handout.tar file from the Moodle assignment page. Start by copying gclab-handout.tar to a protected directory in which you plan to do your work. Then give the command: tar xvf gclab-handout.tar . This will cause a number of files to be unpacked into the directory. The only file you must modify and hand in is gc.c ; however, you have the option of changing other files as we’ll describe later. The test-list.c , etc programs are program that allows you to evaluate the correctness and performance of your solution. Use the command make to generate the test programs and run them with the command ./test-list , etc or the RUN command. Looking at the file gc.c you’ll notice a C structure team into which you should insert the requested identifying information about the one or two individuals comprising your programming team. Do this right away so you don’t forget. When you have completed the lab, you will hand in a zip or tar file containing all the components your solution depends on. 1 4 How to Work on the Lab Your dynamic garbage collector will consist of the following three functions, which are declared in gc.h and defined in gc.c . int gc_init(void); void * gc_alloc(gc_type_info * ); void * gc_collect(); The gc.c file we have given provide some “scaffolding” to implement a memory allocator, but it does not function by itself. Using this as a starting place, modify these functions (and possibly define other private static functions), so that they obey the following semantics: • gc init: Before calling gc alloc function the application program (i.e., the test programs that you will use to evaluate your implementation) calls gc init to perform any necessary initializations, such as allocating the initial heap area. • gc alloc: The gc alloc routine returns a pointer to an allocated block payload sufficiently large to accommodate the object type described via a pointer to an instance of gc_type_info . The entire allocated block should lie within the heap region and should not overlap with any other allocated chunk. The address of the allocated block should be aligned to an 8-byte memory address ( i.e. the lower 3 bits of the returned address should be zero). I describe more of the use of gc_type_info below....
View Full Document
- Fall '08
- Pointer, Garbage collection, garbage collector, gc_alloc, gc.h