Beispiel #1
0
static void test(void) {
 mps_thr_t thread;
 mps_pool_t pool;
 mps_addr_t a, b;
 char *c;

 cdie(mps_arena_create(&arena, mps_arena_class_vmnz(),
  (size_t) (1024*1024*50)), "create arena");
 cdie(mps_thread_reg(&thread, arena), "register thread");

 die(
  mps_pool_create(&pool, arena, mps_class_mvff_debug(), &debugOpts,
                  8192, 8, 8, 0, 0, 1),
  "create MVFF pool");

 die(mps_alloc(&a, pool, 64), "alloc a");
 die(mps_alloc(&b, pool, 64), "alloc b");
 
 c = a;
 c -= 1;
 *c = 0;
 
 mps_pool_check_fenceposts(pool);
 comment("Fencepost check.");

 c += 67;
 *c = 0;

 mps_pool_check_fenceposts(pool);
 comment("Fencepost check.");

 mps_pool_destroy(pool);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
}
static void test(void)
{
 mps_space_t space;
 mps_pool_t pool;
 size_t extendBy;
 size_t avgSize;
 size_t maxSize;

 mps_addr_t obj;

 extendBy = (size_t) 4096;
 avgSize  = (size_t) 32;
 maxSize  = (size_t) 65536;

 cdie(mps_space_create(&space), "create space");

 cdie(
  mps_pool_create(&pool, space, mps_class_mv(),
   extendBy, avgSize, maxSize),
  "create pool");
 cdie(mps_alloc(&obj, pool, 152), "allocate");
 cdie(mps_alloc(&obj, pool, 4), "alloc2");


 mps_free(pool, obj, 512);
 comment("Freed.");

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

 mps_space_destroy(space);
 comment("Destroyed space.");
}
Beispiel #3
0
static void test(void)
{
 mps_arena_t arena;
 mps_pool_t pool;
 mps_thr_t thread;

 mps_addr_t a,b;

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

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

 cdie(
  mps_pool_create(
     &pool, arena, mps_class_mv(),
     (size_t) 4096, (size_t) 32, (size_t) 64*1024),
  "create pool");

 die(mps_alloc(&a, pool, 8),
     "alloc a");
 die(mps_alloc(&b, pool, 32),
     "alloc b");
 mps_free(pool, a, 9);
 mps_pool_destroy(pool);

}
static void arena_commit_test(mps_arena_t arena)
{
  mps_pool_t pool;
  size_t committed;
  size_t reserved;
  size_t limit;
  void *p;
  mps_res_t res;

  committed = mps_arena_committed(arena);
  reserved = mps_arena_reserved(arena);
  cdie(reserved >= committed, "reserved < committed");
  die(mps_pool_create(&pool, arena, mps_class_mv(), 0x1000, 1024, 16384),
      "commit pool create");
  limit = mps_arena_commit_limit(arena);
  die(mps_arena_commit_limit_set(arena, committed), "commit_limit_set before");
  do {
    res = mps_alloc(&p, pool, FILLER_OBJECT_SIZE);
  } while (res == MPS_RES_OK);
  die_expect(res, MPS_RES_COMMIT_LIMIT, "Commit limit allocation");
  die(mps_arena_commit_limit_set(arena, limit), "commit_limit_set after");
  res = mps_alloc(&p, pool, FILLER_OBJECT_SIZE);
  die_expect(res, MPS_RES_OK, "Allocation failed after raising commit_limit");
  mps_pool_destroy(pool);
}
Beispiel #5
0
static void test(void *stack_pointer)
{
 mps_thr_t thread;
 mps_pool_t pool;
 unsigned int i;
 unsigned long nLarge;

 cdie(mps_arena_create(&arena, mps_arena_class_vm(),
  (size_t) (1024*1024*50)), "create arena");
 cdie(mps_thread_reg(&thread, arena), "register thread");

 mps_arena_commit_limit_set(arena, COMLIMIT1);

 die(mps_pool_create(&pool, arena, mps_class_mvff(),
                     (size_t)EXTENDBY, (size_t)8, (mps_align_t)MPS_PF_ALIGN,
                     (mps_bool_t)0, (mps_bool_t)0, (mps_bool_t)1),
     "create MVFF pool");

 for (i = 0; i < NSMALL; i++) {
  die(mps_alloc(&smallObjects[i], pool, SMALLSIZE), "small alloc failed");
 }

 nLarge = 0;
 while (mps_alloc(&largeObjects[nLarge], pool, BIGSIZE) == MPS_RES_OK) {
  nLarge ++;
 }

 report("nLarge", "%lu", nLarge);

 for (i = 0; i < NSMALL; i += 2) {
  mps_free(pool, smallObjects[i], SMALLSIZE);
 }

 comment("Freed every other small object.");

 /* The CBS should be in emergency mode now. */

 for (i = 0; i < nLarge; i += 2) {
  mps_free(pool, largeObjects[i], BIGSIZE);
 }

 comment("Freed every other large object.");

 /* Now there should be lots of big blocks on the CBS. */

 mps_arena_commit_limit_set(arena, COMLIMIT2);

 comment("Raised the commit limit. Will attempt free and alloc.");
 mps_free(pool, largeObjects[1], BIGSIZE);
 die(mps_alloc(&largeObjects[0], pool, BIGSIZE), "alloc failed");

 mps_pool_destroy(pool);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
}
Beispiel #6
0
static void test(void *stack_pointer)
{
 mps_thr_t thread;
 mps_pool_t pool;
 mps_addr_t a;
 char *c;

 cdie(mps_arena_create(&arena, mps_arena_class_vm(),
  (size_t) (1024*1024*50)), "create arena");
 cdie(mps_thread_reg(&thread, arena), "register thread");

 MPS_ARGS_BEGIN(args) {
   MPS_ARGS_ADD(args, MPS_KEY_POOL_DEBUG_OPTIONS, &debugOpts);
   die(mps_pool_create_k(&pool, arena, mps_class_mvff_debug(), args),
       "create MVFF pool");
 } MPS_ARGS_END(args);
 die(mps_alloc(&a, pool, 64), "alloc a");
 
 c = a;
 c -= 1;
 *c = 0;
 
 mps_pool_check_fenceposts(pool);
 comment("Fencepost check.");

 c += 67;
 *c = 0;

 mps_pool_check_fenceposts(pool);
 comment("Fencepost check.");

 mps_pool_destroy(pool);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
}
Beispiel #7
0
static void test(void) {
 mps_thr_t thread;
 mps_pool_t pool;
 mps_addr_t a;
 char * c;

 cdie(mps_arena_create(&arena, mps_arena_class_vm(),
  (size_t) (1024*1024*50)), "create arena");
 cdie(mps_thread_reg(&thread, arena), "register thread");

 die(mps_pool_create(&pool, arena, mps_class_mvff_debug(), &debugOpts,
                     (size_t)8192, (size_t)8, (mps_align_t)8,
                     (mps_bool_t)0, (mps_bool_t)1, (mps_bool_t)0),
     "create MVFF pool");

 die(mps_alloc(&a, pool, 63), "alloc a");
 
 c = a;
 c += 63;
 *c = 0;

 mps_free(pool, a, 63);

 mps_pool_destroy(pool);
 mps_thread_dereg(thread);
 mps_arena_destroy(arena);
}
Beispiel #8
0
static void test(void)
{
 mps_arena_t arena;
 mps_pool_t pool;
 mps_pool_t pool1;
 size_t extendBy;
 size_t avgSize;
 size_t maxSize;

 mps_addr_t obj;

 extendBy = (size_t) 4096;
 avgSize  = (size_t) 32;
 maxSize  = (size_t) 65536;

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

 cdie(
  mps_pool_create(&pool, arena, mps_class_mv(),
   extendBy, avgSize, maxSize),
  "create pool 0");

 cdie(
  mps_pool_create(&pool1, arena, mps_class_mv(),
   extendBy, avgSize, maxSize),
  "create pool 1");

 cdie(mps_alloc(&obj, pool, 152), "allocate in 0");

 mps_free(pool, obj, 512);
 comment("Freed in 1.");

}
Beispiel #9
0
static void test(void *stack_pointer)
{
 mps_pool_t pool = malloc(4096);
 mps_addr_t obj;

 cdie(mps_alloc(&obj, pool, 152), "allocate");
}
static void test(void)
{
 mps_space_t space;
 mps_pool_t pool;
 mps_thr_t thread;

 size_t mysize;
 mps_addr_t a;

 cdie(mps_space_create(&space), "create space");

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

 mysize = 8;

 cdie(
  mps_pool_create(
     &pool, space, mps_class_mfs(), (size_t) 8, mysize),
  "create pool");

 mps_alloc(&a, pool, mysize);
 mps_free(pool, NULL, mysize);
 mps_pool_destroy(pool);

}
Beispiel #11
0
static void test(void *stack_pointer)
{
 mps_arena_t arena;
 mps_pool_t pool;
 mps_thr_t thread;

 size_t mysize;
 mps_addr_t a;

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

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

 mysize = 16;

 cdie(
  mps_pool_create(
     &pool, arena, mps_class_mfs(), mysize, mysize),
  "create pool");

 cdie(mps_alloc(&a, pool, mysize), "alloc");
 mps_free(pool, (mps_addr_t) ((char *)a+8), mysize);
 mps_pool_destroy(pool);

}
static void test(void)
{
 mps_space_t space;
 mps_pool_t pool;
 mps_thr_t thread;

 size_t mysize;
 mps_addr_t a;

 cdie(mps_space_create(&space), "create space");

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

 mysize = 16;

 cdie(
  mps_pool_create(
     &pool, space, mps_class_mfs(), mysize, mysize),
  "create pool");

 cdie(mps_alloc(&a, pool, mysize), "alloc");
 mps_free(pool, (mps_addr_t) ((char *)a+8), mysize);
 error("free");
 mps_pool_destroy(pool);

}
static void test(void) {
 int i;
 mps_addr_t a;

/* create an arena with chunk size of 2 M */

 cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) (1024*1024*20)),
  "create arena");

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

