From mboxrd@z Thu Jan 1 00:00:00 1970 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 1164f8,45b50f14dadfce5b X-Google-Attributes: gid1164f8,public X-Google-Thread: 102b75,45b50f14dadfce5b X-Google-Attributes: gid102b75,public X-Google-Thread: 110292,45b50f14dadfce5b X-Google-Attributes: gid110292,public From: David Chase Subject: WAS Re: Final kick at the "Merced Guessing Game" Date: 1997/10/17 Message-ID: <3447D55B.1CDE@world.std.com>#1/1 X-Deja-AN: 281982366 Sender: news@world.std.com (Mr Usenet Himself) References: <61cqkc$9r@news-rocq.inria.fr> <343AC71D.5531EE2D@powertelglobal.com> <343C1030.4A86F6D6@tonys.ecology.umn.edu> <61iuna$3li@deadzone.rsn.hp.com> <61kek8$9lh$1@goanna.cs.rmit.edu.au> <3444288C.7F4E@world.std.com> <34462D38.167E@lanl.gov> Organization: Natural Bridge LLC Reply-To: chase@world.std.com Newsgroups: comp.sys.intel,comp.arch,comp.sys.dec 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