home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / cplus / 13042 < prev    next >
Encoding:
Text File  |  1992-08-29  |  4.9 KB  |  102 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.714847027@siria>
  6. Sender: news@parc.xerox.com
  7. Organization: Xerox PARC
  8. References: <DAVEG.92Aug17224359@synaptx.synaptics.com> <1992Aug20.213720.16599@microsoft.com> <boehm.714410546@siria> <1992Aug25.185458.10190@microsoft.com>
  9. Date: 26 Aug 92 16:37:07 GMT
  10. Lines: 90
  11.  
  12. jimad@microsoft.com (Jim Adcock) writes:
  13.  
  14. [Discussion of allocation costs for long-lived objects with
  15. generational collection omitted.]
  16.  
  17. >My accounting is simply that the cost of keeping an object alive is
  18. >not the cost of either allocating or deallocating the object.  Before you
  19. >cry "foul" please note that non-moveable-object memory management schemes
  20. >*also* have a cost of keeping objects alive -- namely their non-locality
  21. >of reference leads to costs of cache misses, page turns, and ultimately
  22. >thrashing on heavily loaded systems.  Such costs need to be factored into
  23. >the cost of any memory management scheme -- but estimating such costs is
  24. >extremely variable depending on a given system and how that system is loaded.
  25. >Whereas the costs of allocating and deallocating can be more reasonably
  26. >estimated.
  27.  
  28. (I think we've had this discussion before, but ...)
  29. I agree that the nonlocality costs are hard to estimate.  In fact, I
  30. don't believe that they always favor the moving collector.  At least some
  31. nonmoving allocators do a reasonable job of keeping consecutively
  32. allocated objects close together.  There is some evidence that this is
  33. a better strategy than keeping things in breadth-first traversal order,
  34. as many copying collectors do.
  35.  
  36. Perhaps more importantly, given the ratio of disk access times to cpu
  37. speeds on most modern machines, the real question often is "how long can
  38. you run without any significant paging?".  Copying collectors tend not to
  39. do very well by this measure, since a full collection touches more VM than
  40. any nonmoving scheme is likely to.  Malloc/free (with or without reference
  41. counting) probably wins by this criterion, with compacting Mark-sweep
  42. collection scoring a close second.  (It wins as a result of less fragmentation,
  43. but needs some empty space in the heap to prevent GC thrashing.)
  44.  
  45. At the level of cache performance, there is also no clear winner.
  46. Malloc/free has the big advantage of recycling objects sooner, thus
  47. making it likely that a newly allocated objects is already cached, and
  48. making it less likely that something else will need to be flushed as the
  49. result of the allocation.  I would guess that this usually dominates the
  50. results of fragmentation etc., but I'm not sure.  It's conceivable that
  51. you could make the youngest generation of a copying collector small enough
  52. to get the same effect, at least if the root set is small enough.  But this
  53. can cause excessive promotion rates, at least for small cache sizes.  I
  54. don't know of any existing collectors that really achieve this for say
  55. a 32K cache.
  56.  
  57. >|Generational (esp. copying) collectors win dramatically on short-lived
  58. >|objects, provided you have some efficient way of tracking stores
  59. >|into old objects.  Fortunately most objects fall into this category
  60. >|for most programs.
  61. >|
  62. >|(Ben Zorn has some measurements that substantiate this for some
  63. >|interesting C programs.  It is clearly the case for all known
  64. >|Lisp and Smalltalk implementations.)
  65.  
  66. >I've found surprisingly similar results on a limited number of C++ programs
  67. >I've tested.
  68.  
  69. >|A generational copying collector is probably the worst possible choice if
  70. >|all your program allocates are large long-lived bitmaps  (and indeed
  71. >|generational copying collectors usually treat such things as a special
  72. >|case).
  73.  
  74. >But such cases can already be well handled in C++ using reference counting
  75. >schemes.  Again, I see a Modula-3 like approach where classes of objects
  76. >are either GC or not GC -- and the GC class objects are movable.  Backwards
  77. >compatibility is maintained because adding GC'ed classes is a pure extension.
  78.  
  79. My problem with this is that the two worlds don't mix well, making it
  80. hard to use old libraries with new code.
  81.  
  82. In the case of long-lived
  83. bitmaps, I would prefer to allocate the bitmap off to the side, with
  84. a garbage collected header object that deallocates the bitmap in its
  85. finalizer (or destructor, or whatever).  That probably works fine.  I
  86. was only using the example to argue against a pure copying collector
  87. scheme.
  88.  
  89. >Moveable objects need to be supported not merely for GC, but for more 
  90. >interesting problems of distributed networks, persistence, ODBMS, etc.
  91.  
  92. Agreed.  Support for movable objects is a good thing.  But it also has
  93. a very substantial cost, in that lots of compilers and libraries need to be
  94. fixed.  Some (nonportable but useful) programming paradigms break (e.g.
  95. hashing pointers no longer works.  You need an extra counter field per
  96. allocated object if you want to be able to hash.)  There is a cost (of
  97. one kind or another) in maintaining enough descriptor information.
  98.  
  99. Hans-J. Boehm
  100. (boehm@parc.xerox.com)
  101.  
  102.