Check if a value is rooted by the Garbage Collector (GC)

Given a C-pointer jl_value_t*, I would like to check whether the GC currently has a root to it. With root, I mean that the memory is marked such that it cannot be released when the gc starts its sweeping process.

I’m pretty sure this is only solvable though the julia C-API, which I am fine with. Looking at julia_gcext.h I found no function relevant to this problem.
My current best lead is this field of the thread heap in julia_threads.h, but I’m unsure of how to interact with it. None of this is documented, afaik.

If I could somehow get notified when the GC roots a value, that would solve it too. Any ideas?


EDIT: I am very concious of the fact I shouldn’t be rummaging around the C-APIs internals, but I through careful consideration I have come to the conclusion that it is necessary. Even if it is a bad idea, I would still like to know how to access the list of values

I think you are thinking about this backwards. You should always root an object before calling into C, so from C’s perspective, all objects it can see should be rooted.

I realize this, however, for my specific problem, I cannot be certain a given object is already rooted. That is up to a third party, and I have no control over it.

I am currently rooting every single object to make sure, which incurs a performance overhead for cases where it is already is rooted. I’m trying to avoid this, hence my question.

In that case, you should probably disable gc while the ccall is running.

My API has C as the host language, I have no control over the amount of time any given value may be needed, hence disabling the GC is not an option. I want to avoid asking the user to manually disable and reenable the GC. I’m trying to both automate that process, and avoid doing the double rooting, which is the reason I posed the question.

I know that it is bad practice and probably a bad idea, but I still want to know how to access the list of rooted values anyway

Way way less than running the mark process which is the only way you’ll know for sure that it’s rooted I suspect.