Re: Best Ref-counting algorithms?

"BGB / cr88192" <cr88192@hotmail.com>
Wed, 15 Jul 2009 11:09:07 -0700

          From comp.compilers

Related articles
[7 earlier articles]
Re: Best Ref-counting algorithms? georgeps@xmission.com (GPS) (2009-07-14)
Re: Best Ref-counting algorithms? gneuner2@comcast.net (George Neuner) (2009-07-14)
Re: Best Ref-counting algorithms? DrDiettrich1@aol.com (Hans-Peter Diettrich) (2009-07-15)
Re: Best Ref-counting algorithms? lerno@dragonascendant.com (=?ISO-8859-1?Q?Christoffer_Lern=F6?=) (2009-07-14)
Re: Best Ref-counting algorithms? lerno@dragonascendant.com (=?ISO-8859-1?Q?Christoffer_Lern=F6?=) (2009-07-15)
Re: Best Ref-counting algorithms? torbenm@pc-003.diku.dk (2009-07-15)
Re: Best Ref-counting algorithms? cr88192@hotmail.com (BGB / cr88192) (2009-07-15)
Re: Best Ref-counting algorithms? cr88192@hotmail.com (BGB / cr88192) (2009-07-15)
Re: Best Ref-counting algorithms? cr88192@hotmail.com (BGB / cr88192) (2009-07-15)
Re: Best Ref-counting algorithms? cr88192@hotmail.com (BGB / cr88192) (2009-07-15)
Re: Best Ref-counting algorithms? gene.ressler@gmail.com (Gene) (2009-07-15)
Re: Best Ref-counting algorithms? torbenm@pc-003.diku.dk (2009-07-16)
Re: Best Ref-counting algorithms? bartc@freeuk.com (BartC) (2009-07-16)
[20 later articles]
| List of all articles for this month |
From: "BGB / cr88192" <cr88192@hotmail.com>
Newsgroups: comp.compilers
Date: Wed, 15 Jul 2009 11:09:07 -0700
Organization: albasani.net
References: 09-07-018 09-07-023 09-07-027 09-07-037
Keywords: GC
Posted-Date: 15 Jul 2009 19:24:47 EDT

"Hans Aberg" <haberg_20080406@math.su.se> wrote in message
> Christoffer LernC6 wrote:
>>> It depends on what resources you want to collect, and what
>>> implementation language you are choosing.
>>
>> I'm playing around with a ref-counting based (memory) GC for a
>> language I have yet to construct.
>
> But what language are you planning use for the implementation? If you
> choose C++, then it is hard to find the root set. Suppose you create
> object for use in your language; then global objects and those in th
> stack should be registered somehow for the tracing, but those on the
> heap should not, as the are live when they can be traced from the other.
>


for C and C++ and implementing custom languages, it is not really that much
of a problem in practice.


The main reason is that, since the person is writing the compiler
and/or interpreter, they can directly keep track of whatever
references may exist within their little VM-managed language, making
precise GC and ref-counting fairly easily (especially if, as has been
suggested, a single-threaded implementation is possible...).


I guess it may be noted that there is another possible strategy, namely that
one "could" try to implement their own scheduler (rather than using the OS
scheduler), such that the GC would be able to manage threads by itself (for
example, it could pause all its managed threads during GC).


as-is in my case, I use the OS scheduler, but otherwise create-threads/do
TLS/... via a GC-provided API mostly so that the GC knows about them.


in my case, this also wraps the threading mechanism, so that I can use the
same threads API/... on both Windows and Linux.




now, the great problems are if:
the language is "C-like" (AKA: with raw pointers and like);
one tries to have fine-grained integration with native code;
multithreading becomes involved (this quickly turns a simple GC into a big
mess);
the VM has an extensive C or C++ based utility library (mostly a problem as
then lots of code may end up having to use the GC from C, which can become
very painful, and error prone as one may end up invariably mis-handling
memory references "here and there", which can be disasterous with precise GC
and refcounting);
...


actually, in practice "external integration" has been the main killer of
precise GC's in my case, where typically one will make a language or
interpreter with the intent of either operating it from C-land, or using it
to interface with or control stuff in C-land.


however, the choice in GC strategy becomes a major problem, as it
effectively creates a fragile wall with the outside world, and the effort
required both to maintain this wall, and to allow interfacing through this
wall, can often become terribly awkward.




so, more often, I have ended up falling back to conservative GC, if
anything, because it makes interfacing with the outside world less
problematic...


however, ref-counting+conservative GC may be worthwhile, as it may still
allow ref-counting without many of the complexities and costs of precise GC
(AKA: elaborate root management...).


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.