CS520
Fall 2005
Programming Assignment 5
Due Sunday November 20


For Program 5 you should construct a debugging tool to be used by your garbage collector.

In Program 6 you will add the garbage collector to complete the system.

The debugging tool is a function with the following prototype:

This function should print information about the current state of the memory allocator to stderr. The following items should be printed in the following order:

  1. Global Memory: First, print a line that says "Global Memory: ", "start = ", the start address of global memory, " end = ", the end address of global memory, " length = ", and the length of global memory. Print the addresses with eight hex digits, even if the leading digits are zeroes. The length is in units of words and should be printed in decimal without leading zeros. Then print a blank line. Then print a line for each word in global memory that might point at an allocated block. This line should should first show the address of the word, then a space, then the contents of the word. Both the address and the contents should be printed with eight hex digits, even if the leading digits are zeroes. These lines should be printed so that the addresses are increasing from one line to the next. If at least one word was printed, then print a blank line at the end.

  2. Stack Memory: Should be printed just like Global Memory, except the head line should say "Stack Memory"

  3. Registers: On a single line, print the contents of the ebx, esi and edi registers, in that order. For each register, print the register name and a space, then the contents using eight hex digits, then either two spaces or an asterisk followed by a single space. Print the asterisk if the register contents might point at an allocated block. After printing the register contents, print a blank line.

  4. Heap: First, print a line that simply says "Heap" followed by a blank line. Then print information about each block of the heap. Print the blocks in increasing address order. For each block, print a line that says "Block", followed by a space, followed by the length of the block printed in decimal with no leading zeroes, followed by a space, followed by "Free" if the block is not allocated or "Allocated" if the block is allocated, followed by a space, followed by either "Marked" if the garbage collector is active and the block has been marked by the collector or "Unmarked" if the garbage collector is inactive or the garbage collector is active and the block has not been marked, followed by a space. If the block is allocated then, on the same line, print the block's finalizer function address using eight hex digits, even if the leading digits are zeroes. If the block is allocated then also print the contents of the block using the following format: After all blocks have been printed, print a blank line.

Review the specification for Program 3 to see how the boundaries of global memory and stack memory are determined. Also see the Program 3 specification to see the precise definition for when a word of memory is considered to possibly point to an allocated block.

The memDump function should be visible to the linker. That is, do not make it a "static" function.

If your Program 4 was in pretty good shape, this should be an easy assignment. In which case you might want to begin completing the garbage collector now too, in addition to writing the debugging tool. This might help reduce your "end-of-semester time crunch".

If your Program 4 was pretty weak, then you want to take time now to fix the bugs, fix the code layout, fix the documentation, or whatever else was not done well. Then add the debugging tool required for this assignment.

The goal for Program 6 is to complete a garbage collector that you can be extremely proud of. If someone from industry contacts me to get a reference for you for a job or internship, you want to be comfortable suggesting to me that I show them your code as proof of your capabilities as a software engineer. So take the time to make the code "shine". (I even recommend running a spell checker on your comments!)

Your program will be graded primarily by testing it for correct functionality. Be sure the output of the debugging tool is formatted exactly as specified above! But, the functionality from Program 4 will also be tested. In addition, however, you may lose points if your program is not properly structured and documented.

Your code will be graded using an CIS Linux machine (e.g. turing.unh.edu) so be sure to test in that environment. I will use gcc to compile your code.

You should submit the source code for your memory allocator to two files: C code should be placed in a file called memAlloc.c and any Intel assembly code should be placed in a file called memAllocAsm.s. (If you have no assembly code, then the second file can just contain a blank line.)

Your program should be submitted for grading from a UNH CIS Linux machine (e.g. turing.unh.edu). To turn in this assignment, type:
~cs520/bin/submit prog5 memAlloc.c memAllocAsm.s

Please submit only the above source files. Do not turn in any other files!

Submissions can be checked by typing:
~cs520/bin/scheck prog5

To receive full credit for the assignment, you must turn in your files prior to 8am on Monday November 21. Programming assignments may be handed in late at a penalty of 2 points for one day late, 5 points for two days late, 10 points for three days late, 20 points for four days late, and 40 points for five days late. No program may be turned in more than 5 days late.

Remember: as always you are expected to do your own work on this assignment.


Last modified on November 17, 2005.

Comments and questions should be directed to hatcher@unh.edu