home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / compiler / 1357 < prev    next >
Encoding:
Text File  |  1992-08-12  |  5.4 KB  |  104 lines

  1. Newsgroups: comp.compilers
  2. Path: sparky!uunet!think.com!spdcc!iecc!compilers-sender
  3. From: eifrig@beanworld.cs.jhu.edu (Jonathan Eifrig)
  4. Subject: Re: Garbage Collection
  5. Reply-To: eifrig@beanworld.cs.jhu.edu (Jonathan Eifrig)
  6. Organization: The Johns Hopkins University CS Department
  7. Date: Wed, 12 Aug 1992 15:04:23 GMT
  8. Approved: compilers@iecc.cambridge.ma.us
  9. Message-ID: <92-08-056@comp.compilers>
  10. References: <92-08-015@comp.compilers> <92-08-045@comp.compilers>
  11. Keywords: storage, GC
  12. Sender: compilers-sender@iecc.cambridge.ma.us
  13. Lines: 89
  14.  
  15. boehm@parc.xerox.com (Hans Boehm) writes:
  16. >>(3) A general-purpose garbage collector will probably be used...
  17. >
  18. >Agreed.  In fact, I like to carry this a lot further and argue that at
  19. >least in the short term, the garbage collector should support a variety of
  20. >programming languages, including C, whenever possible.
  21.  
  22.     Here's where our approaches begin to diverge.  I don't think that
  23. a single garbage collector, perhaps as part of the kernel, is appropriate
  24. for all source languages.  For example, you claim that you want a
  25. collector to work with your (presumably stack-oriented) C programs.  Fine.
  26. But what about _my_ non-stack-oriented programs?  Since I don't use a
  27. stack, I may be using the "stack pointer" register as a general-purpose
  28. way.  How is the collector going to know _not_ to try to collect assuming
  29. this register is a pointer to a stack of activation records?
  30.  
  31.     In short, I don't think that it's desirable to shoehorn all
  32. possible modes of operation into a single garbage-collection model.
  33. Different languages have different needs, and will use the heap
  34. differently.
  35.  
  36. >>    Basically, I don't see any reason to jump through hoops to support
  37. >>the "garbage collection at any time" model, when the "garbage collection
  38. >>when I say so" model is (a) inexpensive to implement and (b) permits so
  39. >>much more lattitude in optimizations.  The cost of the garbage collection
  40. >>check will be more than cancelled if I can use registers to optimize out
  41. >>just _one_ memory reference, and I'll win big if I can pass a single
  42. >>parameter in a register.  What do I have to lose?
  43. >
  44. >I think we're making very different assumptions about both the garbage
  45. >collector, and the environment in which it will be used.  For many kinds
  46. >of problems, multiple threads of control in the same address space make
  47. >life much easier.  For example, any application that can accept more than
  48. >one asynchronous input stream (e.g. a terminal emulator) is easier to
  49. >write with threads.  It's hard to take advantage of shared memory
  50. >multiprocessors without multiple threads in the same address space.  All
  51. >recently designed operating systems provide such a facility (including
  52. >UNIX derivatives like IRIX, Solaris 2.0, etc.)  There is an emerging POSIX
  53. >standard for threads.
  54.  
  55.     Sure, threads are important.  Sure, multiple threads in a single
  56. process should share the same heap space.  All I'm saying is that there is
  57. no need to use some external "alarm" interrupt to slavishly switch
  58. contexts immediately upon receipt of such a signal.  We can, as I
  59. explained earlier, switch contexts _only_ at the beginning of basic
  60. blocks.  What's a few more instructions between context switches?
  61.  
  62. >Our main difference is that I usually assume a garbage collector that
  63. >scans the stack and registers conservatively.  This means that objects
  64. >reachable only from the stack or registers must have an address inside the
  65. >object located somewhere on the stack or in the registers.  That's all
  66. >that's required.  This is a very cheap invariant to maintain at all
  67. >program points.
  68.  
  69.     Correct me if I'm wrong, but you seem to be saying that you're
  70. using the stack and the registers as roots of garbage collection.  This
  71. will, of course, work (modulo some details concerning computed addresses
  72. of heap objects) _provided_that_one_can_recognize_the_format_of_stack_
  73. _and_registers_.  Sure all the pointers are there, but which data elements
  74. of the stack are pointers, meaning that we should follow them into the
  75. heap to find things to collect, and which are just integers, which we
  76. should ignore?  If we decide, in an attempt to be _really_conservative_,
  77. to assume everything is a pointer, then we pay a double penalty: since
  78. we're wasting time moving junk around, garbage collection takes longer,
  79. and since we're not reclaiming storage that is actually free, we collect
  80. more often.
  81.  
  82.     It seems clear that this naive approach won't be satisfactory, so
  83. what can we do?  We could label our stack frames with some tag
  84. information, indicating which elements of the frame are pointers and which
  85. integers, _but_what_do_we_do_about_the_registers_?  What if we garbage
  86. collect while we're in the middle of writing one of these tags (do to a
  87. context switch into a thread which triggers collection)?  Our stack is in
  88. an inconsistent state when the collector starts, and we're screwed.
  89.  
  90. >Explicit safe points in garbage collected code are probably a good idea
  91. >for many systems.  But they're inappropriate for other systems.
  92. >
  93.  
  94.     I just don't see how you're going to allow garbage collection to
  95. occur _anywhere_ and handle any sort of tagged heap.  Are you assuming
  96. that procedure calls and heap allocations are atomic?  What happens if I
  97. have to garbage collect while I'm in the middle of allocating a record,
  98. and haven't written the length of the record to the heap yet?
  99. --
  100. Jack Eifrig (eifrig@cs.jhu.edu)       The Johns Hopkins University, C.S. Dept.
  101. -- 
  102. Send compilers articles to compilers@iecc.cambridge.ma.us or
  103. {ima | spdcc | world}!iecc!compilers.  Meta-mail to compilers-request.
  104.