5 #include <AD/gc/gcobject.h>
6 #include <AD/gc/gcheaps.h>
8 #define TRIALS 500 // number of times to test
9 #define DEPTH 4 // depth of the tree
14 struct Junk
: public GCObject
{
18 Junk(TREE
* t
) : tree(t
) {}
22 class TREE
: public GCObject
{
33 TREE(TREE
*l
, TREE
*r
)
35 junk2(new Junk(this)), junk3(new Junk(this)),
36 junk4(new Junk(this)), junk5(new Junk(this))
37 { for (int i
= 0; i
< SIZE
; i
++) junk
[i
] = i
+ tag
; }
40 { assert(junk2
->tree
== this);
41 for (int i
= 0; i
< SIZE
; i
++) assert(junk
[i
] == i
+tag
);
42 if (left
) left
->verify();
43 if (right
) right
->verify();
45 virtual void trace(GC
* gc
) {
46 left
= (TREE
*)gc
->trace(left
);
47 right
= (TREE
*)gc
->trace(right
);
48 junk2
= (Junk
*)gc
->trace(junk2
);
49 junk3
= (Junk
*)gc
->trace(junk3
);
50 junk4
= (Junk
*)gc
->trace(junk4
);
51 junk5
= (Junk
*)gc
->trace(junk5
);
56 void Junk::trace(GC
* gc
) { tree
= (TREE
*)gc
->trace(tree
); }
57 TREE
* tree(TREE
*l
, TREE
*r
) { return new TREE(l
,r
); }
60 int TREE::size() const
63 if (left
) sz
+= left
->size();
64 if (right
) sz
+= right
->size();
68 TREE
* make_tree(int depth
)
70 if(depth
==0) return (TREE
*) 0;
72 TREE
* t
= tree(make_tree(depth
), make_tree(depth
));
81 assert(t
->size() == ((1 << DEPTH
)-1));
86 cout
<< "Testing gc of trees\n";
87 for (int trial
= 1; trial
<= TRIALS
; trial
++) {
88 cout
<< "Trial " << trial
<< "\n" << flush
;
90 cout
<< "Trial " << trial
<< " has passed\n" << flush
;