Usenet comp.sys.dec (1990-2013)
 help / color / mirror / Atom feed
From: David Chase <chase@world.std.com>
Subject: WAS Re: Final kick at the "Merced Guessing Game"
Date: 1997/10/17	[thread overview]
Message-ID: <3447D55B.1CDE@world.std.com> (raw)
In-Reply-To: 34462D38.167E@lanl.gov


William Clodius wrote:

> A minor point, but one aspect in which conventional languages are
> starting to resemble functional languages is in the presence of garbage
> collectors. While I don't know of any C or C++ implementations that
> provide it, the availabiltiy of the Boehm collector and the commercial
> add ons is starting to impact the C/C++ community. Several Fortran 90
> implementations, (but as far as I know only those from UK vendors) now
> provide garbage collection. Java is also having an impact here. However,
> whether or not they have a significant impact on architecture design
> probably requires the development of a benchmark that benefits from GC,
> otherwise the bechmarks will be run with GC turned off.

There's some problems here, at least with respect to C.  Fortran 90
is somewhat saner with its pointers than is C, at least in its
specification.  Working only within the C specification, it is
possible for the programmer to create pointers anywhere within the
interior of a structure or an array, or to the first address after
such an object.  In practice, C programmers commit vastly more
disgusting sins (my favorite -- out-of-bounds pointer arithmetic
from a freed pointer.  How to report this in C++ Expert was a
real head-scratcher, especially since the code works ok, at least
on Unix workstations, and is rather widely used).  Given what I
know of how compilers might mutilate code, and how programmers
sometimes do mutilate code, the Boehm-Weiser collector is
startlingly robust (and perhaps a bit lucky as well).

Where this difference would be more apparent is if anyone attempted
to build a system using (for instance) a fully-copying garbage
collector (for instance, one of the non-treadmill "real-time"
collectors, or an Ungar-style generational collector).  This is
practical in Fortran-90 AS SPECIFIED, though perhaps not as practiced,
because of the restrictions on what may be done with pointers (it
would require some interesting and entertaining custom optimizer work,
but the optimizer is part of the system, at least if I am designing
it).  There are some stunts employed in F77 programs to get the
effect of pointers; these stunts would not work with a compacting
garbage collector.  What this points out, perhaps, is the need to
adhere to the language specification when writing programs.

For C, however, such a system is probably not practical.
Though there is clearly a specification-satisfying way of implementing
it, the performance is likely to be atrocious, and it would certainly
not behave the way that C programmers usually expect (people are
rather lax about converting pointers to integers and back again, or
about comparing unrelated pointers -- both are bad ideas in a compacting
garbage collector).

(*) to deal with garbage like "i = (p - unrelated_p)", it is a simple
matter of tagging i with the expression (expressed as a difference of
pointers) that generated it, and recomputing this expression after a
garbage collection.  Piece-o-cake, in a performance-independent world.
Or, if the value must be preserved, the existing (live)
pointer-difference
expressions can be used as constraints on how the garbage collector may
move data.  It's crap like this which makes me doubt that C++ will ever
really have garbage collection.

However, I believe you are quite correct in the "resembling functional
languages" assertion.  Initially, this will not be very true, since
C programmers will continue to program in the data-modifying style
that they know and love.  However, use of a garbage collector allows
much more complicated sharing patterns, and pretty soon side-effects
to data will be regarded as a risky programming style because you
don't know what other parts of the program are sharing the data, or not.

Extensive use of threads tends to contribute to this as well.

I first had this experience working on a Modula-3 backend written in
C; the guys working on the front-end requested that I quit changing
(or else undo all my changes) the AST during code generation, because
they had plans to reuse it in a "compiler server".  The hack solution
was to remember all changes, and back them out at the end of code
generation.  Not reentrant, but good enough at the time.

-- 
David Chase, chase@world.std.com



  reply	other threads:[~1997-10-17  4:00 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-10-07  4:00 Final kick at the "Merced Guessing Game" Robert Harley
1997-10-07  4:00 ` Martin Rodgers
1997-10-07  4:00 ` Shankar Unni
1997-10-08  4:00   ` boo
1997-10-09  4:00     ` Patrick F. McGehearty
1997-10-10  4:00       ` Richard A. O'Keefe
1997-10-15  4:00         ` David Chase
1997-10-16  4:00           ` William Clodius
1997-10-17  4:00             ` David Chase [this message]
1997-10-18  4:00               ` WAS " Nick Maclaren
1997-10-18  4:00                 ` David Chase
1997-10-18  4:00                 ` [Reposted due to Enlow UCE cancel]: " David Chase
1997-10-19  4:00                   ` Nick Maclaren
1997-10-22  4:00                     ` pointer checking (WAS Re: Final kick at the "Merced Guessing Game") Hans-Juergen Boehm
1997-10-07  4:00 ` Final kick at the "Merced Guessing Game" Nick Maclaren
read-only archive

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