static void * _gcollect_proc(void *arg) { while (AO_load(&pending)) GC_gcollect(); return NULL; }
UInt CollectBags(UInt size, UInt full) { #ifndef DISABLE_GC GC_gcollect(); #endif return 1; }
/* Test that equal object data gives the same object pointer. */ void test(int n_alloc) { int i, J, k; cu_word_t **obj_arr = cu_snewarr(cu_word_t *, n_alloc); for (J = 1; J < MAX_SIZEW; ++J) _testobj_type_arr[J - 1] = cuoo_type_new_opaque_hcs(NULL, J*sizeof(cu_word_t)); for (k = 0; k < 100; ++k) { for (i = 0; i < n_alloc; ++i) { cu_word_t tpl[MAX_SIZEW]; int J = i % (MAX_SIZEW - 1) + 1; _testobj_init(tpl, J, i); obj_arr[i] = cuoo_halloc(_testobj_type_arr[J - 1], J*sizeof(cu_word_t), tpl); } for (i = 0; i < n_alloc; ++i) { cu_word_t *obj; cu_word_t tpl[4]; int J = i % (MAX_SIZEW - 1) + 1; _testobj_init(tpl, J, i); obj = cuoo_halloc(_testobj_type_arr[J - 1], J*sizeof(cu_word_t), tpl); cu_test_assert_ptr_eq(obj, obj_arr[i]); cu_test_assert(memcmp(cu_ptr_add(obj, CUOO_HCOBJ_SHIFT), cu_ptr_add(obj_arr[i], CUOO_HCOBJ_SHIFT), J*sizeof(cu_word_t)) == 0); } memset(obj_arr, 0, sizeof(cu_word_t *)*n_alloc); GC_gcollect(); } }
void *GC_amiga_allocwrapper_fast(size_t size,void *(*AllocFunction)(size_t size2)) { void *ret; ret=(*AllocFunction)(size); if(ret==NULL) { // Enable chip-mem allocation. // printf("ret==NULL\n"); #ifdef GC_AMIGA_GC if(!GC_dont_gc) { GC_gcollect(); #ifdef GC_AMIGA_PRINTSTATS numcollects++; #endif ret=(*AllocFunction)(size); } #endif if(ret==NULL) { #ifndef GC_AMIGA_ONLYFAST GC_AMIGA_MEMF=MEMF_ANY | MEMF_CLEAR; if(GC_amiga_toany!=NULL) (*GC_amiga_toany)(); GC_amiga_allocwrapper_do=GC_amiga_allocwrapper_any; return GC_amiga_allocwrapper_any(size,AllocFunction); #endif } #ifdef GC_AMIGA_PRINTSTATS else { nullretries++; } #endif } return ret; }
void nit_gcollect(void) { switch (gc_option) { #ifdef WITH_LIBGC case gc_opt_boehm: GC_gcollect(); break; #endif } }
void nit_gcollect(void) { switch (gc_option) { #ifdef WITH_LIBGC case gc_opt_boehm: GC_gcollect(); break; #endif default: break; /* nothing can be done */ } }
void java_lang_Runtime_gc__(JAVA_OBJECT me) { //XMLVM_BEGIN_NATIVE[java_lang_Runtime_gc__] #ifndef XMLVM_NO_GC GC_gcollect(); #endif //XMLVM_END_NATIVE }
/** * mono_gc_collect: * @generation: GC generation identifier * * Perform a garbage collection for the given generation, higher numbers * mean usually older objects. Collecting a high-numbered generation * implies collecting also the lower-numbered generations. * The maximum value for @generation can be retrieved with a call to * mono_gc_max_generation(), so this function is usually called as: * * mono_gc_collect (mono_gc_max_generation ()); */ void mono_gc_collect (int generation) { #ifndef DISABLE_PERFCOUNTERS mono_perfcounters->gc_induced++; #endif GC_gcollect (); }
int main(int argc, char** argv) { GC_find_leak = 1; GC_gcollect(); return 1; }
int main() { int i; GC_INIT(); uniq("%s:%d: error: gc library doesn't find all the active pointers in registers or on the stack!\n" " Perhaps GC_push_regs was configured incorrectly.\n", GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)), GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)), GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)), GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)), GC_malloc(12), GC_malloc(12), GC_malloc(12), (GC_gcollect(),GC_malloc(12)), (void *)0); for (i=0; i<20; i++) { if (i%4 == 3) GC_gcollect(); x[i] = GC_malloc(12); } uniq("%s:%d: error: gc library doesn't find all the active pointers in static memory!\n" " Perhaps GC_add_roots needs to be told about static memory.\n", x[0],x[1],x[2],x[3],x[4],x[5],x[6],x[7],x[8],x[9],x[10],x[11],x[12],x[13],x[14],x[15],x[16],x[17],x[18],x[19], (void *)0); for (i=0; i<20; i++) { reg(GC_malloc(12)); } GC_gcollect(); /* just to see if finalizers get called */ return had_error; }
void* gcAllocateUncollectable(size_t size) { void* m = GC_MALLOC_UNCOLLECTABLE(size); if (!m) { // Force GC and try again GC_gcollect(); m = GC_MALLOC_UNCOLLECTABLE(size); } return m; }
void* gcAllocate(size_t size) { void* m = GC_MALLOC(size); if (!m) { // Force GC and try again GC_gcollect(); m = GC_MALLOC(size); } return m; }
static void* gcAllocateKind(size_t size, uint32_t kind) { void* m = GC_generic_malloc(size, kind); if (!m) { // Force GC and try again GC_gcollect(); m = GC_generic_malloc(size, kind); } return m; }
int main(int argc, char **argv) { int i; int model, model_min, model_max; testobj_t *keep_arr; GC_INIT(); GC_init_finalized_malloc(); keep_arr = GC_MALLOC(sizeof(void *)*KEEP_CNT); if (argc == 2 && strcmp(argv[1], "--help") == 0) { fprintf(stderr, "Usage: %s [FINALIZATION_MODEL]\n" "\t0 -- original finalization\n" "\t1 -- finalization on reclaim\n" "\t2 -- no finalization\n", argv[0]); return 1; } if (argc == 2) { model_min = model_max = atoi(argv[1]); if (model_min < 0 || model_max > 2) exit(2); } else { model_min = 0; model_max = 2; } printf("\t\t\tfin. ratio time/s time/fin.\n"); for (model = model_min; model <= model_max; ++model) { double t = 0.0; free_count = 0; # ifdef CLOCK_TYPE CLOCK_TYPE tI, tF; GET_TIME(tI); # endif for (i = 0; i < ALLOC_CNT; ++i) { int k = rand() % KEEP_CNT; keep_arr[k] = testobj_new(model); } GC_gcollect(); # ifdef CLOCK_TYPE GET_TIME(tF); t = MS_TIME_DIFF(tF, tI)*1e-3; # endif if (model < 2) printf("%20s: %12.4lf %12lg %12lg\n", model_str[model], free_count/(double)ALLOC_CNT, t, t/free_count); else printf("%20s: %12.4lf %12lg %12s\n", model_str[model], 0.0, t, "N/A"); } return 0; }
static sexp sexp_gc_op (sexp ctx, sexp self, sexp_sint_t n) { size_t sum_freed=0; #if SEXP_USE_BOEHM GC_gcollect(); #else sexp_gc(ctx, &sum_freed); #endif return sexp_make_unsigned_integer(ctx, sum_freed); }
void epicMemInfo() { GC_gcollect(); int heap = GC_get_heap_size(); int free = GC_get_free_bytes(); int total = GC_get_total_bytes(); printf("Heap size %d\n", heap); printf("Heap used %d\n", heap-free); printf("Total allocations %d\n", total); }
int main(int argc, char** argv) { char* blocks[N]; int i, j; for (i = 0; i < N; ++i) { blocks[i] = (char*) GC_malloc_atomic(SIZE); memset(blocks[i], FILL, SIZE); } GC_gcollect(); for (i = 0; i < N; ++i) GC_malloc(i * 5); GC_gcollect(); for (i = 0; i < N; ++i) for (j = 0; j < SIZE; ++j) if (blocks[i][j] != FILL) { printf("phase 1 - blocks[%d][%d] modified\n", i, j); return 1; } for (i = 0; i < N; ++i) blocks[i] += OFFSET; GC_gcollect(); for (i = 0; i < N; ++i) GC_malloc(i * 5); GC_gcollect(); for (i = 0; i < N; ++i) for (j = 0; j < SIZE; ++j) if (blocks[i][j - OFFSET] != FILL) { printf("phase 2 - blocks[%d][%d] modified\n", i, j); return 1; } return 0; }
void* gcAllocateAtomic(size_t size) { void* m = GC_MALLOC_ATOMIC(size); if (!m) { // Force GC and try again GC_gcollect(); m = GC_MALLOC_ATOMIC(size); } if (m) { memset(m, 0, size); } return m; }
void* gcAllocateAtomicUncollectable(size_t size) { void* m = GC_MALLOC_ATOMIC_UNCOLLECTABLE(size); if (!m) { // Force GC and try again GC_gcollect(); m = GC_MALLOC_ATOMIC_UNCOLLECTABLE(size); } if (m) { memset(m, 0, size); } return m; }
static void perform_final_collection() { unsigned i; word last_fo_entries = 0; /* adjust the stack bottom, because CFM calls us from another stack location. */ GC_stackbottom = (ptr_t)&i; /* try to collect and finalize everything in sight */ for (i = 0; i < 2 || GC_fo_entries < last_fo_entries; i++) { last_fo_entries = GC_fo_entries; GC_gcollect(); } }
void *GC_amiga_gctest_calloc_explicitly_typed(size_t a,size_t lb, GC_descr d){ void *ret=GC_calloc_explicitly_typed(a,lb,d); if(ret==NULL){ if(!GC_dont_gc){ GC_gcollect(); ret=GC_calloc_explicitly_typed(a,lb,d); } if(ret==NULL){ GC_printf("Out of memory, (typed allocations are not directly " "supported with the GC_AMIGA_FASTALLOC option.)\n"); FAIL; } } return ret; }
/** * mono_gc_collect: * @generation: GC generation identifier * * Perform a garbage collection for the given generation, higher numbers * mean usually older objects. Collecting a high-numbered generation * implies collecting also the lower-numbered generations. * The maximum value for @generation can be retrieved with a call to * mono_gc_max_generation(), so this function is usually called as: * * mono_gc_collect (mono_gc_max_generation ()); */ void mono_gc_collect (int generation) { MONO_PROBE_GC_BEGIN (generation); mono_perfcounters->gc_induced++; GC_gcollect (); MONO_PROBE_GC_END (generation); #if defined(ENABLE_DTRACE) && defined(__sun__) /* This works around a dtrace -G problem on Solaris. Limit its actual use to when the probe is enabled. */ if (MONO_PROBE_GC_END_ENABLED ()) sleep(0); #endif }
void *heapstats_alloc2(jsize length, jint isArray) { void *result; stat_t ttl; static int skipped=0; FLEX_MUTEX_DECLARE_STATIC(skipped_lock); /* do the allocation & register finalizer */ result = GC_malloc(length); GC_register_finalizer_no_order(result, isArray ? heapstats_finalizer_array : heapstats_finalizer_object, (GC_PTR) ((ptroff_t) length), NULL, NULL); /* (sometimes) collect all dead objects */ FLEX_MUTEX_LOCK(&skipped_lock); if (skipped || 0 == ((FETCH_STATS(heap_total_alloc_obj_count) + FETCH_STATS(heap_total_alloc_arr_count)) % GC_FREQUENCY)) if (isArray ? (FETCH_STATS(heap_current_live_arr_bytes)+length) > FETCH_STATS(heap_max_live_arr_bytes) : (FETCH_STATS(heap_current_live_obj_bytes)+length) > FETCH_STATS(heap_max_live_obj_bytes)) { GC_gcollect(); skipped = 0; } else skipped = 1; FLEX_MUTEX_UNLOCK(&skipped_lock); if (isArray) { /* update total and current live */ INCREMENT_STATS(heap_total_alloc_arr_count, 1); INCREMENT_STATS(heap_total_alloc_arr_bytes, length); INCREMENT_STATS(heap_current_live_arr_bytes, length); /* update max_live */ ttl = FETCH_STATS(heap_current_live_arr_bytes); UPDATE_STATS(heap_max_live_arr_bytes, ttl > _old_value_ ? ttl : _old_value_); } else { /* update total and current live */ INCREMENT_STATS(heap_total_alloc_obj_count, 1); INCREMENT_STATS(heap_total_alloc_obj_bytes, length); INCREMENT_STATS(heap_current_live_obj_bytes, length); /* update max_live */ ttl = FETCH_STATS(heap_current_live_obj_bytes); UPDATE_STATS(heap_max_live_obj_bytes, ttl > _old_value_ ? ttl : _old_value_); } /* done */ return result; }
/* * The wrapped realloc function. * */ void *GC_amiga_realloc(void *old_object,size_t new_size_in_bytes){ #ifndef GC_AMIGA_FASTALLOC return GC_realloc(old_object,new_size_in_bytes); #else void *ret; latestsize=new_size_in_bytes; ret=GC_realloc(old_object,new_size_in_bytes); if(ret==NULL && new_size_in_bytes != 0 && GC_AMIGA_MEMF==(MEMF_FAST | MEMF_CLEAR)){ /* Out of fast-mem. */ #ifdef GC_AMIGA_GC if(!GC_dont_gc){ GC_gcollect(); #ifdef GC_AMIGA_PRINTSTATS numcollects++; #endif ret=GC_realloc(old_object,new_size_in_bytes); } #endif if(ret==NULL){ #ifndef GC_AMIGA_ONLYFAST GC_AMIGA_MEMF=MEMF_ANY | MEMF_CLEAR; if(GC_amiga_toany!=NULL) (*GC_amiga_toany)(); GC_amiga_allocwrapper_do=GC_amiga_allocwrapper_any; ret=GC_realloc(old_object,new_size_in_bytes); #endif } #ifdef GC_AMIGA_PRINTSTATS else{ nullretries++; } #endif } if(ret==NULL && new_size_in_bytes != 0){ WARN("Out of Memory! Returning NIL!\n", 0); } #ifdef GC_AMIGA_PRINTSTATS if(((char *)ret)<chipmax && ret!=NULL){ chipa+=new_size_in_bytes; } #endif return ret; #endif }
main () { int i,j,k; GC_all_interior_pointers = 1; while (1) { for (i=0; i<20 ;i++) { for (j=0; j<20; j++) { b = (struct x *)GC_malloc(sizeof(struct x)); for (k=0; k<20; k++) { b->p[k] = a[k]; b->h[k] = rand(); } a[j] = b; } } for (k=0; k<20; k++) a[k] = NULL; #ifdef COLLECTOFTEN GC_gcollect(); #endif } }
void Scm_GC() { GC_gcollect(); }
NS_IMETHODIMP nsAboutBloat::NewChannel(nsIURI *aURI, nsIChannel **result) { NS_ENSURE_ARG_POINTER(aURI); nsresult rv; nsAutoCString path; rv = aURI->GetPath(path); if (NS_FAILED(rv)) return rv; nsTraceRefcntImpl::StatisticsType statType = nsTraceRefcntImpl::ALL_STATS; bool clear = false; bool leaks = false; int32_t pos = path.Find("?"); if (pos > 0) { nsAutoCString param; (void)path.Right(param, path.Length() - (pos+1)); if (param.EqualsLiteral("new")) statType = nsTraceRefcntImpl::NEW_STATS; else if (param.EqualsLiteral("clear")) clear = true; else if (param.EqualsLiteral("leaks")) leaks = true; } nsCOMPtr<nsIInputStream> inStr; if (clear) { nsTraceRefcntImpl::ResetStatistics(); rv = NS_NewCStringInputStream(getter_AddRefs(inStr), NS_LITERAL_CSTRING("Bloat statistics cleared.")); if (NS_FAILED(rv)) return rv; } else if (leaks) { // dump the current set of leaks. GC_gcollect(); rv = NS_NewCStringInputStream(getter_AddRefs(inStr), NS_LITERAL_CSTRING("Memory leaks dumped.")); if (NS_FAILED(rv)) return rv; } else { nsCOMPtr<nsIFile> file; rv = NS_GetSpecialDirectory(NS_OS_CURRENT_PROCESS_DIR, getter_AddRefs(file)); if (NS_FAILED(rv)) return rv; rv = file->AppendNative(NS_LITERAL_CSTRING("bloatlogs")); if (NS_FAILED(rv)) return rv; bool exists; rv = file->Exists(&exists); if (NS_FAILED(rv)) return rv; if (!exists) { // On all the platforms that I know use permissions, // directories need to have the executable flag set // if you want to do anything inside the directory. rv = file->Create(nsIFile::DIRECTORY_TYPE, 0755); if (NS_FAILED(rv)) return rv; } nsAutoCString dumpFileName; if (statType == nsTraceRefcntImpl::ALL_STATS) dumpFileName.AssignLiteral("all-"); else dumpFileName.AssignLiteral("new-"); PRExplodedTime expTime; PR_ExplodeTime(PR_Now(), PR_LocalTimeParameters, &expTime); char time[128]; PR_FormatTimeUSEnglish(time, 128, "%Y-%m-%d-%H%M%S.txt", &expTime); dumpFileName += time; rv = file->AppendNative(dumpFileName); if (NS_FAILED(rv)) return rv; FILE* out; rv = file->OpenANSIFileDesc("w", &out); if (NS_FAILED(rv)) return rv; rv = nsTraceRefcntImpl::DumpStatistics(statType, out); ::fclose(out); if (NS_FAILED(rv)) return rv; rv = NS_NewLocalFileInputStream(getter_AddRefs(inStr), file); if (NS_FAILED(rv)) return rv; } nsIChannel* channel; rv = NS_NewInputStreamChannel(&channel, aURI, inStr, NS_LITERAL_CSTRING("text/plain"), NS_LITERAL_CSTRING("utf-8")); if (NS_FAILED(rv)) return rv; *result = channel; return rv; }
EXTERN void neko_gc_major() { GC_gcollect(); }
void epicGC() { GC_gcollect(); }
void *GC_amiga_allocwrapper_any(size_t size,void *(*AllocFunction)(size_t size2)) { void *ret,*ret2; GC_amiga_dontalloc=TRUE; // Pretty tough thing to do, but its indeed necesarry. latestsize=size; ret=(*AllocFunction)(size); if(((char *)ret) <= chipmax) { if(ret==NULL) { //Give GC access to allocate memory. #ifdef GC_AMIGA_GC if(!GC_dont_gc) { GC_gcollect(); #ifdef GC_AMIGA_PRINTSTATS numcollects++; #endif ret=(*AllocFunction)(size); } #endif if(ret==NULL) { GC_amiga_dontalloc=FALSE; ret=(*AllocFunction)(size); if(ret==NULL) { WARN("Out of Memory! Returning NIL!\n", 0); } } #ifdef GC_AMIGA_PRINTSTATS else { nullretries++; } if(ret!=NULL && (char *)ret<=chipmax) chipa+=size; #endif } #ifdef GC_AMIGA_RETRY else { /* We got chip-mem. Better try again and again and again etc., we might get fast-mem sooner or later... */ /* Using gctest to check the effectiviness of doing this, does seldom give a very good result. */ /* However, real programs doesn't normally rapidly allocate and deallocate. */ // printf("trying to force... %d bytes... ",size); if( AllocFunction!=GC_malloc_uncollectable #ifdef ATOMIC_UNCOLLECTABLE && AllocFunction!=GC_malloc_atomic_uncollectable #endif ) { ret2=GC_amiga_rec_alloc(size,AllocFunction,0); } else { ret2=(*AllocFunction)(size); #ifdef GC_AMIGA_PRINTSTATS if((char *)ret2<chipmax || ret2==NULL) { nsucc++; nsucc2+=size; ncur0++; } else { succ++; succ2+=size; cur0++; } #endif } if(((char *)ret2)>chipmax) { // printf("Succeeded.\n"); GC_free(ret); ret=ret2; } else { GC_free(ret2); // printf("But did not succeed.\n"); } } #endif } GC_amiga_dontalloc=FALSE; return ret; }