From 45905ca33b90cad3248b1fcc9b29960bfee5a353 Mon Sep 17 00:00:00 2001 From: Reimer Behrends Date: Sun, 20 Jan 2019 11:51:02 +0100 Subject: [PATCH] Julia GC: fix stack marking. This commit fixes two separate issues. 1. The processor stack was not being marked correctly, as Julia made wrong assumptions about the end of the processor stack; we now use the value of `stack_bottom` that is being supplied to InitBags(). 2. CHANGED_BAG() was not being called on CurrLVars when a collection was initiated, unlike for the GASMAN implementation, where this happens in VarsBeforeCollectBags(). --- src/julia_gc.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/julia_gc.c b/src/julia_gc.c index f2defe283d..761726d35b 100644 --- a/src/julia_gc.c +++ b/src/julia_gc.c @@ -364,6 +364,7 @@ static jl_datatype_t * datatype_mptr; static jl_datatype_t * datatype_bag; static jl_datatype_t * datatype_largebag; static UInt StackAlignBags; +static Bag * GapStackBottom; static jl_ptls_t JuliaTLS, SaveTLS; static size_t max_pool_obj_size; static size_t bigval_startoffset; @@ -527,6 +528,9 @@ void GapRootScanner(int full) // current_task != root_task. char * stackend = (char *)jl_task_stack_buffer(task, &size, &tid); stackend += size; + if (JuliaTLS->tid == 0 && JuliaTLS->root_task == task) { + stackend = (char *)GapStackBottom; + } // allow installing a custom marking function. This is used for // integrating GAP (possibly linked as a shared library) with other code @@ -589,6 +593,13 @@ static void PreGCHook(int full) // a thread-local variable. SaveTLS = JuliaTLS; JuliaTLS = jl_get_ptls_states(); + // This is the same code as in VarsBeforeCollectBags() for GASMAN. + // It is necessary because ASS_LVAR() and related functionality + // does not call CHANGED_BAG() for performance reasons. CHANGED_BAG() + // is only called when the current lvars bag is being changed. Thus, + // we have to add a write barrier at the start of the GC, too. + if (STATE(CurrLVars)) + CHANGED_BAG(STATE(CurrLVars)); /* information at the beginning of garbage collections */ SyMsgsBags(full, 0, 0); memset(MarkCache, 0, sizeof(MarkCache)); @@ -638,6 +649,7 @@ static uintptr_t JMarkBag(jl_ptls_t ptls, jl_value_t * obj) void InitBags(UInt initial_size, Bag * stack_bottom, UInt stack_align) { // HOOK: initialization happens here. + GapStackBottom = stack_bottom; for (UInt i = 0; i < NUM_TYPES; i++) TabMarkFuncBags[i] = MarkAllSubBags; // These callbacks need to be set before initialization so