5 #include <AD/gc/gcobject.h>
6 #include <AD/gc/gcheaps.h>
8 #define TRIALS 50 // number of times to test
9 #define DEPTH 6 // depth of the tree
10 //#define JUNKSIZE 500
17 class TREE
: public GCObject
{
24 TREE(TREE
* l
, TREE
* r
) : left_child(l
), right_child(r
)
28 // tagcnt += 5*JUNKSIZE+17;
29 for (int i
= 0; i
< JUNKSIZE
; i
++) junk
[i
] = i
+ tag
;
34 for (i
= 0; i
< JUNKSIZE
; i
++) assert(junk
[i
] == i
+tag
);
35 if (left_child
) left_child
->verify();
36 if (right_child
) right_child
->verify();
40 left_child
= (TREE
*)gc
->trace(left_child
);
41 right_child
= (TREE
*)gc
->trace(right_child
);
46 // int TREE::tagcnt = 0;
48 int TREE::size() const
51 if (left_child
) sz
+= left_child
->size();
52 if (right_child
) sz
+= right_child
->size();
56 TREE
* make_tree_1(int);
57 TREE
* make_tree_2(int);
59 TREE
* make_tree_1(int depth
)
61 if(depth
==0) return (TREE
*) 0;
63 TREE
* l
= make_tree_2(depth
);
64 TREE
* r
= make_tree_2(depth
);
65 return new (heap1
) TREE(l
,r
);
69 TREE
* make_tree_2(int depth
)
71 if(depth
==0) return (TREE
*) 0;
73 TREE
* l
= make_tree_1(depth
);
74 TREE
* r
= make_tree_1(depth
);
75 return new (heap2
) TREE(l
,r
);
81 t
= make_tree_1(DEPTH
);
83 assert(t
->size() == ((1 << DEPTH
)-1));
88 cout
<< "Testing gc of trees\n";
89 for (int trial
= 1; trial
<= TRIALS
; trial
++) {
90 cout
<< "Trial " << trial
<< "\n" << flush
;
92 cout
<< "Trial " << trial
<< " has passed\n" << flush
;
94 cout
<< "Final cleanup\n" << flush
;