Re: Compiler writers will love this language

Lex Spoon <lex@cc.gatech.edu>
25 Jun 2003 00:52:04 -0400

          From comp.compilers

Related articles
[10 earlier articles]
Re: Compiler writers will love this language ericmuttta@email.com (2003-06-20)
Re: Compiler writers will love this language ericmuttta@email.com (2003-06-20)
Re: Compiler writers will love this language torbenm@diku.dk (2003-06-20)
Re: Compiler writers will love this language d00-mla@nada.kth.se (Mikael 'Zayenz' Lagerkvist) (2003-06-22)
Re: Compiler writers will love this language mwotton@cse.unsw.edu.au (2003-06-22)
Re: Compiler writers will love this language dot@dotat.at (Tony Finch) (2003-06-25)
Re: Compiler writers will love this language lex@cc.gatech.edu (Lex Spoon) (2003-06-25)
Re: Compiler writers will love this language firefly@diku.dk (Peter \Firefly\Lund) (2003-06-25)
Re: Compiler writers will love this language joachim.durchholz@web.de (Joachim Durchholz) (2003-07-02)
Re: Compiler writers will love this language strohm@airmail.net (John R. Strohm) (2003-07-02)
Re: Compiler writers will love this language genew@mail.ocis.net (2003-07-02)
Re: Compiler writers will love this language ericmuttta@email.com (2003-07-02)
Compile-time garbage collection (was Re: Compiler writers will love th dobes@dobesland.com (Dobes Vandermeer) (2003-07-02)
[7 later articles]
| List of all articles for this month |

From: Lex Spoon <lex@cc.gatech.edu>
Newsgroups: comp.compilers
Date: 25 Jun 2003 00:52:04 -0400
Organization: Georgia Institute of Technology
References: 03-05-211 03-06-015 03-06-054 03-06-057 03-06-078
Keywords: storage, GC
Posted-Date: 25 Jun 2003 00:52:04 EDT

ericmuttta@email.com (Eric) writes:


> mwotton@cse.unsw.edu.au (Mark Alexander Wotton) wrote
>> On 5 Jun 2003 23:22:01 -0400, Eric posted:
>> >
>> > I am having difficulty imagining a type which is implemented using
>> > pointers and ensures that null cant occur. This would imply that for a
>> > variable of such a type, memory would be allocated and then never
>> > released.
>>
>> Either that, or only released when all references to it have passed
>> out of scope. This is how many modern garbage-collected language
>> implementations work.
>
> This scheme (reference-counting) is used in VB6 for instance. VB7 (and
> every other .NET language?) uses generational, mark-and-sweep GC (hope
> that's the right term for it). When I read its description, it sounded
> like a rather elaborate scheme and one that would need a good deal of
> implementation effort. I prefer plain vanilla automatic
> reference-counting. Its deterministic (hence useful in real-time
> systems), simple to explain and understand, and a lot easier to
> implement and get right.


Incidentally, generalized garbage collectors (I don't know the right
term, either) have been in use for at least 20-30 years, and have been
very well studied. Personally, I use two garbage collected languages
every day (Smalltalk and Emacs Lisp) and I have used several others,
and I have yet to run into a GC implementation bug. They doen't seem
to be so hard to implement so long as you are *very* careful about
your invariants.


In fact, garbage collectors can be modular. The main requirement is
that the GC module is able to trace data structures through memory at
runtime, which typically requires extra run-time information tagged
onto both objects and stack frames. The simplest implementation of
this requires one word of overhead per object or frame, but there are
lots of tricks available for lowering this overhead. Like most other
parts of a compiler, people tinker and tune for some amount of time
and then force themselves to leave it alone and actually use the
thing. :)


Finally, please consider that reference counting collectors will
surprise the user when they fail, and will require weird tweaks by the
user when they do fail. A generalized garbage collector is much
nicer.


> I admit, reference-counting has its problems and I have been toying
> around with an idea for what I call "compile-time
> reference-counting". Basically, I am looking for a set of rules,
> that will allow the compiler to figure out when to release memory
> for an object, *without* having to allocate memory space for a
> reference counter value. Instead, using these rules, the compiler
> can analyse code at compile time and statically work out the
> life-time of an object. Its a bit wishy washy at the moment but if
> its at all possible, I will write a paper on it :)




Be sure to look up existing work. I'm certain that people have worked
on this kind of thing. Be aware that it won't work for everything;
for example, objects that are saved out into the heap will be awfully
hard to deal with automatically. But you can surely get rid of a lot
of the intermediate increments and decrements in the way you seem to
be thinking about.




Lex
[Garbage collectors don't go back 20 or 40 years, they go back at least as
far as early versions of Lisp around 1960. I think it's safe to say that
any new garbage collection trick someone comes up with is almost certain
to have been discovered and analyzed before. -John]



Post a followup to this message

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