static void stepper(mps_addr_t object, mps_fmt_t format, mps_pool_t pool, void *p, size_t s) { struct stepper_data *sd; mps_arena_t arena; mps_bool_t b; mps_pool_t query_pool; mps_fmt_t query_fmt; Insist(s == sizeof *sd); sd = p; arena = sd->arena; Insist(mps_arena_has_addr(arena, object)); b = mps_addr_pool(&query_pool, arena, object); Insist(b); Insist(query_pool == pool); Insist(pool == sd->expect_pool); b = mps_addr_fmt(&query_fmt, arena, object); Insist(b); Insist(query_fmt == format); Insist(format == sd->expect_fmt); sd->count += 1; return; }
static void stepper(mps_addr_t object, mps_fmt_t format, mps_pool_t pool, void *p, size_t s) { struct stepper_data *sd; mps_arena_t arena; mps_bool_t b; mps_pool_t query_pool; mps_fmt_t query_fmt; size_t size; Insist(s == sizeof *sd); sd = p; arena = sd->arena; Insist(mps_arena_has_addr(arena, object)); b = mps_addr_pool(&query_pool, arena, object); Insist(b); Insist(query_pool == pool); Insist(pool == sd->expect_pool); b = mps_addr_fmt(&query_fmt, arena, object); Insist(b); Insist(query_fmt == format); Insist(format == sd->expect_fmt); size = AddrOffset(object, dylan_skip(object)); if (dylan_ispad(object)) { sd->padSize += size; } else { ++ sd->count; sd->objSize += size; } }
static void test(mps_arena_t arena, mps_class_t pool_class, size_t roots_count) { mps_fmt_t format; mps_chain_t chain; mps_root_t exactRoot, ambigRoot; unsigned long objs; size_t i; mps_word_t collections, rampSwitch; mps_alloc_pattern_t ramp = mps_alloc_pattern_ramp(); int ramping; mps_ap_t busy_ap; mps_addr_t busy_init; mps_pool_t pool; int described = 0; die(dylan_fmt(&format, arena), "fmt_create"); die(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mps_pool_create(&pool, arena, pool_class, format, chain), "pool_create(amc)"); die(mps_ap_create(&ap, pool, mps_rank_exact()), "BufferCreate"); die(mps_ap_create(&busy_ap, pool, mps_rank_exact()), "BufferCreate 2"); for(i = 0; i < exactRootsCOUNT; ++i) exactRoots[i] = objNULL; for(i = 0; i < ambigRootsCOUNT; ++i) ambigRoots[i] = rnd_addr(); 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)"); die(mps_root_create_table(&ambigRoot, arena, mps_rank_ambig(), (mps_rm_t)0, &ambigRoots[0], ambigRootsCOUNT), "root_create_table(ambig)"); /* create an ap, and leave it busy */ die(mps_reserve(&busy_init, busy_ap, 64), "mps_reserve busy"); collections = 0; rampSwitch = rampSIZE; die(mps_ap_alloc_pattern_begin(ap, ramp), "pattern begin (ap)"); die(mps_ap_alloc_pattern_begin(busy_ap, ramp), "pattern begin (busy_ap)"); ramping = 1; objs = 0; while (collections < collectionsCOUNT) { mps_word_t c; size_t r; c = mps_collections(arena); if (collections != c) { if (!described) { die(ArenaDescribe(arena, mps_lib_get_stdout(), 0), "ArenaDescribe"); described = TRUE; } collections = c; report(arena); printf("%lu objects (mps_collections says: %"PRIuLONGEST")\n", objs, (ulongest_t)c); /* test mps_arena_has_addr */ { size_t hitRatio; unsigned hitsWanted = 4; /* aim for 4 hits (on average) */ /* [Note: The for-loop condition used to be "i < 4 * hitRatio", * with "4" an unexplained naked constant. I have now labelled * it "hitsWanted", as I think that is the intent. RHSK] */ /* how many random addrs must we try, to hit the arena once? */ hitRatio = (0xfffffffful / mps_arena_committed(arena)); for (i = 0; i < hitsWanted * hitRatio ; i++) { /* An exact root maybe in the arena, so add a random 32-bit * offset to it. We may get no hits if it is objNULL. */ mps_addr_t p = (char *)exactRoots[rnd() % exactRootsCOUNT] + rnd()-0x80000000ul; if (mps_arena_has_addr(arena, p)) { printf("%p is in the arena\n", p); } } } for (i = 0; i < exactRootsCOUNT; ++i) cdie(exactRoots[i] == objNULL || (dylan_check(exactRoots[i]) && mps_arena_has_addr(arena, exactRoots[i])), "all roots check"); cdie(!mps_arena_has_addr(arena, NULL), "NULL in arena"); if (collections == collectionsCOUNT / 2) { unsigned long object_count = 0; mps_arena_park(arena); mps_arena_formatted_objects_walk(arena, test_stepper, &object_count, 0); mps_arena_release(arena); printf("stepped on %lu objects.\n", object_count); } if (collections == rampSwitch) { int begin_ramp = !ramping || /* Every other time, switch back immediately. */ (collections & 1); rampSwitch += rampSIZE; if (ramping) { die(mps_ap_alloc_pattern_end(ap, ramp), "pattern end (ap)"); die(mps_ap_alloc_pattern_end(busy_ap, ramp), "pattern end (busy_ap)"); ramping = 0; /* kill half of the roots */ for(i = 0; i < exactRootsCOUNT; i += 2) { if (exactRoots[i] != objNULL) { cdie(dylan_check(exactRoots[i]), "ramp kill check"); exactRoots[i] = objNULL; } } } if (begin_ramp) { die(mps_ap_alloc_pattern_begin(ap, ramp), "pattern rebegin (ap)"); die(mps_ap_alloc_pattern_begin(busy_ap, ramp), "pattern rebegin (busy_ap)"); ramping = 1; } } } r = (size_t)rnd(); if (r & 1) { i = (r >> 1) % exactRootsCOUNT; if (exactRoots[i] != objNULL) cdie(dylan_check(exactRoots[i]), "dying root check"); exactRoots[i] = make(roots_count); if (exactRoots[(exactRootsCOUNT-1) - i] != objNULL) dylan_write(exactRoots[(exactRootsCOUNT-1) - i], exactRoots, exactRootsCOUNT); } else {
static void *test(void *arg, size_t s) { mps_arena_t arena; mps_fmt_t format; mps_chain_t chain; mps_root_t exactRoot, ambigRoot; unsigned long objs; size_t i; mps_word_t collections, rampSwitch; mps_alloc_pattern_t ramp = mps_alloc_pattern_ramp(); int ramping; mps_ap_t busy_ap; mps_addr_t busy_init; arena = (mps_arena_t)arg; (void)s; /* unused */ die(dylan_fmt(&format, arena), "fmt_create"); die(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mps_pool_create(&pool, arena, mps_class_amc(), format, chain), "pool_create(amc)"); die(mps_ap_create(&ap, pool, MPS_RANK_EXACT), "BufferCreate"); die(mps_ap_create(&busy_ap, pool, MPS_RANK_EXACT), "BufferCreate 2"); for(i = 0; i < exactRootsCOUNT; ++i) exactRoots[i] = objNULL; for(i = 0; i < ambigRootsCOUNT; ++i) ambigRoots[i] = rnd_addr(); 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)"); die(mps_root_create_table(&ambigRoot, arena, MPS_RANK_AMBIG, (mps_rm_t)0, &ambigRoots[0], ambigRootsCOUNT), "root_create_table(ambig)"); /* create an ap, and leave it busy */ die(mps_reserve(&busy_init, busy_ap, 64), "mps_reserve busy"); collections = 0; rampSwitch = rampSIZE; die(mps_ap_alloc_pattern_begin(ap, ramp), "pattern begin (ap)"); die(mps_ap_alloc_pattern_begin(busy_ap, ramp), "pattern begin (busy_ap)"); ramping = 1; objs = 0; while (collections < collectionsCOUNT) { unsigned long c; size_t r; size_t hitRatio; c = mps_collections(arena); if (collections != c) { collections = c; printf("\nCollection %lu started, %lu objects.\n", c, objs); /* test mps_arena_has_addr */ hitRatio = ((size_t)-1 / mps_arena_committed(arena)); /* That's roughly how often a random addr should hit the arena. */ for (i = 0; i < 4 * hitRatio ; i++) { mps_addr_t p = rnd_addr(); if (mps_arena_has_addr(arena, p)) { printf("%p is in the arena\n", p); } } report(arena); for (i = 0; i < exactRootsCOUNT; ++i) cdie(exactRoots[i] == objNULL || (dylan_check(exactRoots[i]) && mps_arena_has_addr(arena, exactRoots[i])), "all roots check"); cdie(!mps_arena_has_addr(arena, NULL), "NULL in arena"); if (collections == collectionsCOUNT / 2) { unsigned long object_count = 0; mps_arena_park(arena); mps_arena_formatted_objects_walk(arena, test_stepper, &object_count, 0); mps_arena_release(arena); printf("stepped on %lu objects.\n", object_count); } if (collections == rampSwitch) { int begin_ramp = !ramping || /* Every other time, switch back immediately. */ (collections & 1); rampSwitch += rampSIZE; if (ramping) { die(mps_ap_alloc_pattern_end(ap, ramp), "pattern end (ap)"); die(mps_ap_alloc_pattern_end(busy_ap, ramp), "pattern end (busy_ap)"); ramping = 0; /* kill half of the roots */ for(i = 0; i < exactRootsCOUNT; i += 2) { if (exactRoots[i] != objNULL) { cdie(dylan_check(exactRoots[i]), "ramp kill check"); exactRoots[i] = objNULL; } } } if (begin_ramp) { die(mps_ap_alloc_pattern_begin(ap, ramp), "pattern rebegin (ap)"); die(mps_ap_alloc_pattern_begin(busy_ap, ramp), "pattern rebegin (busy_ap)"); ramping = 1; } } } r = (size_t)rnd(); if (r & 1) { i = (r >> 1) % 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); } else {