示例#1
0
static void test(void) {

    mycell *p, *q;
    int i;
    mps_res_t res;
    size_t lim0, avail0, lim1, avail1, commit1, lim2, avail2, commit2;
    size_t lim3, avail3, commit3, lim4, avail4, commit4;
    size_t lim5, avail5, commit5, lim6, avail6, commit6;

    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_pool_create(&poolsnc, arena, mps_class_snc(), format),
        "create pool");

    cdie(
        mps_ap_create(&apsnc, poolsnc, mps_rank_exact()),
        "create ap");

    report("lim0", "%d", lim0 = mps_reservoir_limit(arena));
    report("avail0",  "%d", avail0 = mps_reservoir_available(arena));
    mps_reservoir_limit_set(arena, (size_t) 0);

    mps_reservoir_limit_set(arena, (size_t) (5ul*1024*1024));
    report("lim1", "%d", lim1 = mps_reservoir_limit(arena));
    report("avail1",  "%d", avail1 = mps_reservoir_available(arena));
    report("commit1", "%d", commit1 = arena_committed_and_used(arena));
    report("defecit1", "%d", lim1-avail1);

    mps_reservoir_limit_set(arena, (size_t) (1045));
    report("lim2", "%d", lim2 = mps_reservoir_limit(arena));
    report("avail2",  "%d", avail2 = mps_reservoir_available(arena));
    report("commit2", "%d", commit2 = arena_committed_and_used(arena));
    report("defecit2", "%d", lim2-avail2);

    /* set commit limit to whatever is currently committed plus 1 MB
    */

    die(mps_arena_commit_limit_set(arena, arena_committed_and_used(arena)+1024*1024), "commit limit set");
    mps_reservoir_limit_set(arena, (size_t) (10ul*1024*1024));
    report("lim3", "%d", lim3 = mps_reservoir_limit(arena));
    report("avail3",  "%d", avail3 = mps_reservoir_available(arena));
    report("commit3", "%d", commit3 = arena_committed_and_used(arena));
    report("defecit3", "%d", lim3-avail3);
    report("spill3", "%d", commit3-mps_arena_commit_limit(arena));

    /* now raise it by 1/2 MB -- reservoir should grow
    */

    die(mps_arena_commit_limit_set(arena, arena_committed_and_used(arena)+512*1024), "commit limit set");
    report("lim4", "%d", lim4 = mps_reservoir_limit(arena));
    report("avail4",  "%d", avail4 = mps_reservoir_available(arena));
    report("commit4", "%d", commit4 = arena_committed_and_used(arena));
    report("grow4", "%d", avail4-avail3);
    report("spill4", "%d", commit4-mps_arena_commit_limit(arena));

    /* try some allocation -- more than a small amount should fail
    */

    i = -1;
    p = NULL;
    res = MPS_RES_OK;
    while (res == MPS_RES_OK) {
        res = allocrone(&q, apsnc, 10, mps_rank_exact());
        if (res == MPS_RES_OK) {
            setref(q, 0, p);
            p = q;
        }
        i++;
    }
    report("allocfail", "%d", i);
    report_res("failres", res);

    /* available shouldn't have changed since before allocation
    */

    report("lim5", "%d", lim5 = mps_reservoir_limit(arena));
    report("avail5",  "%d", avail5 = mps_reservoir_available(arena));
    report("commit5", "%d", commit5 = arena_committed_and_used(arena));
    report("grow5", "%d", avail5-avail4);
    report("spill5", "%d", commit5-mps_arena_commit_limit(arena));

    /* try some allocation from reservoir -- not much should fail
    */

    i = -1;
    res = MPS_RES_OK;
    while (res == MPS_RES_OK) {
        res = reservoir_allocrone(&q, apsnc, 10, mps_rank_exact());
        if (res == MPS_RES_OK) {
            setref(q, 0, p);
            p = q;
        }
        i++;
    }
    report("allocfail2", "%d", i);
    report_res("failres2", res);

    /* available should have changed now
    */

    report("lim6", "%d", lim6 = mps_reservoir_limit(arena));
    report("avail6",  "%d", avail6 = mps_reservoir_available(arena));
    report("commit6", "%d", commit6 = arena_committed_and_used(arena));
    report("spill6", "%d", commit6-mps_arena_commit_limit(arena));
    report("shrink6", "%d", avail5-avail6);

    mps_root_destroy(root);
    comment("Destroyed root.");

    mps_ap_destroy(apsnc);
    comment("Destroyed ap.");

    mps_pool_destroy(poolsnc);
    comment("Destroyed pool.");

    mps_fmt_destroy(format);
    comment("Destroyed format.");

    mps_thread_dereg(thread);
    comment("Deregistered thread.");

    mps_arena_destroy(arena);
    comment("Destroyed arena.");
}
示例#2
0
static void test(void)
{
 mps_arena_t arena;
 mps_pool_t poolamc, poolawl;
 mps_thr_t thread;
 mps_root_t root, root1;

 mps_fmt_t format;
 mps_chain_t chain;
 mps_ap_t apamc, apawl;

 size_t size0, size1;
 mycell *a, *b, *c, *d, *e, *f, *g;

 int i;
 int j;

 RC;

 deathcomments = 0;

 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");

 cdie(
  mps_root_create_table(&root1, 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(&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_weak()),
  "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);
  a = allocone(apawl, 5, 1);
  setref(b, 0, a);
  b = a;
  c = a;
  d = a;
  e = a;
  f = a;
  g = a;
  for (i=1; i<1000; i++) {
   if (i%100 == 0) {
    comment("   %i", i);
   }
   if (ranint(2)) {
    c = allocone(apamc, 1000, 1);
   } else {
    c = allocone(apawl, 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;
   setref(b, 0, c);
   setref(c, 1, d);
   setref(c, 2, e);
   setref(c, 3, f);
   setref(c, 4, g);
   b = c;
  }
  if (j==3) {
   DC;
   comment("...collecting:");
   RC;
   size0 = arena_committed_and_used(arena);
   mps_arena_collect(arena);
   size1 = arena_committed_and_used(arena);
   report("sizebefore0", "%lu", (unsigned long) size0);
   report("sizeafter0", "%lu", (unsigned long) size1);
   report("diff0", "%lu", (unsigned long) size0-size1);
   DC;
   mps_arena_release(arena);
   comment("...released");
  }
  DC;
  comment("clamping...");
  mps_arena_park(arena);
  RC;
  for (i=1; i<1000; i++) {
   if (i%100 == 0) {
    comment("   %i", i);
   }
   if (ranint(2)) {
    c = allocone(apamc, 1000, 1);
   } else {
    c = allocone(apawl, 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;
   setref(b, 0, c);
   setref(c, 1, d);
   setref(c, 2, e);
   setref(c, 3, f);
   setref(c, 4, g);
   b = c;
  }
  asserts(counters[COPY_COUNT]==0, "Eppur si muove!");
  DC;
  if (j==9) {
   comment("collecting...");
   size0 = arena_committed_and_used(arena);
   mps_arena_collect(arena);
   size1 = arena_committed_and_used(arena);
   report("sizebefore1", "%lu", (unsigned long) size0);
   report("sizeafter1", "%lu", (unsigned long) size1);
   report("diff1", "%lu", (unsigned long) size0-size1);
   DC;
  }
  mps_arena_release(arena);
  comment("released.");
  RC;
 }

 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_root_destroy(root1);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
 comment("Destroyed arena.");
}
示例#3
0
static void test(void)
{
 int i;
 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, com2;

 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 pool(amc)");
 cdie(mps_ap_create(&ap, pool, mps_rank_exact()), "create ap(amc)");

 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 = arena_committed_and_used(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", arena_committed_and_used(arena));
 comment("collect...");
 mps_arena_collect(arena);
 com1 = arena_committed_and_used(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");
 comment("collect...");
 mps_arena_collect(arena);
 com1 = arena_committed_and_used(arena);
 mps_arena_release(arena);
 report("com", "%ld", com1);
 report("inc2", "%ld", (com1-com)/BIGSIZE);

 /* check initial frame is scanned */

 p = allocone(sap, 2, mps_rank_exact());
 q = allocdumb(ap, BIGSIZE, mps_rank_exact());
 setref(p, 1, q);
 q = allocdumb(ap, SMALLSIZE, mps_rank_exact());
 mps_arena_collect(arena);
 com2 = arena_committed_and_used(arena);
 mps_arena_release(arena);
 report("inc3", "%ld", (com2-com1)/BIGSIZE);

 /* even in ordinary collection */

 for (i=0; i < 500; i++) {
  q = allocdumb(ap, BIGSIZE, mps_rank_exact());
 }
 q = allocdumb(ap, SMALLSIZE, mps_rank_exact());
 mps_arena_collect(arena);
 com2 = arena_committed_and_used(arena);
 mps_arena_release(arena);
 report("inc4", "%ld", (com2-com1)/BIGSIZE);


 mps_ap_destroy(ap);
 mps_ap_destroy(sap);
 mps_pool_destroy(pool);
 mps_pool_destroy(spool);
 mps_chain_destroy(chain);
 mps_fmt_destroy(format);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
 comment("Destroyed arena.");
}
示例#4
0
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);
}