static void messagepoll(mycell **ref, int faction) { mps_message_t message; if (mps_message_get(&message, arena, mps_message_type_finalization())) { final_count -=1; process_mess(message, faction, (mps_addr_t*)ref); } if (mps_message_get(&message, arena, mps_message_type_gc())) { process_stats(message); } }
/* legally finalized. */ static void report(mps_arena_t arena, int expect) { int found = 0; /* Test any finalized objects */ while (mps_message_poll(arena)) { mps_message_t message; mps_word_t *obj; mps_word_t objind; mps_addr_t objaddr; cdie(mps_message_get(&message, arena, mps_message_type_finalization()), "get"); found += 1; mps_message_finalization_ref(&objaddr, arena, message); obj = objaddr; objind = dylan_int_int(obj[vectorSLOT(0)]); printf("Finalizing: object %lu at %p\n", objind, objaddr); cdie(root[objind] == NULL, "finalized live"); cdie(state[objind] == finalizableSTATE, "not finalizable"); state[objind] = finalizedSTATE; mps_message_discard(arena, message); } if(found < expect) { printf("...expected %d finalizations, but got fewer: only %d!\n", expect, found); } else if(found > expect) { printf("...expected %d finalizations, but got more: %d!\n", expect, found); } }
static void report(mps_arena_t arena) { mps_message_t message; static int nCollections = 0; while (mps_message_get(&message, arena, mps_message_type_gc())) { size_t live, condemned, not_condemned; live = mps_message_gc_live_size(arena, message); condemned = mps_message_gc_condemned_size(arena, message); not_condemned = mps_message_gc_not_condemned_size(arena, message); printf("\nCollection %d finished:\n", ++nCollections); printf("live %lu\n", (unsigned long)live); printf("condemned %lu\n", (unsigned long)condemned); printf("not_condemned %lu\n", (unsigned long)not_condemned); mps_message_discard(arena, message); if (condemned > (gen1SIZE + gen2SIZE + (size_t)128) * 1024) /* When condemned size is larger than could happen in a gen 2 * collection (discounting ramps, natch), guess that was a dynamic * collection, and reset the commit limit, so it doesn't run out. */ die(mps_arena_commit_limit_set(arena, 2 * testArenaSIZE), "set limit"); } }
/* report -- get and check messages * * Get messages, report what was got, check they are the expected * messages, and (for finalization messages) check that these objects * should have been finalized (because we made them unreachable). * * .discard: The client should always call mps_message_discard when * it has finished with the message. But calling with the "discard" * parameter set to false lets us check how the MPS handles naughty * clients. The undiscarded messages must be cleared up by * ArenaDestroy. */ static void report(mps_arena_t arena, const char *pm, Bool discard) { int found = 0; char mFound = '\0'; mps_message_type_t type; while (mps_message_queue_type(&type, arena)) { mps_message_t message; mps_word_t *obj; mps_word_t objind; mps_addr_t objaddr; cdie(mps_message_get(&message, arena, type), "get"); found += 1; switch(type) { case mps_message_type_gc_start(): { printf(" Begin Collection\n"); mFound = 'b'; break; } case mps_message_type_gc(): { printf(" End Collection\n"); mFound = 'e'; break; } case mps_message_type_finalization(): { mps_message_finalization_ref(&objaddr, arena, message); obj = objaddr; objind = DYLAN_INT_INT(DYLAN_VECTOR_SLOT(obj, 0)); printf(" Finalization for object %"PRIuLONGEST" at %p\n", (ulongest_t)objind, objaddr); cdie(myroot[objind] == NULL, "finalized live"); cdie(state[objind] == finalizableSTATE, "not finalizable"); state[objind] = finalizedSTATE; mFound = 'f'; break; } default: { cdie(0, "message type"); break; } } if(discard) { mps_message_discard(arena, message); /* .discard */ } cdie('\0' != *pm, "Found message, but did not expect any"); cdie(mFound == *pm, "Found message type != Expected message type"); pm++; } mFound = '\0'; cdie(mFound == *pm, "No message found, but expected one"); }
static void finalpoll(mycell **ref, int faction) { mps_message_t message; if (mps_message_get(&message, arena, MPS_MESSAGE_TYPE_FINALIZATION)) { final_count -=1; process_mess(message, faction, (mps_addr_t*)ref); } }
static void report(mps_arena_t arena) { static int nCollsStart = 0; static int nCollsDone = 0; mps_message_type_t type; while(mps_message_queue_type(&type, arena)) { mps_message_t message; cdie(mps_message_get(&message, arena, type), "message get"); switch(type) { /* @@@@ is using these macros in a switch supported? */ case mps_message_type_gc_start(): { nCollsStart += 1; printf("\n{\n Collection %d started. Because:\n", nCollsStart); printf(" %s\n", mps_message_gc_start_why(arena, message)); printf(" clock: %"PRIuLONGEST"\n", (ulongest_t)mps_message_clock(arena, message)); break; } case mps_message_type_gc(): { size_t live, condemned, not_condemned; nCollsDone += 1; live = mps_message_gc_live_size(arena, message); condemned = mps_message_gc_condemned_size(arena, message); not_condemned = mps_message_gc_not_condemned_size(arena, message); printf("\n Collection %d finished:\n", nCollsDone); printf(" live %"PRIuLONGEST"\n", (ulongest_t)live); printf(" condemned %"PRIuLONGEST"\n", (ulongest_t)condemned); printf(" not_condemned %"PRIuLONGEST"\n", (ulongest_t)not_condemned); printf(" clock: %"PRIuLONGEST"\n", (ulongest_t)mps_message_clock(arena, message)); printf("}\n"); if(condemned > (gen1SIZE + gen2SIZE + (size_t)128) * 1024) { /* When condemned size is larger than could happen in a gen 2 * collection (discounting ramps, natch), guess that was a dynamic * collection, and reset the commit limit, so it doesn't run out. */ die(mps_arena_commit_limit_set(arena, 2 * testArenaSIZE), "set limit"); } break; } default: { cdie(0, "unknown message type"); break; } } mps_message_discard(arena, message); } return; }
static void report(mps_arena_t arena) { static int nCollsStart = 0; static int nCollsDone = 0; mps_message_type_t type; while(mps_message_queue_type(&type, arena)) { mps_message_t message; cdie(mps_message_get(&message, arena, type), "message get"); if (type == mps_message_type_gc_start()) { nCollsStart += 1; printf("\n{\n Collection %d started. Because:\n", nCollsStart); printf(" %s\n", mps_message_gc_start_why(arena, message)); printf(" clock: %"PRIuLONGEST"\n", (ulongest_t)mps_message_clock(arena, message)); } else if (type == mps_message_type_gc()) { size_t live, condemned, not_condemned; nCollsDone += 1; live = mps_message_gc_live_size(arena, message); condemned = mps_message_gc_condemned_size(arena, message); not_condemned = mps_message_gc_not_condemned_size(arena, message); printf("\n Collection %d finished:\n", nCollsDone); printf(" live %"PRIuLONGEST"\n", (ulongest_t)live); printf(" condemned %"PRIuLONGEST"\n", (ulongest_t)condemned); printf(" not_condemned %"PRIuLONGEST"\n", (ulongest_t)not_condemned); printf(" clock: %"PRIuLONGEST"\n", (ulongest_t)mps_message_clock(arena, message)); printf("}\n"); if(condemned > (gen1SIZE + gen2SIZE + (size_t)128) * 1024) { /* When condemned size is larger than could happen in a gen 2 * collection (discounting ramps, natch), guess that was a dynamic * collection, and reset the commit limit, so it doesn't run out. * * GDR 2013-03-12: Fiddling with the commit limit was causing * the test to fail sometimes (see job003440), so I've commented * out this feature. */ /* die(mps_arena_commit_limit_set(arena, 2 * testArenaSIZE), "set limit"); */ } } else { cdie(0, "unknown message type"); break; } mps_message_discard(arena, message); } return; }
static void test_air(int interior, int stack) { size_t n_finalized = 0; size_t i, j; obj_t *s[OBJ_COUNT] = {0}; mps_root_t root = NULL; if (!stack) { mps_addr_t *p = (void *)s; die(mps_root_create_table(&root, scheme_arena, mps_rank_ambig(), 0, p, OBJ_COUNT), "mps_root_create_table"); } mps_message_type_enable(scheme_arena, mps_message_type_finalization()); for (j = 0; j < OBJ_COUNT; ++j) { obj_t n = scheme_make_integer(obj_ap, (long)j); obj_t obj = scheme_make_vector(obj_ap, OBJ_LEN, n); mps_addr_t ref = obj; mps_finalize(scheme_arena, &ref); s[j] = obj->vector.vector; } for (i = 1; i < OBJ_LEN; ++i) { obj_t n = scheme_make_integer(obj_ap, (long)i); mps_message_t msg; for (j = 0; j + 1 < OBJ_COUNT; ++j) { *++s[j] = n; } mps_arena_collect(scheme_arena); mps_arena_release(scheme_arena); if (mps_message_get(&msg, scheme_arena, mps_message_type_finalization())) { mps_addr_t ref; mps_message_finalization_ref(&ref, scheme_arena, msg); ++ n_finalized; if (interior) { obj_t o; o = ref; error("wrongly finalized vector %ld at %p", o->vector.vector[0]->integer.integer, (void *)o); } } } if (!interior && n_finalized < OBJ_COUNT) { error("only finalized %"PRIuLONGEST" out of %"PRIuLONGEST" vectors.", (ulongest_t)n_finalized, (ulongest_t)OBJ_COUNT); } if (!stack) { mps_root_destroy(root); } }
static void report(mps_arena_t arena) { mps_message_t message; static int nCollections = 0; while (mps_message_get(&message, arena, mps_message_type_gc())) { size_t live, condemned, not_condemned; live = mps_message_gc_live_size(arena, message); condemned = mps_message_gc_condemned_size(arena, message); not_condemned = mps_message_gc_not_condemned_size(arena, message); printf("\nCollection %d finished:\n", ++nCollections); printf("live %"PRIuLONGEST"\n", (ulongest_t)live); printf("condemned %"PRIuLONGEST"\n", (ulongest_t)condemned); printf("not_condemned %"PRIuLONGEST"\n", (ulongest_t)not_condemned); mps_message_discard(arena, message); } }
static void report(void) { static int nStart = 0; static int nComplete = 0; mps_message_type_t type; while(mps_message_queue_type(&type, arena)) { mps_message_t message; cdie(mps_message_get(&message, arena, type), "message get"); switch(type) { /* @@@@ is using these macros in a switch supported? */ case mps_message_type_gc_start(): printf("\nCollection start %d. Because:\n", ++nStart); printf("%s\n", mps_message_gc_start_why(arena, message)); break; case mps_message_type_gc(): { size_t live, condemned, not_condemned; live = mps_message_gc_live_size(arena, message); condemned = mps_message_gc_condemned_size(arena, message); not_condemned = mps_message_gc_not_condemned_size(arena, message); printf("\nCollection complete %d:\n", ++nComplete); printf("live %"PRIuLONGEST"\n", (ulongest_t)live); printf("condemned %"PRIuLONGEST"\n", (ulongest_t)condemned); printf("not_condemned %"PRIuLONGEST"\n", (ulongest_t)not_condemned); } break; default: cdie(0, "unknown message type"); } mps_message_discard(arena, message); } return; }
static void report(mps_arena_t arena) { static int nCollsStart = 0; static int nCollsDone = 0; mps_message_type_t type; while(mps_message_queue_type(&type, arena)) { mps_message_t message; cdie(mps_message_get(&message, arena, type), "message get"); if (type == mps_message_type_gc_start()) { nCollsStart += 1; printf("\n{\n Collection %d started. Because:\n", nCollsStart); printf(" %s\n", mps_message_gc_start_why(arena, message)); printf(" clock: %"PRIuLONGEST"\n", (ulongest_t)mps_message_clock(arena, message)); } else if (type == mps_message_type_gc()) { size_t live, condemned, not_condemned; nCollsDone += 1; live = mps_message_gc_live_size(arena, message); condemned = mps_message_gc_condemned_size(arena, message); not_condemned = mps_message_gc_not_condemned_size(arena, message); printf("\n Collection %d finished:\n", nCollsDone); printf(" live %"PRIuLONGEST"\n", (ulongest_t)live); printf(" condemned %"PRIuLONGEST"\n", (ulongest_t)condemned); printf(" not_condemned %"PRIuLONGEST"\n", (ulongest_t)not_condemned); printf(" clock: %"PRIuLONGEST"\n", (ulongest_t)mps_message_clock(arena, message)); printf("}\n"); } else { cdie(0, "unknown message type"); break; } mps_message_discard(arena, message); } }
static void report(void) { static int nStart = 0; static int nComplete = 0; mps_message_type_t type; while(mps_message_queue_type(&type, arena)) { mps_message_t message; cdie(mps_message_get(&message, arena, type), "message get"); if (type == mps_message_type_gc_start()) { printf("\nCollection start %d. Because:\n", ++nStart); printf("%s\n", mps_message_gc_start_why(arena, message)); } else if (type == mps_message_type_gc()) { size_t live, condemned, not_condemned; live = mps_message_gc_live_size(arena, message); condemned = mps_message_gc_condemned_size(arena, message); not_condemned = mps_message_gc_not_condemned_size(arena, message); printf("\nCollection complete %d:\n", ++nComplete); printf("live %"PRIuLONGEST"\n", (ulongest_t)live); printf("condemned %"PRIuLONGEST"\n", (ulongest_t)condemned); printf("not_condemned %"PRIuLONGEST"\n", (ulongest_t)not_condemned); } else { cdie(0, "unknown message type"); } mps_message_discard(arena, message); } return; }
static void *test(void *arg, size_t s) { unsigned i; /* index */ mps_ap_t ap; mps_fmt_t fmt; mps_chain_t chain; mps_pool_t amc; mps_res_t e; mps_root_t mps_root[2]; mps_addr_t nullref = NULL; int state[rootCOUNT]; mps_arena_t arena; void *p = NULL; mps_message_t message; arena = (mps_arena_t)arg; (void)s; die(mps_fmt_create_A(&fmt, arena, dylan_fmt_A()), "fmt_create\n"); die(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mps_pool_create(&amc, arena, mps_class_amc(), fmt, chain), "pool_create amc\n"); die(mps_root_create_table(&mps_root[0], arena, mps_rank_exact(), (mps_rm_t)0, root, (size_t)rootCOUNT), "root_create\n"); die(mps_root_create_table(&mps_root[1], arena, mps_rank_exact(), (mps_rm_t)0, &p, (size_t)1), "root_create\n"); die(mps_ap_create(&ap, amc, mps_rank_exact()), "ap_create\n"); /* Make registered-for-finalization objects. */ /* <design/poolmrg/#test.promise.ut.alloc> */ for(i = 0; i < rootCOUNT; ++i) { do { MPS_RESERVE_BLOCK(e, p, ap, vectorSIZE); die(e, "MPS_RES_OK"); die(dylan_init(p, vectorSIZE, &nullref, 1), "dylan_init"); } while (!mps_commit(ap, p, vectorSIZE)); /* store index in vector's slot */ ((mps_word_t *)p)[vectorSLOT] = dylan_int(i); die(mps_finalize(arena, &p), "finalize\n"); root[i] = p; state[i] = rootSTATE; } p = NULL; mps_message_type_enable(arena, mps_message_type_finalization()); /* <design/poolmrg/#test.promise.ut.churn> */ while (mps_collections(arena) < collectionCOUNT) { /* Perhaps cause (minor) collection */ churn(ap); /* Maybe make some objects ready-to-finalize */ /* <design/poolmrg/#test.promise.ut.drop> */ for (i = 0; i < rootCOUNT; ++i) { if (root[i] != NULL && state[i] == rootSTATE) { if (rnd() % finalizationRATE == 0) { /* for this object, either... */ if (rnd() % 2 == 0) { /* ...definalize it, or */ die(mps_definalize(arena, &root[i]), "definalize\n"); state[i] = deadSTATE; } else { /* ...expect it to be finalized soon */ state[i] = finalizableSTATE; } /* Drop the root reference to it; this makes it */ /* non-E-reachable: so either dead, or ready-to-finalize. */ root[i] = NULL; } } } /* Test any finalized objects, and perhaps resurrect some */ while (mps_message_poll(arena)) { mps_word_t *obj; mps_word_t objind; mps_addr_t objaddr; /* <design/poolmrg/#test.promise.ut.message> */ cdie(mps_message_get(&message, arena, mps_message_type_finalization()), "get"); cdie(0 == mps_message_clock(arena, message), "message clock should be 0 (unset) for finalization messages"); mps_message_finalization_ref(&objaddr, arena, message); obj = objaddr; objind = dylan_int_int(obj[vectorSLOT]); printf("Finalizing: object %lu at %p\n", objind, objaddr); /* <design/poolmrg/#test.promise.ut.final.check> */ cdie(root[objind] == NULL, "finalized live"); cdie(state[objind] == finalizableSTATE, "finalized dead"); state[objind] = finalizedSTATE; /* sometimes resurrect */ if (rnd() % 2 == 0) root[objind] = objaddr; mps_message_discard(arena, message); } } /* @@@@ <design/poolmrg/#test.promise.ut.nofinal.check> missing */ mps_ap_destroy(ap); mps_root_destroy(mps_root[1]); mps_root_destroy(mps_root[0]); mps_pool_destroy(amc); mps_chain_destroy(chain); mps_fmt_destroy(fmt); return NULL; }
static void test(void) { long int i; long int rsize; mps_message_t message; int inramp; mycell *r, *s; cdie(mps_arena_create(&arena, mps_arena_class_vm(), (size_t) 1024*1024*ARENALIMIT), "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_root_create_table(&root1, arena, mps_rank_exact(), 0, &objtab[0], TABSIZE), "create root table"); cdie( mps_fmt_create_A(&format, arena, &fmtA), "create format"); cdie(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); cdie( mps_pool_create(&poolamc, arena, mps_class_amc(), format, chain), "create pool"); cdie( mps_ap_create(&apamc, poolamc, mps_rank_exact()), "create ap"); mps_message_type_enable(arena, mps_message_type_collection_stats()); inramp = 0; for (i = 0; i < ITERATIONS; i++) { if (i % 10000 == 0) { comment("%ld of %ld", i, ITERATIONS); } alloc_back(); if (inramp) { s = allocone(apamc, 3, mps_rank_exact()); setref(r, 0, s); setref(s, 1, r); r = s; s = allocdumb(apamc, RAMPSIZE, mps_rank_exact()); setref(r, 2, s); rsize ++; if (ranint(LEAVERAMP) == 0) { r = allocone(apamc, 2, mps_rank_exact()); s = allocone(apamc, 2, mps_rank_exact()); #ifdef RAMP_INTERFACE mps_ap_alloc_pattern_end(apamc, mps_alloc_pattern_ramp_collect_all()); #endif #ifdef COLLECT_WORLD mps_arena_collect(arena); mps_arena_release(arena); #endif comment("ramp end, %ld objects", rsize); inramp = 0; } } else { if (ranint(ENTERRAMP) == 0) { #ifdef RAMP_INTERFACE mps_ap_alloc_pattern_begin(apamc, mps_alloc_pattern_ramp_collect_all()); #endif comment("ramp begin"); r = allocone(apamc, 3, mps_rank_exact()); inramp = 1; rsize = 0; } } if(mps_message_get(&message, arena, mps_message_type_collection_stats())) { unsigned long live, condemned, notCondemned; live = mps_message_collection_stats_live_size(arena, message); condemned = mps_message_collection_stats_condemned_size(arena, message); notCondemned = mps_message_collection_stats_not_condemned_size(arena, message); comment("Collection: live=%ld, condemned=%ld, not condemned = %ld", live, condemned, notCondemned); mps_message_discard(arena, message); } } mps_ap_destroy(apamc); comment("Destroyed ap."); mps_pool_destroy(poolamc); comment("Destroyed pool."); mps_fmt_destroy(format); comment("Destroyed format."); mps_chain_destroy(chain); comment("Destroyed chain."); mps_root_destroy(root1); mps_root_destroy(root); comment("Destroyed roots."); mps_thread_dereg(thread); comment("Deregistered thread."); mps_arena_destroy(arena); comment("Destroyed arena."); }
static void *test(void *arg, size_t s) { mps_ap_t ap; mps_fmt_t fmt; mps_chain_t chain; mps_word_t finals; mps_pool_t amc; mps_root_t mps_root; mps_arena_t arena; mps_message_t message; size_t i; arena = (mps_arena_t)arg; (void)s; die(mps_fmt_create_A(&fmt, arena, dylan_fmt_A()), "fmt_create\n"); die(mps_chain_create(&chain, arena, genCOUNT, testChain), "chain_create"); die(mps_pool_create(&amc, arena, mps_class_amc(), fmt, chain), "pool_create amc\n"); die(mps_root_create_table(&mps_root, arena, mps_rank_exact(), (mps_rm_t)0, root, (size_t)rootCOUNT), "root_create\n"); die(mps_ap_create(&ap, amc, mps_rank_exact()), "ap_create\n"); mps_message_type_enable(arena, mps_message_type_finalization()); mps_arena_park(arena); object_count = 0; printf("Making some finalized trees of objects.\n"); /* make some trees */ for(i = 0; i < rootCOUNT; ++i) { root[i] = (void *)make_numbered_tree(maxtreeDEPTH, ap); register_numbered_tree((mps_word_t)root[i], arena); } mps_arena_unsafe_expose_remember_protection(arena); mps_arena_unsafe_restore_protection(arena); printf("Losing all pointers to the trees.\n"); /* clean out the roots */ for(i = 0; i < rootCOUNT; ++i) { root[i] = 0; } finals = 0; while ((finals < object_count) && (mps_collections(arena) < collectionCOUNT)) { mps_word_t final_this_time = 0; printf("Collecting..."); (void)fflush(stdout); die(mps_arena_collect(arena), "collect"); printf(" Done.\n"); while (mps_message_poll(arena)) { mps_word_t obj; mps_addr_t objaddr; cdie(mps_message_get(&message, arena, mps_message_type_finalization()), "get"); mps_message_finalization_ref(&objaddr, arena, message); obj = (mps_word_t)objaddr; mps_message_discard(arena, message); ++ final_this_time; testlib_unused(obj); } finals += final_this_time; printf("%"PRIuLONGEST" objects finalized: total %"PRIuLONGEST " of %"PRIuLONGEST"\n", (ulongest_t)final_this_time, (ulongest_t)finals, (ulongest_t)object_count); } object_count = 0; printf("Making some indirectly finalized trees of objects.\n"); /* make some trees */ for(i = 0; i < rootCOUNT; ++i) { root[i] = (void *)make_indirect_tree(maxtreeDEPTH, ap); register_indirect_tree((mps_word_t)root[i], arena); } printf("Losing all pointers to the trees.\n"); /* clean out the roots */ for(i = 0; i < rootCOUNT; ++i) { root[i] = 0; } finals = 0; while ((finals < object_count) && (mps_collections(arena) < collectionCOUNT)) { mps_word_t final_this_time = 0; printf("Collecting..."); (void)fflush(stdout); die(mps_arena_collect(arena), "collect"); printf(" Done.\n"); while (mps_message_poll(arena)) { mps_word_t obj; mps_addr_t objaddr; cdie(mps_message_get(&message, arena, mps_message_type_finalization()), "get"); mps_message_finalization_ref(&objaddr, arena, message); obj = (mps_word_t)objaddr; mps_message_discard(arena, message); ++ final_this_time; testlib_unused(obj); } finals += final_this_time; printf("%"PRIuLONGEST" objects finalized: total %"PRIuLONGEST " of %"PRIuLONGEST"\n", (ulongest_t)final_this_time, (ulongest_t)finals, (ulongest_t)object_count); } mps_ap_destroy(ap); mps_root_destroy(mps_root); mps_pool_destroy(amc); mps_chain_destroy(chain); mps_fmt_destroy(fmt); return NULL; }