Homework # 8
due Tuesday, March 29th, 3:30PM
In this Homework, you will implement mark-sweep garbage collection in Squeak.
You will also implement first-fit allocation, with help from code
developed in lecture.
Allocation (in the presence of a garbage collector) works as follows:
- Start with the first block in the free-list.
- If there are no more blocks (we're at a null pointer),
skip ahead to step 6.
- If the current block is not big enough, go back to
step 2 with the next block.
- If the block is more than 1 word bigger than what is requested,
shave the requested number of words (plus one) from the end of
the current block, and return that.
- Otherwise, unlink the whole block from the free list and return it.
- Perform garbage collection (which resets the
free-list).
- Repeat the process from step 1, except if we run out
of blocks (step 2), it should return null (not nil!)
instead of doing garbage collection again.
Mark-sweep garbage collection works by marking all nodes accessible
from a distinguished ``root'' pointer and then sweeping together
unmarked words into blocks of a new free-list:
- Clear all marks.
- Mark starting at the root:
mark(p)
if p is a non-null pointer then
if p is NOT already marked then
mark all words of the block
call mark on the contents of every word in the block
endif
endif
- Set the free-list to null.
- Find all consecutive unmarked groups of words (of at least two words)
and add them to the free list.
Start with the skeleton file for the homework,
and implement the class ManagedHeap.
It should accept the following messages (and other internal ones):
- root
- Return the current value of the root pointer
(initially null).
- root:

- Set the root pointer to
.
- allocate:

- First-fit allocation of a block of
words.
- at:

- Return the contents of the location pointed to by
.
- at:
put:
- Change the contents of the location pointed
to by
to be
.
We have provided a few tests for you. You may need more.
Leave your code in the directory homework8 in your AFS folder:
About this document
John Tang Boyland
2011-03-15