comp.lang.ada
 help / color / mirror / Atom feed
From: barmar@think.COM (Barry Margolin)
Subject: Re: Garbage Collection
Date: 11 Jan 89 09:22:46 GMT	[thread overview]
Message-ID: <35328@think.UUCP> (raw)
In-Reply-To: 4054@hubcap.UUCP

In article <4054@hubcap.UUCP> billwolf@hubcap.clemson.edu writes:
>    Let's assume the existence of a suitably implemented warning container,
>    which has been appropriately hardened for use as a shared variable.
>    Our compiler proceeds by read-locking the file and write-locking the
>    warning structure; having acquired the locks, the warning structure
>    for that particular file is updated, and the locks are then released.
>    Our editor proceeds by write-locking the file and read-locking the
>    warning structure, updating the file, and then releasing all locks.
>    Our warning destroyer proceeds by write-locking and then destroying
>    the specified warning structure(s).
>
>    That was almost too easy.  Did I misunderstand the problem?

First of all, whether the file is locked is immaterial to the
discussion (I never actually said that the compiler compiles files --
in Lisp the compiler can also be invoked on in-core interpreted
functions, and many Lisp programming environments allow in-core editor
buffers to be compiled).

However, I did imagine locking of the COMPILER_WARNINGS database.  I
expected that it would be read-locked during the operation of the
SELECT operation, and write-locked during ADD and DELETE.  But once
SELECT returns, the lock would be released.  The lock serves to
protect the collection structure (either an array or linked list,
probably), but not the individual elements (since there are no
operations that modify an existing warning object).

So, I envision that the editor proceeds by read-locking the warnings
structure, selecting the appropriate warnings, and then releasing the
lock.  It then displays the selected warnings to the user and allows
him to perform operations such as "go to line referenced in next
warning".

