static void dt(int kind, size_t extendBy, size_t avgSize, unsigned long mins, unsigned long maxs, int number, int iter) { mps_pool_t pool; int i, hd; clock_t time0, time1; size_t size; double secs; asserts(number <= MAXNUMBER, "number too big"); time0 = clock(); asserts(time0 != -1, "processor time not available"); MPS_ARGS_BEGIN(args) { MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, extendBy); MPS_ARGS_ADD(args, MPS_KEY_MEAN_SIZE, avgSize); cdie(mps_pool_create_k(&pool, arena, mps_class_mvff(), args), "pool"); } MPS_ARGS_END(args); 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, (unsigned char) (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, (unsigned char) (hd%256)), "corrupt at %x (%s: %x, %x, %lx, %lx, %i, %i)", queue[hd].addr, tdesc[kind], (int) extendBy, (int) avgSize, mins, 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, (unsigned char) (hd%256)); queue[hd].size = size; } } mps_pool_destroy(pool); time1=clock(); secs=(time1-time0)/(double)CLOCKS_PER_SEC; comment("%s test (%x, %x, %lx, %lx, %i, %i) in %.2f s", tdesc[kind], (int) extendBy, (int) avgSize, mins, maxs, number, iter, secs); }
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 */ die( mps_pool_create(&poolhi, arena, mps_class_mvff(), MVFF_HI_PARMS), "create high pool"); die( mps_pool_create(&poollo, arena, mps_class_mvff(), MVFF_LO_PARMS), "create low pool"); /* flush hysteresis fund, then set limit */ mps_arena_spare_commit_limit_set(arena, SPARE_ZERO); mps_arena_spare_commit_limit_set(arena, SPARE_LIMIT); /* allocate something in each pool (to reduce risk of subsidiary allocation being neede later */ die(mps_alloc(&objlo, poollo, EXTEND), "low alloc"); die(mps_alloc(&objhi, poolhi, EXTEND), "high alloc"); /* 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("Spare useful/total %i/%i. Limit %i. Size %i. Expected %s. Got %s", spare, spare_total, commit, obj_size, err_text(res_expected), err_text(res)); report("failed", "yes"); } mps_pool_destroy(poollo); mps_pool_destroy(poolhi); }
static void dt(int kind, size_t minSize, size_t avgSize, size_t maxSize, mps_word_t depth, mps_word_t fragLimit, unsigned long mins, unsigned long maxs, int number, int iter) { mps_pool_t pool; mps_ap_t ap; int i, hd; clock_t time0, time1; size_t size; double secs; asserts(number <= MAXNUMBER, "number too big"); time0 = clock(); asserts(time0 != -1, "processor time not available"); die( mps_pool_create(&pool, arena, mps_class_mvt(), minSize, avgSize, maxSize, depth, fragLimit), "create MVT pool"); die(mps_ap_create(&ap, pool, mps_rank_ambig()), "create ap"); for(hd=0; hd<number; hd++) { size = ranrange(mins, maxs); if ((ranint(2) && (kind & 2)) || (kind==DUMMY)) { queue[hd].addr=NULL; } else { die(mvt_alloc(&queue[hd].addr, ap, size), "alloc"); setobj(queue[hd].addr, size, (unsigned char) (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, (unsigned char) (hd%256)), "corrupt at %x (%s: %x, %x, %x, %i, %i, %lx, %lx, %i, %i)", queue[hd].addr, tdesc[kind], (int) minSize, (int) avgSize, (int) maxSize, (int) depth, (int) fragLimit, mins, 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(mvt_alloc(&queue[hd].addr, ap, size),"alloc"); setobj(queue[hd].addr, size, (unsigned char) (hd%256)); queue[hd].size = size; } } mps_ap_destroy(ap); mps_pool_destroy(pool); time1=clock(); secs=(time1-time0)/(double)CLOCKS_PER_SEC; comment("%s test (%x, %x, %x, %i, %i, %lx, %lx, %i, %i) in %.2f s", tdesc[kind], (int) minSize, (int) avgSize, (int) maxSize, (int) depth, (int) fragLimit, mins, maxs, number, iter, secs); }
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); }