Post AYb50CvEf2aRGe08Aq by icedquinn@blob.cat
 (DIR) More posts by icedquinn@blob.cat
 (DIR) Post #AYb4d0ROtqHrtgz01g by Mek101@fosstodon.org
       2023-08-10T19:03:48Z
       
       0 likes, 0 repeats
       
       Does anyone know how a precise garbage collector works? Mostly, how does it find the roots inside stack objects? #programming #GarbageCollector
       
 (DIR) Post #AYb4dT7YGidoqWv3c8 by icedquinn@blob.cat
       2023-08-10T19:10:20.897002Z
       
       0 likes, 0 repeats
       
       @Mek101 precise collectors deal with explicit graphs of objects. whenever it stores a pointer to another managed object, that is stored in a way that the collector can audit at runtime.so you have generation counters like white/black, all gc allocations are in a huge pointer chain so it can traverse all known allocations, it knows the current generation, so you go through starting at the roots and asking those objects to please paint all objects it knows of in the opposite color (the mark phase), then it goes through the list of all known allocations and destroys elements of the wrong color.objects on the stack aren't allocated through the GC. their memory belongs to the stack and is swept when you pop the stack frame. (if you mean a stack handle to a GC object, there are some ways of dealing with this like having an atomic reference counter to hold a temporary lock)
       
 (DIR) Post #AYb50CvEf2aRGe08Aq by icedquinn@blob.cat
       2023-08-10T19:14:34.439377Z
       
       1 likes, 0 repeats
       
       @Mek101 i think this is what you're talking about https://langdev.stackexchange.com/questions/1685/how-do-precise-garbage-collectors-find-roots-in-the-stack and i guess they don't use an atomic counter for it, but some shenanigans so it can find them on the stack. :blabcat:
       
 (DIR) Post #AYbPnCqXjGi6J0RqG8 by Mek101@fosstodon.org
       2023-08-10T22:43:07Z
       
       0 likes, 0 repeats
       
       @icedquinn @alcinnz I'm already using a linked list of stack arrays to keep track of pure references to heap objects.Each function that allocates has a fixed size `void* stack_node[N];` with the first index having a pointer to the previous node and the second the size of the array.I can only think of 2 solutions.1 Root each field into the array as if it was a free reference2 Add a second contiguos array where a pointer to a stack struct and one to it's typeinfo alternate
       
 (DIR) Post #AYbPnDdSnNqGkjKuVk by icedquinn@blob.cat
       2023-08-10T23:06:59.574744Z
       
       0 likes, 0 repeats
       
       @Mek101 @alcinnz that sounds fangly :neocat_woozy: