There is a simple class called GCVerify that can be used to verify the integrity of a complex allocated data structure. This is frequently useful during the development of a new collector, or a complex class derive class of GCObject.
The interface of this class is shown below.
class GCVerifier : protected GC {
public:
virtual bool is_valid_pointer (GCObject *);
virtual bool is_valid_interior_pointer (GCObject *);
virtual bool is_valid_structure (GCObject *);
virtual bool is_valid_pointer (GCObject *, GC *);
virtual bool is_valid_interior_pointer (GCObject *, GC *);
virtual bool is_valid_structure (GCObject *, GC *);
size_t number_of_nodes() const;
};
Class GCVerify is derived from class GC so that the same object tracing protocol can be used. Briefly, three different methods are provided for verification:
is_valid_pointer(p,gc) verifies that
p is a valid pointer to an object within the collector gc.
is_valid_pointer(p,gc) verifies that
p is a valid interior pointer to an object
within the collector gc.
is_valid_structure(p,gc) verifies the entire
structure reachable by p is valid. This method uses
GCObject::trace to locate the correct sub-structures.
There are alternative versions of the same methods that assumes the default collector is used. Furthermore
number_of_nodes() returns the node count of the
last structure traced using is_valid_structure, and
set_verbosity(GC::gc_print_debugging_info) is used
then error messages will be printed during structure tracing.