static void test(void) { mps_thr_t thread; mps_pool_t pool; mps_addr_t a, b; char *c; cdie(mps_arena_create(&arena, mps_arena_class_vmnz(), (size_t) (1024*1024*50)), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); die( mps_pool_create(&pool, arena, mps_class_mvff_debug(), &debugOpts, 8192, 8, 8, 0, 0, 1), "create MVFF pool"); die(mps_alloc(&a, pool, 64), "alloc a"); die(mps_alloc(&b, pool, 64), "alloc b"); c = a; c -= 1; *c = 0; mps_pool_check_fenceposts(pool); comment("Fencepost check."); c += 67; *c = 0; mps_pool_check_fenceposts(pool); comment("Fencepost check."); mps_pool_destroy(pool); mps_thread_dereg(thread); mps_arena_destroy(arena); }
static void test(void *stack_pointer) { mps_thr_t thread; mps_pool_t pool; mps_addr_t a; char *c; cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*50)), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_POOL_DEBUG_OPTIONS, &debugOpts); die(mps_pool_create_k(&pool, arena, mps_class_mvff_debug(), args), "create MVFF pool"); } MPS_ARGS_END(args); die(mps_alloc(&a, pool, 64), "alloc a"); c = a; c -= 1; *c = 0; mps_pool_check_fenceposts(pool); comment("Fencepost check."); c += 67; *c = 0; mps_pool_check_fenceposts(pool); comment("Fencepost check."); mps_pool_destroy(pool); mps_thread_dereg(thread); mps_arena_destroy(arena); }
static mps_res_t stress(mps_arena_t arena, mps_pool_debug_option_s *options, size_t (*size)(size_t i), mps_align_t align, const char *name, mps_pool_class_t pool_class, mps_arg_s *args) { mps_res_t res; mps_pool_t pool; size_t i, k; int *ps[testSetSIZE]; size_t ss[testSetSIZE]; size_t allocated = 0; /* Total allocated memory */ size_t debugOverhead = options ? 2 * alignUp(options->fence_size, align) : 0; printf("Pool class %s, alignment %u\n", name, (unsigned)align); res = mps_pool_create_k(&pool, arena, pool_class, args); if (res != MPS_RES_OK) return res; /* allocate a load of objects */ for (i=0; i<testSetSIZE; ++i) { mps_addr_t obj; ss[i] = (*size)(i); res = mps_alloc(&obj, pool, ss[i]); if (res != MPS_RES_OK) return res; ps[i] = obj; allocated += alignUp(ss[i], align) + debugOverhead; if (ss[i] >= sizeof(ps[i])) *ps[i] = 1; /* Write something, so it gets swap. */ check_allocated_size(pool, allocated); } mps_pool_check_fenceposts(pool); for (k=0; k<testLOOPS; ++k) { /* shuffle all the objects */ for (i=0; i<testSetSIZE; ++i) { size_t j = rnd()%(testSetSIZE-i); void *tp; size_t ts; tp = ps[j]; ts = ss[j]; ps[j] = ps[i]; ss[j] = ss[i]; ps[i] = tp; ss[i] = ts; } /* free half of the objects */ /* upper half, as when allocating them again we want smaller objects */ /* see randomSize() */ for (i=testSetSIZE/2; i<testSetSIZE; ++i) { mps_free(pool, (mps_addr_t)ps[i], ss[i]); /* if (i == testSetSIZE/2) */ /* PoolDescribe((Pool)pool, mps_lib_stdout); */ Insist(alignUp(ss[i], align) + debugOverhead <= allocated); allocated -= alignUp(ss[i], align) + debugOverhead; } /* allocate some new objects */ for (i=testSetSIZE/2; i<testSetSIZE; ++i) { mps_addr_t obj; ss[i] = (*size)(i); res = mps_alloc(&obj, pool, ss[i]); if (res != MPS_RES_OK) return res; ps[i] = obj; allocated += alignUp(ss[i], align) + debugOverhead; } check_allocated_size(pool, allocated); } die(PoolDescribe(pool, mps_lib_get_stdout(), 0), "PoolDescribe"); mps_pool_destroy(pool); return MPS_RES_OK; }