static void check_allocated_size(mps_pool_t pool, mps_ap_t ap, size_t allocated) { size_t total_size = mps_pool_total_size(pool); size_t free_size = mps_pool_free_size(pool); size_t ap_free = (size_t)((char *)ap->limit - (char *)ap->init); Insist(total_size - free_size == allocated + ap_free); }
static void check_allocated_size(mps_pool_t pool, size_t allocated) { size_t total_size = mps_pool_total_size(pool); size_t free_size = mps_pool_free_size(pool); Insist(total_size - free_size == allocated); }
static void test(mps_arena_t arena, mps_pool_class_t pool_class) { mps_chain_t chain; mps_fmt_t format; mps_pool_t pool; mps_root_t exactRoot; size_t i; size_t totalSize, freeSize, allocSize, bufferSize; unsigned long objs; struct stepper_data sdStruct, *sd; PoolClass class; die(dylan_fmt(&format, arena), "fmt_create"); die(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_FORMAT, format); MPS_ARGS_ADD(args, MPS_KEY_CHAIN, chain); die(mps_pool_create_k(&pool, arena, pool_class, args), "pool_create"); } MPS_ARGS_END(args); die(mps_ap_create(&ap, pool, mps_rank_exact()), "ap_create"); for(i = 0; i < exactRootsCOUNT; ++i) exactRoots[i] = objNULL; die(mps_root_create_table_masked(&exactRoot, arena, mps_rank_exact(), (mps_rm_t)0, &exactRoots[0], exactRootsCOUNT, (mps_word_t)1), "root_create_table(exact)"); objs = 0; while(objs < objCOUNT) { size_t r; r = objs; i = r % exactRootsCOUNT; if(exactRoots[i] != objNULL) { cdie(dylan_check(exactRoots[i]), "dying root check"); } exactRoots[i] = make(); if(exactRoots[(exactRootsCOUNT-1) - i] != objNULL) dylan_write(exactRoots[(exactRootsCOUNT-1) - i], exactRoots, exactRootsCOUNT); ++objs; } mps_arena_park(arena); sd = &sdStruct; sd->arena = arena; sd->expect_pool = pool; sd->expect_fmt = format; sd->count = 0; sd->objSize = 0; sd->padSize = 0; mps_arena_formatted_objects_walk(arena, stepper, sd, sizeof *sd); Insist(sd->count == objs); totalSize = mps_pool_total_size(pool); freeSize = mps_pool_free_size(pool); allocSize = totalSize - freeSize; bufferSize = AddrOffset(ap->init, ap->limit); class = ClassOfPoly(Pool, pool); printf("%s: obj=%lu pad=%lu total=%lu free=%lu alloc=%lu buffer=%lu\n", ClassName(class), (unsigned long)sd->objSize, (unsigned long)sd->padSize, (unsigned long)totalSize, (unsigned long)freeSize, (unsigned long)allocSize, (unsigned long)bufferSize); Insist(sd->objSize + sd->padSize + bufferSize == allocSize); mps_ap_destroy(ap); mps_root_destroy(exactRoot); mps_pool_destroy(pool); mps_chain_destroy(chain); mps_fmt_destroy(format); mps_arena_release(arena); }