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
|
/*
TEST_HEADER
id = $Id$
summary = test of ramp allocation with tiny arena
language = c
link = testlib.o rankfmt.o
parameters = ARENA=1024*60 ITERATIONS=10000
OUTPUT_SPEC
result = pass
END_HEADER
*/
#include "testlib.h"
#include "mpscamc.h"
#include "mpsavm.h"
#include "rankfmt.h"
#define ARENALIMIT (ARENA)
#define TABSIZE (ITERATIONS * 5 / 10)
#define ENTERRAMP (ITERATIONS * 3 / 100)
#define LEAVERAMP (ITERATIONS / 10)
#define BACKSIZE (128)
#define BACKITER (32)
#define RAMPSIZE (128)
#define RAMP_INTERFACE
/*
#define COLLECT_WORLD
*/
#define genCOUNT (3)
static mps_gen_param_s testChain[genCOUNT] = {
{ 6000, 0.90 }, { 8000, 0.65 }, { 16000, 0.50 } };
mps_arena_t arena;
mps_pool_t poolamc;
mps_thr_t thread;
mps_root_t root, root1;
mps_chain_t chain;
mps_fmt_t format;
mps_ap_t apamc;
static mps_addr_t objtab[TABSIZE];
static void alloc_back(void) {
long int i, j;
for (j = 0; j < BACKITER; j++) {
i = ranint(ranint(ranint(ranint(TABSIZE)+1)+1)+1);
objtab[i] = allocdumb(apamc, BACKSIZE, mps_rank_exact());
}
}
static void test(void *stack_pointer)
{
long int i;
long int rsize = 0;
int inramp;
mycell *r = NULL, *s;
cdie(mps_arena_create(&arena, mps_arena_class_vm(),
(size_t) ARENALIMIT),
"create arena");
cdie(mps_thread_reg(&thread, arena), "register thread");
cdie(mps_root_create_thread(&root, arena, thread, stack_pointer), "thread root");
cdie(
mps_root_create_table(&root1, arena, mps_rank_exact(), 0, &objtab[0], TABSIZE),
"create root table");
cdie(
mps_fmt_create_A(&format, arena, &fmtA),
"create format");
cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create");
cdie(
mps_pool_create(&poolamc, arena, mps_class_amc(), format, chain),
"create pool");
cdie(
mps_ap_create(&apamc, poolamc, mps_rank_exact()),
"create ap");
inramp = 0;
for (i = 0; i < ITERATIONS; i++) {
if (i * 10 % ITERATIONS == 0) {
comment("%ld of %ld", i, ITERATIONS);
}
alloc_back();
if (inramp) {
s = allocone(apamc, 3, mps_rank_exact());
setref(r, 0, s);
setref(s, 1, r);
r = s;
s = allocdumb(apamc, RAMPSIZE, mps_rank_exact());
setref(r, 2, s);
rsize ++;
if (ranint(LEAVERAMP) == 0) {
r = allocone(apamc, 2, mps_rank_exact());
s = allocone(apamc, 2, mps_rank_exact());
#ifdef RAMP_INTERFACE
mps_ap_alloc_pattern_end(apamc, mps_alloc_pattern_ramp());
#endif
#ifdef COLLECT_WORLD
mps_arena_collect(arena);
mps_arena_release(arena);
#endif
comment("ramp end, %ld objects", rsize);
inramp = 0;
}
} else {
if (ranint(ENTERRAMP) == 0) {
#ifdef RAMP_INTERFACE
mps_ap_alloc_pattern_begin(apamc, mps_alloc_pattern_ramp());
#endif
comment("ramp begin");
r = allocone(apamc, 3, mps_rank_exact());
inramp = 1;
rsize = 0;
}
}
}
mps_arena_park(arena);
mps_ap_destroy(apamc);
comment("Destroyed ap.");
mps_pool_destroy(poolamc);
comment("Destroyed pool.");
mps_fmt_destroy(format);
comment("Destroyed format.");
mps_chain_destroy(chain);
comment("Destroyed chain.");
mps_root_destroy(root1);
mps_root_destroy(root);
comment("Destroyed roots.");
mps_thread_dereg(thread);
comment("Deregistered thread.");
mps_arena_destroy(arena);
comment("Destroyed arena.");
}
int main(void)
{
run_test(test);
report("result", "pass");
return 0;
}
|