home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12272 < prev    next >
Encoding:
Internet Message Format  |  1992-08-12  |  10.7 KB

  1. Path: sparky!uunet!sun-barr!cs.utexas.edu!usc!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbeh.san.uc.edu!uceng.uc.edu!babbage.ece.uc.edu!dain
  2. Newsgroups: comp.lang.c++
  3. Subject: Re: Garbage Collection for C++
  4. Message-ID: <1992Aug12.161219.11877@babbage.ece.uc.edu>
  5. From: dain@holmes.ece.uc.edu (Dain Samples)
  6. Date: Wed, 12 Aug 1992 16:12:19 GMT
  7. Reply-To: Dain.Samples@uc.edu
  8. Sender: root@babbage.ece.uc.edu (Operator)
  9. References: <1992Aug6.014619.2111@ucc.su.OZ.AU> <3907@starlab.UUCP>
  10. Organization: University of Cincinnati
  11. Originator: dain@holmes.ece.uc.edu
  12. Nntp-Posting-Host: holmes.ece.uc.edu
  13. Lines: 195
  14.  
  15.  
  16. In article <3907@starlab.UUCP>, mi@starlab.UUCP (Michael Hoennig) writes:
  17. |> In article <1992Aug6.014619.2111@ucc.su.OZ.AU> maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) writes:
  18. |> 
  19. |> >GC classes cannot be allocated on the stack or statically,
  20. |> >so when one is, it is silently converted to a GC pointer
  21. |> >to an object.
  22. |> 
  23. |> >Pointers to GC class objects will be GC pointers.
  24. |> >GC pointers are like classes, they have built in destructors and
  25. |> >constructors so they can't just disappear.
  26. |> 
  27. |> I think this is a neverending loop. If pointers to GC class objects will be
  28. |> GC pointers too, they will be silently converted to a GC pointer (which is
  29. |> a pointer to a GC class) and must be silently converted to a GC ...
  30. |> 
  31. |> => GC class objects must be allocatable on the stack - but the compiler
  32. |> must recocnize this.
  33.  
  34.  
  35. Before I saw this thread in this newsgroup (I'v just started
  36. re-reading after a long hiatus), I posted the following to
  37. comp.compilers.  I apologize to those of you that read both groups for
  38. the duplication.
  39.  
  40.  
  41. I have been doing some work on implementing garbage collection for
  42. C++, but some of these comments will apply to GC for C.
  43. I will summarize some of the contents of a paper I will be presenting
  44. at the Int'l Workshop on Memory Management in Sept.  A copy of the
  45. paper can be ftp'd from the e-address below.  I would be interested in
  46. any commentary.
  47.  
  48. babbage.ece.uc.edu:~ftp/pub/biblio/papers/ads-iwmm92.ps.Z
  49.  
  50. I have reached the conclusion that only conservative garbage
  51. collection allows no changes to the existing language.  Even so, as
  52. Hans Boehm has pointed out, there are (relatively easily solved)
  53. problems with code produced by highly intelligent optimizers (i.e.,
  54. make them less intelligent, or even more intelligent, depending on
  55. your point of view).  Any other GC-scheme that assumes no changes to C
  56. (or C++) requires prodigious amounts of compiler-generated information
  57. to describe the structure of runtime objects based on the most general
  58. of possibilities (e.g., see the '92 SIGPLAN paper by Diwan, Moss, and
  59. Hudson), or constrains the programming idioms that can be used by
  60. programmers.  (Much of the discussion about using C as an IL has
  61. focused on the observation that a translator emitting C can in fact
  62. easily constrain itself.)
  63.  
  64. Since such constraints border on language redefinition anyway, I
  65. addressed the question: what is a minimum number of language
  66. enhancements that could be added to C++ to allow reasonable garbage
  67. collection to be implemented as part of the runtime system?  I haven't
  68. tried to back-pedal the language changes to C since I take advantage
  69. of the class/object structure in C++ to simplify the declaration of
  70. *which* thingies are going to be collected.  I also have not totally
  71. removed the need for `prodigious amounts of information', but I do
  72. think it is more manageable and reasonably generated.
  73.  
  74. I added three additional keywords: collected, heap, and embedded.  The
  75. latter keyword is used to declare pointers that can be used to point
  76. into objects that are collected, and the other two are used to declare
  77. collectible objects and allow the programmer to allocate normally gc'd
  78. objects on the heap.
  79.  
  80. The long-range goal is to allow garbage collection to be treated as
  81. malloc/free is treated in C programming systems: not `really' part of
  82. the language, but assumed to exist, assumed to work, assumed to have a
  83. certain (minimal) functionality, and replaceable by the user.  (An
  84. aside: does anyone really want to argue that C without malloc [or
  85. other dynamic memory allocator] is still C?)  The paper describes the
  86. language enhancements to C++, and describes how the compiler can
  87. generate data structures that support many flavors of GC, including
  88. copying, conservative, mark-and-sweep, etc.
  89.  
  90. I'm currently working on a prototype that implements a basic,
  91. non-copying mark-and-sweep collector with conservative collection of
  92. the runtime stack.  I hope to have it completed by Sept.
  93.  
  94. If you have read this far and still aren't sure whether the paper
  95. would interest you or not, I include a section of it that describes
  96. some of the sub-goals of the design:
  97.  
  98. To streamline what follows, we define some terms.  C++ classes that
  99. have been declared collectible are referred to as {\em gc-classes\/}
  100. or {\em gc-types}, their instantiations as {\em gc-objects}, and the
  101. space in which they are collected as {\em gc-space}.  Objects that are
  102. pointed to by an application from outside gc-space are said to be {\em
  103. rooted}, and the pointers are called {\em roots}.  Gc-objects to which
  104. there exists a path of pointers from a rooted object are said to be
  105. {\em grounded}; rooted objects are trivially grounded.  Pointers to or
  106. into gc-objects are called {\em gc-pointers}.  Gc-pointers {\em
  107. into\/} gc-objects are also called {\em embedded\/} pointers (also
  108. called {\em interior\/} pointers by some).  Variables that contain
  109. bit-patterns that could be interpreted as gc-pointers but might
  110. actually be something that just happens to look like a gc-pointer
  111. (e.g., an integer, a sequence of characters, etc.) are called {\em
  112. ambiguous roots}.  The act of informing the GC system that a pointer
  113. may point to a gc-object is called {\em registration}.
  114.  
  115. As mentioned, the primary goal of this design is to retro-fit C++ with
  116. garbage collection facilities while not changing the spirit of the
  117. language.  That spirit, based on the spirit of C, can be summarized
  118. provocatively as: (1) Programmers should be able to do anything they
  119. want, subject to their willingness to deal with the consequences
  120. (side-effects and interactions of features whose invariants are
  121. violated).  (2) No one pays for any feature of the language that they
  122. do not use.
  123.  
  124. Based on this spirit, we consequently adopt the following goals for
  125. the system.
  126.  
  127. Adding GC to C++ should not force overhead on users that do not use
  128. it.  When GC is used, it should not interfere with software modules
  129. that do not use it.  GC must not interfere with the current and/or
  130. standard definitions of the language.  That is, a GC facility should
  131. not cause re-definition or loss of language features.
  132.  
  133. The dual of this requirement is that programmers that use GC must take
  134. the responsibility either for not violating the invariants of the
  135. design, or for knowing how to deal with the consequences.  Almost any
  136. restriction imposed by a GC-cooperative C++ compiler can be bypassed
  137. by a sufficiently determined programmer.  The compiler therefore can
  138. take responsibility only for maintaining its GC invariants, but cannot
  139. be expected to find any and all ways in which users may have violated
  140. those invariants.
  141.  
  142. The language should be changed as little as possible.  A strict goal
  143. of no change was seen rather quickly to be unrealistic.  Either all
  144. runtime objects would have to be garbage collected---a {\em major\/}
  145. change to the design of the language and a violation of the spirit of
  146. the language---or, at a minimum, programmers would need language
  147. support to be able to specify which (classes of) objects are to be
  148. garbage collected.  A design consequence of this goal is that a
  149. program can have two dynamic memory spaces: the space dedicated to
  150. objects that are to be garbage collected, and the usual `heap' of
  151. dynamically allocatable memory.
  152.  
  153. Use of a garbage collector must not impose a complete dichotomy on
  154. runtime objects: collected objects must be able to refer to, contain,
  155. and be contained in non-collected objects, and {\em vice versa}.
  156. Gc-objects are not restricted to exist only in gc-space: gc-objects
  157. should be instantiable as global, automatic, or heap objects, if the
  158. programmer so desires.  Obviously, only those that are in gc-space can
  159. and will be automatically reclaimed.  While it may be necessary to add
  160. data to an object to support GC, it must be the case that objects of a
  161. type have exactly one memory representation, no matter where they
  162. reside (global space, stack, heap, or gc-space).  Furthermore, it
  163. should be possible for the user to declare that a specific object is
  164. to be automatically reclaimed.  For instance, the programmer should
  165. not have to declare a special class or data type to have arrays of
  166. characters (strings) automatically reclaimed.
  167.  
  168. Arrays of gc-objects must be supported.
  169.  
  170. The design should support pointers into objects and pointer-to-member.
  171. For instance, if a gc-object has an array of characters as an element,
  172. the programmer should still be able to traverse that array with a
  173. pointer-to-char.  Compiler and runtime mechanisms must exist that
  174. allow correct reclamation of gc-objects that have such `embedded'
  175. pointers into them.  (`Embedded' here refers to where the pointer is
  176. pointing, and not to the location of the pointer itself.)
  177.  
  178. C unions and Pascal tagless variant records are a way of hiding
  179. information from the compiler and/or exposing representation
  180. information to the user.  Unions should be supported wherever
  181. possible.  (However, unions can be supported only with non- or
  182. mostly-copying GC strategies; cf.~\S\ref{unions}).
  183.  
  184. It would be nice if the design did not preclude supporting multiple
  185. and discontiguous gc-spaces, where each gc-space may have a different
  186. GC strategy.  The prototype being constructed does not yet support
  187. multiple gc-spaces, and so this paper does not pursue this goal
  188. directly.  The problem of cross-registration of root pointers between
  189. GC strategies is complex enough that more data is needed on the
  190. desirability of this feature to justify a design to support it at this
  191. time.
  192.  
  193.  
  194.  
  195. ========================================================================
  196. A. Dain Samples, Dain.Samples@uc.edu, wk:(513)556-4783, hm:(513)771-5492
  197. Dept of ECE, ML#30        University of Cincinnati, Cin'ti OH 45221-0030
  198. ------------------------------------------------------------------------
  199.  
  200. -- 
  201. ========================================================================
  202. A. Dain Samples, Dain.Samples@uc.edu, wk:(513)556-4783, hm:(513)771-5492
  203. ------------------------------------------------------------------------
  204. It is so difficult to find the beginning.  Or, better, it is difficult
  205. to begin at the beginning.  And not try to go further back.
  206.                       -Wittgentstein (from "On Certainty")
  207.  
  208. May the background be with you.
  209.                       -Heidegger (from "Being and Time", paraphrased)
  210.