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;

 mycell *cells;
 int h,i,j,k,l;
 mycell *pobj;
 size_t bytes;
 size_t alignment;
 mps_addr_t q;
 int nextid = 0x1000000;

 /* turn on comments about copying and scanning */
 formatcomments = BLAH;
 fixcomments = BLAH;

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

 for (i=0; i<NAPS; i++) {
  die(mps_ap_create(&ap[i], pool, MPS_RANK_EXACT), "create ap");
  ap_state[i] = 0;
 }

 cells = allocone(ap[0], NCELLS);

 /* ap_state can have the following values:
  0 before reserve
  1 after reverse
  2 after init
  3 after I=A
  0 after commit
 */

 for(h=0; h<100; h++) {
   comment("%i of 100", h);

   for(j=0; j<1000; j++) {
     i = ranint(NAPS);

     switch (ap_state[i]) {
     case 0:
       nrefs[i] = NUMREFS;
       bytes = offsetof(struct data, ref)+nrefs[i]*sizeof(struct refitem);
       alignment = MPS_PF_ALIGN;
       bytes = (bytes+alignment-1)&~(alignment-1);
       s[i] = bytes;
       die(mps_reserve(&q, ap[i], s[i]), "reserve: ");
       p[i] = q;
       p[i]->data.tag = 0xD033E2A6;
       p[i]->data.id = nextid;
       ap_state[i] = 1;
       commentif(BLAH, "%i: reserve %li at %p", i, nextid, q);
       nextid +=1;
       break;
     case 1:
       commentif(BLAH, "%i: init %li", i, p[i]->data.id);
       p[i]->data.tag = MCdata;
       p[i]->data.numrefs = nrefs[i];
       p[i]->data.size = s[i];
       ap_state[i] = 2;
       for (k=0; k<nrefs[i]; k++) {
         if PNULL {
           p[i]->data.ref[k].addr = NULL;
           p[i]->data.ref[k].id   = 0;
         } else {
           l = ranint(NCELLS);
           pobj = getref(cells, l);
           p[i]->data.ref[k].addr = pobj;
           p[i]->data.ref[k].id = (pobj==NULL ? 0 : pobj->data.id);
         }
         commentif(BLAH, "    ref %i -> %li", k, p[i]->data.ref[k].id);
       }
       break;
     case 2:
       commentif(BLAH, "%i: begin commit %li", i, p[i]->data.id);
       ap[i]->init = ap[i]->alloc;
       ap_state[i] = 3;
       break;
     case 3:
       commentif(BLAH, "%i: end commit %li", i, p[i]->data.id);
       q = p[i];
       if (ap[i]->limit != 0 || mps_ap_trip(ap[i], p[i], s[i])) {
         l = ranint(NCELLS);
         setref(cells, l, q);
         commentif(BLAH, "%i -> %i", i, l);
       }
       ap_state[i] = 0;
       break;
     }
   }
   checkfrom(cells);
 }
