From: ยทยทยท@cs.umass.edu
Subject: Advising the Garbage Collector
Date:
Message-ID: <26878@dime.cs.umass.edu>
Barry Margolin writes, in response to Scott Turner's posting:
>>I've been thinking about the subject since my original post, and one
>>facility I think might be interesting is a garbage collection advisor.
>>Currently gc collects an object if it has no references. The idea
>>here is to let gc collect an object if the (user-supplied) advisor
>>predicate returns true.
>An interesting idea, but potentially very dangerous. An object may have
>references that the application isn't aware of. For instance, the user
>could have assigned an object to a global variable while in the debugger.
>Or in a Dynamic Windows or CLIM environment, just printing out the object
>creates a new reference to the object from the window's output history
>structure.
I feel strongly that features which make garbage-collection unsafe are most
undesirable. Garbage collection is the one brilliant technological
innovation that makes it possible to design a functional language
that operates on non-trivial objects. While I accept the perturbation
of the functional model provided in Lisp by the SET... operations,
and in POP-11 by the assignment arrow (->), I am suspicious of any
facility that would make garbage collection unsafe. I have not
personally debugged a garbage collector since 1968, but I
have clear memories of the baffling nature of the bugs that arose in the
process (and remember the LISP machine collector rumoured to be so buggy
that it was left permanently turned off by programmers).
However there is a possible and (possibly) safe application for a garbage
collector advisor, namely to permit the user to modify a structure that is
receiving the attentions of the garbage collector. There is an instance
of this capability hard-wired into POP-11 properties, which are a functional
presentation of the ideas embodied in the Common Lisp hash tables.
There is an an argument of the property-creating function, newanyproperty,
which specifies the behaviour of the property during garbage collection,
allowing the garbage collector to remove some of the associations
embodied in the property as follows (taken from the POPLOG V14 online
manual).
Keyword Meaning
------- -------
"perm" Permanent: entries are never discarded.
"tmparg" Temporary on the argument: entries are discarded
for which the argument items are otherwise
garbage.
"tmpval" Temporary on the value: entries are discarded
for which the value items are otherwise garbage.
"tmpboth" Temporary on both: entries are discarded for
which either the argument or value items are
otherwise garbage.
"tmpclr" Temporary cleared: all entries are cleared from
the property at every garbage collection.
Properties are a basic tool for memoisation (or function caching if you
will) so the "tmpclr" option is not as dumb as you might think.
Now, the question is, is there any way in which a user could safely be given
the ability to implement capabilities like newanyproperty, which create
objects that take special action during garbage collection? One has to
remember that there are some things you may not do during garbage
collection (at least with some standard implementations thereof)
such as call any constructor function. And supporting the "otherwise garbage"
requirement supposes that properties are looked at last, or held over to
be processed after the main sweep through the store.