Re: [MLton] MLton Object Root Sets
Matthew Fluet <[email protected]> Tue, 8 Sep 2015 21:50:46 -0400
| Newsgroups | gmane.comp.lang.ml.mlton.devel |
|---|---|
| Message-ID | <CAMrhFL5EyqZ_vdfQLDaZY8dLRECo3EiTky2=ujOh=eGDeF_ZUw@mail.gmail.com> |
On Tue, Sep 8, 2015 at 12:41 AM, muyuanli <[email protected]> wrote: > Hi, > I'm writing a simple real time mark & sweep GC for MLton and I > encountered some problems: > > 1. In the Mark & Sweep phase, it looks like the GC wind up collecting > some objects that are still in use. I wonder if I missed some objects > in the root sets for DFS mark. The code logic looks like: > > performGC: > GC_stack currentStack = getStackCurrent(s); > foreachGlobalObjptr (s, markObjects); > foreachObjptrInObject(s, (pointer) currentStack, markObjects, FALSE); > > // sweep & clean mark In general, that looks ok. But, some comments: * foreachGlobalObjptr will visit the current stack (by way of visiting the current thread); see https://github.com/MLton/mlton/blob/master/runtime/gc/foreach.c#L18 * What do you mean by "markObjects"? If this simply sets the mark bit of the object, then that is insufficient --- it won't perform the tracing that marks all reachable objects. You really need to use a specialization of dfsMarkByMode (https://github.com/MLton/mlton/blob/master/runtime/gc/dfs-mark.c#L29). > 2. In the object allocation phase, I saw some arrays allocated with > length 0. What is the purpose with these arrays? "Array.array (0, 42)" will allocate a length 0 array. Such arrays still need to be allocated in order to have identity (for polymorphic equality of arrays) and to have a length field in the header metadata (for Array.length). Also vectors are initially allocated as arrays and then cast to vectors. So "Vector.tabulate (0, fn _ => raise Subscript)" will allocate a length 0 array. ------------------------------------------------------------------------------ Monitor Your Dynamic Infrastructure at Any Scale With Datadog! Get real-time metrics from all of your servers, apps and tools in one place. SourceForge users - Click here to start your Free Trial of Datadog now! http://pubads.g.doubleclick.net/gampad/clk?id=241902991&iu=/4140