Skip to content

Refactoring code that is specific to stock GC write barriers #57237

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

Merged
merged 1 commit into from
Feb 24, 2025

Conversation

udesou
Copy link
Contributor

@udesou udesou commented Feb 3, 2025

This PR moves some code responsible for implementing write barriers around: the write barrier functions are lifted from julia.h into the new gc-wb-*.h files.

@udesou udesou added the GC Garbage collector label Feb 3, 2025
@udesou udesou force-pushed the refactor/write-barriers branch 3 times, most recently from 1ff7739 to 1ce72aa Compare February 3, 2025 03:36
Copy link
Member

@vchuravy vchuravy left a comment

Choose a reason for hiding this comment

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

Do we know yet how the write barriers for mmtk will look like?

The GCs share a tag layout?

I would prefer doing this code movement when we have a functional implementaion and not a "TODO implement these". That would also include tests for the new lowering in https://github.com/JuliaLang/julia/tree/master/test/llvmpasses

@udesou udesou force-pushed the refactor/write-barriers branch from 1ce72aa to 19eb356 Compare February 3, 2025 22:30
@udesou
Copy link
Contributor Author

udesou commented Feb 3, 2025

Do we know yet how the write barriers for mmtk will look like?
I would prefer doing this code movement when we have a functional implementaion and not a "TODO implement these". That would also include tests for the new lowering in https://github.com/JuliaLang/julia/tree/master/test/llvmpasses

I agree that it's not ideal to have only the stubs for the MMTk implementation. This branch currently has the final implementation of sticky working: https://github.com/udesou/julia/tree/upstream-ready/sticky.
But what I've been doing is to try to create smaller PRs that encapsulate these refactorings before adding the code that actually implements MMTk's sticky (generational) collector. As for the tests, that's a great reminder. I think we should definitely add tests, but perhaps it makes more sense to add them in a separate PR (the one in which we add sticky immix?)

The GCs share a tag layout?

No, the log bit is currently implemented as part of a side metadata maintained by MMTk. We can potentially look into reusing Julia's tag layout but I think the code movement in this PR is actually orthogonal to it. Any other GC that we'd eventually plug in with a different layout would have to reimplement the barriers accordingly. So I think it makes sense that the code for implementing and lowering the write barriers should live in each gc-specific file.

@vchuravy
Copy link
Member

vchuravy commented Feb 4, 2025

No, the log bit is currently implemented as part of a side metadata maintained by MMTk.

Huh, okay. That means we will need quite some more code-modifications in areas where we are currently directly modifying the GC bits?

But what I've been doing is to try to create smaller PRs that encapsulate these refactorings

I love small refactorings, but they must make the code clearer on their own. Currently, without knowing the other side of this code, it's difficult to tell if this refactoring is beneficial or if a different strategy would be better.

As for the tests, that's a great reminder. I think we should definitely add tests, but perhaps it makes more sense to add them in a separate PR (the one in which we add sticky immix?)

It's good to start with tests for the code as is. Then you can test everything and show that once you actually add the implementation what the emitted code will look like.

@d-netto
Copy link
Member

d-netto commented Feb 4, 2025

The general idea here looks fine to me (have some minor comments which I will post shortly).

I believe that we proposed this refactor in the GC interface document already -- https://docs.google.com/document/d/1v0jtSrIpdEDNOxj5S9g1jPqSpuAkNWhr_T8ToFC9RLI/edit?usp=drivesdk.

The pattern we will follow to ensure that we inline these short functions in the
runtime is to conditionally #include in src/julia.h a header containing the write-barrier
implementation of Julia's stock GC or the implementation of the third-party GC.

@d-netto
Copy link
Member

d-netto commented Feb 4, 2025

I love small refactorings, but they must make the code clearer on their own. Currently, without knowing the other side of this code, it's difficult to tell if this refactoring is beneficial or if a different strategy would be better.

Could you clarify these concerns about code clarity @vchuravy?

