comp.lang.ada
 help / color / mirror / Atom feed
From: Robert A Duff <bobduff@world.std.com>
Subject: Re: Better support for garbage collection
Date: Wed, 14 Mar 2001 19:29:48 GMT
Date: 2001-03-14T19:29:48+00:00	[thread overview]
Message-ID: <wcc1ys0du8j.fsf@world.std.com> (raw)
In-Reply-To: 98m938$2iod0$1@ID-25716.news.dfncis.de

"Nick Roberts" <nickroberts@callnetuk.com> writes:

> I would like to make a proposal for the next revision of the language which
> would provide standardised support for partially user-defined garbage
> collection, and a standard mechanism for disposability.

If you're interested in garbage collection, you should get on the gc
mailing list (gclist-digest@iecc.com).  You should also read Jones and
Lins' excellent book called "Garbage Collection", if you haven't
already.

I too think it would be cool if GC for Ada were widely available.
But I think youll have a hard time convincing others.  After all, any
implementation is allowed to provide GC, but nobody has done so, except
when the GC is unavoidable (the Ada 83 implementation on top of the
Symbolics Lisp Machine, and the Ada 95 implementations on top of the
JVM).  Why not?

Robert Dewar would argue that it's because nobody wants it (at least,
nobody wants it enough to pay for it).  A more pessimistic take on this
is that all the folks who understand the glorious benefits of GC have
long since abandoned Ada in favor of "better" languages.

It is also possible to use Boehm's conservative collector with Ada.
Does anybody do so?

(I find the idea of conservative collection somewhat distasteful,
but it does seem to work in many cases.)

You seem to be saying that the user provides the compaction phase, and
the implementation provides the tracing phase.  But the tracing phase is
the hard part.  So how does this make GC so easy to implement that
implementers will do it when they haven't already?

Now to the technical points: I'm completely confused about what this
proposal means.  I don't see how the user can write the Tidy routine.
(Why not call it Compact?)  The Tidy routine needs to modify all the
pointers to objects in the repositioning pool -- how is it supposed to
find them?  It doesn't know the layout of all the records in the pool.
Also, it can't find all the pointers from outside the pool to objects in
the pool.

A sample implementation of package Repositioning would help me
understand.  Eg, what is the intended implementation of tokens?
(Or at least one possible implementation?)

Note that you can have pointers into the middle of objects -- these also
need to be adjusted when objects move around in memory.  (Pointers to
aliased components.  Renamings of components.  Components passed by
reference.)

Note that the tracing phase needs to trace the whole world (all stacks
and storage pools) whenever *any* repositioning pool is collected,
because you haven't proposed to restrict pointers from the outside.

You didn't say when the compiler is supposed to generate calls to the
Allocate and Deallocate routines (the ones with token parameter), so I
don't understand the point of them.

Note that it is not always known at compile time whether a given access
type's pool is a repositioning pool, so the code generated for "new" and
"Unchecked_Deallocation" must be as in the RM (eg, these can't call the
new Allocate).

>       procedure Allocate(
>          Pool : in out Repositioning_Storage_Pool;
>          Token : out Object_Token) is abstract;

> Each pool element has a 'lock count', of an unspecified integer (or
> modular) subtype, whose range does not exceed that of Standard.Natural. The
> element is said to be 'locked' if its lock count is a value other than 0.

Nonnegative, right?

> The overloading of the Allocate procedure with a Token parameter sets the
> lock count of the pool element it allocates to 0, reserves a block of
> memory, and reserves a token for the element, whose value is passed out to
> the Token parameter.

I don't see how it can reserve a block of memory, since it doesn't take
size and alignment parameters.  I'm confused as to what this routine is
for.

> I suggest a recommendation (or perhaps a stipulation) that the maximum lock
> count is never less than 15. (Although this recommendation will apply to
> the user rather than the implementation, except for implementation-supplied
> repositioning pools.)

I don't see the point of such a recommendation.

> The first stage of the garbage collection process is 'scavenging', the
> recognition and deallocation of allocated objects which have become
> 'unreachable' (inaccessible by any degree of indirection). This stage needs
> to be carried out by code specially generated by the compiler.

But that's not really how many (most?) GC's work.  The don't recognize
unreachable objects, and they don't deallocate them individually.  They
find all the *reachable* objects, and whatever's left over is garbage.
In a copying collector, the garbage need not be touched.  So the cost of
GC is proportional to the amount of reachable data.  If you have to
individually deallocate all the garbage objects, then it's proportional
to the size of the heap, which seems bad.

