Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: save registers of tasks that were active right before GC on a ucontext_t for conservative scanning #55003

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

d-netto
Copy link
Member

@d-netto d-netto commented Jul 2, 2024

Garbage collectors that are fully or partially conservative usually need to look at what was stored in the registers of the tasks right before GC started, and may also benefit from having information about the stack pointer at the time GC started in order to determine the lower/upper bounds of the stack.

Let's expose a call to support register saving for conservative GCs.

The current implementation is WIP because:

  • Can be optimized for space by saving the context into the tasks' jl_ucontext_t itself, instead of adding a new field to the TLS as I'm doing now.
  • It's only x86_64 Linux for now.

CC: @qinsoon, @kpamnany.

@d-netto d-netto added the GC Garbage collector label Jul 2, 2024
@d-netto d-netto requested review from vtjnash and gbaraldi July 2, 2024 18:17
@d-netto d-netto marked this pull request as draft July 2, 2024 18:20
@d-netto
Copy link
Member Author

d-netto commented Jul 2, 2024

One clarification: this call allows us to get the contexts of the tasks that were scheduled right before GC started (i.e. the tasks that read from the safe-point page and incurred a segmentation fault).

Getting register/stack-pointer information for tasks that were de-scheduled when GC started is easier because they were saved in a jl_ucontext_t in the last task switch.

@d-netto d-netto force-pushed the dcn-save-registers-for-conservative-scanning branch from 5c958a5 to b47b0ea Compare July 2, 2024 18:56
// Requires `GC_SAVE_CONTEXT_FOR_CONSERVATIVE_SCANNING` to be defined.
// If ctx is NULL, the registers of the thread at the moment of the call are saved, else
// the registers of the context ctx are saved into the `ctx_at_the_time_gc_started` field of Julia's TLS.
JL_DLLEXPORT void jl_save_context_for_conservative_scanning(jl_ptls_t ptls, void *ctx);
Copy link
Contributor

Choose a reason for hiding this comment

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

It's not clear to me who would be calling this and when. And depending on the answer to that possibly also whether it is idempotent (i.e. if I accidentally call it twice, is that safe).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GC Garbage collector
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants