home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / lang / cplus / 12652 < prev    next >
Encoding:
Text File  |  1992-08-20  |  3.7 KB  |  74 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!decwrl!parc!boehm
  3. From: boehm@parc.xerox.com (Hans Boehm)
  4. Subject: Re: Garbage Collection for C++
  5. Message-ID: <boehm.714326151@siria>
  6. Sender: news@parc.xerox.com
  7. Organization: Xerox PARC
  8. References: <1992Aug6.014619.2111@ucc.su.OZ.AU>     <DAVEG.92Aug13025629@synaptx.synaptics.com>     <TMB.92Aug16164940@arolla.idiap.ch>     <1992Aug18.021453.24394@news.mentorg.com>     <DAVEG.92Aug17224359@synaptx.synaptics.com> <boehm.714158406@siria> <DAVEG.92Aug20022559@synaptx.synaptics.com>
  9. Date: 20 Aug 92 15:55:51 GMT
  10. Lines: 62
  11.  
  12. daveg@synaptics.com (Dave Gillespie) writes:
  13. >Do you really think incremental or generational collectors are
  14. >feasible in C++?  I've never looked in the guts of one of these
  15. >collectors, but as I understand it they tend to depend on the
  16. >ability to move data around, and other things that a C++ collector
  17. >might not be able to get away with.  (C++'s use of pointers is so
  18. >unrestricted that it's a minor miracle it's possible to do garbage
  19. >collection at all...)
  20.  
  21. Traditionally these techniques have been used with copying collectors.
  22. (My impression is the issue of copying collection and C++ hasn't been
  23. resolved yet.  Bartlett's mostly copying collector for C++ is one
  24. possible solution.  Another is to use special compilers that insist on
  25. safety.  I personally don't think either of these is optimal in the
  26. short term, but ...)
  27.  
  28. There is a very easy way to build a two generation mark-sweep collector.
  29. The most recent generation consists of those objects that were allocated
  30. since the last collection.  (This is known to be suboptimal, but sometimes
  31. good enough.)  To collect the most recent generation, you leave the mark
  32. bits set from the previous collection.  You then mark from roots (stack etc.)
  33. and from already marked objects that were potentially modified.
  34.  
  35. This gets you most of the pause time and locality advantages of copying
  36. generational collection.  It doesn't usually get you much of a cpu time
  37. improvement, and it may actually cost you a little in cpu time.  The problem
  38. is that you can't easily confine the most recent generation to a mostly
  39. empty section of the heap.  But for moderate allocation rates, pause times
  40. and locality tend to be most of the issue.
  41.  
  42. The glitch is that you need to be able to identify potentially modified
  43. objects.  Under some versions of UNIX, you can coerce this information
  44. out of the OS (with page level granularity, which is usually good enough).
  45. Under many other systems, it's very hard to get a hold of.  PCR currently
  46. does this under SunOS 4.X, but it works only because PCR is in a position
  47. to intercept all system calls.  It's supposed to be much easier under
  48. Solaris 2.0.
  49.  
  50. If you can't get the information out of the VM system, you need to modify
  51. the compiler so that it explicitly tracks pointer writes into the heap
  52. (at a minimum).  Note that these are exactly the same constraints as for
  53. copying generational collectors.
  54.  
  55. Once you have this facility, it's also possible to build incremental or
  56. parallel noncopying collectors.  (In fact nonmoving parallel collectors
  57. are easier than copying parallel collectors, in my opinion.  You don't
  58. have to worry about the collector munging the clients data structures
  59. while it's looking at them.  You still need to worry about the converse
  60. problem.)  The details are in
  61.  
  62. Boehm, Demers, and Shenker,
  63. ``Mostly Parallel Garbage Collection'',
  64. PLDI '91, June 1991 SIGPLAN Notices.
  65.  
  66. In my experience, you don't really want to bother with any of this
  67. unless your heaps get reasonably large relative to your CPU speed.
  68. PCR does use all of the above techniques, since it supports
  69. the Cedar programming environment, which usually has more
  70. than 10 MB live data, and sometimes much more than that.
  71.  
  72. Hans-J. Boehm
  73.  
  74.