1 //////////////////////////////////////////////////////////////////////////////
2 // Testing the ability to trace cross heap pointers.
3 // We'll allocate a list in two different collectors.
4 // Garbage collection should preserve the shape of the list.
5 //////////////////////////////////////////////////////////////////////////////
10 #include <AD/gc/bgc.h>
11 #include <AD/gc/gcobject.h>
12 #include <AD/gc/gcheaps.h>
17 #define TRIALS 5 // number of times to test
18 #define LENGTH 100 // length of list to allocate
20 class LIST
: public GCObject
{
25 LIST(LIST
* n
) : next(n
)
26 { for (int i
= 0; i
< 500; i
++) junk
[i
] = i
+ tag
; }
29 { for (int i
= 0; i
< 500; i
++) assert(junk
[i
] == i
+tag
);
30 if (next
) next
->verify();
32 void trace(GC
* gc
) { next
= (LIST
*)gc
->trace(next
); }
37 for (len
= 0; l
; l
= l
->next
)
45 for (int i
= 0; i
< LENGTH
; i
++) {
46 l
= new (heap1
) LIST(l
);
47 new (heap1
) LIST(l
); // some garbage for heap1
48 new (heap1
) LIST(l
); // some garbage for heap1
49 new (heap1
) LIST(l
); // some garbage for heap1
50 l
= new (heap2
) LIST(l
);
51 new (heap2
) LIST(l
); // some garbage for heap2
52 new (heap2
) LIST(l
); // some garbage for heap2
53 new (heap2
) LIST(l
); // some garbage for heap2
56 assert(length(l
) == LENGTH
* 2);
61 cout
<< "Testing crossheap pointers\n";
62 for (int trial
= 1; trial
<= TRIALS
; trial
++) {
63 cout
<< "Trial " << trial
<< "\n" << flush
;
65 cout
<< "Trial " << trial
<< " has passed\n" << flush
;
67 cout
<< "Now cleaning up\n";