Asking because I'd expect the code structure to remain fairly similar after we merge the generational MMTk and implement proper write barriers.

I.e. I think the call-sites of these functions will remain the same, though we will change some of them (e.g. jl_gc_wb) from no-ops to something actually functional.

@d-netto
Copy link
Member

d-netto commented Feb 4, 2025

I.e. I think the call-sites of these functions will remain the same, though we will change some of them (e.g. jl_gc_wb) from no-ops to something actually functional.

If that's the kind of refactor we will do, then I'm not sure how much more clarity we will be able to get by squashing this into a larger PR that introduces the generational MMTk.

@udesou udesou force-pushed the refactor/write-barriers branch 5 times, most recently from ed999a6 to 1253399 Compare February 6, 2025 02:47
@udesou
Copy link
Contributor Author

udesou commented Feb 6, 2025

I've removed the llvm-specific code, and left the refactoring of the jl_gc_wb* write barriers only. I'll leave the other changes to the PR that we add sticky so we have a better idea of what the code for MMTk will look like.

@d-netto d-netto force-pushed the refactor/write-barriers branch from 1253399 to 5b5c0e8 Compare February 6, 2025 14:14
@d-netto
Copy link
Member

d-netto commented Feb 6, 2025

The MMTk build seems to be segfaulting.

@udesou
Copy link
Contributor Author

udesou commented Feb 6, 2025

The MMTk build seems to be segfaulting.

The PR #57253 has changed the layout for _jl_module_t and added a new root. I'm updating the binding to propagate that change and fix the build for MMTk.

@udesou udesou force-pushed the refactor/write-barriers branch 2 times, most recently from d05772f to ebf6838 Compare February 9, 2025 22:27
@udesou udesou force-pushed the refactor/write-barriers branch 4 times, most recently from 5e520f4 to 6effd12 Compare February 17, 2025 22:26
@udesou udesou force-pushed the refactor/write-barriers branch 2 times, most recently from ef6435f to f8cbb6a Compare February 20, 2025 05:20
oscardssmith pushed a commit that referenced this pull request Feb 20, 2025
…rom `genericmemory.c` (#57252)

This PR moves stock-specific write barriers from
`jl_genericmemory_copyto` into `julia.h`. Note that this PR can be
merged independently, but is heavily connected with
#57237. Ideally they should be
combined, but this PR actually introduces new functions to the GC
interface, and that is the main reason I'd like them to be reviewed
separately. The code for either PR will have to be adapted depending on
which one gets merged first.
@udesou udesou force-pushed the refactor/write-barriers branch 3 times, most recently from c5d10ef to 755e511 Compare February 20, 2025 22:30
Copy link
Member

@d-netto d-netto left a comment

Choose a reason for hiding this comment

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

LGTM. Perhaps rewrite the comments at the top of the WB header files

@udesou udesou force-pushed the refactor/write-barriers branch 3 times, most recently from 6dcfa67 to 2248ab1 Compare February 21, 2025 01:34
@udesou udesou added the merge me PR is reviewed. Merge when all tests are passing label Feb 21, 2025
@udesou udesou force-pushed the refactor/write-barriers branch from 2248ab1 to 73018de Compare February 23, 2025 22:58
@oscardssmith
Copy link
Member

The OOMs on 32 bit architectures are a bit concerning.

@d-netto
Copy link
Member

d-netto commented Feb 24, 2025

The OOMs on 32 bit architectures are a bit concerning.

I'm skeptical they are related to this PR (which only moves a few functions to new files).

Let's rebase to rerun CI and see.

@d-netto d-netto force-pushed the refactor/write-barriers branch from 73018de to 40fb554 Compare February 24, 2025 15:05
@KristofferC
Copy link
Member

The OOMs on 32 bit architectures are a bit concerning.

I see these all the time

@d-netto d-netto merged commit 925a8fe into JuliaLang:master Feb 24, 2025
7 checks passed
@giordano giordano removed the merge me PR is reviewed. Merge when all tests are passing label Feb 25, 2025
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.

6 participants