Skip to content

Commit 26179c5

Browse files
committed
Merge pull request JuliaLang#14278 from JuliaLang/yyc/gc/cleanup
Do not assume the GC is always running on the master thread.
2 parents 05301b9 + d43226c commit 26179c5

File tree

3 files changed

+11
-19
lines changed

3 files changed

+11
-19
lines changed

src/gc.c

+11-14
Original file line numberDiff line numberDiff line change
@@ -1028,7 +1028,7 @@ static size_t array_nbytes(jl_array_t *a)
10281028
return sz;
10291029
}
10301030

1031-
void jl_gc_free_array(jl_array_t *a)
1031+
static void jl_gc_free_array(jl_array_t *a)
10321032
{
10331033
if (a->how == 2) {
10341034
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
16301630
static void gc_mark_task_stack(jl_task_t *ta, int d)
16311631
{
16321632
int stkbuf = (ta->stkbuf != (void*)(intptr_t)-1 && ta->stkbuf != NULL);
1633+
int16_t tid = ta->tid;
1634+
jl_tls_states_t *ptls = jl_all_task_states[tid].ptls;
16331635
if (stkbuf) {
16341636
#ifndef COPY_STACKS
1635-
if (ta != jl_root_task) // stkbuf isn't owned by julia for the root task
1637+
if (ta != ptls->root_task) // stkbuf isn't owned by julia for the root task
16361638
#endif
16371639
gc_setmark_buf(ta->stkbuf, gc_bits(jl_astaggedvalue(ta)));
16381640
}
1639-
if (ta == jl_all_task_states[ta->tid].ptls->current_task) {
1640-
gc_mark_stack((jl_value_t*)ta, *jl_all_pgcstacks[ta->tid], 0, d);
1641+
if (ta == ptls->current_task) {
1642+
gc_mark_stack((jl_value_t*)ta, ptls->pgcstack, 0, d);
16411643
}
16421644
else if (stkbuf) {
16431645
ptrint_t offset;
16441646
#ifdef COPY_STACKS
1645-
offset = (char *)ta->stkbuf - ((char *)jl_stackbase - ta->ssize);
1647+
offset = (char *)ta->stkbuf - ((char *)ptls->stackbase - ta->ssize);
16461648
#else
16471649
offset = 0;
16481650
#endif
@@ -1907,8 +1909,6 @@ static void pre_mark(void)
19071909

19081910
// invisible builtin values
19091911
if (jl_an_empty_cell) gc_push_root(jl_an_empty_cell, 0);
1910-
gc_push_root(jl_exception_in_transit, 0);
1911-
gc_push_root(jl_task_arg_in_transit, 0);
19121912
if (jl_module_init_order != NULL)
19131913
gc_push_root(jl_module_init_order, 0);
19141914

@@ -2037,7 +2037,7 @@ static void print_obj_profile(htable_t nums, htable_t sizes)
20372037
}
20382038
}
20392039

2040-
void print_obj_profiles(void)
2040+
static void print_obj_profiles(void)
20412041
{
20422042
jl_printf(JL_STDERR, "Transient mark :\n");
20432043
print_obj_profile(obj_counts[0], obj_sizes[0]);
@@ -2054,10 +2054,6 @@ static int saved_mark_sp = 0;
20542054
static int sweep_mask = GC_MARKED;
20552055
#define MIN_SCAN_BYTES 1024*1024
20562056

2057-
void prepare_sweep(void)
2058-
{
2059-
}
2060-
20612057
JL_DLLEXPORT void jl_gc_collect(int full)
20622058
{
20632059
if (!is_gc_enabled) return;
@@ -2466,8 +2462,9 @@ void jl_print_gc_stats(JL_STREAM *s)
24662462
jl_thread_heap_t *jl_mk_thread_heap(void)
24672463
{
24682464
#ifdef JULIA_ENABLE_THREADING
2469-
// FIXME - should be cache-aligned malloc
2470-
jl_thread_heap = (jl_thread_heap_t*)malloc(sizeof(jl_thread_heap_t));
2465+
// Cache-aligned malloc
2466+
jl_thread_heap =
2467+
(jl_thread_heap_t*)jl_malloc_aligned(sizeof(jl_thread_heap_t), 64);
24712468
#endif
24722469
FOR_CURRENT_HEAP () {
24732470
const int* szc = sizeclasses;

src/threading.c

-4
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ JL_DLLEXPORT JL_CONST_FUNC jl_tls_states_t *(jl_get_ptls_states)(void)
127127
JL_DLLEXPORT int jl_n_threads; // # threads we're actually using
128128
JL_DLLEXPORT int jl_max_threads; // # threads possible
129129
jl_thread_task_state_t *jl_all_task_states;
130-
jl_gcframe_t ***jl_all_pgcstacks;
131130

132131
// return calling thread's ID
133132
JL_DLLEXPORT int16_t jl_threadid(void) { return ti_tid; }
@@ -139,7 +138,6 @@ static void ti_initthread(int16_t tid)
139138
{
140139
ti_tid = tid;
141140
jl_pgcstack = NULL;
142-
jl_all_pgcstacks[tid] = &jl_pgcstack;
143141
#ifdef JULIA_ENABLE_THREADING
144142
jl_all_heaps[tid] = jl_mk_thread_heap();
145143
#else
@@ -291,7 +289,6 @@ void jl_init_threading(void)
291289

292290
// set up space for per-thread heaps
293291
jl_all_heaps = (struct _jl_thread_heap_t **)malloc(jl_n_threads * sizeof(void*));
294-
jl_all_pgcstacks = (jl_gcframe_t ***)malloc(jl_n_threads * sizeof(void*));
295292
jl_all_task_states = (jl_thread_task_state_t *)malloc(jl_n_threads * sizeof(jl_thread_task_state_t));
296293

297294
#if PROFILE_JL_THREADING
@@ -538,7 +535,6 @@ void jl_init_threading(void)
538535
jl_all_task_states = &_jl_all_task_states;
539536
jl_max_threads = 1;
540537
jl_n_threads = 1;
541-
jl_all_pgcstacks = (jl_gcframe_t***) malloc(jl_n_threads * sizeof(jl_gcframe_t**));
542538

543539
#if defined(__linux__) && defined(JL_USE_INTEL_JITEVENTS)
544540
if (jl_using_intel_jitevents)

src/threading.h

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ extern JL_DLLEXPORT int jl_n_threads; // # threads we're actually using
2222
// GC
2323
extern struct _jl_thread_heap_t **jl_all_heaps;
2424
#endif
25-
extern jl_gcframe_t ***jl_all_pgcstacks;
2625

2726
// thread state
2827
enum {

0 commit comments

Comments
 (0)