static void test(void) { mps_pool_t poolmv, poolawl, poolamc; mps_thr_t thread; mps_root_t root0, root1, root2; mps_addr_t p; mps_chain_t chain; mps_fmt_t format; mps_ap_t apawl, apamc; mps_addr_t base; mps_addr_t *addr; int i,j,merge,stale,prevstale; mycell *held[AMBIGHOLD]; RC; cdie(mps_arena_create(&arena, mps_arena_class_vm(), 100*1024*1024), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); base = &exfmt_root; addr = base; cdie( mps_root_create_table(&root0, arena, mps_rank_ambig(), 0, addr, 1), "create exfmt root"); cdie( mps_root_create_table(&root2, arena, mps_rank_exact(), 0, (mps_addr_t *)obj_table, MAXLDS), "create table root"); cdie( mps_root_create_reg(&root1, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create register and stack root"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie( mps_pool_create(&poolawl, arena, mps_class_awl(), format, getassociated), "create awl pool"); cdie( mps_pool_create(&poolmv, arena, mps_class_mv(), 0x4000, 128, 0x4000), "create mv pool"); cdie( mps_ap_create(&apawl, poolawl, mps_rank_exact()), "create ap"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie( mps_pool_create(&poolamc, arena, mps_class_amc(), format, chain), "create amc pool"); cdie( mps_ap_create(&apamc, poolamc, mps_rank_exact()), "create ap"); /* allocate MAXLDS objects, and make each LD depend on the corresponding object */ for (i=0; i < MAXLDS; i++) { mps_alloc(&p, poolmv, sizeof(mps_ld_s)); lds[i] = (mps_ld_t) p; mps_alloc(&p, poolmv, sizeof(mps_ld_s)); ldm[i] = (mps_ld_t) p; } for (i=0; i < MAXLDS; i++) { obj_table[i] = allocone(apamc, ranint(1000), mps_rank_exact()); mps_ld_reset(lds[i], arena); mps_ld_add(lds[i], arena, (mps_addr_t) obj_table[i]); addr_table[i] = obj_table[i]; } for (merge = 1; merge <= MAXMERGE; merge++) { comment("Merge %d", merge); for (i=0; i < MAXLDS; i++) { if (ranint(100) < BLATPERCENT) { obj_table[i] = allocone(apamc, ranint(1000), mps_rank_exact()); mps_ld_reset(lds[i], arena); mps_ld_add(lds[i], arena, (mps_addr_t) obj_table[i]); addr_table[i] = obj_table[i]; } } mergelds(merge); stale = 0; prevstale = 0; i = 0; while (stale < MAXLDS) { for (j = 0; j < AMBIGHOLD; j++) { held[j] = obj_table[ranint(MAXLDS)]; } i++; stale = checklds(merge); if (stale > prevstale) { prevstale = stale; comment("inc to %d at %d", stale, i); } for (j = 0; j < JUNK; j++) { (void)allocdumb(apamc, ranint(1000), mps_rank_exact()); } } } comment("held[0] = %p", held[0]); /* avoid warning about unused variable */ mps_arena_park(arena); mps_ap_destroy(apawl); mps_ap_destroy(apamc); comment("Destroyed aps."); mps_pool_destroy(poolmv); mps_pool_destroy(poolamc); mps_pool_destroy(poolawl); comment("Destroyed pools."); mps_fmt_destroy(format); comment("Destroyed format."); mps_chain_destroy(chain); comment("Destroyed chain."); mps_root_destroy(root0); mps_root_destroy(root1); mps_root_destroy(root2); comment("Destroyed roots."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mps_arena_t arena; mps_pool_t pool; mps_thr_t thread; mps_root_t root; mps_chain_t chain; mps_fmt_t format; mps_ap_t ap; mycell *a,*b,*c; size_t inpsize; int i; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie( mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie( mps_pool_create(&pool, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_ap_create(&ap, pool, mps_rank_exact()), "create ap"); scanf("%lx", &inpsize); a = allocone(ap, 0, NULL, NULL, inpsize); comment("%x\n", (int) a); b = a; for (i=1; i<100; i++) { c = allocone(ap, i, NULL, NULL, inpsize); b->ref[0] = c; b = c; comment("%d: %lx\n", i, (mps_word_t) b); /* getchar(); */ } b = a; while (b != c) { comment("%ld: %x\n", b->data, (int) b); b = b->ref[0]; } mps_arena_park(arena); mps_ap_destroy(ap); comment("Destroyed ap."); mps_pool_destroy(pool); comment("Destroyed pool."); mps_fmt_destroy(format); comment("Destroyed format."); mps_chain_destroy(chain); comment("Destroyed chain."); mps_root_destroy(root); comment("Destroyed root."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void dt(int kind, size_t extendBy, size_t avgSize, size_t maxSize, size_t mins, size_t maxs, int number, int iter) { mps_pool_t pool; int i, hd; clock_t time0, time1; size_t size; int secs; asserts(number <= MAXNUMBER, "number too big"); time0 = clock(); asserts(time0 != -1, "processor time not available"); die( mps_pool_create(&pool, arena, mps_class_mv(), extendBy, avgSize, maxSize), "create pool"); for(hd=0; hd<number; hd++) { size = ranrange(mins, maxs); if ((ranint(2) && (kind & 2)) || (kind==DUMMY)) { queue[hd].addr=NULL; } else { die(mps_alloc(&queue[hd].addr, pool, size), "alloc"); setobj(queue[hd].addr, size, hd%256); queue[hd].size = size; } }; hd=-1; for(i=0; i<iter; i++) { if (kind & 1) hd = ranint(number); else {ranint(number); hd=(hd+1)%number;} /* call raninit anyway to use same time */ if (queue[hd].addr != NULL) { asserts(chkobj(queue[hd].addr, queue[hd].size, hd%256), "corrupt at %x (%s: %x, %x, %x, %x, %x, %i, %i)", queue[hd].addr, tdesc[kind], (int) extendBy, (int) avgSize, (int) maxSize, (int) mins, (int) maxs, number, iter); mps_free(pool, queue[hd].addr, queue[hd].size); } size = ranrange(mins, maxs); if ((ranint(2) && (kind & 2)) || (kind==DUMMY)) { queue[hd].addr=NULL; } else { die(mps_alloc(&queue[hd].addr, pool, size),"alloc"); setobj(queue[hd].addr, size, hd%256); queue[hd].size = size; } } mps_pool_destroy(pool); time1=clock(); secs=(int) 100*(time1-time0)/CLOCKS_PER_SEC; comment("%s test (%x, %x, %x, %x, %x, %i, %i) in %i centisecs", tdesc[kind], (int) extendBy, (int) avgSize, (int) maxSize, (int) mins, (int) maxs, number, iter, secs); }
static void test(void) { long int i; long int rsize; mps_message_t message; int inramp; mycell *r, *s; cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) 1024*1024*ARENALIMIT), "create space"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie( mps_root_create_reg(&root, arena, MPS_RANK_AMBIG, 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); cdie( mps_root_create_table(&root1, arena, MPS_RANK_EXACT, 0, &objtab[0], TABSIZE), "create root table"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie( mps_pool_create(&poolamc, arena, mps_class_amc(), format), "create pool"); cdie( mps_ap_create(&apamc, poolamc, MPS_RANK_EXACT), "create ap"); mps_message_type_enable(arena, mps_message_type_gc()); inramp = 0; for (i = 0; i < ITERATIONS; i++) { if (i % 10000 == 0) { comment("%ld of %ld", i, ITERATIONS); } alloc_back(); if (inramp) { s = allocone(apamc, 3, MPS_RANK_EXACT); setref(r, 0, s); setref(s, 1, r); r = s; s = allocdumb(apamc, RAMPSIZE, MPS_RANK_EXACT); setref(r, 2, s); rsize ++; if (ranint(LEAVERAMP) == 0) { r = allocone(apamc, 2, MPS_RANK_EXACT); s = allocone(apamc, 2, MPS_RANK_EXACT); #ifdef RAMP_INTERFACE mps_ap_alloc_pattern_end(apamc, mps_alloc_pattern_ramp()); #endif #ifdef COLLECT_WORLD mps_arena_collect(arena); mps_arena_release(arena); #endif comment("ramp end, %ld objects", rsize); inramp = 0; } } else { if (ranint(ENTERRAMP) == 0) { #ifdef RAMP_INTERFACE mps_ap_alloc_pattern_begin(apamc, mps_alloc_pattern_ramp()); #endif comment("ramp begin"); r = allocone(apamc, 3, MPS_RANK_EXACT); inramp = 1; rsize = 0; } } if(mps_message_get(&message, arena, mps_message_type_gc())) { unsigned long live, condemned, notCondemned; live = mps_message_gc_live_size(arena, message); condemned = mps_message_gc_condemned_size(arena, message); notCondemned = mps_message_gc_not_condemned_size(arena, message); comment("Collection: live=%ld, condemned=%ld, not condemned = %ld", live, condemned, notCondemned); mps_message_discard(arena, message); } } mps_ap_destroy(apamc); comment("Destroyed ap."); mps_pool_destroy(poolamc); comment("Destroyed pool."); mps_fmt_destroy(format); comment("Destroyed format."); mps_root_destroy(root1); mps_root_destroy(root); comment("Destroyed roots."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed space."); }
static void test(void) { mps_space_t space; mps_pool_t pool; mps_thr_t thread; mps_root_t root; mps_fmt_t format; mps_ap_t ap; mycell *a, *b; cdie(mps_space_create(&space), "create space"); cdie(mps_thread_reg(&thread, space), "register thread"); cdie( mps_root_create_reg(&root, space, MPS_RANK_AMBIG, 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); cdie( mps_fmt_create_A(&format, space, &fmtA), "create format"); cdie( mps_pool_create(&pool, space, mps_class_amc(), format), "create pool"); cdie( mps_ap_create(&ap, pool, MPS_RANK_EXACT), "create ap"); a = allocone(ap, 1024, 1); z = a; b = allocone(ap, 1024, 1); setref(b, 0, a); a = allocdumb(ap, 1024*64, 1); a = allocdumb(ap, 1024*64, 1); comment("Collecting..."); mps_arena_collect(space); asserts(z != a, "Didn't move!"); comment("Writing bad pointer..."); b->data.ref[0].addr = z; mps_arena_collect(space); comment("Bad pointer not spotted in collection"); fail(); mps_ap_destroy(ap); comment("Destroyed ap."); mps_pool_destroy(pool); comment("Destroyed pool."); mps_fmt_destroy(format); comment("Destroyed format."); mps_root_destroy(root); comment("Destroyed root."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_space_destroy(space); comment("Destroyed space."); }
static void test(void) { mps_pool_t poolamc, poolawl, poolamcz; mps_thr_t thread; mps_root_t root0, root1; mps_fmt_t format; mps_chain_t chain; mps_ap_t apamc, apawl, apamcz; mycell *a, *b, *c, *d, *z; long int j; cdie(mps_arena_create_k(&arena, mps_arena_class_vm(), mps_args_none), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie(mps_root_create_reg(&root0, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); cdie(mps_root_create_table(&root1, arena, mps_rank_ambig(), 0, (mps_addr_t*)&exfmt_root, 1), "create table root"); cdie(mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie(mmqa_pool_create_chain(&poolamc, arena, mps_class_amc(), format, chain), "create pool(amc)"); cdie(mps_pool_create(&poolawl, arena, mps_class_awl(), format, getassociated), "create pool(awl)"); cdie(mmqa_pool_create_chain(&poolamcz, arena, mps_class_amcz(), format, chain), "create pool(amcz)"); cdie(mps_ap_create(&apawl, poolawl, mps_rank_weak()), "create ap(awl)"); cdie(mps_ap_create(&apamc, poolamc, mps_rank_exact()), "create ap(amc)"); cdie(mps_ap_create(&apamcz, poolamcz, mps_rank_exact()), "create ap(amcz)"); mps_message_type_enable(arena, mps_message_type_finalization()); /* register loads of objects for finalization (1000*4) */ a = allocone(apamc, 2, 1); b = a; for (j=0; j<1000; j++) { a = allocone(apamc, 2, mps_rank_exact()); c = allocone(apawl, 2, mps_rank_weak()); d = allocone(apamcz, 2, mps_rank_exact()); /* rank irrelevant here! */ mps_finalize(arena, (mps_addr_t*)&a); mps_finalize(arena, (mps_addr_t*)&c); mps_finalize(arena, (mps_addr_t*)&d); mps_finalize(arena, (mps_addr_t*)&d); final_count += 4; setref(a, 0, b); setref(a, 1, c); setref(c, 1, d); b = a; } /* throw them all away and collect everything */ a = NULL; b = NULL; c = NULL; d = NULL; mps_arena_collect(arena); while (mps_message_poll(arena)) { finalpoll(&z, FINAL_DISCARD); } /* How many are left? (Ideally, this would be 0 but there's no guarantee.) */ report("count1", "%i", final_count); /* now to test leaving messages open for a long time! */ for (j=0; j<1000; j++) { comment("%d of 1000", j+1); a = allocone(apamc, 10000, mps_rank_exact()); mps_finalize(arena, (mps_addr_t*)&a); final_count +=1; comment("finalize"); finalpoll(&z, FINAL_QUEUE); } comment("reregister"); for (j=0; j<500; j++) { comment("%d of 500", j+1); qpoll(&z, FINAL_REREGISTER); } b = a; z = a; for (j=0; j<1000; j++) { comment("%d of 1000", j+1); finalpoll(&z, FINAL_QUEUE); qpoll(&z, FINAL_STORE); a = allocone(apamc, 2, mps_rank_exact()); setref(z, 0, b); setref(a, 1, z); b = a; } for (j=0; j<1000; j++) { a = allocone(apamc, 2, mps_rank_exact()); qpoll(&z, FINAL_DISCARD); finalpoll(&z, FINAL_DISCARD); setref(a, 0, b); b = a; } /* Force old objects to be killed */ while (qmt() == 0) { qpoll(&z, FINAL_DISCARD); } mps_root_destroy(root0); mps_root_destroy(root1); comment("Destroyed roots."); mps_arena_collect(arena); comment("Collected arena."); while (mps_message_poll(arena)) { finalpoll(&z, FINAL_DISCARD); } report("count2", "%d", final_count); mps_arena_park(arena); mps_ap_destroy(apawl); mps_ap_destroy(apamc); mps_ap_destroy(apamcz); comment("Destroyed aps."); mps_pool_destroy(poolamc); mps_pool_destroy(poolawl); mps_pool_destroy(poolamcz); comment("Destroyed pools."); mps_chain_destroy(chain); mps_fmt_destroy(format); mps_thread_dereg(thread); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mycell *p, *q; int i; mps_res_t res; size_t lim7, avail7, commit7, lim8, avail8, commit8; size_t lim9, avail9, commit9; cdie(mps_arena_create(&arena, mps_arena_class_vm(), ARENA_SIZE), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie(mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create stack root"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie( mps_pool_create(&poolamc, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_ap_create(&apamc, poolamc, mps_rank_exact()), "create ap"); mps_arena_commit_limit_set(arena, mps_arena_committed(arena)+1024*1024); mps_reservoir_limit_set(arena, 0); report("lim7", "%d", lim7 = mps_reservoir_limit(arena)); report("avail7", "%d", avail7 = mps_reservoir_available(arena)); report("commit7", "%d", commit7 = mps_arena_committed(arena)); /* available should be zero, but should be able to allocate with reservoir permit, until commit_limit is reached */ i = -1; p = NULL; res = MPS_RES_OK; while (res == MPS_RES_OK) { res = reservoir_allocrone(&q, apamc, 10, mps_rank_exact()); if (res == MPS_RES_OK) { setref(q, 0, p); p = q; } i++; } report("allocfail3", "%d", i); report_res("failres3", res); /* should be none left to make available */ mps_reservoir_limit_set(arena, 10ul*1024*1024); report("lim8", "%d", lim8 = mps_reservoir_limit(arena)); report("avail8", "%d", avail8 = mps_reservoir_available(arena)); report("commit8", "%d", commit8 = mps_arena_committed(arena)); report("spill8", "%d", commit8-mps_arena_commit_limit(arena)); /* throw away objects and collect world */ p = NULL; q = NULL; mps_root_destroy(root); mps_arena_collect(arena); /* available should have gone up now */ report("lim9", "%d", lim9 = mps_reservoir_limit(arena)); report("avail9", "%d", avail9 = mps_reservoir_available(arena)); report("commit9", "%d", commit9 = mps_arena_committed(arena)); report("grow9", "%d", avail9-avail8); report("spill9", "%d", commit9-mps_arena_commit_limit(arena)); /* destroy everything remaining */ mps_ap_destroy(apamc); comment("Destroyed ap."); mps_pool_destroy(poolamc); comment("Destroyed pool."); mps_fmt_destroy(format); comment("Destroyed format."); mps_chain_destroy(chain); comment("Destroyed chain."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void t_alloc(int spare, int spare_total, int commit, int obj_size) { size_t size, hisize, comsize, comlimit; size_t spsize = 0, losize = 0; /* stop warnings */ mps_res_t res, res_expected; if (obj_size == OBJ_SMALL) size = SMALL_SIZE; else size = BIG_SIZE; switch (spare_total) { case SPARE_EMPTY: spsize = 0; break; case SPARE_LESS: if (size > DIFF_SIZE) { spsize = size-DIFF_SIZE; } else { spsize = 0; } break; case SPARE_EXACT: spsize = size; break; case SPARE_MORE: spsize = size+DIFF_SIZE; break; default: error("Illegal spare.\n"); break; } switch (spare) { case SPARE_EMPTY: losize = 0; break; case SPARE_LESS: if (size > DIFF_SIZE) { losize = size-DIFF_SIZE; } else { losize = 0; } break; case SPARE_EXACT: losize = size; break; case SPARE_MORE: losize = size+DIFF_SIZE; break; } if (losize > spsize) { losize = spsize; hisize = 0; } else { hisize = spsize-losize; } /* turn off commit limit for a moment */ mps_arena_commit_limit_set(arena, HUGE); /* create low and high pools */ MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, EXTEND); MPS_ARGS_ADD(args, MPS_KEY_MEAN_SIZE, AVGSIZE); MPS_ARGS_ADD(args, MPS_KEY_MVFF_ARENA_HIGH, 1); MPS_ARGS_ADD(args, MPS_KEY_MVFF_SLOT_HIGH, 1); MPS_ARGS_ADD(args, MPS_KEY_MVFF_FIRST_FIT, 0); MPS_ARGS_ADD(args, MPS_KEY_SPARE, 0.0); die(mps_pool_create_k(&poolhi, arena, mps_class_mvff(), args), "create high pool"); } MPS_ARGS_END(args); MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, EXTEND); MPS_ARGS_ADD(args, MPS_KEY_MEAN_SIZE, AVGSIZE); MPS_ARGS_ADD(args, MPS_KEY_MVFF_ARENA_HIGH, 0); MPS_ARGS_ADD(args, MPS_KEY_MVFF_SLOT_HIGH, 0); MPS_ARGS_ADD(args, MPS_KEY_MVFF_FIRST_FIT, 1); MPS_ARGS_ADD(args, MPS_KEY_SPARE, 0.0); die(mps_pool_create_k(&poollo, arena, mps_class_mvff(), args), "create low pool"); } MPS_ARGS_END(args); /* flush hysteresis fund, then set limit */ mps_arena_spare_set(arena, SPARE_ZERO); mps_arena_spare_set(arena, SPARE_LIMIT); /* allocate something in each pool (to reduce risk of subsidiary allocation being needed later) */ die(mps_alloc(&objlo, poollo, EXTEND), "low alloc"); mps_free(poollo, objlo, EXTEND); die(mps_alloc(&objhi, poolhi, EXTEND), "high alloc"); mps_free(poolhi, objhi, EXTEND); /* set up spare committed the way we want it */ if (losize>0) { die(mps_alloc(&objlo, poollo, losize), "low setup"); mps_free(poollo, objlo, losize); } if (hisize>0) { die(mps_alloc(&objhi, poolhi, hisize), "high setup"); mps_free(poolhi, objhi, hisize); } /* spare is now set up correctly */ /* now we need to set the commit limit correctly */ comsize = arena_committed_and_used(arena); /* allow for 1/16th memory overhead in setting commit limit */ if (commit == COMMIT_EXACT) { comlimit = comsize+size+(size/16); } else if (commit == COMMIT_NOCHANGE) { comlimit = mps_arena_committed(arena); } else if (commit == COMMIT_PLENTY) { comlimit = HUGE; } else /* commit == COMMIT_LITTLE */ { if (size > DIFF_SIZE) { comlimit = comsize+size+(size/16)+DIFF_SIZE; } else { comlimit = comsize+size+(size/16); } } die(mps_arena_commit_limit_set(arena, comlimit), "commit limit set"); res = mps_alloc(&objlo, poollo, size); asserts(comlimit >= comsize, "comlimit was less than comsize!"); if (size <= (comlimit-comsize)) { res_expected = MPS_RES_OK; } else { res_expected = MPS_RES_COMMIT_LIMIT; } if (res != res_expected) { comment("hisize=%lu losize=%lu\n" "comsize=%lu comlimit=%lu\n" "Expected %s. Got %s", (unsigned long)hisize, (unsigned long)losize, (unsigned long)comsize, (unsigned long)comlimit, err_text(res_expected), err_text(res)); report("failed", "yes"); } mps_pool_destroy(poollo); mps_pool_destroy(poolhi); }
static void test(void) { mps_ap_t ap, sap; mps_arena_t arena; mps_fmt_t format; mps_chain_t chain; mps_pool_t pool, spool; mps_thr_t thread; mps_frame_t frame1; mycell *p, *q; size_t com, com1; formatcomments=1; alloccomments=1; fixcomments=1; /* create an arena (no particular size limit) */ cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t)ARENA_SIZE), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); /* because we know objects in the stack pool don't move, we can do without roots. Hooray! */ cdie(mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mmqa_pool_create_chain(&pool, arena, mps_class_amc(), format, chain), "create AMC pool"); cdie(mps_ap_create(&ap, pool, mps_rank_exact()), "create ap"); cdie(mps_pool_create(&spool, arena, mps_class_snc(), format), "create SNC pool"); cdie(mps_ap_create(&sap, spool, mps_rank_exact()), "create ap"); /* push, alloc, check object is scanned */ com = mps_arena_committed(arena); report("com", "%ld", com); cdie(mps_ap_frame_push(&frame1, sap), "push"); p = allocone(sap, 2, mps_rank_exact()); q = allocdumb(ap, BIGSIZE, mps_rank_exact()); setref(p, 0, q); q = allocdumb(ap, SMALLSIZE, mps_rank_exact()); report("com", "%ld", mps_arena_committed(arena)); comment("collect..."); mps_arena_collect(arena); com1 = mps_arena_committed(arena); mps_arena_release(arena); report("com", "%ld", com1); report("inc1", "%d", (com1-com)/BIGSIZE); /* pop, check object isn't scanned */ cdie(mps_ap_frame_pop(sap, frame1), "pop"); p = allocone(sap, 2, mps_rank_exact()); comment("collect..."); mps_arena_collect(arena); com1 = mps_arena_committed(arena); mps_arena_release(arena); report("com", "%ld", com1); report("inc2", "%ld", (com1-com)/BIGSIZE); mps_arena_park(arena); mps_ap_destroy(ap); mps_ap_destroy(sap); comment("Destroyed ap."); mps_pool_destroy(pool); mps_pool_destroy(spool); comment("Destroyed pool."); mps_chain_destroy(chain); mps_fmt_destroy(format); mps_thread_dereg(thread); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mps_arena_t arena; mps_pool_t pool; mps_thr_t thread; mps_root_t root; mps_fmt_t format; mps_chain_t chain; mps_ap_t ap; mycell *a, *b, *c; mycell *p; mps_ld_t ld; int i, j; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie(mps_root_create_reg(&root, arena, MPS_RANK_AMBIG, 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); cdie(mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie(mmqa_pool_create_chain(&pool, arena, mps_class_amc(), format, chain), "create pool"); cdie(mps_ap_create(&ap, pool, MPS_RANK_EXACT), "create ap"); a = allocone(ap, 100); b = a; c = a; for (j = 1; j < 100; j++) { comment("%i of 100", j); p = allocdumb(ap, sizeof(mps_ld_s)); ld = (mps_ld_t) getdata(p); b = a; c = a; for (i = 1; i < 100; i++) { mps_ld_reset(ld, arena); UC; c = allocone(ap, 200); UC; setref(b, 0, c); UC; b = c; } } mps_ap_destroy(ap); mps_pool_destroy(pool); mps_chain_destroy(chain); mps_fmt_destroy(format); mps_root_destroy(root); mps_thread_dereg(thread); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mps_arena_t arena; mps_pool_t pool; mps_thr_t thread; mps_root_t root; mps_root_t root2; mps_fmt_t format; mps_chain_t chain; mps_ap_t ap; mycell *z[10]; mycell **a = &z[0]; mycell **b = &z[1]; mycell **c = &z[2]; mycell **d = &z[3]; mycell **e = &z[4]; mycell **f = &z[5]; mycell **g = &z[6]; int i; int j; RC; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); die(mps_thread_reg(&thread, arena), "register thread"); cdie( mps_root_create_table(&root, arena, MPS_RANK_AMBIG, 0, (mps_addr_t*)&z[0], 10), "create table root"); cdie( mps_root_create_table(&root2, arena, MPS_RANK_AMBIG, 0, &exfmt_root, 1), "create exfmt root"); die(mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mmqa_pool_create_chain(&pool, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_ap_create(&ap, pool, MPS_RANK_EXACT), "create ap"); for (j=1; j<10; j++) { comment("%i of 10.", j); UC; *a = allocone(ap, 5, 1); *b = *a; *c = *a; *d = *a; *e = *a; *f = *a; *g = *a; for (i=1; i<1000; i++) { UC; *c = allocone(ap, 1000, 1); if (ranint(8) == 0) *d = *c; if (ranint(8) == 0) *e = *c; if (ranint(8) == 0) *f = *c; if (ranint(8) == 0) *g = *c; UC; setref(*b, 0, *c); UC; setref(*c, 1, *d); UC; setref(*c, 2, *e); UC; setref(*c, 3, *f); UC; setref(*c, 4, *g); UC; *b = *c; } checkfrom(*a); } DC; DMC; checkfrom(*a); mps_ap_destroy(ap); mps_pool_destroy(pool); mps_chain_destroy(chain); mps_fmt_destroy(format); mps_root_destroy(root); mps_root_destroy(root2); mps_thread_dereg(thread); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mps_pool_t poolmv, poolawl, poolamc; mps_thr_t thread; mps_root_t root0, root1, root2; mps_addr_t p; mps_fmt_t format; mps_ap_t apawl, apamc; mycell *a, *b; int i,j; RC; cdie(mps_space_create(&space), "create space"); cdie(mps_thread_reg(&thread, space), "register thread"); cdie( mps_root_create_table(&root0, space, MPS_RANK_AMBIG, 0, &exfmt_root, 1), "create exfmt root"); cdie( mps_root_create_table(&root2, space, MPS_RANK_EXACT, 0, (mps_addr_t *)obj_table, MAXLDS), "create table root"); cdie( mps_root_create_reg(&root1, space, MPS_RANK_AMBIG, 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create register and stack root"); cdie( mps_fmt_create_A(&format, space, &fmtA), "create format"); cdie( mps_pool_create(&poolawl, space, mps_class_awl(), format), "create awl pool"); cdie( mps_pool_create(&poolmv, space, mps_class_mv(), 0x4000, 128, 0x4000), "create mv pool"); cdie( mps_ap_create(&apawl, poolawl, MPS_RANK_EXACT), "create ap"); cdie( mps_pool_create(&poolamc, space, mps_class_amc(), format), "create amc pool"); cdie( mps_ap_create(&apamc, poolamc, MPS_RANK_EXACT), "create ap"); /* first we'll use only pool classes MV and AWL. So LDs shouldn't go stale at all. */ b = allocone(apawl, 5, MPS_RANK_EXACT); for (i=0; i < MAXLDS; i++) { comment("%d", i); mps_alloc(&p, poolmv, sizeof(mps_ld_s)); a = allocone(apawl, 5, MPS_RANK_EXACT); setref(a, 0, b); b = a; a = allocdumb(apamc, 256*1024, MPS_RANK_EXACT); a = allocdumb(apawl, 256*1024, MPS_RANK_EXACT); comment("alloc"); lds[i] = p; mps_ld_reset(lds[i], space); comment("reset"); if (i>0) { mps_ld_add(lds[i], space, (mps_addr_t) b); } comment("add"); } for (i=0; i < MAXLDS; i++) { comment("%d", i); asserts(mps_ld_isstale(lds[i], space, p) == 0, "%d stale but shouldn't be", i); } /* allocate MAXLDS objects, and make each LD depend on the corresponding object */ for (i=0; i < MAXLDS; i++) { comment("%d", i); obj_table[i] = allocone(apamc, ranint(100), MPS_RANK_EXACT); mps_ld_add(lds[i], space, (mps_addr_t) obj_table[i]); } for (i=0; i < 1000; i++) { comment("%d of 1000", i); checklds(); for (j=0; j < 4; j++) { a = allocdumb(apamc, 32*1024, MPS_RANK_EXACT); } } mps_ap_destroy(apawl); mps_ap_destroy(apamc); comment("Destroyed aps."); mps_pool_destroy(poolmv); mps_pool_destroy(poolamc); mps_pool_destroy(poolawl); comment("Destroyed pools."); mps_fmt_destroy(format); comment("Destroyed format."); mps_root_destroy(root0); mps_root_destroy(root1); mps_root_destroy(root2); comment("Destroyed roots."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_space_destroy(space); comment("Destroyed space."); }
static void test(void) { mps_arena_t arena; mps_pool_t poolamc, poolawl; mps_thr_t thread; mps_root_t root; mps_fmt_t format; mps_chain_t chain; mps_ap_t apamc, apawl; mycell *a[100]; int i; int j; int k,z; alloccomments = 1; formatcomments = 1; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); die(mps_thread_reg(&thread, arena), "register thread"); die(mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); die(mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mmqa_pool_create_chain(&poolamc, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_pool_create(&poolawl, arena, mps_class_awl(), format, getassociated), "create pool"); cdie( mps_ap_create(&apawl, poolawl, mps_rank_exact()), "create ap"); cdie( mps_ap_create(&apamc, poolamc, mps_rank_exact()), "create ap"); for(i=0; i<100; i++) { a[i] = allocone(apawl, 6, 1); } for(i=0; i<10000; i++) { j = ranint(100); k = 5 + ranint(50); comment("New object %i, %i", j, k); a[j] = allocone(apawl, k, 1); k = ranint(100); z = ranint(2); comment("setting %i (%p) %i", k, a[k], z); setref(a[k], z, a[j]); (void)allocdumb(apamc, 0x400*64, 0); } mps_arena_park(arena); mps_ap_destroy(apawl); mps_ap_destroy(apamc); mps_pool_destroy(poolamc); mps_pool_destroy(poolawl); mps_chain_destroy(chain); mps_fmt_destroy(format); mps_root_destroy(root); mps_thread_dereg(thread); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { long int i; long int rsize; int inramp; mycell *r, *s; cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) 1024*1024*ARENALIMIT), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie( mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); cdie( mps_root_create_table(&root1, arena, mps_rank_exact(), 0, &objtab[0], TABSIZE), "create root table"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie( mps_pool_create(&poolamc, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_ap_create(&apamc, poolamc, 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) { s = allocone(apamc, 3, mps_rank_exact()); setref(r, 0, s); setref(s, 1, r); r = s; s = allocdumb(apamc, RAMPSIZE, mps_rank_exact()); setref(r, 2, s); rsize ++; if (ranint(LEAVERAMP) == 0) { r = allocone(apamc, 2, mps_rank_exact()); s = allocone(apamc, 2, mps_rank_exact()); #ifdef RAMP_INTERFACE mps_ap_alloc_pattern_end(apamc, mps_alloc_pattern_ramp()); #endif #ifdef COLLECT_WORLD mps_arena_collect(arena); mps_arena_release(arena); #endif comment("ramp end, %ld objects", rsize); inramp = 0; } } else { if (ranint(ENTERRAMP) == 0) { #ifdef RAMP_INTERFACE mps_ap_alloc_pattern_begin(apamc, mps_alloc_pattern_ramp()); #endif comment("ramp begin"); r = allocone(apamc, 3, mps_rank_exact()); inramp = 1; rsize = 0; } } } mps_arena_park(arena); mps_ap_destroy(apamc); comment("Destroyed ap."); mps_pool_destroy(poolamc); comment("Destroyed pool."); mps_fmt_destroy(format); comment("Destroyed format."); mps_chain_destroy(chain); comment("Destroyed chain."); mps_root_destroy(root1); mps_root_destroy(root); comment("Destroyed roots."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mps_arena_t arena; mps_pool_t pool; mps_thr_t thread; mps_root_t root; mps_chain_t chain; mps_fmt_t format; mps_ap_t ap; mycell *a, *b; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie( mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie( mps_pool_create(&pool, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_ap_create(&ap, pool, mps_rank_exact()), "create ap"); a = allocone(ap, 1024, 1); z = a; b = allocone(ap, 1024, 1); setref(b, 0, a); a = allocdumb(ap, 1024*64, 1); a = allocdumb(ap, 1024*64, 1); comment("Collecting..."); mps_arena_collect(arena); asserts(z != a, "Didn't move!"); comment("Writing bad pointer..."); b->data.ref[0].addr = z; mps_arena_collect(arena); comment("Bad pointer not spotted in collection"); fail(); mps_arena_park(arena); mps_ap_destroy(ap); comment("Destroyed ap."); mps_pool_destroy(pool); comment("Destroyed pool."); mps_fmt_destroy(format); comment("Destroyed format."); mps_chain_destroy(chain); comment("Destroyed chain."); mps_root_destroy(root); comment("Destroyed root."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mps_chain_t chain; mycell *x; cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) 1024*1024*30), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie( mps_root_create_table_masked(&root1, arena, mps_rank_exact(), 0, (mps_addr_t*)&a[0], 4, 0x4), "create a root table"); cdie( mps_root_create_table(&root2, arena, mps_rank_ambig(), 0, (mps_addr_t*)&b[0], 4), "create b root table"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mmqa_pool_create_chain(&poolamc, arena, mps_class_amc(), format, chain), "create pool"); die(mmqa_pool_create_chain(&poollo, arena, mps_class_amcz(), format, chain), "create pool"); cdie( mps_pool_create(&poolawl, arena, mps_class_awl(), format, getassociated), "create pool"); cdie( mps_ap_create(&apamc, poolamc, mps_rank_exact()), "create ap"); cdie( mps_ap_create(&aplo, poollo, mps_rank_exact()), "create ap"); cdie( mps_ap_create(&apawl, poolawl, mps_rank_exact()), "create ap"); newstamp = 0; alloccomments = 1; die(allocrdumb(&a[0], aplo, 64, mps_rank_exact()), "alloc"); die(allocrdumb(&a[1], apamc, 64, mps_rank_exact()), "alloc"); die(allocrdumb(&a[3], apawl, 64, mps_rank_exact()), "alloc"); a[2] = (mycell *)((mps_word_t)a[3] | 4); die(allocrdumb(&b[0], aplo, 64, mps_rank_exact()), "alloc"); die(allocrdumb(&b[1], apamc, 64, mps_rank_exact()), "alloc"); b[2] = NULL; die(allocrdumb(&b[3], apawl, 64, mps_rank_exact()), "alloc"); rootcount = 0; walkroots(NULL); report("count1", "%ld", rootcount); cdie(mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create stack root"); x = allocdumb(apamc, 64, mps_rank_exact()); (void)allocdumb(apamc, 64, mps_rank_exact()); (void)allocdumb(apamc, 64, mps_rank_exact()); rootcount = 0; speccount = 0; walkroots(x); report("count2", "%ld", rootcount); report("countspec", "%ld", speccount); mps_arena_park(arena); mps_ap_destroy(apamc); mps_ap_destroy(aplo); mps_ap_destroy(apawl); comment("Destroyed aps."); mps_pool_destroy(poolamc); mps_pool_destroy(poollo); mps_pool_destroy(poolawl); comment("Destroyed pools."); mps_chain_destroy(chain); mps_fmt_destroy(format); comment("Destroyed format."); mps_root_destroy(root2); mps_root_destroy(root1); mps_root_destroy(root); comment("Destroyed roots."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mps_arena_t arena; mps_pool_t pool; mps_thr_t thread; mps_root_t root; mps_chain_t chain; mps_fmt_t format; mps_ap_t ap; mps_addr_t p; mps_addr_t q; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie( mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie( mps_pool_create(&pool, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_ap_create(&ap, pool, mps_rank_exact()), "create ap"); do { cdie(mps_reserve(&p, ap, 0x100), "Reserve: "); q = (mps_addr_t) ((char *)p + 0x10); } while (!mps_commit(ap, q, 0x100)); comment("Committed."); mps_ap_destroy(ap); comment("Destroyed ap."); mps_pool_destroy(pool); comment("Destroyed pool."); mps_fmt_destroy(format); comment("Destroyed format."); mps_chain_destroy(chain); comment("Destroyed chain."); mps_root_destroy(root); comment("Destroyed root."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { /* a is a table of exact roots b a table of ambiguous roots f a table of non-roots */ mycell *a[4], *b[4], *f[4]; mps_addr_t addr; int i, j, k; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); addr = &a[0]; cdie( mps_root_create_table(&root, arena, mps_rank_exact(), 0, addr, 4), "create a root table"); addr = &b[0]; cdie( mps_root_create_table(&root1, arena, mps_rank_ambig(), 0, addr, 4), "create b root table"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie( mps_pool_create(&poolamc, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_pool_create(&poollo, arena, mps_class_lo(), format), "create pool"); cdie( mps_pool_create(&poolawl, arena, mps_class_awl(), format, getassociated), "create pool"); cdie( mps_ap_create(&apamc, poolamc, mps_rank_exact()), "create ap"); cdie( mps_ap_create(&aplo, poollo, mps_rank_exact()), "create ap"); cdie( mps_ap_create(&apawl, poolawl, mps_rank_exact()), "create ap"); newstamp = 0; for (i=0; i<4; i++) { addr = &a[i]; die(allocrdumb(addr, aplo, 64, mps_rank_exact()), "alloc failed"); addr = &b[i]; die(allocrone(addr, apawl, 5, mps_rank_exact()), "alloc failed"); b[i]->data.ref[0].addr = a[i]; addr = &a[i]; die(allocrone(addr, apamc, 5, mps_rank_exact()), "alloc failed"); a[i]->data.ref[0].addr = b[i]; } for (j=0; j<100; j++) { comment("%i of 100", j); for (i=0; i<10000; i++) { k = ranint(4); addr = &a[k]; die(allocrdumb(addr, aplo, 64, mps_rank_exact()), "alloc failed"); k = ranint(4); addr = &b[k]; die(allocrone(addr, apawl, 5, mps_rank_exact()), "alloc failed"); b[k]->data.ref[0].addr = a[ranint(4)]; b[k]->data.ref[1].addr = b[ranint(4)]; addr = &a[k]; die(allocrone(addr, apamc, 5, mps_rank_exact()), "alloc failed"); f[k] = a[k]->data.ref[2].addr; a[k]->data.ref[2].addr = b[ranint(4)]; } comment("walking..."); mps_arena_park(arena); mps_arena_collect(arena); oldstamp = newstamp; newstamp += 1; mps_arena_formatted_objects_walk(arena, stepper, (void *) MAGICPOINT, MAGICSIZE); mps_arena_release(arena); comment("tracing..."); oldstamp = newstamp; newstamp += 1; tracegraph((mycell *) exfmt_root); tracegraph(a[0]); tracegraph(a[1]); tracegraph(a[2]); tracegraph(a[3]); tracegraph(b[0]); tracegraph(b[1]); tracegraph(b[2]); tracegraph(b[3]); comment("ok"); } mps_ap_destroy(apamc); mps_ap_destroy(aplo); mps_ap_destroy(apawl); comment("Destroyed aps."); mps_pool_destroy(poolamc); mps_pool_destroy(poollo); mps_pool_destroy(poolawl); comment("Destroyed pools."); mps_fmt_destroy(format); comment("Destroyed format."); mps_chain_destroy(chain); comment("Destroyed chain."); mps_root_destroy(root); mps_root_destroy(root1); comment("Destroyed roots."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void testInArena(mps_arena_t arena, mps_bool_t failcase, mps_bool_t usefulFailcase) { mps_pool_t lopool, hipool, temppool; PoolStatStruct lostruct; /* stats about lopool */ PoolStatStruct histruct; /* stats about lopool */ PoolStatStruct tempstruct; /* stats about temppool */ PoolStat lostat = &lostruct; PoolStat histat = &histruct; PoolStat tempstat = &tempstruct; int i; die(mps_pool_create(&hipool, arena, mps_class_mvff(), chunkSize, chunkSize, (size_t)1024, TRUE, TRUE, TRUE), "Create HI MFFV"); die(mps_pool_create(&lopool, arena, mps_class_mvff(), chunkSize, chunkSize, (size_t)1024, FALSE, FALSE, TRUE), "Create LO MFFV"); die(mps_pool_create_k(&temppool, arena, mps_class_mvff(), mps_args_none), "Create TEMP"); if(failcase) { if(usefulFailcase) { /* describe a useful failure case */ } else { /* describe a misleading failure case */ } } poolStatInit(lostat, lopool, chunkSize); poolStatInit(histat, hipool, chunkSize); poolStatInit(tempstat, temppool, chunkSize); /* iterate, allocating objects */ for (i=0; i<iterationCount; ++i) { mps_res_t res; res = allocMultiple(lostat); if (res != MPS_RES_OK) break; res = allocMultiple(histat); if (res != MPS_RES_OK) break; res = allocMultiple(tempstat); if (res != MPS_RES_OK) break; } /* report results */ reportResults(lostat, "the low MVFF pool"); reportResults(histat, "the high MVFF pool"); reportResults(tempstat, "the temp pool"); mps_pool_destroy(hipool); mps_pool_destroy(lopool); mps_pool_destroy(temppool); }
static void test(void *stack_pointer) { mps_arena_t arena; mps_pool_t pool; mps_thr_t thread; mps_root_t root; mps_root_t root2; mps_fmt_t format; mps_chain_t chain; mps_ap_t ap; mycell *z[100]; int i; formatcomments = 1; RC; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); die(mps_root_create_table_masked(&root, arena, mps_rank_exact(), 0, (mps_addr_t*)&z[0], 100, 0x4), "create table root"); die(mps_root_create_table(&root2, arena, mps_rank_ambig(), 0, &exfmt_root, 1), "create exfmt root"); die(mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mmqa_pool_create_chain(&pool, arena, mps_class_amc(), format, chain), "create pool(amc)"); cdie( mps_ap_create(&ap, pool, mps_rank_exact()), "create ap"); for (i=0; i<100; i++) { comment("%i of 10.", i); UC; z[i] = allocone(ap, 1, 1); if (i % 8 == 0) { z[i] = (mycell *) ((mps_word_t)z[i] + 4); } /* error to scan this! */ } for (i=0; i<1000; i++) { z[0] = allocone(ap, 1000, 0); } DC; DMC; mps_arena_park(arena); mps_ap_destroy(ap); mps_pool_destroy(pool); mps_chain_destroy(chain); mps_fmt_destroy(format); mps_root_destroy(root); mps_root_destroy(root2); comment("Destroyed roots."); mps_thread_dereg(thread); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mps_arena_t arena; mps_pool_t poolamc, poolawl; mps_thr_t thread; mps_root_t root; mps_fmt_t format; mps_chain_t chain; mps_ap_t apamc, apawl, apweak; mycell *a, *b, *c, *d, *e, *f, *g; int i; int j; RC; cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create arena"); die(mps_thread_reg(&thread, arena), "register thread"); die(mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); die(mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mmqa_pool_create_chain(&poolamc, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_pool_create(&poolawl, arena, mps_class_awl(), format, getassociated), "create pool"); cdie( mps_ap_create(&apweak, poolawl, mps_rank_weak()), "create ap"); cdie( mps_ap_create(&apawl, poolawl, mps_rank_exact()), "create ap"); cdie( mps_ap_create(&apamc, poolamc, mps_rank_exact()), "create ap"); b = allocone(apamc, 1, 1); for (j=1; j<10; j++) { comment("%i of 10.", j); UC; a = allocone(apawl, 5, mps_rank_exact()); setref(b, 0, a); b = a; c = a; d = a; e = a; f = a; g = a; for (i=1; i<1000; i++) { UC; if (ranint(3) == 0) { c = allocone(apawl, 500, mps_rank_exact()); } else if (ranint(2) == 0) { c = allocone(apweak, 500, mps_rank_weak()); } else { c = allocone(apamc, 500, mps_rank_exact()); } if (ranint(8) == 0) d = c; if (ranint(8) == 0) e = c; if (ranint(8) == 0) f = c; if (ranint(8) == 0) g = c; UC; setref(b, 0, c); UC; setref(c, 1, d); UC; setref(c, 2, e); UC; setref(c, 3, f); UC; setref(c, 4, g); UC; b = c; } DC; DMC; } mps_ap_destroy(apawl); mps_ap_destroy(apamc); mps_ap_destroy(apweak); mps_pool_destroy(poolamc); mps_pool_destroy(poolawl); mps_chain_destroy(chain); mps_fmt_destroy(format); mps_root_destroy(root); mps_thread_dereg(thread); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void test(void) { mps_pool_t pool; mps_thr_t thread; mps_root_t root; mps_chain_t chain; mps_fmt_t format; mps_ap_t ap, ap2; mycell *a, *b; mps_res_t res; int i; /* create an arena that can't grow beyond 30 M */ cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*30)), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie(mps_root_create_reg(&root, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create root"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie( mps_pool_create(&pool, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_ap_create(&ap, pool, mps_rank_exact()), "create ap"); /* allocate until full */ i = 0; b = NULL; while (allocrone(&a, ap, 128, mps_rank_exact()) == MPS_RES_OK) { i++; setref(a, 0, b); b = a; } comment("%d objs allocated.", i); /* try to allocate 10 times */ cdie(mps_ap_create(&ap2, pool, mps_rank_exact()), "create second ap"); mps_ap_destroy(ap); for (i = 0; i < 10; i++) { res = allocrone(&a, ap2, 128, mps_rank_exact()); report("predie", "%s", err_text(res)); } /* now let everything die, and try to allocate 10 times */ mps_root_destroy(root); for (i = 0; i < 10; i++) { res = allocrone(&a, ap2, 128, mps_rank_exact()); report("postdie", "%s", err_text(res)); } mps_ap_destroy(ap2); comment("Destroyed ap."); mps_pool_destroy(pool); comment("Destroyed pool."); mps_fmt_destroy(format); comment("Destroyed format."); mps_chain_destroy(chain); comment("Destroyed chain."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }