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
|
/*
TEST_HEADER
id = $Id$
summary = allocate in 2 arenas
language = c
link = testlib.o rankfmt.o
parameters = ITERATIONS=10000
OUTPUT_SPEC
result = pass
END_HEADER
*/
/* This test is basically MMQA_test_function!124.c modified to
used two arenas
*/
#include "testlib.h"
#include "mpscamc.h"
#include "mpsavm.h"
#include "rankfmt.h"
#define ARENALIMIT (100)
#define TABSIZE (ITERATIONS / 2)
#define ENTERRAMP (ITERATIONS / 10)
#define LEAVERAMP (ITERATIONS / 10)
#define BACKSIZE (32)
#define BACKITER (32)
#define RAMPSIZE (128)
#define RAMP_INTERFACE
/*
#define COLLECT_WORLD
*/
mps_arena_t arena1, arena2;
mps_pool_t poolamc1, poolamc2;
mps_thr_t thread1, thread2;
mps_root_t root1, root1a, root2, root2a;
mps_fmt_t format1, format2;
mps_ap_t apamc1, apamc2;
static mps_addr_t objtab1[TABSIZE], objtab2[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);
objtab1[i] = allocdumb(apamc1, BACKSIZE*2, mps_rank_exact());
i = ranint(ranint(ranint(ranint(TABSIZE)+1)+1)+1);
objtab2[i] = allocdumb(apamc2, BACKSIZE, mps_rank_exact());
}
}
static void test(void *stack_pointer)
{
long int i;
long int rsize = 0;
int inramp;
mycell *r1 = NULL, *r2 = NULL, *s1, *s2;
cdie(mps_arena_create(&arena1, mps_arena_class_vm(),
(size_t) 1024*1024*ARENALIMIT), "create arena");
cdie(mps_arena_create(&arena2, mps_arena_class_vm(),
(size_t) 1024*1024*ARENALIMIT), "create arena");
cdie(mps_thread_reg(&thread1, arena1), "register thread");
cdie(mps_thread_reg(&thread2, arena2), "register thread");
cdie(mps_root_create_thread(&root1, arena1, thread1, stack_pointer), "thread root"); cdie(mps_root_create_thread(&root2, arena2, thread2, stack_pointer), "thread root");
cdie(
mps_root_create_table(&root1a, arena1, mps_rank_exact(), 0, &objtab1[0], TABSIZE),
"create root table");
cdie(
mps_root_create_table(&root2a, arena2, mps_rank_exact(), 0, &objtab2[0], TABSIZE),
"create root table");
cdie(
mps_fmt_create_A(&format1, arena1, &fmtA),
"create format");
cdie(
mps_fmt_create_A(&format2, arena2, &fmtA),
"create format");
MPS_ARGS_BEGIN(args) {
MPS_ARGS_ADD(args, MPS_KEY_FORMAT, format1);
cdie(mps_pool_create_k(&poolamc1, arena1, mps_class_amc(), args),
"create pool");
} MPS_ARGS_END(args);
MPS_ARGS_BEGIN(args) {
MPS_ARGS_ADD(args, MPS_KEY_FORMAT, format2);
cdie(mps_pool_create_k(&poolamc2, arena2, mps_class_amc(), args),
"create pool");
} MPS_ARGS_END(args);
cdie(
mps_ap_create(&apamc1, poolamc1, mps_rank_exact()),
"create ap");
cdie(
mps_ap_create(&apamc2, poolamc2, 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) {
s1 = allocone(apamc1, 3, mps_rank_exact());
s2 = allocone(apamc2, 3, mps_rank_exact());
setref(r1, 0, s1);
setref(r2, 0, s2);
setref(s1, 1, r1);
setref(s2, 1, r2);
r1 = s1;
r2 = s2;
s1 = allocdumb(apamc1, RAMPSIZE, mps_rank_exact());
s2 = allocdumb(apamc2, RAMPSIZE, mps_rank_exact());
setref(r1, 2, s1);
setref(r2, 2, s2);
rsize ++;
if (ranint(LEAVERAMP) == 0) {
r1 = allocone(apamc1, 2, mps_rank_exact());
r2 = allocone(apamc2, 2, mps_rank_exact());
s1 = allocone(apamc1, 2, mps_rank_exact());
s2 = allocone(apamc2, 2, mps_rank_exact());
#ifdef RAMP_INTERFACE
mps_ap_alloc_pattern_end(apamc1, mps_alloc_pattern_ramp());
mps_ap_alloc_pattern_end(apamc2, mps_alloc_pattern_ramp());
#endif
#ifdef COLLECT_WORLD
mps_arena_collect(arena1);
mps_arena_collect(arena2);
mps_arena_release(arena1);
mps_arena_release(arena2);
#endif
comment("ramp end, %ld objects", rsize);
inramp = 0;
}
} else {
if (ranint(ENTERRAMP) == 0) {
#ifdef RAMP_INTERFACE
mps_ap_alloc_pattern_begin(apamc1, mps_alloc_pattern_ramp());
mps_ap_alloc_pattern_begin(apamc2, mps_alloc_pattern_ramp());
#endif
comment("ramp begin");
r1 = allocone(apamc1, 3, mps_rank_exact());
r2 = allocone(apamc2, 3, mps_rank_exact());
inramp = 1;
rsize = 0;
}
}
}
mps_arena_park(arena1);
mps_arena_park(arena2);
mps_ap_destroy(apamc1);
mps_ap_destroy(apamc2);
comment("Destroyed ap.");
mps_pool_destroy(poolamc1);
mps_pool_destroy(poolamc2);
comment("Destroyed pool.");
mps_fmt_destroy(format1);
mps_fmt_destroy(format2);
comment("Destroyed format.");
mps_root_destroy(root1);
mps_root_destroy(root1a);
mps_root_destroy(root2);
mps_root_destroy(root2a);
comment("Destroyed roots.");
mps_thread_dereg(thread1);
mps_thread_dereg(thread2);
comment("Deregistered thread.");
mps_arena_destroy(arena1);
mps_arena_destroy(arena2);
comment("Destroyed arena.");
}
int main(void)
{
run_test(test);
report("result", "pass");
return 0;
}
|