static void checkloop(mycell *obj, int dir) { mycell *toj; int tid; int i; asserts(obj->tag == MCdata, "checkfrom: non data object in graph at %p.", obj); if (obj->data.checkedflag != dir) { commentif(checkcomments, "checking %p = %li", obj, obj->data.id); checkobjcount += 1; obj->data.checkedflag = dir; for (i=0; i<(obj->data.numrefs); i+=1) { if (obj->data.ref[i].addr != NULL) { toj = (obj->data.ref[i].addr); tid = (obj->data.ref[i].id); asserts(toj->data.id == tid, "checkfrom: corrupt graph at %p, %d.", obj, i); checkloop(toj, dir); } } } }
int main(int o_argc, const string const* o_argv) { struct sembuf _buf; _buf.sem_num = 0; _buf.sem_flg = 0; string _path = getExecPath("sys_v_sem"); key_t _key = ftok(_path, 'x'); asserts(_key, "ftok"); free(_path); _path = NULL; /* Try to obtain an id of the set of semaphores. */ int _semid = semget(_key, 1, S_IRUSR | S_IWUSR); asserts(_semid); /* lock the semaphore */ _buf.sem_op = -1; asserts( semop(_semid, &_buf, 1) ); /* enter critical section */ for(size_t i = 0; i < 5; i++) { printfln( "Hello!, %ld", cast(ulong)getpid() ); sleep(1); } println(""); /* unlock the semaphore */ _buf.sem_op = 1; asserts( semop(_semid, &_buf, 1) ); exit(EXIT_SUCCESS); }
static void tracegraph(mycell *obj) { int i; if (obj == NULL) { return; } asserts((obj->tag & 3) == MCdata, "odd check at %p (%p)", obj, obj->tag); if (obj->data.checkedflag == oldstamp) { obj->data.checkedflag = newstamp; if (obj->data.assoc != NULL) { tracegraph(obj->data.assoc); } for (i=0; i<(obj->data.numrefs); i++) { if (obj->data.ref[i].addr != NULL) { tracegraph(obj->data.ref[i].addr); } } } else { asserts(obj->data.checkedflag == newstamp, "I. trace on old object at %p", obj); } }
static mps_res_t myscan(mps_ss_t ss, mps_addr_t base, mps_addr_t limit) { int i; INCCOUNT(SCANCALL_COUNT); MPS_SCAN_BEGIN(ss) { while (base < limit) { mycell *obj = base; mps_res_t res; mps_addr_t p; switch (obj->tag) { case MCpadsingle: INCCOUNT(SCANPS_COUNT); base = (mps_addr_t) ((char *) obj + MPS_PF_ALIGN); break; case MCpadmany: INCCOUNT(SCANPM_COUNT); base = (obj->padmulti.next); break; case MCdata: INCCOUNT(SCANOBJ_COUNT); /* actual scanning is done in here */ asserts(obj->data.id != MCerrorid, "scan on error object"); commentif(formatcomments, "scan %li at %p.", obj->data.id, base); for (i=0; i<(obj->data.numrefs); i++) { p = obj->data.ref[i].addr; if (p != NULL) { /* copy ref to p for fixing, to avoid a pun (although the pun would probably work fine almost everywhere) */ commentif(fixcomments, "fix %li[%i] -> %li", obj->data.id, i, obj->data.ref[i].id); res = MPS_FIX(ss, (mps_addr_t *) &p); if (res != MPS_RES_OK) return res; obj->data.ref[i].addr = p; } } base = (mps_addr_t) ((char *) obj + (obj->data.size)); break; case MCheart: INCCOUNT(SCANHEART_COUNT); base = (mps_addr_t) ((char *) obj + (obj->heart.size)); break; default: asserts(0, "scan: bizarre obj tag at %p.", obj); } } } MPS_SCAN_END(ss); return MPS_RES_OK; }
void setref(mycell *obj, int n, mycell *to) { asserts(obj->tag == MCdata, "setref: from non-data object."); asserts((to==NULL)||(to->tag == MCdata), "setref: to non-data object."); asserts(obj->data.numrefs > n, "setref: access beyond object size."); obj->data.ref[n].addr = to; obj->data.ref[n].id = (to==NULL ? 0 : to->data.id); }
int main(int o_argc, const_stringv_t o_argv) { if(o_argc < 2) { println("Usage: client values ..."); exit(EXIT_SUCCESS); } byte _buffer[MSG_SIZE]; /* recieved message buffer */ struct st_msg _stout ; /* send message data structure */ Msg _msg, _out ; /* send and recieved message references */ size_t _msglen ; /* length of the send message string */ _out = &_stout; key_t _key ; /* IPC key */ int _handle; /* IPC id */ struct msgbuf* _msgbuf = cast(struct msgbuf*)_buffer; /* open an existing quaue */ asserts( _key = ftok(".", 'x') ); asserts( _handle = msgget(_key, S_IRUSR | S_IWUSR) ); _out->from = getpid() ; /* set 'from' field into current process id */ _out->to = 1 ; /* set 'to' field into 1 which means server */ _out->length = o_argc - 1; /* set vector length to number of command line arguments */ /* allocate space for apropriate number of values */ assertnz( _out->values = malloc(sizeof(int) * _out->length) ); /* setup values */ for(size_t i = 0; i < _out->length; i++) { _out->values[i] = atoi(o_argv[i + 1]); } /* prepare message buffer */ _msgbuf->mtype = _out->to; assertnz( msg_save(_out, _msgbuf->mtext, MSG_SIZE - sizeof(long) ) ); _msglen = strlen(_msgbuf->mtext) + sizeof(msgbuf); assertnz(_msglen <= MSG_SIZE); /* respect the message size limit */ /* send the request */ asserts( msgsnd(_handle, _msgbuf, _msglen, 0) ); /* wait for the respose */ asserts( msgrcv(_handle, _msgbuf, MSG_SIZE, _out->from, 0) ); assertnz( _msg = msg_load(_msgbuf->mtext) ); /* write the respose into the standard output */ println("client recieved:"); println(_msgbuf->mtext); _msg = msg_destroy(_msg); exit(EXIT_SUCCESS); }
static void mycopy(mps_addr_t object, mps_addr_t to) { locell *boj = object; locell *toj = to; asserts(allowlocopies, "locopy on LO object"); asserts(boj->tag == LOdata, "locopy: non-data object"); memmove(to, object, boj->data.size); toj->data.copycount = (toj->data.copycount)+1; }
static void process_mess(mps_message_t message, int faction, mps_addr_t *ref) { mps_addr_t ffref; switch (faction) { case FINAL_DISCARD: mps_message_discard(arena, message); break; case FINAL_REREGISTER: mps_message_finalization_ref(&ffref, arena, message); mps_finalize(arena, &ffref); final_count +=1; mps_message_discard(arena, message); break; case FINAL_STORE: mps_message_finalization_ref(ref, arena, message); mps_message_discard(arena, message); break; case FINAL_QUEUE: nq(message); break; default: asserts(0, "Unknown finalization action."); } }
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!"); }
static void mypad(mps_addr_t base, size_t size) { locell *obj = base; asserts(size >= MPS_PF_ALIGN, "pad: size too small."); if (size == MPS_PF_ALIGN) { asserts(sizeof(obj->padsingle) <= MPS_PF_ALIGN, "impossible pad"); obj->padsingle.tag = LOpadsingle; } else { asserts(size >= sizeof(struct lopadmulti), "pad: awkward size."); obj->padmulti.tag = LOpadmany; obj->padmulti.next = (mps_addr_t) ((char *) base + size); } }
std::unique_ptr<VMFace> VMFactory::create(u256 _gas) { #if ETH_EVMJIT return std::unique_ptr<VMFace>(g_kind == VMKind::JIT ? static_cast<VMFace*>(new JitVM(_gas)) : static_cast<VMFace*>(new VM(_gas))); #else asserts(g_kind == VMKind::Interpreter && "JIT disabled in build configuration"); return std::unique_ptr<VMFace>(new VM(_gas)); #endif }
static void test_apply(mps_addr_t addr, void *V, size_t S) { mycell *a; long int id; asserts(S == MAGICSIZE, "Size didn't get passed!"); a = addr; asserts(((a->tag) & 0x3) == MCdata || ((a->tag) & 0x3) == MCpad, "apply on non-data and non-pad object at %p", addr); if (((a->tag) & 0x3) == MCdata) { appcount += 1; id = getid(a); if (id < cutoff_id) { junk_size += a->data.size; } } else { apppadcount +=1; } }
static void mypad(mps_addr_t base, size_t size) { mycell *obj = base; asserts(size >= MPS_PF_ALIGN, "pad: size too small."); if (size == MPS_PF_ALIGN) { INCCOUNT(PAD_SINGLE_COUNT); asserts(sizeof(obj->padsingle) <= MPS_PF_ALIGN, "impossible pad"); obj->padsingle.tag = MCpadsingle; } else { asserts(size >= sizeof(struct padmulti), "pad: awkward size."); INCCOUNT(PAD_MULTI_COUNT); obj->padmulti.tag = MCpadmany; obj->padmulti.next = (mps_addr_t) ((char *) base + size); } }
static void root_step(mps_addr_t* ref, mps_root_t r, void *V, size_t S) { mycell *a; mycell *spec; spec = (mycell *) V; asserts(S == MAGICSIZE, "VII. Size didn't get passed!"); asserts((r == root || r == root1 || r == root2), "Root didn't get passed!"); a = *ref; comment("root: %p -> %p", ref, a); rootcount++; if (spec == a) { speccount++; } if (r != root) { asserts(((a->tag) & 0x3) == MCdata, "spurious ref claimed in root at %p->%p", ref, a); a->data.checkedflag = newstamp; } }
static void test(void) { mps_arena_t arena, previousArena = NULL; mps_res_t res; size_t size = (size_t)(1024*1024*10L); int p = 0, i; /* make sure you can create at least 10 */ while ((res = mps_arena_create(&arena, mps_arena_class_vm(), size)) == MPS_RES_OK) { p++; report("arena", "%i", p); } asserts(res == MPS_RES_RESOURCE, "wrong error loop"); /* fill address space with arenas */ while (size > 2 * minArenaSIZE) { size /= 2; res = mps_arena_create(&arena, mps_arena_class_vm(), size); asserts(res == MPS_RES_OK || res == MPS_RES_RESOURCE, "error fill"); if (res == MPS_RES_OK) p++; } report("arena2", "%i", p); report("size", "%i", size); /* there could still be holes, fill some more */ while ((res = mps_arena_create(&arena, mps_arena_class_vm(), minArenaSIZE)) == MPS_RES_OK) { p++; previousArena = arena; } mps_arena_destroy(previousArena); report("arena3", "%i", p); /* test that you can create and fail without leaking */ for (i = 0; i < minArenaSIZE / 1024; ++i) { res = mps_arena_create(&arena, mps_arena_class_vm(), (size_t)(1024*1024*10L)); asserts(res == MPS_RES_RESOURCE, "error leak"); die(mps_arena_create(&arena, mps_arena_class_vm(), minArenaSIZE), "leak"); report("arena_tight", "%i", i); mps_arena_destroy(arena); } }
static void stepper(mps_addr_t addr, mps_fmt_t fmt, mps_pool_t pool, void *V, size_t S) { mycell *a; asserts((mycell *) V == MAGICPOINT, "VII. Void * didn't get passed!"); asserts(S == MAGICSIZE, "VII. Size didn't get passed!"); asserts(fmt == format, "VII. Format didn't get passed!"); a = addr; asserts(((a->tag) & 0x3) == MCdata || ((a->tag) & 0x3) == MCpad, "V. step onto bad object at %p", addr); if (((a->tag) & 0x3) == MCdata) { appcount += 1; asserts(a->data.checkedflag != newstamp, "III/IV. step on object again at %p", a); commentif(a->data.checkedflag != oldstamp, "*. step on unreachable object at %p", a); a->data.checkedflag = newstamp; } else { apppadcount +=1; } }
static void checklds(void) { int i; for (i=0; i < MAXLDS; i++) { if (obj_table[i]->data.copycount != 0) { asserts(mps_ld_isstale(lds[i], space, (mps_addr_t) obj_table[i]), "%d isn't stale but should be", i); if (ranint(4) == 0) { obj_table[i]->data.copycount = 0; mps_ld_reset(lds[i], space); comment("reset %d", i); mps_ld_add(lds[i], space, (mps_addr_t) obj_table[i]); } } } }
static int checklds(int merge) { int i, j, k, thisstale, stalecount; stalecount = 0; for (i=0; i < MAXLDS; i++) { thisstale = 0; for (j=0; j < merge; j++) { k = (i+j) % MAXLDS; if (obj_table[k] != addr_table[k]) { thisstale = 1; asserts(mps_ld_isstale(ldm[i], arena, (mps_addr_t) obj_table[k]), "%d isn't stale but should be", i); } } stalecount += thisstale; } return stalecount; }
static mps_addr_t myskip(mps_addr_t object) { locell *obj = object; switch(obj->tag) { case LOpadsingle: return (mps_addr_t) ((char *) obj + MPS_PF_ALIGN); case LOpadmany: return obj->padmulti.next; case LOheart: return (mps_addr_t) ((char *) obj + (obj->heart.size)); case LOdata: return (mps_addr_t) ((char *) obj + (obj->data.size)); default: asserts(0, "loskip: bizarre obj tag at %p.", obj); return 0; /* not reached */ } }
static void myfwd(mps_addr_t object, mps_addr_t to) { locell *obj = object; size_t size; asserts(obj->tag == LOdata || obj->tag == LOheart, "lofwd: unexpected object tag at %p.", obj); if (obj->tag == LOdata) { size = obj->data.size; } else /* obj->tag == LOheart */ { size = obj->heart.size; } obj->data.tag = LOheart; obj->heart.obj = to; obj->heart.size = size; }
constant_string_t err_text(mps_res_t err) { switch (err) { case MPS_RES_OK: return "OK"; case MPS_RES_FAIL: return "FAIL"; case MPS_RES_RESOURCE: return "RESOURCE"; case MPS_RES_MEMORY: return "MEMORY"; case MPS_RES_LIMIT: return "LIMIT"; case MPS_RES_UNIMPL: return "UNIMPL"; case MPS_RES_IO: return "IO"; #ifdef MMQA_SYMBOL_MPS_RES_COMMIT_LIMIT case MPS_RES_COMMIT_LIMIT: return "COMMIT_LIMIT"; #endif #ifdef MMQA_SYMBOL_MPS_RES_PARAM case MPS_RES_PARAM: return "PARAMETER"; #endif } asserts(0, "Unknown result code"); return "*** Unknown result code ***"; }
static void myfwd(mps_addr_t object, mps_addr_t to) { mycell *obj = object; size_t size; asserts(obj->tag == MCdata || obj->tag == MCheart, "fwd: unexpected object tag at %p.", obj); INCCOUNT(FWD_COUNT); if (obj->tag == MCdata) { size = obj->data.size; } else /* obj->tag == MCheart */ { size = obj->heart.size; } obj->data.tag = MCheart; obj->heart.obj = to; obj->heart.size = size; }
static void mycopy(mps_addr_t object, mps_addr_t to) { mycell *boj = object; mycell *toj = to; asserts(boj->tag == MCdata, "copy: non-data object"); INCCOUNT(COPY_COUNT); commentif(formatcomments, "copy: %li: %p -> %p\n", boj->data.id, object, to); /* this line would be bad, because the objects might overlap, and then C doesn't guarantee to do the right thing! *toj = *boj; */ memmove(to, object, boj->data.size); if (!freeze) { toj->data.copycount = (toj->data.copycount)+1; if (toj->data.copycount > maxcopy) maxcopy = toj->data.copycount; } }
static void test(void) { mps_arena_t arena; 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[3]; int i,j,k; clock_t time0, time1; formatcomments = 1; cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t)1024*1024*30), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie(mps_root_create_table(&root, arena, mps_rank_ambig(), 0, (mps_addr_t*)&a[0], 3), "create table root"); cdie(mps_root_create_table(&root1, arena, mps_rank_ambig(), 0, (mps_addr_t *)&exfmt_root, 1), "exfmt 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"); time0 = clock(); asserts(time0 != -1, "processor time not available"); for (k=0; k<100; k++) { for (j=0; j<100; j++) { a[0] = allocone(ap, 50, mps_rank_exact()); a[1] = a[0]; for (i=1; i<100; i++) { a[2] = allocone(ap, 50, mps_rank_exact()); setref(a[1], 0, a[2]); a[1] = a[2]; } } time1 = clock(); comment("%d: %i", k, (int) (100*(time1-time0)/CLOCKS_PER_SEC)); time0 = time1; } 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."); }
int main(int argc, char *argv[]) { std::string testSuite; std::string testFillString; json_spirit::mValue testmValue; bool checktest = false; bool filldebug = false; bool debug = false; bool filltest = false; for (auto i = 0; i < argc; ++i) { auto arg = std::string{argv[i]}; dev::test::Options& options = const_cast<dev::test::Options&>(dev::test::Options::get()); if (arg == "--fulloutput") options.fulloutput = true; else if (arg == "-t" && i + 1 < argc) { testSuite = argv[i + 1]; if (testSuite != "BlockChainTests" && testSuite != "TransactionTests" && testSuite != "StateTests" && testSuite != "VMTests") testSuite = ""; } else if ((arg == "-checktest" || arg == "-filltest") && i + 1 < argc) { std::string s; for (int j = i+1; j < argc; ++j) s += argv[j]; if (asserts(s.length() > 0)) { std::cout << "Error! Content of argument is empty! (Usage -checktest textstream) \n"; return 1; } if (arg == "-filltest") { testFillString = s; filltest = true; } else { read_string(s, testmValue); checktest = true; } } else if (arg == "--debug") debug = true; else if (arg == "--filldebug") filldebug = true; } if (testSuite == "") { std::cout << "Error! Test suite not supported! (Usage -t TestSuite)"; return 1; } else { if (checktest) std::cout << "Testing: " << testSuite.substr(0, testSuite.length() - 1) << std::endl; if (testSuite == "BlockChainTests") { if (checktest) return checkRandomTest(dev::test::doBlockchainTests, testmValue, debug); else fillRandomTest(dev::test::doBlockchainTests, (filltest) ? testFillString : c_testExampleBlockchainTest, filldebug); } else if (testSuite == "TransactionTests") { if (checktest) return checkRandomTest(dev::test::doTransactionTests, testmValue, debug); else fillRandomTest(dev::test::doTransactionTests, (filltest) ? testFillString : c_testExampleTransactionTest, filldebug); } else if (testSuite == "StateTests") { if (checktest) return checkRandomTest(dev::test::doStateTests, testmValue, debug); else fillRandomTest(dev::test::doStateTests, (filltest) ? testFillString : c_testExampleStateTest, filldebug); } else if (testSuite == "VMTests") { if (checktest) { dev::eth::VMFactory::setKind(dev::eth::VMKind::JIT); return checkRandomTest(dev::test::doVMTests, testmValue, debug); } else fillRandomTest(dev::test::doVMTests, (filltest) ? testFillString : c_testExampleVMTest, filldebug); } } return 0; }
static void nq(mps_message_t mess) { mqueue[qhd] = mess; qhd = (qhd+1) % 10000; asserts(qhd != qtl, "No space in message queue."); }
int main(int o_argc, const string const* o_argv) { MyData _data; int _shmd; size_t _off ; const string SEM_NAME = "/posix_sem"; const string SHM_NAME = "/posix_shm"; /* Nowaday, memory is so cheap that I just do not care about the unused memory. * If is it too waste, then just compile with DYN_SEG_SIZE switch. **/ #ifndef DYN_SEG_SIZE const off_t SEG_SIZE = sizeof(mydata_t); #else off_t _segSz = sizeof(size_t); for(size_t i = 1; i < o_argc; i++) { _segSz += strlen(o_argv[i]) + 1; } #endif /* DYN_SEG_SIZE */ /* open/create semaphore and lock */ sem_t* _sem = sem_open(SEM_NAME, O_CREAT, S_IRUSR | S_IWUSR, 1); assertv(_sem, SEM_FAILED); assertz( sem_wait(_sem) ); /* Critical section: */ /* there is no arguments so print shared memory object content */ if(o_argc == 1) { /* obtain the descriptor of shared memory object */ asserts( _shmd = shm_open(SHM_NAME, O_RDONLY, S_IRUSR | S_IWUSR) ); /* map shared memory object into a virtual address */ #ifdef DYN_SEG_SIZE struct stat _buf; assertz( fstat(_shmd, &_buf) ); assertv(_data = mmap(NULL, _segSz = _buf.st_size, PROT_READ, MAP_SHARED, _shmd, 0), MAP_FAILED); #else assertv(_data = mmap(NULL, SEG_SIZE, PROT_READ, MAP_SHARED, _shmd, 0), MAP_FAILED); #endif /* DYN_SEG_SIZE */ /* read from shared memory object */ _off = 0; for(size_t i = 0; i < _data->len; i++) { print(_data->vals + _off); print(" "); _off += strlen(_data->vals + _off) + 1; } println(""); } /* write arguments in the reveres order into shared memory object */ else { #ifdef ALLOW_CLEANUP int _ret; /* if shared memory object already exist obtain its id and destroy, otherwise do nothing */ if( o_argc == 2 && !strcmp(o_argv[1], "cleanup") ) { _ret = shm_unlink(SHM_NAME); if(_ret == -1 && errno != ENOENT) asserts(_ret); /* destroy the semaphore before exit */ _ret = sem_unlink(SEM_NAME); if(_ret == -1 && errno != ENOENT) asserts(_ret); exit(EXIT_SUCCESS); } #endif /* ALLOW_CLEANUP */ /* use existing shared memory object or create the new one */ asserts( _shmd = shm_open(SHM_NAME, O_CREAT | O_RDWR, S_IRUSR | S_IWUSR) ); /* allocate a space for the maximum line length */ #ifdef DYN_SEG_SIZE assertz( ftruncate(_shmd, _segSz) ); #else assertz( ftruncate(_shmd, SEG_SIZE) ); #endif /* DYN_SEG_SIZE */ /* map shared memory object into virtual address */ #ifdef DYN_SEG_SIZE assertv(_data = mmap(NULL, _segSz, PROT_READ | PROT_WRITE, MAP_SHARED, _shmd, 0), MAP_FAILED); #else assertv(_data = mmap(NULL, SEG_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, _shmd, 0), MAP_FAILED); #endif /* DYN_SEG_SIZE */ /* write into the shared memory object */ _data->len = o_argc - 1; _off = 0; for(size_t i = o_argc - 1; i > 0; i--) { /* it is safe to use strcpy, because we got enought memory */ strcpy(_data->vals + _off, o_argv[i]); _off += strlen(o_argv[i]) + 1; } } /* unmap shared memory object from virtual address space */ #ifdef DYN_SEG_SIZE assertz( munmap(_data, _segSz) ); #else assertz( munmap(_data, SEG_SIZE) ); #endif /* DYN_SEG_SIZE */ _data = NULL; /* close the unused descriptor of shared memory object */ assertz( close(_shmd) ); /* unlock the semaphore */ assertz( sem_post(_sem) ); exit(EXIT_SUCCESS); }
static void test(void) { mps_pool_t poolmv, poolawl, poolamc; mps_thr_t thread; mps_root_t root0, root1, root2; mps_addr_t p; mps_fmt_t format; mps_chain_t chain; mps_ap_t apawl, apamc; mycell *a, *b; int i,j; RC; cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t)1024*1024*30), "create arena"); cdie(mps_thread_reg(&thread, arena), "register thread"); cdie(mps_root_create_table(&root0, arena, mps_rank_ambig(), 0, (mps_addr_t*)&exfmt_root, 1), "create exfmt root"); cdie(mps_root_create_table(&root2, arena, mps_rank_exact(), 0, (mps_addr_t *)obj_table, MAXLDS), "create table root"); cdie(mps_root_create_reg(&root1, arena, mps_rank_ambig(), 0, thread, mps_stack_scan_ambig, stackpointer, 0), "create register and stack 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(&poolawl, arena, mps_class_awl(), format, getassociated), "create awl pool"); cdie(mps_pool_create(&poolmv, arena, mps_class_mv(), 0x4000, 128, 0x4000), "create mv pool"); cdie(mps_ap_create(&apawl, poolawl, mps_rank_exact()), "create ap"); /* First we'll use only pool classes MV and AWL. So LDs shouldn't */ /* go stale at all. */ b = allocone(apawl, 5, mps_rank_exact()); for (i=0; i < MAXLDS; i++) { comment("%d", i); mps_alloc(&p, poolmv, sizeof(mps_ld_s)); a = allocone(apawl, 5, mps_rank_exact()); setref(a, 0, b); b = a; a = allocdumb(apawl, 256*1024, mps_rank_exact()); comment("alloc"); lds[i] = p; mps_ld_reset(lds[i], arena); comment("reset"); if (i>0) { mps_ld_add(lds[i], arena, (mps_addr_t) b); } comment("add"); } for (i=0; i < MAXLDS; i++) { comment("%d", i); asserts(mps_ld_isstale(lds[i], arena, p) == 0, "%d stale but shouldn't be", i); } /* Then use AMC, so object do move and LDs go stale. */ die(mmqa_pool_create_chain(&poolamc, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_ap_create(&apamc, poolamc, mps_rank_exact()), "create ap"); /* Allocate MAXLDS objects, and make each LD depend on the corresponding */ /* object. */ for (i=0; i < MAXLDS; i++) { comment("%d", i); obj_table[i] = allocone(apamc, ranint(100), mps_rank_exact()); mps_ld_add(lds[i], arena, (mps_addr_t) obj_table[i]); } for (i=0; i < 1000; i++) { comment("%d of 1000", i); checklds(); for (j=0; j < 8; j++) { a = allocdumb(apamc, 32*1024, mps_rank_exact()); } } mps_ap_destroy(apawl); mps_ap_destroy(apamc); mps_pool_destroy(poolmv); mps_pool_destroy(poolamc); mps_pool_destroy(poolawl); comment("Destroyed pools."); mps_chain_destroy(chain); mps_fmt_destroy(format); mps_root_destroy(root0); mps_root_destroy(root1); mps_root_destroy(root2); comment("Destroyed roots."); mps_thread_dereg(thread); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void dt(int kind, size_t extendBy, size_t avgSize, size_t maxSize, size_t mins, size_t maxs, int number, int iter) { mps_pool_t pool; int i, hd; clock_t time0, time1; size_t size; int secs; asserts(number <= MAXNUMBER, "number too big"); time0 = clock(); asserts(time0 != -1, "processor time not available"); die( mps_pool_create(&pool, arena, mps_class_mv(), extendBy, avgSize, maxSize), "create MV pool"); for(hd=0; hd<number; hd++) { size = ranrange(mins, maxs); if ((ranint(2) && (kind & 2)) || (kind==DUMMY)) { queue[hd].addr=NULL; } else { die(mps_alloc(&queue[hd].addr, pool, size), "alloc"); setobj(queue[hd].addr, size, (unsigned char) (hd%256)); queue[hd].size = size; } }; hd=-1; for(i=0; i<iter; i++) { if (kind & 1) hd = ranint(number); else {ranint(number); hd=(hd+1)%number;} /* call raninit anyway to use same time */ if (queue[hd].addr != NULL) { asserts(chkobj(queue[hd].addr, queue[hd].size, (unsigned char) (hd%256)), "corrupt at %x (%s: %x, %x, %x, %x, %x, %i, %i)", queue[hd].addr, tdesc[kind], (int) extendBy, (int) avgSize, (int) maxSize, (int) mins, (int) maxs, number, iter); mps_free(pool, queue[hd].addr, queue[hd].size); } size = ranrange(mins, maxs); if ((ranint(2) && (kind & 2)) || (kind==DUMMY)) { queue[hd].addr=NULL; } else { die(mps_alloc(&queue[hd].addr, pool, size),"alloc"); setobj(queue[hd].addr, size, (unsigned char) (hd%256)); queue[hd].size = size; } } mps_pool_destroy(pool); time1=clock(); secs=(int) 100*(time1-time0)/CLOCKS_PER_SEC; comment("%s test (%x, %x, %x, %x, %x, %i, %i) in %i centisecs", tdesc[kind], (int) extendBy, (int) avgSize, (int) maxSize, (int) mins, (int) maxs, number, iter, secs); }
static void check_chunks(mps_arena_t arena, unsigned expected) { unsigned chunks = (unsigned)RingLength(ArenaChunkRing((Arena)arena)); asserts(chunks == expected, "expected %u chunks, got %u", expected, chunks); }