Repository: JuliaLang/julia
File: src/task.c (C)

Code before:
#endif
#ifdef COPY_STACKS
            if (jl_setjmp(lasttstate.copy_ctx.uc_mcontext, 0)) {
#ifdef MIGRATE_TASKS
                ptls = lastt->ptls;
#endif
                lastt->ctx.copy_ctx = NULL;
                sanitizer_finish_switch_fiber(&ptls->previous_task->ctx, &lastt->ctx);
                return;
            }
            save_stack(ptls, lastt, pt); // allocates (gc-safepoint, and can also fail)
            lastt->ctx.copy_ctx = &lasttstate.copy_ctx;
#else
            abort();
#endif
        }
        else {
            *pt = NULL; // can't fail after here: clear the gc-root for the target task now
            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;
    jl_atomic_store_relaxed(&ptls->current_task, t);
    JL_GC_PROMISE_ROOTED(t);
    jl_signal_fence();
    jl_set_pgcstack(&t->gcstack);
    jl_signal_fence();
    lastt->ptls = NULL;
#ifdef MIGRATE_TASKS
    ptls->previous_task = lastt;
#endif

    if (t->ctx.started) {
        if (t->ctx.copy_stack) {
#ifdef COPY_STACKS
            if (lastt->ctx.copy_stack) {
                // Switching from copystack to copystack. Clear any shadow stack
                // memory above the saved shadow stack.
                uintptr_t stacktop = (uintptr_t)ptls->stackbase - t->ctx.copy_stack;
                uintptr_t stackbottom = ((uintptr_t)jl_get_frame_addr() & ~15);
                if (stackbottom < stacktop)
                    asan_unpoison_stack_memory(stackbottom, stacktop - stackbottom);
            }

Review comment (suggestion):
```suggestion
    // let the gc figure that out next time it does a quick mark
```

Code after:
#endif
#ifdef COPY_STACKS
            if (jl_setjmp(lasttstate.copy_ctx.uc_mcontext, 0)) {
#ifdef MIGRATE_TASKS
                ptls = lastt->ptls;
#endif
                lastt->ctx.copy_ctx = NULL;
                sanitizer_finish_switch_fiber(&ptls->previous_task->ctx, &lastt->ctx);
                return;
            }
            save_stack(ptls, lastt, pt); // allocates (gc-safepoint, and can also fail)
            lastt->ctx.copy_ctx = &lasttstate.copy_ctx;
#else
            abort();
#endif
        }
        else {
            *pt = NULL; // can't fail after here: clear the gc-root for the target task now
            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 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;
    jl_atomic_store_relaxed(&ptls->current_task, t);
    JL_GC_PROMISE_ROOTED(t);
    jl_signal_fence();
    jl_set_pgcstack(&t->gcstack);
    jl_signal_fence();
    lastt->ptls = NULL;
#ifdef MIGRATE_TASKS
    ptls->previous_task = lastt;
#endif

    if (t->ctx.started) {
        if (t->ctx.copy_stack) {
#ifdef COPY_STACKS
            if (lastt->ctx.copy_stack) {
                // Switching from copystack to copystack. Clear any shadow stack
                // memory above the saved shadow stack.
                uintptr_t stacktop = (uintptr_t)ptls->stackbase - t->ctx.copy_stack;
                uintptr_t stackbottom = ((uintptr_t)jl_get_frame_addr() & ~15);
                if (stackbottom < stacktop)
                    asan_unpoison_stack_memory(stackbottom, stacktop - stackbottom);
            }