-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
[mono] Don't generate safepoints inside write barrier wrapper #58346
Conversation
There is no need for a m2n transition since the method just marks the card table. No exception can be thrown, no marshalling is required, no gc can happen during its execution etc. In addition to the redundancy of the wrapper, it also contains gc safepoints which is wrong. Having a GC between the ref store and the corresponding card table marking can in theory crash the GC.
This wrapper is called immediately after a store to a ref field. The ref store and the card table marking should be atomic in relation to GCs. Therefore we shouldn't have a safepoint in the wrapper.
Do we have a list of LLVM passes that we use somewhere? It should be the https://llvm.org/docs/Statepoints.html#placesafepoints PlaceSafepoints pass that adds calls to I think the decision of which functions should get safepoints is controlled by I guess the way to mark a |
Calls to |
We don't have a centralized list of all the LLVM passes we use, and the passes we use differ between LLVM AOT and LLVM as a JIT. For AOT, the flags we pass to opt and llc are here. For JIT, the passes we use are listed here and here.
You could call |
@BrzVlad So add the barrier wrapper here: runtime/src/mono/mono/mini/mini-llvm.c Lines 11464 to 11470 in b6cc822
@imhameed Why do we bother with a "mono" GC type when the runtime actually uses "coreclr" 🤪 |
Refactored the code a little bit so we disable safepoints in GC wrappers both on aot and !aot. |
@BrzVlad do we want this for 6.0? How risky is it? |
I think the risk is low but not negligible. I don't know if this issue ever lead to a crash, so I don't think it is a mandatory backport. This change might have some noticeable perf gains on AOT since we avoid wrapper + safepoints for stores into ref fields, so that could be a motivating factor. Maybe if we see some crazy perf gains in the benchmark runs that could justify it. |
A ref store and its associated write barrier need to happen atomically relative to garbage collections. No GCs should happen between the ref store and the card mark.