diff --git a/gc.c b/gc.c index 8c718aca..a092f387 100644 --- a/gc.c +++ b/gc.c @@ -1648,11 +1648,29 @@ void gc_thread_data_init(gc_thread_data * thd, int mut_num, char *stack_base, fprintf(stderr, "Unable to initialize thread mutex\n"); exit(1); } + thd->heap = calloc(1, sizeof(gc_heap_root)); + thd->heap->heap = calloc(1, sizeof(gc_heap *) * NUM_HEAP_TYPES); + thd->heap->heap[HEAP_REST] = gc_heap_create(HEAP_REST, INITIAL_HEAP_SIZE, 0, 0); + thd->heap->heap[HEAP_SM] = gc_heap_create(HEAP_SM, INITIAL_HEAP_SIZE, 0, 0); + thd->heap->heap[HEAP_64] = gc_heap_create(HEAP_64, INITIAL_HEAP_SIZE, 0, 0); + if (sizeof(void *) == 8) { // Only use this heap on 64-bit platforms + thd->heap[HEAP_96] = gc_heap_create(HEAP_96, INITIAL_HEAP_SIZE, 0, 0); + } + thd->heap->heap[HEAP_HUGE] = gc_heap_create(HEAP_HUGE, 1024, 0, 0); + thd->cached_heap_free_sizes = calloc(5, sizeof(uint64_t)); + thd->cached_heap_total_sizes = calloc(5, sizeof(uint64_t)); } void gc_thread_data_free(gc_thread_data * thd) { if (thd) { +// +// !! +// TODO: (not necessarily here, but somewhere need to roll heap pages into +// another thread data. need to include cached heap sizes/total, too. +// then free cached heap vars here. +// !! +// if (pthread_mutex_destroy(&thd->lock) != 0) { // TODO: can only destroy the lock if it is unlocked. need to make sure we // can guarantee that is the case prior to making this call diff --git a/include/cyclone/types.h b/include/cyclone/types.h index 2c586a2b..af6e6090 100644 --- a/include/cyclone/types.h +++ b/include/cyclone/types.h @@ -17,6 +17,7 @@ #include #include #include +#include // Maximum number of args that GC will accept #define NUM_GC_ARGS 128 @@ -141,6 +142,9 @@ struct gc_thread_data_t { int mark_buffer_len; pthread_mutex_t lock; pthread_t thread_id; + gc_heap_root *heap; + uint64_t *cached_heap_free_sizes; + uint64_t *cached_heap_total_sizes; // Data needed for call history char **stack_traces; int stack_trace_idx; diff --git a/runtime.c b/runtime.c index 76e6f8bd..55d15ad4 100644 --- a/runtime.c +++ b/runtime.c @@ -140,7 +140,6 @@ if (type_is_pair_prim(clo)) { \ /*END closcall section */ /* Global variables. */ -static gc_heap_root *Cyc_heap; object Cyc_global_variables = NULL; int _cyc_argc = 0; char **_cyc_argv = NULL; @@ -261,17 +260,6 @@ static bool set_insert(ck_hs_t * hs, const void *value) void gc_init_heap(long heap_size) { - size_t initial_heap_size = INITIAL_HEAP_SIZE; - Cyc_heap = calloc(1, sizeof(gc_heap_root)); - Cyc_heap->heap = calloc(1, sizeof(gc_heap *) * NUM_HEAP_TYPES); - Cyc_heap->heap[HEAP_REST] = gc_heap_create(HEAP_REST, initial_heap_size, 0, 0); - Cyc_heap->heap[HEAP_SM] = gc_heap_create(HEAP_SM, initial_heap_size, 0, 0); - Cyc_heap->heap[HEAP_64] = gc_heap_create(HEAP_64, initial_heap_size, 0, 0); - if (sizeof(void *) == 8) { // Only use this heap on 64-bit platforms - Cyc_heap->heap[HEAP_96] = gc_heap_create(HEAP_96, initial_heap_size, 0, 0); - } - Cyc_heap->heap[HEAP_HUGE] = gc_heap_create(HEAP_HUGE, 1024, 0, 0); - if (!ck_hs_init(&symbol_table, CK_HS_MODE_OBJECT | CK_HS_MODE_SPMC, hs_hash, hs_compare,