mmtk / ruby

Fork of The Ruby Programming Language [mirror], with added support for MMTk
https://www.ruby-lang.org/
Other
0 stars 1 forks source link

[GC API] Change implementation of objects freed at shutdown to use heap walking #87

Open peterzhu2118 opened 3 months ago

peterzhu2118 commented 3 months ago

Right now, we place objects that need to be freed at shutdown into a weak list that is traversed at shutdown. This makes allocation slower and increases memory used.

Allocation:

https://github.com/mmtk/ruby/blob/9903af45b366238734403ad3b709102e418598d1/gc/mmtk.c#L224

Shutdown:

https://github.com/mmtk/ruby/blob/9903af45b366238734403ad3b709102e418598d1/gc/mmtk.c#L495-L503

Instead, we should use heap walking at shutdown to free these objects.

wks commented 3 months ago

mmtk_add_obj_free_candidate will make allocation slow if the object needs obj_free. But we also need the list of obj_free candidates during normal GC, too, not just during shutdown. During GC, after the liveness of all objects are determined (i.e. after the transitive closure), we go through the list of obj_free candidates to free them. So freeing objects at shutdown using heap walking can't eliminate the need of mmtk_add_obj_free_candidate.

But there is one alternative. We may walk the heap during GC (after transitive closure) to find dying obj_free candidates. Then we don't need mmtk_add_obj_free_candidate at allocation sites. I am not sure if it profitable.