4 #include <AD/gc/markswp.h>
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
11 //#define JUNKSIZE 2000
16 class TREE
: public GCObject
{
23 TREE(TREE
* l
, TREE
* r
) : left_child(l
), right_child(r
)
27 tagcnt
+= 5*JUNKSIZE
+17;
28 for (int i
= 0; i
< JUNKSIZE
; i
++) junk
[i
] = i
+ tag
;
33 for (i
= 0; i
< JUNKSIZE
; i
++) assert(junk
[i
] == i
+tag
);
34 if (left_child
) left_child
->verify();
35 if (right_child
) right_child
->verify();
39 left_child
= (TREE
*)gc
->trace(left_child
);
40 right_child
= (TREE
*)gc
->trace(right_child
);
47 int TREE::size() const
50 if (left_child
) sz
+= left_child
->size();
51 if (right_child
) sz
+= right_child
->size();
55 TREE
* make_tree_1(int);
56 TREE
* make_tree_2(int);
58 TREE
* make_tree_1(int depth
)
60 if(depth
==0) return (TREE
*) 0;
62 TREE
* l
= make_tree_2(depth
);
63 TREE
* r
= make_tree_2(depth
);
64 return new (heap1
) TREE(l
,r
);
68 TREE
* make_tree_2(int depth
)
70 if(depth
==0) return (TREE
*) 0;
72 TREE
* l
= make_tree_1(depth
);
73 TREE
* r
= make_tree_1(depth
);
74 return new (heap2
) TREE(l
,r
);
80 t
= make_tree_1(DEPTH
);
82 assert(t
->size() == ((1 << DEPTH
)-1));
87 cout
<< "Testing gc of trees\n";
88 for (int trial
= 1; trial
<= TRIALS
; trial
++) {
89 cout
<< "Trial " << trial
<< "\n" << flush
;
91 cout
<< "Trial " << trial
<< " has passed\n" << flush
;
93 cout
<< "Final cleanup\n" << flush
;