Exemplo n.º 1
0
void cdie(mps_res_t err, const char *str)
{
 if (err != MPS_RES_OK) {
  error("%s: %s\n", str, err_text(err));
 }
 else comment("%s: OK", str);
}
Exemplo n.º 2
0
Arquivo: 23.c Projeto: Ravenbrook/mps
static void test(void *stack_pointer)
{
 mps_arena_t arena;
 mps_pool_t poolMVFF, poolAMC;
 mps_thr_t thread;

 mps_fmt_t format;
 mps_chain_t chain;
 mps_ap_t ap;
 mps_res_t r;

 mycell *a;
 mps_addr_t p;

 int i;
 int s1, s2, s3;

 cdie(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE),
      "create arena");

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

 die(mps_fmt_create_A(&format, arena, &fmtA), "create format");
 cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create");

 formatcomments = 0;

 die(mmqa_pool_create_chain(&poolAMC, arena, mps_class_amc(), format, chain),
      "create pool");

 cdie(
  mps_ap_create(&ap, poolAMC, mps_rank_exact()),
  "create ap");

 comment("Sizes in megabytes:");

 MPS_ARGS_BEGIN(args) {
   MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, EXTEND_BY);
   MPS_ARGS_ADD(args, MPS_KEY_MEAN_SIZE, MEAN_SIZE);
   cdie(mps_pool_create_k(&poolMVFF, arena, mps_class_mvff(), args),
        "create MVFF pool");
 } MPS_ARGS_END(args);
 i = 0;
 while ((r=mps_alloc(&p, poolMVFF, 1024*1024)) == 0) i++;
 report("refuse1", "%s", err_text(r));
 report("size1", "%i", i);
 s1 = i;
 mps_pool_destroy(poolMVFF);

 MPS_ARGS_BEGIN(args) {
   MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, EXTEND_BY);
   MPS_ARGS_ADD(args, MPS_KEY_MEAN_SIZE, MEAN_SIZE);
   cdie(mps_pool_create_k(&poolMVFF, arena, mps_class_mvff(), args),
        "create MVFF pool");
 } MPS_ARGS_END(args);
 i = 0;
 while ((r=mps_alloc(&p, poolMVFF, 1024*1024)) == 0) i++;
 report("refuse2", "%s", err_text(r));
 report("size2", "%i", i);
 s2 = i;
 mps_pool_destroy(poolMVFF);

 a = allocdumb(ap, 1024*1024*30); /* allocate 30 M object */


 MPS_ARGS_BEGIN(args) {
   MPS_ARGS_ADD(args, MPS_KEY_EXTEND_BY, EXTEND_BY);
   MPS_ARGS_ADD(args, MPS_KEY_MEAN_SIZE, MEAN_SIZE);
   cdie(mps_pool_create_k(&poolMVFF, arena, mps_class_mvff(), args),
        "create MVFF pool");
 } MPS_ARGS_END(args);
 i=0;
 while ((r=mps_alloc(&p, poolMVFF, 1024*1024)) == 0) i++;
 report("refuse3", "%s", err_text(r));
 report("size3", "%i", i);
 s3 = i;

 report("diff12", "%i", s1-s2);
 report("diff23", "%i", s2-s3);

 for(i = 0; i < 10; i++) {
  r = mps_alloc(&p, poolMVFF, 1024*1024);
  report("refuse4", "%s", err_text(r));
 }

 mps_arena_park(arena);
 mps_pool_destroy(poolMVFF);

 mps_ap_destroy(ap);

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

 mps_chain_destroy(chain);
 mps_fmt_destroy(format);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
 comment("Destroyed arena.");
}
Exemplo n.º 3
0
static void test(void)
{
 mps_pool_t pool;
 mps_thr_t thread;

 mps_root_t root;

 mps_fmt_t format;
 mps_chain_t chain;
 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*40)),
  "create arena");
 mps_arena_commit_limit_set(arena, (size_t) (1024*1024*30));

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

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

 /* 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);
 report("committed", "%ld", mps_arena_committed(arena));

 /* 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);
 mps_pool_destroy(pool);
 mps_chain_destroy(chain);
 mps_fmt_destroy(format);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
 comment("Destroyed arena.");
}
Exemplo n.º 4
0
static void test(void)
{
 mps_pool_t pool;
 mps_thr_t thread;
 mps_root_t root, root1;

 mps_fmt_t format;
 mps_chain_t chain;
 mps_ap_t ap;

 mycell *a, *b;
 mps_addr_t addr;

 mps_res_t res;
 int j;

 /* 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_arena_commit_limit_set(arena, (size_t) (1024*1024*30)), "limit");

 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,
                            (mps_addr_t *)&exfmt_root, 1),
      "create table 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");

/* allocate 16 M of (live) stuff */

 b = allocone(ap, 2, mps_rank_exact());
 for (j=0; j<160; j++) {
  a = allocone(ap, 2, mps_rank_exact());
  setref(a, 0, b);
  b = allocdumb(ap, 1024*100, mps_rank_exact());
  setref(a, 1, b);
  b = a;
 }

 comment("created 16M of live objects");

 for (j=0; j<1000; j++) {
  res=allocrdumb(&a, ap, 1024*1024, mps_rank_exact());
 }

 fillup();

 comment("finalizing...");

 addr = a;
 for (j=0; j<100; j++) {
  comment(err_text(mps_finalize(arena, &addr)));
 }

 comment("try to make collectm by allocating another 1G...");
 
 empty();

 for (j=0; j<1024; j++) {
  res=allocrdumb(&a, ap, 1024 * 1024, mps_rank_exact());
  if (res == MPS_RES_OK) {
   comment("%i ok", j);
  } else {
   break;
  }
 }

 comment("collect world...");

 for (j=0; j<100; j++) {
  mps_arena_collect(arena);
 }

 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(root1);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
 comment("Destroyed arena.");
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
0
void report_res(const char *str, mps_res_t res)
{
 report(str, err_text(res));
}
Exemplo n.º 7
0
void adie(mps_res_t err, const char *str)
{
 error("%s: %s\n", str, err_text(err));
}
Exemplo n.º 8
0
void die(mps_res_t err, const char *str)
{
 if (err != MPS_RES_OK) {
  error("%s: %s\n", str, err_text(err));
 }
}