In many traditional systems the warnings database is a text file
containing the output of the compiler, and the SELECT operation works
by reading this file and parsing it into a set of warnings structures
internal to the editor.  The command processor's DELETE_WARNINGS
operation is then just a Delete File command.  However, this mechanism
effectively involves a copy operation (the contents of the warning
file are copied into the editor's memory), and it is this copy that
I'm trying to avoid by having the editor and compiler in the same
address space and allowing them to share the warning object
structures.

If we do put read and write locks on the individual warning objects,
we have effectively implemented reference counts.  The multiple-reader
locking schemes I'm familiar with increment a counter or add an
element to some list every time a reader grabs the lock, and do the
opposite when unlocking, so that they will know when all the readers
are gone.  So, if your answer is that reference counts are the right
solution, just say so.  It's possibly the case that all well-designed
applications can be implemented using either manual or ref-count-based
deallocation.  However, reference counts add a significant fixed
overhead to every assignment of a ref-count-protected data type; what
was probably a single instruction becomes:
	if target not null
	   decrement target.refcount
	   if target.refcount = 0 then deallocate target.all
	increment source.refcount
	target = source

Most modern GC schemes have time overhead that is a function (often
linear) of the frequency of allocation.  Since assignments are
always more frequent than allocations, and I suspect usually MUCH more
frequent, this difference is important.

Ada prevents many of the worst types of pointer problems by only
allowing pointers to be created by the heap allocation primitive
(NEW).  In other languages, where pointers to existing objects may be
created (C's "&", PL/I's "ADDR") things can get pretty bad without a
GC.  I ran into such a problem last year when I was trying to use a
subroutine library originally designed for display of a database in a
facility for editing that database.  The database is implemented as a
text file, with each line representing a record, and each field of the
record separated by a delimiter character.  The programs are in C, and
the subroutine for reading the database into memory read each line
into a newly allocated string, replaced each delimiter with a null
character (C's string terminator), and allocated structures containing
pointers to the first character of each field.  This was fine for the
read-only applications, as they could simply deallocate all the
strings and record structures that were allocated (they didn't
actually bother, since the programs run on Unix and they depended on
everything being deallocated when the program terminated).  I tried to
write a program that reads in this database and then allows the user
to edit fields.  If the new field value is shorter than the original,
I simply overwrote the original value; if not, I allocated a new
string for the new value, and changed the record's field pointer to
point there instead of into the middle of the original line.  But when
it came time to deallocate, I needed to know whether individual fields
needed to be deallocated independently of the lines.  Had I gotten
around to finishing this program, I probably would have added a
parallel data structure containing flags indicating whether each field
had been reallocated.

In general, what I see coming out of this is that manual deallocation
may always be possible, but it frequently requires a non-trivial
amount of extra coding to provide bookkeeping to let the program know
when it is safe to deallocate things.  Remember, every additional line
of code in a program increases its complexity and is another potential
failure point.  And details such as storage management are generally
uninteresting to the application programmer, who is probably more
interested in the problem domain, so it is likely that he won't be as
careful when designing, coding, and testing them (storage management
is also difficult to test, unless you or the runtime library include
extra mechanisms just to improve debuggability).  Garbage collectors,
on the other hand, are usually implemented by system programmers who
find them interesting and can be expected to care enough to do the
very best.  And if you don't think these psychological factors are
important, then you're working with programmers of a different species
than I'm familiar with (that reminds me, I wonder where my "Psychology
of Computer Programming" is -- probably in my parents' house,
unfortunately, or I'd look up references), and I wouldn't want to work
with them!

In conclusion, I expect that I can manage storage as well as you can.
And I could also manually convert a number to a character string and
send these characters to an I/O device.  Every major language provides
runtime support for the latter so we don't all have to waste our time
writing it.  What's so special about storage management that we
should all be burdened with it?

Barry Margolin
Thinking Machines Corp.

barmar@think.com
{uunet,harvard}!think!barmar

  reply	other threads:[~1989-01-11  9:22 UTC|newest]

Thread overview: 79+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1989-01-06 22:17 Garbage Collection Erland Sommarskog
1989-01-08 18:40 ` William Thomas Wolfe,2847,
1989-01-09  3:56   ` Barry Margolin
1989-01-09 16:22     ` William Thomas Wolfe,2847,
1989-01-09 19:00       ` Barry Margolin
1989-01-10  2:50         ` William Thomas Wolfe,2847,
1989-01-11  9:22           ` Barry Margolin [this message]
1989-01-11 16:01             ` William Thomas Wolfe,2847,
1989-01-11 18:21               ` Barry Margolin
1989-01-12  2:43                 ` William Thomas Wolfe,2847,
1989-01-15  7:14                   ` Barry Margolin
  -- strict thread matches above, loose matches on Subject: below --
1999-08-18  0:00 garbage collection Ronald Ayoub
1999-08-18  0:00 ` tmoran
1999-08-18  0:00   ` Keith Thompson
1999-08-19  0:00     ` Tucker Taft
1999-08-19  0:00       ` Robert Dewar
1999-08-19  0:00       ` Robert Dewar
1999-08-20  0:00     ` tmoran
1999-08-20  0:00       ` Keith Thompson
1999-08-20  0:00         ` Matthew Heaney
1999-08-20  0:00           ` Keith Thompson
1999-08-21  0:00             ` Robert Dewar
1999-08-21  0:00               ` Matthew Heaney
1999-08-21  0:00             ` Matthew Heaney
1999-08-21  0:00           ` Robert Dewar
1999-08-21  0:00         ` Brian Rogoff
1999-08-21  0:00       ` Robert Dewar
1999-08-18  0:00 ` Pascal MALAISE
1999-08-20  0:00   ` David Botton
1999-08-18  0:00 ` Gisle S�lensminde
1999-08-18  0:00 ` Robert I. Eachus
1999-08-19  0:00   ` Gautier
1999-08-19  0:00     ` Robert I. Eachus
1999-08-20  0:00   ` Keith Thompson
1999-08-20  0:00     ` Robert Dewar
1996-10-24  0:00 Garbage Collection H Brett Bolen
1989-01-10 19:16 Erland Sommarskog
1989-01-11 16:10 ` William Thomas Wolfe,2847,
1989-01-05 23:26 Erland Sommarskog
1988-12-31  0:04 Erland Sommarskog
1989-01-05  8:13 ` William Thomas Wolfe,2847,
1988-12-28 19:20 Erland Sommarskog
1988-12-30  0:52 ` Bill Wolfe
1988-12-26 23:37 Erland Sommarskog
1988-12-27 21:24 ` William Thomas Wolfe,2847,
1988-12-28 16:09   ` Snorri Agnarsson
1988-12-30  0:46     ` Bill Wolfe
1988-12-27 22:24 ` Bob Hathaway
1988-12-18 20:12 Erland Sommarskog
1988-12-20 19:04 ` Bill Wolfe
1988-12-13 20:07 Erland Sommarskog
1988-12-15 19:13 ` William Thomas Wolfe,2847,
1988-12-07 15:22 Collective response to := messa ron
1988-12-11 19:11 ` Garbage Collection William Thomas Wolfe,2847,
1988-12-12  5:29   ` John Gateley
1988-12-12 18:19     ` William Thomas Wolfe,2847,
1988-12-13  1:02       ` Alexander Klaiber
1988-12-13 18:37         ` William Thomas Wolfe,2847,
1988-12-13 23:36           ` Alexander Klaiber
1988-12-14  3:26             ` William Thomas Wolfe,2847,
1988-12-14 17:16             ` Stephe Leake
1988-12-15 14:43             ` Thomas P. Morris
1988-12-14 23:30           ` John Gateley
1988-12-15 19:25             ` William Thomas Wolfe,2847,
1988-12-19 16:12               ` John Gateley
1988-12-20 19:34                 ` Bill Wolfe
1988-12-13 20:22         ` William Thomas Wolfe,2847,
1988-12-14  6:40           ` Richard A. O'Keefe
1988-12-14 17:43             ` William Thomas Wolfe,2847,
1989-01-02 17:51   ` ryer
1989-01-05  8:31     ` William Thomas Wolfe,2847,
1989-01-06 16:58   ` ryer
1989-01-08 19:24     ` William Thomas Wolfe,2847,
     [not found] <145@krafla.rhi.hi.is>
     [not found] ` <272@fang.ATT.COM>
1988-03-29 13:47   ` From Modula to Oberon Denis Fortin
1988-03-30 15:32     ` Lawrence Crowl
1988-03-30 22:41       ` Hans Boehm
1988-03-31  6:27         ` Garbage Collection Richard Harter
1988-03-31 19:49           ` Hans Boehm
1988-04-01  5:43             ` Richard Harter
1988-04-01 18:43               ` Hans Boehm
1988-04-04 23:14           ` 00704a-Liber
1986-03-16 22:24 Garbage collection "Alexander L. Wolf"
     [not found] <1979@mit-eddi.UUCP>
     [not found] ` <2144@mit-eddie.UUCP>
1984-06-18 19:28   ` Abstraction In Ada Jon Mauney
1984-06-22  7:47     ` Doug Alan
1984-06-25  2:15       ` brad
1984-07-17 10:34         ` garbage collection Eric Smith
replies disabled

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