Пример #1
0
int main(int argc, char *argv[])
{
    mps_arena_t arena;
    mps_thr_t thread;

    testlib_init(argc, argv);

    die(mps_arena_create(&arena, mps_arena_class_vm(),
                         testArenaSIZE),
        "arena_create");
    die(mps_thread_reg(&thread, arena), "thread_reg");

    test(arena, mps_class_amc());
    test(arena, mps_class_amcz());
    test(arena, mps_class_ams());
    test(arena, mps_class_awl());
    test(arena, mps_class_lo());
    test(arena, mps_class_snc());

    mps_thread_dereg(thread);
    mps_arena_destroy(arena);

    printf("%s: Conclusion: Failed to find any defects.\n", argv[0]);
    return 0;
}
Пример #2
0
static void test(void)
{
 int i = 0;
 mps_ap_t sap;
 mps_arena_t arena;
 mps_fmt_t format;
 mps_pool_t spool;
 mps_thr_t thread;
 mps_frame_t frame;
 mycell *p;

/* create an arena that can't grow beyond 30 M */

 cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t)THIRTY_MEG),
  "create arena");
 cdie(mps_arena_commit_limit_set(arena, (size_t)THIRTY_MEG),
  "commit limit set");

 cdie(mps_thread_reg(&thread, arena), "register thread");

 cdie(
  mps_fmt_create_A(&format, arena, &fmtA),
  "create format");

 cdie(
  mps_pool_create(&spool, arena, mps_class_snc(), format),
  "create SNC pool");

 cdie(
  mps_ap_create(&sap, spool, mps_rank_exact()),
  "create ap");

/* repeatedly push, alloc 1MB object, and pop to first stack frame.
   This shouldn't use much more than 1MB of memory.
*/

 for (i=0; i < ITERATIONS; i++) {
  die(mps_ap_frame_push(&frame, sap), "push");
  p = allocdumb(sap, OBJSIZE, mps_rank_exact());
  die(mps_ap_frame_pop(sap, frame), "pop");
  comment("%i of %i", i, ITERATIONS);
 }

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

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

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

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

 mps_arena_destroy(arena);
 comment("Destroyed arena.");

}
Пример #3
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.");
}
Пример #4
0
static void test(void)
{
 int i = 0, f = 0;
 mps_ap_t sap;
 mps_arena_t arena;
 mps_fmt_t format;
 mps_pool_t spool;
 mps_thr_t thread;
 mps_frame_t frames[MAXFRAMES];
 int nobj[MAXFRAMES+1];
 mycell *p;

/* create an arena that can't grow beyond 30 M */

 cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t)THIRTY_MEG),
  "create arena");
 cdie(mps_arena_commit_limit_set(arena, (size_t)THIRTY_MEG),
  "commit limit set");

 cdie(mps_thread_reg(&thread, arena), "register thread");

 cdie(
  mps_fmt_create_A(&format, arena, &fmtA),
  "create format");

 cdie(
  mps_pool_create(&spool, arena, mps_class_snc(), format),
  "create SNC pool");

 cdie(
  mps_ap_create(&sap, spool, mps_rank_exact()),
  "create ap");

/* repeatedly push and pop stack frames, and allocate objects in them
   at random. Parameters ensure that max allocation can't get too high.
*/

 for (i=0; i < ITERATIONS; i++) {
  switch (ranint(12)) {
  case 1: case 2: case 3: case 4: case 5:
   if (f < MAXFRAMES) {
    die(mps_ap_frame_push(&frames[f], sap), "push");
    comment("push %i", f);
    f++;
    nobj[f] = 0;
   }
   break;
  case 6: case 7: case 8: case 9: case 10:
   if (nobj[f] < MAXLEVOBJS) {
    p = allocone(sap, 16, mps_rank_exact());
    setref(p, 0, NULL);
    nobj[f]++;
   }
   break;
  case 11:
   if (f>0) {
    f -= 1+ranint(1+ranint(f)); /* new f is in [0, old f) */
    die(mps_ap_frame_pop(sap, frames[f]), "pop");
    comment("pop %i", f);
   }
   break;
  }
 }

 mps_arena_park(arena);
 mps_ap_destroy(sap);
 comment("Destroyed ap.");

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

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

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

 mps_arena_destroy(arena);
 comment("Destroyed arena.");

}
Пример #5
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.");
}