README.darwin 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. 6.5 update:
  2. I disabled incremental GC on Darwin in this version, since I couldn't
  3. get gctest to pass when the GC was built as a dynamic library. Building
  4. with -DMPROTECT_VDB (and threads) on the command line should get you
  5. back to the old state. - HB
  6. ./configure --enable-cplusplus results in a "make check" failure, probably
  7. because the ::delete override ends up in a separate dl, and Darwin dynamic
  8. loader semantics appear to be such that this is not really visible to the
  9. main program, unlike on ELF systems. Someone who understands dynamic
  10. loading needs to lookat this. For now, gc_cpp.o needs to be linked
  11. statically, if needed. - HB
  12. Darwin/MacOSX Support - December 16, 2003
  13. =========================================
  14. Important Usage Notes
  15. =====================
  16. GC_init() MUST be called before calling any other GC functions. This
  17. is necessary to properly register segments in dynamic libraries. This
  18. call is required even if you code does not use dynamic libraries as the
  19. dyld code handles registering all data segments.
  20. When your use of the garbage collector is confined to dylibs and you
  21. cannot call GC_init() before your libraries' static initializers have
  22. run and perhaps called GC_malloc(), create an initialization routine
  23. for each library to call GC_init():
  24. #include <gc/gc.h>
  25. extern "C" void my_library_init() { GC_init(); }
  26. Compile this code into a my_library_init.o, and link it into your
  27. dylib. When you link the dylib, pass the -init argument with
  28. _my_library_init (e.g. gcc -dynamiclib -o my_library.dylib a.o b.o c.o
  29. my_library_init.o -init _my_library_init). This causes
  30. my_library_init() to be called before any static initializers, and
  31. will initialize the garbage collector properly.
  32. Note: It doesn't hurt to call GC_init() more than once, so it's best,
  33. if you have an application or set of libraries that all use the
  34. garbage collector, to create an initialization routine for each of
  35. them that calls GC_init(). Better safe than sorry.
  36. The incremental collector is still a bit flaky on darwin. It seems to
  37. work reliably with workarounds for a few possible bugs in place however
  38. these workaround may not work correctly in all cases. There may also
  39. be additional problems that I have not found.
  40. Thread-local GC allocation will not work with threads that are not
  41. created using the GC-provided override of pthread_create(). Threads
  42. created without the GC-provided pthread_create() do not have the
  43. necessary data structures in the GC to store this data.
  44. Implementation Information
  45. ==========================
  46. Darwin/MacOSX support is nearly complete. Thread support is reliable on
  47. Darwin 6.x (MacOSX 10.2) and there have been reports of success on older
  48. Darwin versions (MacOSX 10.1). Shared library support had also been
  49. added and the gc can be run from a shared library. There is currently only
  50. support for Darwin/PPC although adding x86 support should be trivial.
  51. Thread support is implemented in terms of mach thread_suspend and
  52. thread_resume calls. These provide a very clean interface to thread
  53. suspension. This implementation doesn't rely on pthread_kill so the
  54. code works on Darwin < 6.0 (MacOSX 10.1). All the code to stop and
  55. start the world is located in darwin_stop_world.c.
  56. Since not all uses of the GC enable clients to override pthread_create()
  57. before threads have been created, the code for stopping the world has
  58. been rewritten to look for threads using Mach kernel calls. Each
  59. thread identified in this way is suspended and resumed as above. In
  60. addition, since Mach kernel threads do not contain pointers to their
  61. stacks, a stack-walking function has been written to find the stack
  62. limits. Given an initial stack pointer (for the current thread, a
  63. pointer to a stack-allocated local variable will do; for a non-active
  64. thread, we grab the value of register 1 (on PowerPC)), it
  65. will walk the PPC Mach-O-ABI compliant stack chain until it reaches the
  66. top of the stack. This appears to work correctly for GCC-compiled C,
  67. C++, Objective-C, and Objective-C++ code, as well as for Java
  68. programs that use JNI. If you run code that does not follow the stack
  69. layout or stack pointer conventions laid out in the PPC Mach-O ABI,
  70. then this will likely crash the garbage collector.
  71. The original incremental collector support unfortunatelly no longer works
  72. on recent Darwin versions. It also relied on some undocumented kernel
  73. structures. Mach, however, does have a very clean interface to exception
  74. handing. The current implementation uses Mach's exception handling.
  75. Much thanks goes to Andrew Stone, Dietmar Planitzer, Andrew Begel,
  76. Jeff Sturm, and Jesse Rosenstock for all their work on the
  77. Darwin/OS X port.
  78. -Brian Alliet
  79. brian@brianweb.net
  80. Older Information (Most of this no longer applies to the current code)
  81. ======================================================================
  82. While the GC should work on MacOS X Server, MacOS X and Darwin, I only tested
  83. it on MacOS X Server.
  84. I've added a PPC assembly version of GC_push_regs(), thus the setjmp() hack is
  85. no longer necessary. Incremental collection is supported via mprotect/signal.
  86. The current solution isn't really optimal because the signal handler must decode
  87. the faulting PPC machine instruction in order to find the correct heap address.
  88. Further, it must poke around in the register state which the kernel saved away
  89. in some obscure register state structure before it calls the signal handler -
  90. needless to say the layout of this structure is no where documented.
  91. Threads and dynamic libraries are not yet supported (adding dynamic library
  92. support via the low-level dyld API shouldn't be that hard).
  93. The original MacOS X port was brought to you by Andrew Stone.
  94. June, 1 2000
  95. Dietmar Planitzer
  96. dave.pl@ping.at
  97. Note from Andrew Begel:
  98. One more fix to enable gc.a to link successfully into a shared library for
  99. MacOS X. You have to add -fno-common to the CFLAGS in the Makefile. MacOSX
  100. disallows common symbols in anything that eventually finds its way into a
  101. shared library. (I don't completely understand why, but -fno-common seems to
  102. work and doesn't mess up the garbage collector's functionality).
  103. Feb 26, 2003
  104. Jeff Sturm and Jesse Rosenstock provided a patch that adds thread support.
  105. GC_MACOSX_THREADS should be defined in the build and in clients. Real
  106. dynamic library support is still missing, i.e. dynamic library data segments
  107. are still not scanned. Code that stores pointers to the garbage collected
  108. heap in statically allocated variables should not reside in a dynamic
  109. library. This still doesn't appear to be 100% reliable.
  110. Mar 10, 2003
  111. Brian Alliet contributed dynamic library support for MacOSX. It could also
  112. use more testing.