> A 'disposable object' is a dynamically allocated object which an
> implementation (of Ada) is permitted to deallocate at any time, if it needs
> to do so in order to successfully complete the allocation of another
> object.
> 
> The language should define a subtype in the package System:
> 
>    subtype Disposability_Level is
>       Integer range 0..implementation_defined;

Why "implementation_defined"?  It seems like a useless non-portability.

> and an attribute Disposability, which applies to any pool-specific access
> type, and has a static value of subtype Disposability_Level.

This is the first attribute of a non-scalar type that is static.

>... A value other
> than 0 indicates that objects referenced by access values of this access
> type are disposable.

It makes no sense to talk about the objects "referenced by access values
of this access type", because there can be many access values, of many
different types, all pointing to the same object.  Perhaps you mean
"allocated by allocators for this access type"?  (BTW, "designated" is
the Ada jargon -- not "referenced".)

> Whenever an implementation makes an attempt to allocate an object in a
> repositioning pool, and that attempt fails (Storage_Error being raised), it
> can intervene by carrying out garbage collection (both stages) and then
> attempting the allocation again. If the second attempt fails, the
> implementation may attempt to deallocate a disposable object, and then try
> once more. Eventually, on repeated failures, defeat must be conceded (and
> the Storage_Error exception propagated as normal).

Deallocating a disposable object can leave dangling pointers (which is
the whole point of GC to avoid).  Are you assuming the Finalize routine
will track them all down and do something about them (eg null them out)?
What happens if it doesn't.

You didn't mention anything about finalization of normal
(non-disposable) objects.  There are nasty interactions
there.  Eg, can the finalization routine resurrect the object
by creating a new pointer to it?  Java has an answer to this
(not a very good one, IMHO).

> Additional calls to Tidy may be made, by the implementation or the user,
> e.g. as part of an ongoing garbage collection strategy.
> 
> The imlementation must always lock a pool element before reading from it or
> writing into it, in order to prevent it being moved at an inopportune
> moment. On the other hand, the implementation should unlock elements as
> frequently as possible (without overly reducing execution speed), so that
> the Tidy procedure is not stymied by locked elements to the point of being
> made ineffective.

It seems like the compiler must generate a Lock before each call where a
movable object is passed by reference (or a part of such an object).
And it must remain locked throughout that call, because the called
procedure doesn't know whether it has a pointer into a repositioning
pool.  Doesn't sound very "frequent".

For that matter, it seems like it has to Lock even if the thing is
passed by copy, because the address of the actual is presumably saved at
the call site (at least in some cases).

- Bob



  parent reply	other threads:[~2001-03-14 19:29 UTC|newest]

