lestes::std::mem::gc Class Reference

Garbage collector. More...

#include <gc.hh>

List of all members.

Static Public Member Functions

static ulint live_roots (void)
 Returns number of live root pointers.
static ulint live_keystones (void)
 Returns number of live keystones.
static void run (void)
 Runs garbage collection.

Private Member Functions

 gc (const gc &)
 Hides copy constructor.
gcoperator= (const gc &)
 Hides assignment operator.

Static Private Member Functions

static void init (void)
 Initializes static variables.
static void cleanup (void)
 Performs cleanup of static variables.

Static Private Attributes

static ulint initialized = 0
 Guard flag to prevent multiple initialization.
static root_pointerroots
 Doubly linked list of all root pointers.
static keystonekeystones
 Singly linked list of all keystones.
static keystonemarked
 Singly linked list of marked keystones.

Friends

class init_gc
 Initializer accesses gc private methods.
class root_pointer
 Root pointer accesses gc private fields for speed.
class keystone
 Keystone accesses gc private fields for speed.


Detailed Description

Garbage collector.

Provides garbage collector functionality.

Definition at line 78 of file gc.hh.


Constructor & Destructor Documentation

lestes::std::mem::gc::gc ( const gc  )  [private]

Hides copy constructor.


Member Function Documentation

ulint lestes::std::mem::gc::live_roots ( void   )  [static]

Returns number of live root pointers.

Counts live root pointers.

Returns:
The number of live root pointers.

Definition at line 114 of file gc.cc.

References lestes::std::mem::root_pointer::next, and roots.

Referenced by lestes::std::mem::gc_test().

00115 {
00116         ulint cnt = 0;
00117         for (root_pointer *p = roots->next; p != roots; p = p->next) {
00118                 cnt++;
00119         }
00120         return cnt;
00121 }

ulint lestes::std::mem::gc::live_keystones ( void   )  [static]

Returns number of live keystones.

Counts live keysones.

Returns:
The number of live keystones.

Definition at line 127 of file gc.cc.

References keystones, and lestes::std::mem::keystone::keystones_next.

Referenced by lestes::std::mem::gc_test().

00128 {
00129         ulint cnt = 0;
00130         for (keystone *p = keystones; p != NULL; p = p->keystones_next) {
00131                 cnt++;
00132         }
00133         return cnt;
00134 }

void lestes::std::mem::gc::run ( void   )  [static]

Runs garbage collection.

Runs garbage collection, invoked in new_handler. Should be invoked explicitly after completing task.

Definition at line 140 of file gc.cc.

References lestes::std::mem::keystone::enqueue(), lestes::std::mem::keystone::gc_mark(), keystones, lestes::std::mem::keystone::keystones_next, marked, lestes::std::mem::keystone::marked_next, lestes::std::mem::root_pointer::next, roots, and lestes::std::mem::keystone::sweep().

Referenced by cleanup().

00141 {
00142         // initialize the global marked list
00143         marked = NULL;
00144         // walk through all root pointers and
00145         // insert keystones into marked list
00146         for (root_pointer *p = roots->next; p != roots; p = p->next) {
00147                 keystone *key = p->pointer_get();
00148                 if (key) key->enqueue();
00149         }
00150         
00151         // mark all levels of keystones
00152         while (marked != NULL) {
00153                 keystone *old = marked;
00154                 // initialize the global list for new marking
00155                 marked = NULL;
00156                 while (old) {
00157                         // mark directly reachable keystones
00158                         old->gc_mark();
00159                         old = old->marked_next;
00160                 }
00161         }
00162         
00163         keystone *key = keystones;
00164 
00165         // initialize the linked list before new connecting
00166         keystones = NULL;
00167         
00168         // walk through all keystones and sweep unmarked
00169         while (key != NULL) {
00170                 // save the pointer to next
00171                 keystone *tmp = key->keystones_next;
00172                 // after sweep_object, obj may be invalid
00173                 key->sweep();
00174                 // restore pointer to next
00175                 key = tmp;
00176         }
00177 }

void lestes::std::mem::gc::init ( void   )  [static, private]

Initializes static variables.

Initializes static fields of gc class. Prevents multiple initialization.

Definition at line 71 of file gc.cc.

References initialized, keystones, marked, root_pointer, and roots.

Referenced by lestes::std::mem::init_gc::init_gc().

00072 {
00073         if (initialized++) return;
00074         // create head of linked list
00075         roots = new root_pointer(false);
00076         keystones = NULL;
00077         marked = NULL;
00078 }

void lestes::std::mem::gc::cleanup ( void   )  [static, private]

Performs cleanup of static variables.

Performs cleanup of static fields of gc class.

TMA: also cleans all remaining objects.

Definition at line 85 of file gc.cc.

References initialized, roots, and run().

Referenced by lestes::std::mem::init_gc::~init_gc().

00086 {
00087         if (--initialized) return;
00088         run();
00089         delete roots;
00090 }

gc& lestes::std::mem::gc::operator= ( const gc  )  [private]

Hides assignment operator.


Friends And Related Function Documentation

friend class init_gc [friend]

Initializer accesses gc private methods.

Definition at line 88 of file gc.hh.

friend class root_pointer [friend]

Root pointer accesses gc private fields for speed.

Definition at line 96 of file gc.hh.

Referenced by init().

friend class keystone [friend]

Keystone accesses gc private fields for speed.

Definition at line 98 of file gc.hh.


Member Data Documentation

ulint lestes::std::mem::gc::initialized = 0 [static, private]

Guard flag to prevent multiple initialization.

Counter to keep track of number of initializaton objects. Reaches zero only after all initialization objects are destroyed.

Definition at line 94 of file gc.hh.

Referenced by cleanup(), and init().

root_pointer * lestes::std::mem::gc::roots [static, private]

Doubly linked list of all root pointers.

Start of doubly linked list of all root pointers. Initialized to point to the fake head entry.

Definition at line 100 of file gc.hh.

Referenced by cleanup(), init(), live_roots(), lestes::std::mem::root_pointer::root_pointer(), and run().

keystone * lestes::std::mem::gc::keystones [static, private]

Singly linked list of all keystones.

Start of singly linked list of all keystones. Initially the list is empty.

Definition at line 102 of file gc.hh.

Referenced by init(), lestes::std::mem::keystone::keystone(), live_keystones(), run(), and lestes::std::mem::keystone::sweep().

keystone * lestes::std::mem::gc::marked [static, private]

Singly linked list of marked keystones.

Start of singly linked list of marked keystones. Initially the list is empty.

Definition at line 104 of file gc.hh.

Referenced by lestes::std::mem::keystone::enqueue(), init(), and run().


The documentation for this class was generated from the following files:
Generated on Mon Feb 12 18:26:01 2007 for lestes by doxygen 1.5.1-20070107