Homework # 7
due Tuesday, March 30, 4:00 PM

Binary Search Trees in Java

Do Exercise 13 on page 238. Also write a driver IntSetDriver.java that has a main method that tests the IntSet class to make sure it works. You will be partly graded on how well your code tests the ADT.

Garbage Collection

For this part of the homework, you will implement a mark-sweep collector. The framework of the problem is provided in two files: Client.java which uses the heap manager, and HeapManager which defines it. These files are in

/afs/cs.uwm.edu/users/classes/cs431/src/homework7/
The HeapManager class is incomplete. You need to define the code to look for a block in the free list, and the code to perform the mark-sweep garbage collection.

Unlike the code in the book, each cell in the memory is either an Integer object or a Pointer object. In order to tell which you have, you will need to use instanceof checks and casts. For instance, to determine if the memory pointed to by a pointer is an Integer object, one may write:


p.peek(0) instanceof Integer
To assume that it is an Integer object, one writes:

(Integer)p.peek(0)
An Integer object is not very useful. In order to get the int value out, one will need to write

((Integer)p.peek(0)).intValue()
(The peek method is defined in the class HeapManager.Pointer and accesses memory using the pointer p.) In this system, we represent null pointers by a Pointer object with a -1 address.

In a mark-sweep collector (described on page 265), the collector starts from the ``root'' pointer (which will be the current frame pointer) and traverses the heap links marking every heap location that is accessible. It uses the size of allocated blocks, and traverses Pointer values, but not Integer values. You may assume that all non-null pointers point to the beginning of a block. The allocator should ensure that the size of the block is stored just before the beginning of each block.

Submitting Your Work

You submit your program work by putting it in the homework7 directory in your AFS class volume. You may do all your work in this directory, or you may wish to do your work in a different directory and copy things when correct into this directory. In any case, you will lose permission to write things in this directory after the deadline, which is 4:00pm on Tuesday, March 30. In other words, you must be done before lecture starts.

The homework7 directory should include the following:

There are no paper problems associated with this homework.


About this document



John Tang Boyland
2004-03-17