4 #include <AD/gc/markswp.h>
6 #include <AD/gc/gcobject.h>
7 #include <AD/gc/gcheaps.h>
9 #define TRIALS 50 // number of times to test
10 #define DEPTH 6 // depth of the tree
12 //#define JUNKSIZE 2000
18 class TREE
: public GCObject
{
25 TREE(TREE
* l
, TREE
* r
) : left_child(l
), right_child(r
)
29 tagcnt
+= 5*JUNKSIZE
+17;
30 for (int i
= 0; i
< JUNKSIZE
; i
++) junk
[i
] = i
+ tag
;
35 for (i
= 0; i
< JUNKSIZE
; i
++) assert(junk
[i
] == i
+tag
);
36 if (left_child
) left_child
->verify();
37 if (right_child
) right_child
->verify();
41 left_child
= (TREE
*)gc
->trace(left_child
);
42 right_child
= (TREE
*)gc
->trace(right_child
);
49 int TREE::size() const
52 if (left_child
) sz
+= left_child
->size();
53 if (right_child
) sz
+= right_child
->size();
57 TREE
* make_tree_1(int);
58 TREE
* make_tree_2(int);
59 TREE
* make_tree_3(int);
61 TREE
* make_tree_1(int depth
)
63 if(depth
==0) return (TREE
*) 0;
65 TREE
* l
= make_tree_2(depth
);
66 TREE
* r
= make_tree_2(depth
);
67 return new (heap1
) TREE(l
,r
);
71 TREE
* make_tree_2(int depth
)
73 if(depth
==0) return (TREE
*) 0;
75 TREE
* l
= make_tree_3(depth
);
76 TREE
* r
= make_tree_3(depth
);
77 return new (heap2
) TREE(l
,r
);
80 TREE
* make_tree_3(int depth
)
82 if(depth
==0) return (TREE
*) 0;
84 TREE
* l
= make_tree_1(depth
);
85 TREE
* r
= make_tree_1(depth
);
86 return new (heap3
) TREE(l
,r
);
91 t
= make_tree_1(DEPTH
);
93 assert(t
->size() == ((1 << DEPTH
)-1));
98 cout
<< "Testing gc of trees\n";
99 for (int trial
= 1; trial
<= TRIALS
; trial
++) {
100 cout
<< "Trial " << trial
<< "\n" << flush
;
102 cout
<< "Trial " << trial
<< " has passed\n" << flush
;
104 cout
<< "Final cleanup\n" << flush
;