Benjamin Goldberg <[EMAIL PROTECTED]> wrote: > I'd like to reiterate (and clarify) my idea, of a hybrid scheme > combining refcounting and DoD.
I'll try to translate this to parrot speak. I hope that I fully understand your scheme, but lets see. > All values needing timely destruction would inherit from a class > RefCounted. All such variables?! ... have a special vtable and additionally a refcount, where the ... > All operations on a variable or variables having the "is refcounted" > trait result in opcodes to call the refcount(inc|dec) method(s) of the > values in those variables. ... get_val and the set_val part of the value access does inc|dec the refcount: if (--PTimer->refcount == 0) if (PObj_is_referenced(PTimer)) interpreter->need_lazy_dod = 1 else VTABLE_destroy( .. PTimer); > Under normal circumstances, when a refcounted value's refcount goes > to zero, it self destructs^W^W cleans itself up. > To avoid premature cleanup, any time that the contents of a > refcounted variable is assigned to a non-refcounted variable, an opcode > to set a "reachable by non-refcounted variable" flag on the value > precedes the assignment. If a refcounted values's refcount goes to > zero, and it has this flag set, it does NOT self-destruct[*]. set_is_referenced PTimer := PObj_is_referenced_SET(PTimer) set PAgggregate[key], PTimer > A global counter keeps track of how many values have a refcount of zero > and have this flag set. IMHO no counter just a flag, but doesn't matter now. > From here, we are in a similar situation as other proposals -- for the > timeliest possible destruction, then on every single scope exit, we > check if this global counter is nonzero, and if so, do a DoD run. lazysweep # as currently > During the course of a DoD run, when we look for what PMCs are reachable, > we keep track of what each thing was reachable *from*. > If a PMC was found to be reachable through a non-refcounted variable, > then we set a flag saying so. At the end of DoD, every reachable refcounted > value which has the first flag set, but this other flag not set, gets it's > first flag cleared. I think I don't understand the "first & other flag". If a PTimer is e.g. inside an aggregate (i.e. reachable through non-refcounted) the live_FLAG of the PTimer gets set and it will not get destroyed. If during the DOD run the PTimer is not referenced it will have the live_FLAG cleared and will be destroyed. If there are any objects with a refcount live after a DOD run, we set again the interpreter->need_lazy_dod flag. leo