card table and write barriers in .net GC

那年仲夏 提交于 2020-01-15 03:57:05

问题


Can anybody explain the concept of card table and write barriers in Garbage Collection process in .Net? I really can't get the explanation of these terms i.e what are they,how are they useful and how do they paticipate in GC. Any help would be really appreciated.


回答1:


The card table is an array of bits, one bit for each chunk of 256 bytes of memory in the old generation. The bits are normally zero but when a field of an object in the old generation is written to, the bit corresponding to the objects memory address is set to one. That is called executing the write barrier.

The garbage collector in .NET is generational and has a phase which only traces and collects objects in the young generation. So it goes through the object graph starting with the roots but does not recurse into objects in the old generation. In that way, it only traces a small fraction of the whole object graph.

To find the roots to start tracing from, it scans the programs local and global variables for young generation objects. But it would miss objects only referenced from old generation objects. Therefore it also scans fields of objects in the old generation whose card table bit is set.

Then after the young generation collection is complete it resets all card table bits to zero.



来源:https://stackoverflow.com/questions/39309806/card-table-and-write-barriers-in-net-gc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!