From a63b365890276532e09066b32784aa10a0f4fa0f Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Fri, 9 Jan 2026 14:55:53 +0000 Subject: [PATCH 1/2] add wb_back on all task switch paths Since this task's stack or scope field could have been modified after it was marked by an incremental collection (and not just for copy stacks), move the barrier back unconditionally here. --- src/task.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/task.c b/src/task.c index 18d21b2343053..ec327c77e2c4a 100644 --- a/src/task.c +++ b/src/task.c @@ -198,10 +198,6 @@ static void NOINLINE save_stack(jl_ptls_t ptls, jl_task_t *lastt, jl_task_t **pt lastt->ctx.copy_stack = nb; lastt->sticky = 1; memcpy_stack_a16((uint64_t*)buf, (uint64_t*)frame_addr, nb); - // this task's stack could have been modified after - // it was marked by an incremental collection - // move the barrier back instead of walking it again here - jl_gc_wb_back(lastt); } JL_NO_ASAN static void NOINLINE JL_NORETURN restore_stack(jl_ucontext_t *t, jl_ptls_t ptls, char *p) @@ -499,6 +495,12 @@ JL_NO_ASAN static void ctx_switch(jl_task_t *lastt) lastt->ctx.ctx = &lasttstate.ctx; } } + // this task's stack or scope field could have been modified after + // it was marked by an incremental collection + // move the barrier back instead of walking the shadow stack again here to check if that is required + // even if killed (dropping the stack) and just the scope field matters, + // let the gc figure out that out next time it does a quick mark + jl_gc_wb_back(lastt); // set up global state for new task and clear global state for old task t->ptls = ptls; From f4b6ae5f7d64fe9696d8404417c6266c0d4345a2 Mon Sep 17 00:00:00 2001 From: Valentin Churavy Date: Wed, 14 Jan 2026 14:41:22 +0100 Subject: [PATCH 2/2] Apply suggestion from @JeffBezanson Co-authored-by: Jeff Bezanson --- src/task.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/task.c b/src/task.c index ec327c77e2c4a..e8404a9213d28 100644 --- a/src/task.c +++ b/src/task.c @@ -499,7 +499,7 @@ JL_NO_ASAN static void ctx_switch(jl_task_t *lastt) // it was marked by an incremental collection // move the barrier back instead of walking the shadow stack again here to check if that is required // even if killed (dropping the stack) and just the scope field matters, - // let the gc figure out that out next time it does a quick mark + // let the gc figure that out next time it does a quick mark jl_gc_wb_back(lastt); // set up global state for new task and clear global state for old task