void InitBags(UInt initial_size, Bag * stack_bottom, UInt stack_align) { UInt i; /* loop variable */ /* install the marking functions */ for (i = 0; i < NUM_TYPES; i++) { TabMarkTypeBags[i] = -1; } #ifndef DISABLE_GC #ifdef HPCGAP if (!getenv("GC_MARKERS")) { /* The Boehm GC does not have an API to set the number of * markers for the parallel mark and sweep implementation, * so we use the documented environment variable GC_MARKERS * instead. However, we do not override it if it's already * set. */ static char marker_env_str[32]; unsigned num_markers = 2; if (!SyNumGCThreads) SyNumGCThreads = SyNumProcessors; if (SyNumGCThreads) { if (SyNumGCThreads <= MAX_GC_THREADS) num_markers = (unsigned)SyNumProcessors; else num_markers = MAX_GC_THREADS; } sprintf(marker_env_str, "GC_MARKERS=%u", num_markers); putenv(marker_env_str); } #endif GC_set_all_interior_pointers(0); GC_init(); GC_set_free_space_divisor(1); TLAllocatorInit(); GC_register_displacement(0); GC_register_displacement(sizeof(BagHeader)); initial_size *= 1024; if (GC_get_heap_size() < initial_size) GC_expand_hp(initial_size - GC_get_heap_size()); if (SyStorKill) GC_set_max_heap_size(SyStorKill * 1024); #ifdef HPCGAP AddGCRoots(); CreateMainRegion(); #else void * p = ActiveGAPState(); GC_add_roots(p, (char *)p + sizeof(GAPState)); #endif for (i = 0; i <= MAX_GC_PREFIX_DESC; i++) { BuildPrefixGCDescriptor(i); /* This is necessary to initialize some internal structures * in the garbage collector: */ GC_generic_malloc(sizeof(BagHeader) + i * sizeof(Bag), GCMKind[i]); } #endif /* DISABLE_GC */ }
int main (void) { GC_set_all_interior_pointers(0); GC_set_max_heap_size(16000000); /*GC_set_java_finalization(1);*/ GC_INIT(); myTest(); return 0; }
int main(void) { #if THREAD_CNT > 1 pthread_t th[THREAD_CNT]; int i; #endif GC_set_all_interior_pointers(0); /* for a stricter test */ GC_INIT(); GC_init_finalized_malloc(); test_misc_sizes(); #if THREAD_CNT > 1 printf("Threaded disclaim test.\n"); for (i = 0; i < THREAD_CNT; ++i) { int err = pthread_create(&th[i], NULL, test, NULL); if (err) { fprintf(stderr, "Failed to create thread # %d: %s\n", i, strerror(err)); exit(1); } } for (i = 0; i < THREAD_CNT; ++i) { int err = pthread_join(th[i], NULL); if (err) { fprintf(stderr, "Failed to join thread # %d: %s\n", i, strerror(err)); exit(69); } } #else printf("Unthreaded disclaim test.\n"); test(NULL); #endif return 0; }
tort_v _tort_m_initializer__malloc(tort_tp tort_v init) { const char *var; _tort_gc_disabled ++; // temporarily disabled till boot is finished. (void) _tort_finalization_proc; // avoid warning. var = getenv("TORT_GC"); if ( ! var || ! *var || ! strcmp(var, "0") ) var = "bdw"; #if TORT_GC_BDW if ( ! strcmp(var, "bdw") ) { GC_set_all_interior_pointers(1); GC_set_finalize_on_demand(0); GC_INIT(); _tort_gc_mode = "bdw"; _tort_malloc = GC_malloc; _tort_malloc_atomic = GC_malloc_atomic; _tort_free = GC_free; _tort_free_atomic = GC_free; /* ??? */ _tort_realloc = GC_realloc; _tort_realloc_atomic = GC_realloc; /* ??? */ _tort_gc_collect = GC_gcollect; _tort_gc_register_finalizer = _tort_gc_register_finalizer_bdw; _tort_gc_invoke_finalizers = (void*) GC_invoke_finalizers; _tort_gc_stats = _tort_gc_stats_bdw; } #endif #if TORT_GC_SMAL if ( ! strcmp(var, "smal") ) { _tort_gc_mode = "smal"; smal_debug_set_level(smal_debug_all, 1); smal_init(); _tort_gc_collect = _tort_gc_collect_smal; _tort_object_alloc = _tort_object_alloc_smal; _tort_gc_stats = _tort_gc_stats_smal; { const char *s = getenv("TORT_GC_ALLOCS_PER_GC"); allocs_per_gc = s && *s ? atoi(s) : 10000; } } #endif if ( ! strcmp(var, "malloc") ) _tort_gc_mode = "malloc"; if ( ! _tort_gc_mode ) { _tort_gc_mode = "malloc"; fprintf(stderr, " tort: WARNING: defaulting to TORT_GC=%s\n", _tort_gc_mode); } if ( ! strcmp(_tort_gc_mode, "malloc") ) fprintf(stderr, " tort: WARNING: using malloc(), NO GC!\n"); { /* assert alignments. */ void *p; assert((size_t) (p = tort_malloc(sizeof(tort_header))) % sizeof(tort_v) == 0); tort_free(p); assert((size_t) (p = tort_malloc_atomic(sizeof(tort_header))) % sizeof(tort_v) == 0); tort_free_atomic(p); } return init; }