static void testInArena(mps_arena_class_t arena_class, mps_arg_s *arena_args, mps_pool_debug_option_s *options) { mps_arena_t arena; die(mps_arena_create_k(&arena, arena_class, arena_args), "mps_arena_create"); MPS_ARGS_BEGIN(args) { mps_align_t align = sizeof(void *) << (rnd() % 4); MPS_ARGS_ADD(args, MPS_KEY_ALIGN, align); MPS_ARGS_ADD(args, MPS_KEY_MVFF_ARENA_HIGH, TRUE); MPS_ARGS_ADD(args, MPS_KEY_MVFF_SLOT_HIGH, TRUE); MPS_ARGS_ADD(args, MPS_KEY_MVFF_FIRST_FIT, TRUE); MPS_ARGS_ADD(args, MPS_KEY_SPARE, rnd_double()); die(stress(arena, NULL, randomSize8, align, "MVFF", mps_class_mvff(), args), "stress MVFF"); } MPS_ARGS_END(args); MPS_ARGS_BEGIN(args) { mps_align_t align = sizeof(void *) << (rnd() % 4); MPS_ARGS_ADD(args, MPS_KEY_ALIGN, align); MPS_ARGS_ADD(args, MPS_KEY_MVFF_ARENA_HIGH, TRUE); MPS_ARGS_ADD(args, MPS_KEY_MVFF_SLOT_HIGH, TRUE); MPS_ARGS_ADD(args, MPS_KEY_MVFF_FIRST_FIT, TRUE); MPS_ARGS_ADD(args, MPS_KEY_SPARE, rnd_double()); MPS_ARGS_ADD(args, MPS_KEY_POOL_DEBUG_OPTIONS, options); die(stress(arena, options, randomSize8, align, "MVFF debug", mps_class_mvff_debug(), args), "stress MVFF debug"); } MPS_ARGS_END(args); MPS_ARGS_BEGIN(args) { mps_align_t align = (mps_align_t)1 << (rnd() % 6); MPS_ARGS_ADD(args, MPS_KEY_ALIGN, align); die(stress(arena, NULL, randomSize, align, "MV", mps_class_mv(), args), "stress MV"); } MPS_ARGS_END(args); MPS_ARGS_BEGIN(args) { mps_align_t align = (mps_align_t)1 << (rnd() % 6); MPS_ARGS_ADD(args, MPS_KEY_ALIGN, align); MPS_ARGS_ADD(args, MPS_KEY_POOL_DEBUG_OPTIONS, options); die(stress(arena, options, randomSize, align, "MV debug", mps_class_mv_debug(), args), "stress MV debug"); } MPS_ARGS_END(args); MPS_ARGS_BEGIN(args) { fixedSizeSize = 1 + rnd() % 64; MPS_ARGS_ADD(args, MPS_KEY_MFS_UNIT_SIZE, fixedSizeSize); MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, 100000); die(stress(arena, NULL, fixedSize, MPS_PF_ALIGN, "MFS", mps_class_mfs(), args), "stress MFS"); } MPS_ARGS_END(args); /* Manual allocation should not cause any garbage collections. */ Insist(mps_collections(arena) == 0); mps_arena_destroy(arena); }
static double expdev(void) { double dum; do dum=rnd_double(); while (dum == 0.0); return (float)-log(dum); }
/* new_tree - Make a new tree from an old tree. * The new tree is the same depth as the old tree and * reuses old nodes with probability preuse. * NOTE: If a new node is reused multiple times, the total size * will be smaller. * NOTE: Changing preuse will dramatically change how much work * is done. In particular, if preuse==1, the old tree is returned * unchanged. */ static obj_t new_tree(mps_ap_t ap, obj_t oldtree, unsigned d) { obj_t subtree; size_t i; if (rnd_double() < preuse) { subtree = random_subtree(oldtree, depth - d); } else { if (d == 0) return objNULL; subtree = mkvector(ap, width); for (i = 0; i < width; ++i) { aset(subtree, i, new_tree(ap, oldtree, d - 1)); } } return subtree; }
// Select and flip a cell according to Metropolis void metropolis(void) { long n, e; double p; n = rnd_cell(); e = cell_energy(n); if (e < 0) // a flip will raise the energy of the system { p = exp(beta * e * 2.0); if (rnd_double() < p) { flip(n); } } else flip(n); }
/* Update tree to be identical tree but with nodes reallocated * with probability pupdate. This avoids writing to vector slots * if unecessary. */ static obj_t update_tree(mps_ap_t ap, obj_t oldtree, unsigned d) { obj_t tree; size_t i; if (oldtree == objNULL || d == 0) return oldtree; if (rnd_double() < pupdate) { tree = mkvector(ap, width); for (i = 0; i < width; ++i) { aset(tree, i, update_tree(ap, aref(oldtree, i), d - 1)); } } else { tree = oldtree; for (i = 0; i < width; ++i) { obj_t oldsubtree = aref(oldtree, i); obj_t subtree = update_tree(ap, oldsubtree, d - 1); if (subtree != oldsubtree) { aset(tree, i, subtree); } } } return tree; }
unsigned long rnd_long(long n) // Return a random integer 0 <= x < n { return (unsigned long) (rnd_double() * (double) n); }