Thread overview: 115+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-03-13 18:37 Better support for garbage collection Nick Roberts
2001-03-14  8:16 ` Florian Weimer
2001-03-14 18:52   ` Robert A Duff
2001-03-14 19:40     ` Florian Weimer
2001-03-15 13:18       ` Nick Roberts
2001-03-14 19:29 ` Robert A Duff [this message]
2001-03-14 20:59   ` Brian Rogoff
2001-03-16 16:42     ` Robert A Duff
2001-03-17  6:13       ` Lao Xiao Hai
2001-03-24  4:08       ` Brian Rogoff
2001-03-15  4:35   ` Nick Roberts
2001-03-15 21:37     ` Randy Brukardt
2001-03-15 22:36     ` Stephen Leake
2001-03-16 16:26     ` Robert A Duff
2001-03-16 16:59       ` Brian Rogoff
2001-03-16 17:31         ` Robert A Duff
2001-03-16 18:29           ` Brian Rogoff
2001-03-17  2:30           ` Nick Roberts
2001-03-17 21:59             ` Robert A Duff
2001-03-17 22:57             ` Static typing (Was Re: Better support for garbage collection) Brian Rogoff
2001-03-17 23:45               ` Robert A Duff
2001-03-18  0:58                 ` Brian Rogoff
2001-03-19 15:24                   ` Robert A Duff
2001-03-20  4:21                     ` Brian Rogoff
2001-03-21  1:32                       ` Ken Garlington
2001-03-21 13:28                         ` Robert A Duff
2001-03-22  2:08                           ` Ken Garlington
2001-03-22 16:40                             ` Robert A Duff
2001-03-25 16:21                               ` Ken Garlington
2001-03-25 16:56                                 ` Ken Garlington
2001-03-25 22:31                                 ` Robert A Duff
2001-03-27  0:24                                   ` Ken Garlington
2001-03-28 23:15                                     ` Robert A Duff
2001-03-29  5:02                                       ` Ken Garlington
2001-03-29  6:13                                         ` David Starner
2001-03-29 10:10                                           ` AG
2001-03-29 14:28                                           ` Ken Garlington
2001-03-29 23:46                                         ` Robert A Duff
2001-03-30  3:41                                           ` Ken Garlington
2001-03-30 21:21                                             ` Robert A Duff
2001-03-31 19:30                                               ` Ken Garlington
2001-04-02 15:27                                                 ` Robert A Duff
2001-04-02 23:29                                                   ` Ken Garlington
2001-03-30 21:29                                             ` Robert A Duff
2001-03-30  9:16                                           ` Dmitry Kazakov
2001-03-30  9:51                                             ` Florian Weimer
2001-04-02  8:54                                               ` Dmitry Kazakov
2001-03-30 16:13                                             ` Ken Garlington
2001-04-02 11:00                                               ` Dmitry Kazakov
2001-03-30 20:44                                             ` Robert C. Leif, Ph.D.
2001-04-02 11:29                                               ` Dmitry Kazakov
2001-04-02 13:15                                                 ` Robert A Duff
2001-04-03  8:57                                                   ` Dmitry Kazakov
2001-03-27  2:39                             ` Andrew Berg
2001-03-27  3:33                               ` Ken Garlington
2001-03-27 14:23                                 ` Robert A Duff
2001-03-27 23:36                                   ` Ken Garlington
2001-03-29 23:50                       ` Robert A Duff
2001-03-19 18:24       ` Better support for garbage collection Tucker Taft
     [not found]   ` <87bsr46kxv.fsf@deneb.enyo.de>
2001-03-15 14:18     ` Robert A Duff
2001-03-15 16:36       ` Florian Weimer
2001-03-14 22:05 ` Laurent Guerby
2001-03-16 16:47   ` Robert A Duff
2001-03-16 19:46     ` Laurent Guerby
2001-03-16 20:10       ` Robert A Duff
2001-03-17 13:14         ` Support for per allocation pool selection (was: Better support for garbage collection) Laurent Guerby
2001-03-17 17:06           ` Robert A Duff
2001-03-17 19:19           ` Florian Weimer
2001-03-17 21:10             ` Robert A Duff
2001-03-15 17:56 ` Better support for garbage collection Ray Blaak
2001-03-21 16:15 ` Implementing C/C++ style #include bhazzard
2001-03-21 16:45   ` Marin David Condic
2001-03-22 15:13     ` Ira D. Baxter
2001-03-22 15:23       ` Marin David Condic
2001-03-25 15:45         ` Anton Gibbs
2001-03-26 14:24           ` Ted Dennison
2001-03-26 15:00             ` Marin David Condic
2001-03-26 14:49           ` Marin David Condic
2001-03-26 18:19             ` Stephen Leake
2001-03-26 18:44               ` Pascal Obry
2001-03-26 21:44                 ` Robert A Duff
2001-03-27  3:02                   ` Andrew Berg
2001-03-27  3:27                     ` Phaedrus
2001-03-27 17:41                   ` Pascal Obry
2001-03-26 19:18               ` Ted Dennison
2001-03-27 18:51                 ` Anton Gibbs
2001-03-26 19:35               ` Marin David Condic
2001-03-26 23:04                 ` Mark Lundquist
2001-03-27 14:38                   ` Marin David Condic
2001-03-26 16:12           ` Florian Weimer
2001-03-26 17:34             ` David Starner
2001-03-26 22:25               ` Florian Weimer
2001-03-27  3:29                 ` David Starner
2001-03-26 18:23             ` Stephen Leake
2001-03-26 22:34               ` Florian Weimer
2001-03-27  7:34         ` Ole-Hjalmar Kristensen
2001-03-27 12:43           ` Dale Stanbrough
2001-03-27 14:40             ` Marin David Condic
2001-03-27 15:01             ` Ted Dennison
2001-03-27 13:20           ` Preben Randhol
2001-03-23 17:39       ` Wes Groleau
2001-03-21 18:07   ` Mark Lundquist
2001-03-22 12:50   ` Chris M. Moore
2001-03-22 14:30     ` Marin David Condic
2001-03-22 21:15       ` singlespeeder
2001-03-22 21:42         ` Marin David Condic
2001-03-23 14:43           ` Georg Bauhaus
2001-03-23 18:51             ` Marin David Condic
2001-03-22 15:02     ` Pat Rogers
2001-03-22 15:28       ` Marin David Condic
2001-03-22 16:32       ` Chris M. Moore
2001-03-22 16:57       ` Robert A Duff
2001-03-26 16:13   ` Martin Dowie
2001-03-26 22:55   ` Phaedrus
2001-03-27  1:36     ` tmoran
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox