garbage collection - Checkpoint and restore the heap in Ruby -
ruby's callcc
captures current continuation, can subsequently called restore control, not data. capture current continuation along current image of memory.
it seems me capturing heap shouldn't difficult; can rely on objectspace::each_object
, objectspace::dump_all
, or marshal.dump
, or object.clone
. however, don't see straightforward way restore heap. ideally, traverse object_id -> object
map, restoring old image of object every object_id
(and re-adding object_id
if corresponding object had been gc'd). unsurprisingly, there no ruby-level api lets me this. wondering if there low-level hooks ruby's gc can use.
any appreciated, including suggestions alternative approaches.
to answer own question, process.fork
can used more-or-less achieve effect of heap checkpointing , restoration. whenever have checkpoint heap, fork new process , let child continue. parent process contains checkpointed heap:
def checkpoint if process.fork.nil? # if child, resume execution return else # if parent, wait child exit. process.wait end return # parent resumes execution state in before forking. end
when state has restored, child process exits:
def restore process.exit end
i using solution, , haven't encountered problems far. edit answer if find in future.
Comments
Post a Comment