/* set the commit limit to 10MB */

 report_res("commit0",
  mps_arena_commit_limit_set(arena, (size_t) (1024*1024*10)));


/* create a pool */

 cdie(mps_pool_create(&pool, arena, mps_class_mv(), (size_t) 64, (size_t) 64, (size_t) 64), "pool create");
 
 for (i=0; i<200; i++) {
  report("count", "%i", i);
  die(mps_alloc(&a, pool, (size_t) 1024*1024), "alloc");
 }

 mps_pool_destroy(pool);

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

}
Beispiel #14
0
static void test(void *stack_pointer)
{
  mps_arena_t arena;
  mps_pool_t pool;
  mps_addr_t block[ITERATIONS];
  unsigned i;

  MPS_ARGS_BEGIN(args) {
    MPS_ARGS_ADD(args, MPS_KEY_ARENA_SIZE, CHUNKSIZE);
    die(mps_arena_create_k(&arena, mps_arena_class_vm(), args), "arena_create");
  } MPS_ARGS_END(args);

  MPS_ARGS_BEGIN(args) {
    MPS_ARGS_ADD(args, MPS_KEY_SPARE, 0);
    die(mps_pool_create_k(&pool, arena, mps_class_mvff(), args), "pool_create");
  } MPS_ARGS_END(args);
  check_chunks(arena, 1);

  for (i = 0; i < ITERATIONS; ++i) {
    die(mps_alloc(&block[i], pool, CHUNKSIZE), "mps_alloc");
    check_chunks(arena, i + 2);
  }

  for (i = ITERATIONS; i > 0; --i) {
    mps_free(pool, block[i - 1], CHUNKSIZE);
    mps_arena_collect(arena); /* ensure ArenaCompact is called */
    check_chunks(arena, i);
  }

  mps_pool_destroy(pool);
  mps_arena_destroy(arena);
}
Beispiel #15
0
static void test(void)
{
 mps_arena_t arena;
 mps_pool_t pool;
 size_t extendBy;
 size_t avgSize;
 size_t maxSize;

 mps_addr_t obj;

 extendBy = (size_t) 4096;
 avgSize  = (size_t) 32;
 maxSize  = (size_t) 65536;

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

 cdie(
  mps_pool_create(&pool, arena, mps_class_mv(),
   extendBy, avgSize, maxSize),
  "create pool");

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

 cdie(mps_alloc(&obj, pool, 152), "allocate");

 mps_arena_destroy(arena);
 comment("Destroyed arena.");
}
static void alignmentTest(mps_arena_t arena)
{
  mps_pool_t pool;
  void *p;
  int dummy = 0;
  size_t j, size;

  die(mps_pool_create(&pool, arena, mps_class_mv(), 0x1000, 1024, 16384),
      "alignment pool create");
  size = max(sizeof(double), sizeof(long));
#ifdef HAS_LONG_LONG
  size = max(size, sizeof(long_long_t));
#endif
  for(j = 0; j <= size + (size_t)1; ++j) {
    die(mps_alloc(&p, pool, size + 1), "alignment alloc");

#define access(type, p) *(type*)(p) = (type)dummy; dummy += (int)*(type*)(p);

    access(double, p);
    access(long, p);
#ifdef HAS_LONG_LONG
    access(long_long_t, p);
#endif
  }
  mps_pool_destroy(pool);
}
Beispiel #17
0
static void test(void) {
 mps_arena_t arena;
 mps_pool_t pool;
 mps_thr_t thread;
 mps_fmt_t format;
 mps_root_t root;
 mps_addr_t q;

 int p;

 die(mps_arena_create(&arena, mps_arena_class_vm(), mmqaArenaSIZE), "create");
 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_pool_create(&pool, arena, mps_class_mv(),
  1024*32, 1024*16, 1024*256), "pool");

 while (mps_alloc(&q, pool, 64*1024)==MPS_RES_OK);
 p=0;

 while (1) {
  p++;
  die(mps_fmt_create_A(&format, arena, &fmtA), "create format");
  report("format", "%i", p);
 }

 asserts(1, "Unreachable!");
}
Beispiel #18
0
/** Tries to reclaim as much of the reserve as is more valuable than the
    given cost. Returns success. */
