• Keine Ergebnisse gefunden

Memory Management

N/A
N/A
Protected

Academic year: 2022

Aktie "Memory Management"

Copied!
2
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

System Software Project

Memory Management

The goal of this project is to implement a heap with a freelist as well as a Mark &

Sweep garbage collector. Since it is a large project you can implement it in teams of two students. It is recommended to use C++ or C as an implementation language because the low-level programming required for a garbage collector is hard (if not impossible) to do in Java or C#.

1. Memory Allocation

Implement a class Heap representing a heap of size 32 Kbytes. The list of free heap blocks should be managed with the first-fit method. Objects should be allocated with an alloc function. In order to allocate an object of a class Student, say, one should call

adr = Heap::alloc("Student");

This function should allocate an object with the required size, install in it a pointer to the type descriptor of class Student, and return the address of the new object.

object size type descriptor type tag

data of Student adr

mark bit object

-n

n: value to subtract from the type tag in order to set the tag pointer to its original value

The least significant bit of the type tag is used as the mark bit of the garbage collector.

For every class (e.g. Student) there is exactly one type descriptor. Normally, type descriptors are generated by the compiler. In your project, however, they should be created and initialized by the user program. The type descriptor of every class should be registered at the heap using the call:

Heap::registerType("Student", studentDescAdr);

The heap maintains a list of all type descriptors and assigns them to the type tags of newly allocated objects.

In the beginning the free list contains a single large block (i.e., the whole heap).

2. Garbage Collector

Implement a Mark & Sweep garbage collector using the Deutsch-Schorr-Waite algorithm. It should be invoked by

Heap::gc(roots);

where roots is an array of root pointers terminated with a null value. The mark phase should traverse and mark all objects that can be directly or indirectly reached from the roots (use the least significant bit of the type tag for marking an object). You can assume that the method call stack does not contain any pointers when gc is called. The sweep phase should build a new freelist and merge adjacent free blocks.

For testing the garbage collector, implement a method

Heap::dump();

which prints a list of all live objects as well as a list of free blocks. For every live object the following values should be printed:

(2)

 address (hexadecimal)

 name of the object's type

 the first 4 bytes of the object in hex form (to get a clue of the object's contents)

 a list of all pointers in this object (in hexadecimal form)

dump() should also print the total amount of memory used by live objects.

When dumping the freelist the address and length of every free block should be printed as well as the total amount of free memory.

3. Test program

Test your memory management system with a real application. For example, you could implement a program that manages students and courses according to the following class diagram.

A snapshot of such a data structure could look as follows:

Lecture StudentList StudNode

Student

LectNode

At the start of your program create all type descriptors for your classes and register them at the heap. In order to create a Student object in C++, you can then write

Student s = (Student) Heap::alloc("Student");

Build a sufficiently complex data structure with your objects and then delete some objects by removing all pointers to them. Call the garbage collector and check if all unreferenced objects are collected correctly. Finally delete the pointer to the

StudentList node and call the garbage collector again. The heap should now consist of a single free block again.

Assume that your program has a single root pointer pointing to the StudentList node.

StudentList first: StudNode add(student) remove (student)

StudNode next: StudNode stud: Student

Student id: int name: String lect: LectNode add(lecture) remove (lecture)

LectNode next: LectNode lect: Lecture

Lecture id: int name: String semester: int

Referenzen

ÄHNLICHE DOKUMENTE

For each viewpoint, the link between 3D CAD models used for training and natural test images is established by a local shape representation of object parts, based on

The challenges of cloud computing data management can be summarized as mas- sively parallel and widely distributed data storage and processing, integration of novel processing

If this rule is learned with the stimuli involving only two of the three positive or negative fea- tures (top column), then transfer should occur to the novel stimuli having all

Since the model and view components contain elements which are defined by a semantic convention – the data, ser- vice and GUI objects as well as the event handling methods – the

El primero, la metáfora como objeto de estudio, nos sitúa en las cuestiones y las implicaciones epistemológicas de la expresión metafórica, que son precisamente las que hacen que

Under the hood, data model mapping, persisting and retrieving objects as well as traversing object associations result in relational database specific SQL statements.. While this

This work therefore describes an approach to integrate fuzzy sets and constraints expressed in the Object Constraint Language (OCL) in a combined constraint reasoning process..

Rhapsody (see [Inc]) is based on the executable modeling work presented in [HG97], which was originally intended as a carefully worked out language set based on Booch and OMT