-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Description
Instead of maintaining our own GC stack frames – which is slow and easy to mess up, likely accounting for a large portion of our tough-to-track-down core Julia bugs in the past years – we've occasionally talked about doing conservative stack scanning. That is, scanning the stack and conservatively assuming that anything that happens to look like a pointer to a valid heap-allocated Julia object actually is.
Pros:
- much simpler
- faster (RFC: Create local gc frame for
throw
#11508, Throw exceptions with arguments without creating a GC frame #11284) - makes stack allocation much easier (WIP: on-stack gc allocation #8134)
- immutables with references trivially become as efficient as reference-free immutables
- fewer segfaults
Cons:
- might retain objects that should be freed
- pointers passed into C code could still expect objects to live but not point to the head of the object
- performance of stack scanning
The second con seems like it can be avoided with the same kind of rooting we do now, except only needed at the ccall entry point. The chances of the first con happening – i.e. random values in the stack pointing valid heap objects – seems pretty slim. There might be situations like when you take a pointer to an array and then use it – but in that case you probably want the array to remain rooted while someone has a pointer to it. Are there other potential cons that I'm not seeing?
cc: @carnaval, @vtjnash, @JeffBezanson