aboutsummaryrefslogtreecommitdiffstats
path: root/mps/code
diff options
context:
space:
mode:
authorDavid Jones2003-11-19 13:55:41 +0000
committerDavid Jones2003-11-19 13:55:41 +0000
commitae2ecc91b4107e8c56859e8bfec1da92c21eb563 (patch)
tree771b24eeeba4aa1572c049791729234e27165d78 /mps/code
parent72ffc59e3cff9cb477673a1c51937fbdf554626a (diff)
downloademacs-ae2ecc91b4107e8c56859e8bfec1da92c21eb563.tar.gz
emacs-ae2ecc91b4107e8c56859e8bfec1da92c21eb563.zip
Mps: test for bug in job000825
Copied from Perforce Change: 64980 ServerID: perforce.ravenbrook.com
Diffstat (limited to 'mps/code')
-rw-r--r--mps/code/comm.gmk4
-rw-r--r--mps/code/expt825.c305
2 files changed, 309 insertions, 0 deletions
diff --git a/mps/code/comm.gmk b/mps/code/comm.gmk
index d4ee97c25da..b9057e678dc 100644
--- a/mps/code/comm.gmk
+++ b/mps/code/comm.gmk
@@ -292,6 +292,7 @@ testrun: mpmss apss sacss amcss amcsshe amsss amssshe segsmss awlut awluthe \
292mpmss sacss amcss amcssth amcsshe amsss amssshe segsmss awlut awlutth \ 292mpmss sacss amcss amcssth amcsshe amsss amssshe segsmss awlut awlutth \
293 awluthe mpsicv lockcov poolncv locv qs apss \ 293 awluthe mpsicv lockcov poolncv locv qs apss \
294 finalcv finaltest arenacv bttest teletest \ 294 finalcv finaltest arenacv bttest teletest \
295 expt825 \
295 abqtest cbstest btcv mv2test \ 296 abqtest cbstest btcv mv2test \
296 messtest steptest \ 297 messtest steptest \
297 walkt0 \ 298 walkt0 \
@@ -353,6 +354,9 @@ $(PFM)/$(VARIETY)/finalcv: $(PFM)/$(VARIETY)/finalcv.o \
353$(PFM)/$(VARIETY)/finaltest: $(PFM)/$(VARIETY)/finaltest.o \ 354$(PFM)/$(VARIETY)/finaltest: $(PFM)/$(VARIETY)/finaltest.o \
354 $(FMTDYTSTOBJ) $(MPMOBJ) $(AMCOBJ) $(TESTLIBOBJ) 355 $(FMTDYTSTOBJ) $(MPMOBJ) $(AMCOBJ) $(TESTLIBOBJ)
355 356
357$(PFM)/$(VARIETY)/expt825: $(PFM)/$(VARIETY)/expt825.o \
358 $(FMTDYTSTOBJ) $(MPMOBJ) $(AMCOBJ) $(TESTLIBOBJ)
359
356$(PFM)/$(VARIETY)/locv: $(PFM)/$(VARIETY)/locv.o \ 360$(PFM)/$(VARIETY)/locv: $(PFM)/$(VARIETY)/locv.o \
357 $(MPMOBJ) $(LOOBJ) $(TESTLIBOBJ) 361 $(MPMOBJ) $(LOOBJ) $(TESTLIBOBJ)
358 362
diff --git a/mps/code/expt825.c b/mps/code/expt825.c
new file mode 100644
index 00000000000..458e0c0870f
--- /dev/null
+++ b/mps/code/expt825.c
@@ -0,0 +1,305 @@
1/* expt825.c: Test for bug described in job000825
2 *
3 * $Id$
4 * Copyright (c) 2001,2003 Ravenbrook Limited. See end of file for license.
5 * Portions copyright (C) 2002 Global Graphics Software.
6 *
7 * DESIGN
8 *
9 * DEPENDENCIES
10 *
11 * This test uses the dylan object format, but the reliance on this
12 * particular format is not great and could be removed.
13 *
14 * NOTES
15 *
16 * This code was created by first copying <code/finalcv.c>
17 * and then further by copying <code/finaltest.c>
18 */
19
20#include "testlib.h"
21#include "mps.h"
22#include "mpscamc.h"
23#include "mpsavm.h"
24#include "fmtdy.h"
25#include "fmtdytst.h"
26#include "mpstd.h"
27#ifdef MPS_OS_W3
28#include "mpsw3.h"
29#endif
30#include <stdlib.h>
31
32
33#define testArenaSIZE ((size_t)16<<20)
34#define rootCOUNT 20
35#define maxtreeDEPTH 2
36#define collectionCOUNT 10
37#define genCOUNT 2
38
39/* testChain -- generation parameters for the test */
40
41static mps_gen_param_s testChain[genCOUNT] = {
42 { 150, 0.85 }, { 170, 0.45 } };
43
44
45/* global object counter */
46
47static mps_word_t object_count = 0;
48
49static mps_word_t make_numbered_cons(mps_word_t car, mps_word_t cdr,
50 mps_ap_t ap)
51{
52 mps_word_t cons;
53 die(make_dylan_vector(&cons, ap, 3), "make_dylan_vector");
54 DYLAN_VECTOR_SLOT(cons, 0) = car;
55 DYLAN_VECTOR_SLOT(cons, 1) = cdr;
56 DYLAN_VECTOR_SLOT(cons, 2) = DYLAN_INT(object_count);
57 ++ object_count;
58 return cons;
59}
60
61static mps_word_t make_numbered_tree(mps_word_t depth,
62 mps_ap_t ap)
63{
64 mps_word_t left, right;
65 if (depth < 2) {
66 left = DYLAN_INT(object_count);
67 right = DYLAN_INT(object_count);
68 } else {
69 left = make_numbered_tree(depth-1, ap);
70 right = make_numbered_tree(depth-1, ap);
71 }
72 return make_numbered_cons(left, right, ap);
73}
74
75static void register_numbered_tree(mps_word_t tree, mps_arena_t arena)
76{
77 /* don't finalize ints */
78 if ((tree & 1) == 0) {
79 mps_finalize(arena, (mps_addr_t *)&tree);
80 register_numbered_tree(DYLAN_VECTOR_SLOT(tree, 0), arena);
81 register_numbered_tree(DYLAN_VECTOR_SLOT(tree, 1), arena);
82 }
83}
84
85static mps_word_t make_indirect_cons(mps_word_t car, mps_word_t cdr,
86 mps_ap_t ap)
87{
88 mps_word_t cons, indirect;
89 die(make_dylan_vector(&indirect, ap, 1), "make_dylan_vector");
90 DYLAN_VECTOR_SLOT(indirect, 0) = DYLAN_INT(object_count);
91 die(make_dylan_vector(&cons, ap, 3), "make_dylan_vector");
92 DYLAN_VECTOR_SLOT(cons, 0) = car;
93 DYLAN_VECTOR_SLOT(cons, 1) = cdr;
94 DYLAN_VECTOR_SLOT(cons, 2) = indirect;
95 ++ object_count;
96 return cons;
97}
98
99static mps_word_t make_indirect_tree(mps_word_t depth,
100 mps_ap_t ap)
101{
102 mps_word_t left, right;
103 if (depth < 2) {
104 left = DYLAN_INT(object_count);
105 right = DYLAN_INT(object_count);
106 } else {
107 left = make_indirect_tree(depth-1, ap);
108 right = make_indirect_tree(depth-1, ap);
109 }
110 return make_indirect_cons(left, right, ap);
111}
112
113static void register_indirect_tree(mps_word_t tree, mps_arena_t arena)
114{
115 /* don't finalize ints */
116 if ((tree & 1) == 0) {
117 mps_word_t indirect = DYLAN_VECTOR_SLOT(tree,2);
118 mps_finalize(arena, (mps_addr_t *)&indirect);
119 register_indirect_tree(DYLAN_VECTOR_SLOT(tree, 0), arena);
120 register_indirect_tree(DYLAN_VECTOR_SLOT(tree, 1), arena);
121 }
122}
123
124
125static void *root[rootCOUNT];
126
127static void *test(void *arg, size_t s)
128{
129 mps_ap_t ap;
130 mps_fmt_t fmt;
131 mps_chain_t chain;
132 mps_word_t finals;
133 mps_pool_t amc;
134 mps_root_t mps_root;
135 mps_arena_t arena;
136 mps_message_t message;
137 size_t i;
138
139 arena = (mps_arena_t)arg;
140 (void)s;
141
142 die(mps_fmt_create_A(&fmt, arena, dylan_fmt_A()), "fmt_create\n");
143 die(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create");
144 die(mps_pool_create(&amc, arena, mps_class_amc(), fmt, chain),
145 "pool_create amc\n");
146 die(mps_root_create_table(&mps_root, arena, MPS_RANK_EXACT, (mps_rm_t)0,
147 root, (size_t)rootCOUNT),
148 "root_create\n");
149 die(mps_ap_create(&ap, amc, MPS_RANK_EXACT), "ap_create\n");
150
151 mps_message_type_enable(arena, mps_message_type_finalization());
152
153 mps_arena_park(arena);
154
155 object_count = 0;
156
157 printf("Making some finalized trees of objects.\n");
158 /* make some trees */
159 for(i = 0; i < rootCOUNT; ++i) {
160 root[i] = (void *)make_numbered_tree(maxtreeDEPTH, ap);
161 register_numbered_tree((mps_word_t)root[i], arena);
162 }
163
164 mps_arena_unsafe_expose_remember_protection(arena);
165 mps_arena_unsafe_restore_protection(arena);
166
167 printf("Losing all pointers to the trees.\n");
168 /* clean out the roots */
169 for(i = 0; i < rootCOUNT; ++i) {
170 root[i] = 0;
171 }
172
173 finals = 0;
174
175 while ((finals < object_count) &&
176 (mps_collections(arena) < collectionCOUNT)) {
177 mps_word_t final_this_time = 0;
178 printf("Collecting...");
179 fflush(stdout);
180 die(mps_arena_collect(arena), "collect");
181 printf(" Done.\n");
182 while (mps_message_poll(arena)) {
183 mps_word_t obj;
184 mps_addr_t objaddr;
185 cdie(mps_message_get(&message, arena,
186 mps_message_type_finalization()),
187 "get");
188 mps_message_finalization_ref(&objaddr, arena, message);
189 obj = (mps_word_t)objaddr;
190 mps_message_discard(arena, message);
191 ++ final_this_time;
192 }
193 finals += final_this_time;
194 printf("%lu objects finalized: total %lu of %lu\n",
195 final_this_time, finals, object_count);
196 }
197
198 object_count = 0;
199
200 printf("Making some indirectly finalized trees of objects.\n");
201 /* make some trees */
202 for(i = 0; i < rootCOUNT; ++i) {
203 root[i] = (void *)make_indirect_tree(maxtreeDEPTH, ap);
204 register_indirect_tree((mps_word_t)root[i], arena);
205 }
206
207 printf("Losing all pointers to the trees.\n");
208 /* clean out the roots */
209 for(i = 0; i < rootCOUNT; ++i) {
210 root[i] = 0;
211 }
212
213 finals = 0;
214
215 while ((finals < object_count) &&
216 (mps_collections(arena) < collectionCOUNT)) {
217 mps_word_t final_this_time = 0;
218 printf("Collecting...");
219 fflush(stdout);
220 die(mps_arena_collect(arena), "collect");
221 printf(" Done.\n");
222 while (mps_message_poll(arena)) {
223 mps_word_t obj;
224 mps_addr_t objaddr;
225 cdie(mps_message_get(&message, arena,
226 mps_message_type_finalization()),
227 "get");
228 mps_message_finalization_ref(&objaddr, arena, message);
229 obj = (mps_word_t)objaddr;
230 mps_message_discard(arena, message);
231 ++ final_this_time;
232 }
233 finals += final_this_time;
234 printf("%lu objects finalized: total %lu of %lu\n",
235 final_this_time, finals, object_count);
236 }
237
238 mps_ap_destroy(ap);
239 mps_root_destroy(mps_root);
240 mps_pool_destroy(amc);
241 mps_chain_destroy(chain);
242 mps_fmt_destroy(fmt);
243
244 return NULL;
245}
246
247
248int main(int argc, char **argv)
249{
250 mps_arena_t arena;
251 mps_thr_t thread;
252 void *r;
253
254 die(mps_arena_create(&arena, mps_arena_class_vm(), testArenaSIZE),
255 "arena_create\n");
256 die(mps_thread_reg(&thread, arena), "thread_reg\n");
257 mps_tramp(&r, test, arena, 0);
258 mps_thread_dereg(thread);
259 mps_arena_destroy(arena);
260
261 fflush(stdout); /* synchronize */
262 return 0;
263}
264
265
266/* C. COPYRIGHT AND LICENSE
267 *
268 * Copyright (C) 2001-2003 Ravenbrook Limited <http://www.ravenbrook.com/>.
269 * All rights reserved. This is an open source license. Contact
270 * Ravenbrook for commercial licensing options.
271 *
272 * Redistribution and use in source and binary forms, with or without
273 * modification, are permitted provided that the following conditions are
274 * met:
275 *
276 * 1. Redistributions of source code must retain the above copyright
277 * notice, this list of conditions and the following disclaimer.
278 *
279 * 2. Redistributions in binary form must reproduce the above copyright
280 * notice, this list of conditions and the following disclaimer in the
281 * documentation and/or other materials provided with the distribution.
282 *
283 * 3. Redistributions in any form must be accompanied by information on how
284 * to obtain complete source code for this software and any accompanying
285 * software that uses this software. The source code must either be
286 * included in the distribution or be available for no more than the cost
287 * of distribution plus a nominal fee, and must be freely redistributable
288 * under reasonable conditions. For an executable file, complete source
289 * code means the source code for all modules it contains. It does not
290 * include source code for modules or files that typically accompany the
291 * major components of the operating system on which the executable file
292 * runs.
293 *
294 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
295 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
296 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
297 * PURPOSE, OR NON-INFRINGEMENT, ARE DISCLAIMED. IN NO EVENT SHALL THE
298 * COPYRIGHT HOLDERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
299 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
300 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
301 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
302 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
303 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
304 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
305 */