From 65dc14419961dcc9f310e90d771e0fd289502b1d Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Sat, 5 Dec 2015 09:09:11 -0500 Subject: [PATCH 1/2] Do not assume the GC is always running on the master thread. Plus clean up. --- src/gc.c | 20 ++++++++------------ src/threading.c | 4 ---- src/threading.h | 1 - 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/gc.c b/src/gc.c index 5a7fe6d057cdd..7de6d90fd7beb 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1028,7 +1028,7 @@ static size_t array_nbytes(jl_array_t *a) return sz; } -void jl_gc_free_array(jl_array_t *a) +static void jl_gc_free_array(jl_array_t *a) { if (a->how == 2) { char *d = (char*)a->data - a->offset*a->elsize; @@ -1630,19 +1630,21 @@ static void gc_mark_stack(jl_value_t* ta, jl_gcframe_t *s, ptrint_t offset, int static void gc_mark_task_stack(jl_task_t *ta, int d) { int stkbuf = (ta->stkbuf != (void*)(intptr_t)-1 && ta->stkbuf != NULL); + int16_t tid = ta->tid; + jl_tls_states_t *ptls = jl_all_task_states[tid].ptls; if (stkbuf) { #ifndef COPY_STACKS - if (ta != jl_root_task) // stkbuf isn't owned by julia for the root task + if (ta != ptls->root_task) // stkbuf isn't owned by julia for the root task #endif gc_setmark_buf(ta->stkbuf, gc_bits(jl_astaggedvalue(ta))); } - if (ta == jl_all_task_states[ta->tid].ptls->current_task) { - gc_mark_stack((jl_value_t*)ta, *jl_all_pgcstacks[ta->tid], 0, d); + if (ta == ptls->current_task) { + gc_mark_stack((jl_value_t*)ta, ptls->pgcstack, 0, d); } else if (stkbuf) { ptrint_t offset; #ifdef COPY_STACKS - offset = (char *)ta->stkbuf - ((char *)jl_stackbase - ta->ssize); + offset = (char *)ta->stkbuf - ((char *)ptls->stackbase - ta->ssize); #else offset = 0; #endif @@ -1907,8 +1909,6 @@ static void pre_mark(void) // invisible builtin values if (jl_an_empty_cell) gc_push_root(jl_an_empty_cell, 0); - gc_push_root(jl_exception_in_transit, 0); - gc_push_root(jl_task_arg_in_transit, 0); if (jl_module_init_order != NULL) gc_push_root(jl_module_init_order, 0); @@ -2037,7 +2037,7 @@ static void print_obj_profile(htable_t nums, htable_t sizes) } } -void print_obj_profiles(void) +static void print_obj_profiles(void) { jl_printf(JL_STDERR, "Transient mark :\n"); print_obj_profile(obj_counts[0], obj_sizes[0]); @@ -2054,10 +2054,6 @@ static int saved_mark_sp = 0; static int sweep_mask = GC_MARKED; #define MIN_SCAN_BYTES 1024*1024 -void prepare_sweep(void) -{ -} - JL_DLLEXPORT void jl_gc_collect(int full) { if (!is_gc_enabled) return; diff --git a/src/threading.c b/src/threading.c index fed8bf3eaa672..c51ddea7b1aa0 100644 --- a/src/threading.c +++ b/src/threading.c @@ -127,7 +127,6 @@ JL_DLLEXPORT JL_CONST_FUNC jl_tls_states_t *(jl_get_ptls_states)(void) JL_DLLEXPORT int jl_n_threads; // # threads we're actually using JL_DLLEXPORT int jl_max_threads; // # threads possible jl_thread_task_state_t *jl_all_task_states; -jl_gcframe_t ***jl_all_pgcstacks; // return calling thread's ID JL_DLLEXPORT int16_t jl_threadid(void) { return ti_tid; } @@ -139,7 +138,6 @@ static void ti_initthread(int16_t tid) { ti_tid = tid; jl_pgcstack = NULL; - jl_all_pgcstacks[tid] = &jl_pgcstack; #ifdef JULIA_ENABLE_THREADING jl_all_heaps[tid] = jl_mk_thread_heap(); #else @@ -291,7 +289,6 @@ void jl_init_threading(void) // set up space for per-thread heaps jl_all_heaps = (struct _jl_thread_heap_t **)malloc(jl_n_threads * sizeof(void*)); - jl_all_pgcstacks = (jl_gcframe_t ***)malloc(jl_n_threads * sizeof(void*)); jl_all_task_states = (jl_thread_task_state_t *)malloc(jl_n_threads * sizeof(jl_thread_task_state_t)); #if PROFILE_JL_THREADING @@ -538,7 +535,6 @@ void jl_init_threading(void) jl_all_task_states = &_jl_all_task_states; jl_max_threads = 1; jl_n_threads = 1; - jl_all_pgcstacks = (jl_gcframe_t***) malloc(jl_n_threads * sizeof(jl_gcframe_t**)); #if defined(__linux__) && defined(JL_USE_INTEL_JITEVENTS) if (jl_using_intel_jitevents) diff --git a/src/threading.h b/src/threading.h index 8508d448cb37a..95091eb58a5f1 100644 --- a/src/threading.h +++ b/src/threading.h @@ -22,7 +22,6 @@ extern JL_DLLEXPORT int jl_n_threads; // # threads we're actually using // GC extern struct _jl_thread_heap_t **jl_all_heaps; #endif -extern jl_gcframe_t ***jl_all_pgcstacks; // thread state enum { From d43226c3d90349487024bf014d8f548feffa4758 Mon Sep 17 00:00:00 2001 From: Yichao Yu Date: Sat, 5 Dec 2015 10:24:54 -0500 Subject: [PATCH 2/2] Make sure the GC heap is cache line aligned. --- src/gc.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/gc.c b/src/gc.c index 7de6d90fd7beb..0adc3602e74be 100644 --- a/src/gc.c +++ b/src/gc.c @@ -2462,8 +2462,9 @@ void jl_print_gc_stats(JL_STREAM *s) jl_thread_heap_t *jl_mk_thread_heap(void) { #ifdef JULIA_ENABLE_THREADING - // FIXME - should be cache-aligned malloc - jl_thread_heap = (jl_thread_heap_t*)malloc(sizeof(jl_thread_heap_t)); + // Cache-aligned malloc + jl_thread_heap = + (jl_thread_heap_t*)jl_malloc_aligned(sizeof(jl_thread_heap_t), 64); #endif FOR_CURRENT_HEAP () { const int* szc = sizeclasses;