Beispiel #2
0
static void test(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;
  mps_pool_t pool;

  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) {
    mps_word_t c;
    size_t r;

    c = mps_collections(arena);
    if (collections != c) {
      collections = c;
      report(arena);

      printf("%lu objects (mps_collections says: %lu)\n", objs, 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();
      if (exactRoots[(exactRootsCOUNT-1) - i] != objNULL)
        dylan_write(exactRoots[(exactRootsCOUNT-1) - i],
                    exactRoots, exactRootsCOUNT);
    } else {
Beispiel #3
0
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.");
}
Beispiel #4
0
Datei: 45.c Projekt: bhanug/mps
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;

 mycell *cells;

 int h,i,j,k,l;
 mycell *pobj;

 mycell *ambig[NAPS];

 size_t size0, size1;
 long mdiff = 0;
 size_t bytes;
 size_t alignment;
 mps_addr_t q;
 int nextid = 0x1000000;

 /* turn on comments about copying and scanning */
 formatcomments = VERBOSE;
 fixcomments = VERBOSE;

 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(&pool, arena, mps_class_amc(), format, chain),
     "create pool");

 for (i = 0; i < NAPS; i++) {
   die(mps_ap_create(&ap[i], pool, mps_rank_exact()), "create ap");
   ap_state[i] = 0;
 }

 cells = allocone(ap[0], NCELLS);

 /* ap_state can have the following values:
  0 before reserve
  1 after reverse
  2 after init
  3 after I=A
  0 after commit
 */

 for(h=0; h<ITERATIONS; h++) {
   comment("%i of %i", h, ITERATIONS);

   for(j=0; j<1000; j++) {
     if (j == 500) {
       size0 = mps_arena_committed(arena) - mps_arena_spare_committed(arena);
       mps_arena_collect(arena);
       size1 = mps_arena_committed(arena) - mps_arena_spare_committed(arena);
       asserts(((long) size1)-((long) size0) < 1024*1024,
               "Collection made arena bigger: %lu -> %lu",
               (unsigned long) size0, (unsigned long) size1);
       if (((long) size1)-((long) size0) > mdiff) {
         mdiff = ((long) size1) - ((long) size0);
       }
     }
     i = ranint(NAPS);

     switch (ap_state[i]) {
     case 0:
       nrefs[i] = NUMREFS;
       bytes = offsetof(struct data, ref)+nrefs[i]*sizeof(struct refitem);
       alignment = MPS_PF_ALIGN;
       bytes = (bytes+alignment-1)&~(alignment-1);
       s[i] = bytes;
       die(mps_reserve(&q, ap[i], s[i]), "reserve: ");
       p[i] = q;
       p[i]->data.tag = 0xD033E2A6;
       p[i]->data.id = nextid;
       ap_state[i] = 1;
       commentif(VERBOSE, "%i: reserve %li at %p", i, nextid, q);
       nextid +=1;
       break;
     case 1:
       commentif(VERBOSE, "%i: init %li", i, p[i]->data.id);
       p[i]->data.tag = MCdata;
       p[i]->data.numrefs = nrefs[i];
       p[i]->data.size = s[i];
       ap_state[i] = 2;
       for (k=0; k<nrefs[i]; k++) {
         if PNULL {
           p[i]->data.ref[k].addr = NULL;
           p[i]->data.ref[k].id   = 0;
         } else {
           l = ranint(NCELLS);
           pobj = getref(cells, l);
           p[i]->data.ref[k].addr = pobj;
           p[i]->data.ref[k].id = (pobj==NULL ? 0 : pobj->data.id);
         }
         commentif(VERBOSE, "    ref %i -> %li", k, p[i]->data.ref[k].id);
       }
       break;
     case 2:
       commentif(VERBOSE, "%i: begin commit %li", i, p[i]->data.id);
       ambig[i] = p[i];
       ap[i]->init = ap[i]->alloc;
       ap_state[i] = 3;
       break;
     case 3:
       commentif(VERBOSE, "%i: end commit %li", i, p[i]->data.id);
       q=p[i];
       if (ap[i]->limit != 0 || mps_ap_trip(ap[i], p[i], s[i])) {
         l = ranint(NCELLS);
         setref(cells, l, q);
         commentif(VERBOSE, "%i -> %i", i, l);
       }
       ap_state[i] = 0;
       ambig[i] = NULL;
       break;
     }
   }
   checkfrom(cells);
 }
Beispiel #5
0
Datei: amcsshe.c Projekt: epu/mps
static void *test(mps_arena_t arena, mps_pool_class_t pool_class,
                  size_t roots_count)
{
  mps_fmt_t format;
  mps_chain_t chain;
  mps_root_t exactRoot, ambigRoot, bogusRoot;
  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;

  die(EnsureHeaderFormat(&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)");
  die(mps_root_create_table(&bogusRoot, arena,
                            mps_rank_ambig(), (mps_rm_t)0,
                            &bogusRoots[0], bogusRootsCOUNT),
      "root_create_table(bogus)");

  /* 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) {
      collections = c;
      printf("\nCollection %"PRIuLONGEST", %lu objects.\n",
             (ulongest_t)c, objs);
      report(arena);
      for (r = 0; r < exactRootsCOUNT; ++r) {
        if (exactRoots[r] != objNULL)
          die(HeaderFormatCheck(exactRoots[r]), "wrapper check");
      }
      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) {
              die(HeaderFormatCheck(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;
        }
      }
      /*  fill bogusRoots with variations of a real pointer */
      r = rnd() % exactRootsCOUNT;
      if (exactRoots[r] != objNULL) {
        char *p = (char*)exactRoots[r];

        for(i = 0; i < bogusRootsCOUNT; ++i, ++p)
          bogusRoots[i] = (mps_addr_t)p;
      }
    }

    r = (size_t)rnd();
    if (r & 1) {
      i = (r >> 1) % exactRootsCOUNT;
      if (exactRoots[i] != objNULL)
        die(HeaderFormatCheck(exactRoots[i]), "wrapper check");
      exactRoots[i] = make(roots_count);
      if (exactRoots[(exactRootsCOUNT-1) - i] != objNULL)
        dylan_write(exactRoots[(exactRootsCOUNT-1) - i],
                    exactRoots, exactRootsCOUNT);
    } else {