Skip to content

Add write barriers when setting Tasks' scope field.#60571

Closed
NHDaly wants to merge 1 commit intorelease-1.12from
nhd-Task-scope-write_barriers
Closed

Add write barriers when setting Tasks' scope field.#60571
NHDaly wants to merge 1 commit intorelease-1.12from
nhd-Task-scope-write_barriers

Conversation

@NHDaly
Copy link
Member

@NHDaly NHDaly commented Jan 6, 2026

This is needed because the field is a jl_value_t* being set in native code.
Presumably this will fix #59483

This is needed because the field is a jl_value_t* being set in native
code.
Presumably this will fix #59483
Copy link
Member

@vtjnash vtjnash left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assigning to the fields of current task does not use a write barrier (the gc knows this would be too costly)

@Keno
Copy link
Member

Keno commented Jan 6, 2026

fields of current task

all, tasks right?

julia/src/gc-stock.c

Lines 2362 to 2363 in e8bf6c4

// assume tasks always reference young objects: set lowest bit
uintptr_t nptr = (npointers << 2) | 1 | bits;

@vtjnash
Copy link
Member

vtjnash commented Jan 7, 2026

Are they always trapped in the remset? I thought I was told it was only the current task, since the task itself isn't colored (just the metadata update here) when being stored back

@Keno
Copy link
Member

Keno commented Jan 8, 2026

You're right, only the current task on all threads gets queued to the remset: https://github.com/JuliaLang/julia/blob/master/src/gc-stock.c#L2770-L2774

So what does that imply for the semantics of the write barrier? Do we need to wb on context switch if we're switching out the task (plus the one assignment in task creation where the task we're assigning is not the current task).

@vtjnash
Copy link
Member

vtjnash commented Jan 8, 2026

Yes, it is supposed to have one on context switch too

julia/src/task.c

Lines 201 to 204 in e57442f

// 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);

The one in creation is usually either jl_gc_wb_knownold or jl_gc_wb_fresh (a no-op in either case), since the only value we have constructed during bootstrapping by the time we need to allocate a task is nothing

jl_atomic_store_relaxed(&t->_isexception, 0);
// Inherit scope from parent task
t->scope = ct->scope;
jl_gc_wb(t, ct->scope);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given discussion then - I think this is the only one that is required.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Except, the task is fresh and jl_malloc_stack is JL_NOTSAFEPOINT, so I think we're back to mystery.

@NHDaly
Copy link
Member Author

NHDaly commented Jan 8, 2026

Okay, well, this PR didn't help with our crash anyway, so indeed maybe none of these write barriers are needed.

I can close the PR -- but reading the thread above, i'm not left with confidence in whether any of these are needed. Are you guys sure that none of them are needed? If you are sure, please close this PR. Or feel free to take it over however you see fit - i relinquish unto you :)

@Keno
Copy link
Member

Keno commented Jan 8, 2026

Are you guys sure that none of them are needed? I

Yeah, we're pretty sure. The one that assigns to the newly allocated task could possibly use a jl_gc_wb_fresh to annotate the no-op, but that's neither here nor there.

@Keno Keno closed this Jan 8, 2026
@DilumAluthge DilumAluthge deleted the nhd-Task-scope-write_barriers branch January 16, 2026 15:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants