Why is method call treated as a safe point for GC

Hi all,

In the LLVM GC framework, we are talking about the safe points which are used to run the GC. When selecting the safe points, methods call are considered as safe points. I cannot understand the reason to treat method calls as safe points. Can you explain the reason?

Thank you,
Kavindu

Hi,

I believe this is to permit local reasoning. A method call is not necessarily a real safe point, but if the callee reaches a safe point then the entire stack must be treated as a safe point. Without this assumption, you could reach a safe point in the current leaf function but the caller would not be in a safe point and so your stack would be in an inconsistent state.

In theory, you could make may-be-a-safepoint an attribute on methods and avoid making the call site a safe point for cases where you can statically prove that nothing reachable from the callee contains a safe point.

In practice, if you have sufficient analysis to be able to guarantee that the callee doesn't contain safe points (which also implies that it has a sufficiently short execution time that the lack of safepoints will not impact overall performance) then you probably want to inline it. At this point, the method call no longer exists and so you don't have to worry about it as a potential safe point.

David

Hi David,

Thank you for your detailed response.