1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208
|
/*
TEST_HEADER
id = $Id$
summary = sort-of-leak in arena_collect
language = c
link = testlib.o exfmt.o
OUTPUT_SPEC
junksize = 0
result = pass
END_HEADER
*/
#include "testlib.h"
#include "mpscamc.h"
#include "mpsavm.h"
#include "exfmt.h"
#define MAGICSIZE ((size_t) 10342)
#define genCOUNT (3)
static mps_gen_param_s testChain[genCOUNT] = {
{ 6000, 0.90 }, { 8000, 0.65 }, { 16000, 0.50 } };
long int appcount;
long int apppadcount;
long int cutoff_id;
size_t junk_size;
static void test_apply(mps_addr_t addr, void *V, size_t S)
{
mycell *a;
long int id;
asserts(S == MAGICSIZE, "Size didn't get passed!");
a = addr;
asserts(((a->tag) & 0x3) == MCdata || ((a->tag) & 0x3) == MCpad,
"apply on non-data and non-pad object at %p", addr);
if (((a->tag) & 0x3) == MCdata) {
appcount += 1;
id = getid(a);
if (id < cutoff_id) {
junk_size += a->data.size;
}
} else {
apppadcount +=1;
}
}
static void test(void *stack_pointer)
{
mps_arena_t arena;
mps_pool_t poolamc;
mps_thr_t thread;
mps_root_t root, root2, root3, root4, root5, root6, root7, root1;
mps_fmt_t format;
mps_chain_t chain;
mps_ap_t apamc;
typedef mycell * myroot;
myroot a, b, c, d, e, f, g;
int i;
int j;
RC;
cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE),
"create arena");
die(mps_thread_reg(&thread, arena), "register thread");
cdie(
mps_root_create_table(&root1, arena, mps_rank_exact(), 0, (mps_addr_t*)&a, 1),
"root");
cdie(
mps_root_create_table(&root2, arena, mps_rank_exact(), 0, (mps_addr_t*)&b, 1),
"root");
cdie(
mps_root_create_table(&root3, arena, mps_rank_exact(), 0, (mps_addr_t*)&c, 1),
"root");
cdie(
mps_root_create_table(&root4, arena, mps_rank_exact(), 0, (mps_addr_t*)&d, 1),
"root");
cdie(
mps_root_create_table(&root5, arena, mps_rank_exact(), 0, (mps_addr_t*)&e, 1),
"root");
cdie(
mps_root_create_table(&root6, arena, mps_rank_exact(), 0, (mps_addr_t*)&f, 1),
"root");
cdie(
mps_root_create_table(&root7, arena, mps_rank_exact(), 0, (mps_addr_t*)&g, 1),
"root");
cdie(
mps_root_create_table(&root, arena, mps_rank_exact(), 0, &exfmt_root, 1),
"create exfmt root");
die(mps_fmt_create_A(&format, arena, &fmtA), "create format");
cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create");
die(mmqa_pool_create_chain(&poolamc, arena, mps_class_amc(), format, chain),
"create pool");
cdie(
mps_ap_create(&apamc, poolamc, mps_rank_exact()),
"create ap");
comment("parking...");
mps_arena_park(arena);
b = allocone(apamc, 1, 1);
for (j=1; j<10; j++) {
comment("%i of 10.", j);
a = allocone(apamc, 5, 1);
cutoff_id = getid(a);
b = a;
c = a;
d = a;
e = a;
f = a;
g = a;
for (i=1; i<1000; i++) {
c = allocone(apamc, 1000, 1);
if (ranint(8) == 0) d = c;
if (ranint(8) == 0) e = c;
if (ranint(8) == 0) f = c;
if (ranint(8) == 0) g = c;
setref(c, 0, b);
setref(c, 1, d);
setref(c, 2, e);
setref(c, 3, f);
setref(c, 4, g);
b = c;
}
for (i=1; i<1000; i++) {
c = allocone(apamc, 1000, 1);
if (ranint(8) == 0) d = c;
if (ranint(8) == 0) e = c;
if (ranint(8) == 0) f = c;
if (ranint(8) == 0) g = c;
setref(c, 0, b);
setref(c, 1, d);
setref(c, 2, e);
setref(c, 3, f);
setref(c, 4, g);
b = c;
}
a = c;
b = c;
d = c;
e = c;
f = c;
g = c;
exfmt_root = c;
mps_arena_collect(arena);
comment(" reserved: %lu", (unsigned long) mps_arena_reserved(arena));
comment("committed: %lu", (unsigned long) mps_arena_committed(arena));
comment("calling amc_apply:");
checkfrom(c);
appcount = 0;
apppadcount = 0;
junk_size = 0;
mps_amc_apply(poolamc, &test_apply, NULL, MAGICSIZE);
comment("finished amc_apply");
report("junksize", "%lu", (unsigned long) junk_size);
report("appcount", "%ld", appcount);
report("apppadcount", "%ld", apppadcount);
RC;
}
mps_arena_release(arena);
comment("released.");
mps_arena_park(arena);
mps_ap_destroy(apamc);
mps_pool_destroy(poolamc);
mps_chain_destroy(chain);
mps_fmt_destroy(format);
mps_root_destroy(root);
mps_root_destroy(root1);
mps_root_destroy(root2);
mps_root_destroy(root3);
mps_root_destroy(root4);
mps_root_destroy(root5);
mps_root_destroy(root6);
mps_root_destroy(root7);
comment("Destroyed roots.");
mps_thread_dereg(thread);
mps_arena_destroy(arena);
comment("Destroyed arena.");
}
int main(void)
{
run_test(test);
pass();
return 0;
}
|