static Bool mm_reserve_get(mm_cost_t limit)
{
  mps_res_t res;

  HQASSERT( mm_reserve_level >= 0 &&
            mm_reserve_level <= mm_reserve_numlevels,
            "mm_reserve_get: mm_reserve_level is invalid" );

  while ( mm_reserve_level > 0
          && mm_cost_less_than(limit,
                               mm_reserve_table[mm_reserve_level-1].cost) ) {
    res = mps_alloc( & mm_reserve_table[mm_reserve_level - 1].ptr,
                     mm_pool_reserve,
                     (size_t)mm_reserve_table[mm_reserve_level - 1].size );
    if ( res != MPS_RES_OK )
      return FALSE;
    mm_reserve_level--;
    MM_LOG(( LOG_RG, "%u 0x%08x 0x%08x",
             mm_reserve_level + 1,
             (unsigned)mm_reserve_table[mm_reserve_level].ptr,
             mm_reserve_table[mm_reserve_level].size ));
  }
  if ( mm_reserve_level == 0 && mm_commit_limit == mm_commit_base ) {
#if defined(DEBUG_BUILD)
    if ( debug_lowmemory_count > 0 )
      --debug_lowmemory_count;
    else
#endif
      mm_memory_is_low = FALSE;
  }
  return TRUE;
}
Beispiel #19
0
static mps_addr_t allocObject(mps_pool_t pool, size_t size)
{
  mps_addr_t addr;
  die(mps_alloc(&addr, pool, size),
      "Allocate Object");
  return addr;
}
Beispiel #20
0
static void test(void)
{
    mps_arena_t arena;
    mps_pool_t pool;
    mps_thr_t thread;

    size_t mysize;
    mps_addr_t a;

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

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

    mysize = 8;

    cdie(
        mps_pool_create(
            &pool, arena, mps_class_mfs(), (size_t) 8, mysize),
        "create pool");

    mps_alloc(&a, pool, mysize);
    mps_free(NULL, a, mysize);
    mps_pool_destroy(pool);

}
Beispiel #21
0
static void test(void) {
 mps_arena_t arena;
 mps_pool_t pool;
 mps_addr_t q, r;
 int p;

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

 die(mps_pool_create(&pool, arena, mps_class_mv(),
  1024*32, 1024*16, 1024*256), "pool");

 die(mps_alloc(&q, pool, 1024*1024), "alloc");

 for (p=0; p<2000; p++) {
  report("promise", "%i", p);
  die(mps_alloc(&r, pool, 1024*1024), "alloc");
  mps_free(pool, q, 256*1024-8);
  q = (mps_addr_t) ((char *) r + 8);
 }
}
Beispiel #22
0
static void test(void) {
 mps_arena_t arena;
 mps_pool_t pool;
 mps_addr_t q;

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

 cdie(mps_pool_create(&pool, arena, mps_class_mv(),
  1024*32, 1024*16, 1024*256), "pool");

 cdie(mps_alloc(&q, pool, (size_t) -1), "alloc");

 mps_pool_destroy(pool);
 mps_arena_destroy(arena);
}
static void test(void) {
 mps_space_t space;
 mps_pool_t pool;
 mps_addr_t q;

 cdie(mps_space_create(&space), "create");

 cdie(mps_pool_create(&pool, space, mps_class_mv(),
  1024*32, 1024*16, 1024*256), "pool");

 cdie(mps_alloc(&q, pool, (size_t) -1), "alloc");

 mps_pool_destroy(pool);
 mps_space_destroy(space);
}
Beispiel #24
0
Datei: 228.c Projekt: bhanug/mps
static void test(void)
{
  mps_arena_t arena;
  mps_pool_t pool;
  mps_addr_t p;

  die(mps_arena_create_k(&arena, mps_arena_class_vm(), mps_args_none),
      "arena_create");
  die(mps_pool_create_k(&pool, arena, mps_class_mvff(), mps_args_none),
      "pool_create");
  die(mps_alloc(&p, pool, 4096), "alloc");
  die(mps_finalize(arena, &p), "finalize");

  mps_pool_destroy(pool);
  mps_arena_destroy(arena);
}
Beispiel #25
0
static void test(void *stack_pointer)
{
 mps_arena_t arena;
 mps_pool_t pool;
 mps_addr_t obj;

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

 cdie(mps_pool_create_k(&pool, arena, mps_class_mvff(), mps_args_none), "pool");

 cdie(mps_alloc(&obj, pool, 152), "allocate");

 mps_free(pool, obj, 512);

 mps_pool_destroy(pool);
 mps_arena_destroy(arena);
}
Beispiel #26
0
static void fillup(void)
{
 size_t size;
 mps_addr_t a;
 char *b;

 mps_pool_create(&poolmv, arena, mps_class_mv(), 64, 64, 64);
 size=1024ul*1024ul;
 while (size) {
  while (mps_alloc(&a, poolmv, size)==MPS_RES_OK) {
   for(b=a; b<(char *)a+size; b++) {
    *b = 97;
   }
  }
  size = size / 2;
 }
}
static void test(void) {
 mps_space_t space;
 mps_pool_t pool;
 mps_addr_t q;
 int p;

 die(mps_space_create(&space), "create");

 die(mps_pool_create(&pool, space, mps_class_mv(),
  1024*32, 1024*16, 1024*256), "pool");

 for (p=0; p<2000; p++) {
  die(mps_alloc(&q, pool, 1024*1024), "alloc");
  q = (mps_addr_t) ((char *) q + 8);
  mps_free(pool, q, 256*1024-8);
  report("promise", "%i", p);
 }
}
Beispiel #28
0
static void ps_write(int8 level, OBJECT *dest, OBJECT *src)
{
  corecontext_t *corecontext = get_core_context() ;

  /* Save it if the array will survive the object being written into it. */
  if (level < (theMark(*src) & SAVEMASK)) {
    void *p;
    saveRecord *sl;
    size_t saveIndex = NUMBERSAVES(corecontext->savelevel);

    die(mps_alloc(&p, savePool, sizeof(saveRecord)), "save alloc");
    sl = (saveRecord *)p;
    sl->slot = dest;
    Copy( &sl->oldvalue, dest );
    sl->next = saves[saveIndex]; saves[saveIndex] = sl;
    SETSLOTSAVED(*dest, FALSE, corecontext);
  }
  Copy(dest, src);
}
static void test(void)
{
 mps_space_t space;
 mps_pool_t pool;
 mps_fmt_t format;
 mps_fmt_A_s fmtA;

 mps_addr_t obj;

 cdie(mps_space_create(&space), "create space");

 fmtA.align = (mps_align_t) 1;
 fmtA.scan  = &zilch;
 fmtA.skip  = &myskip;
 fmtA.copy  = &zilch;
 fmtA.fwd   = &zilch;
 fmtA.isfwd = &zilch;
 fmtA.pad   = &zilch;

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

 cdie(
  mps_pool_create(&pool, space, mps_class_lo(), format),
  "create pool");

 cdie(mps_alloc(&obj, pool, 152), "allocate");

 mps_free(pool, obj, 152);
 comment("Freed.");

 mps_free(pool, obj, 152);
 comment("Freed again.");

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

 mps_space_destroy(space);
 comment("Destroyed space.");
}
Beispiel #30
0
static mps_res_t allocMultiple(PoolStat stat)
{
  mps_addr_t objects[contigAllocs];
  int i;

  /* allocate a few objects, and record stats for them */
  for (i = 0; i < contigAllocs; i++) {
    mps_addr_t obj;
    mps_res_t res = mps_alloc(&obj, stat->pool, stat->objSize);
    if (res != MPS_RES_OK)
      return res;
    recordNewObjectStat(stat, obj);
    objects[i] = obj;
  }

  /* free one of the objects, to make the test more interesting */
  i = rnd() % contigAllocs;
  mps_free(stat->pool, objects[i], stat->objSize);
  recordFreedObjectStat(stat);

  return MPS_RES_OK;
}