playXE/rsgc

Finalization & Destructors

playXE opened this issue · 1 comments

Storage

  • How to store list of finalizeable and destructible objects?
  • How to put object into finalizable or destructible list or remove from it? (RegisterFinalizer, SupressFinalizer)

For finalizer storage I can see this solution: maintain segmented queue with free-list of some threshold. When we order finalizers we append to this list or delete from it, if enough entries is deleted segment is put into free-list, if there is enough segments that reach threshold we free all of the segments in free-list to the system. Pushing to finalizer queue would happen under lock to prevent any races.

Finalizers

  • How to order finalizers before execution? We can potentially use algorithm from PyPy's MiniMark.
  • How to handle finalizers that resurrect objects?

Destructors

  • Effective way to invoke destructors? Simply invoking destructors while sweeping region degrades performance, this can potentially run in background thread or in parallel.

One solution I can see for this is: Store list of destructible objects per region, when sweeping we simply pop from that list and invoke destructor if object is dead, for humongous objects we can check if object needs destruction directly avoiding destructible list. This way we solve storage problem by probably using simple segmented vector and concurrency problem because destructors will be invoked together with region being swept.

In the end i decided to not support destructors & finalizer. They complicate GC runtime by too much and reduce performance and latency of applications. If users want to imlement some kind of finalization they can use weak references and periodically check if weak reference is dead.