📄 readme.darwin
字号:
Darwin/MacOSX Support - December 16, 2003=========================================Important Usage Notes=====================GC_init() MUST be called before calling any other GC functions. This is necessary to properly register segments in dynamic libraries. Thiscall is required even if you code does not use dynamic libraries as thedyld code handles registering all data segments.When your use of the garbage collector is confined to dylibs and youcannot call GC_init() before your libraries' static initializers haverun and perhaps called GC_malloc(), create an initialization routinefor each library to call GC_init():#include <gc/gc.h>extern "C" void my_library_init() { GC_init(); }Compile this code into a my_library_init.o, and link it into yourdylib. When you link the dylib, pass the -init argument with_my_library_init (e.g. gcc -dynamiclib -o my_library.dylib a.o b.o c.omy_library_init.o -init _my_library_init). This causesmy_library_init() to be called before any static initializers, andwill initialize the garbage collector properly. Note: It doesn't hurt to call GC_init() more than once, so it's best,if you have an application or set of libraries that all use thegarbage collector, to create an initialization routine for each ofthem that calls GC_init(). Better safe than sorry. The incremental collector is still a bit flaky on darwin. It seems to work reliably with workarounds for a few possible bugs in place howeverthese workaround may not work correctly in all cases. There may alsobe additional problems that I have not found. Thread-local GC allocation will not work with threads that are notcreated using the GC-provided override of pthread_create(). Threadscreated without the GC-provided pthread_create() do not have thenecessary data structures in the GC to store this data. Implementation Information==========================Darwin/MacOSX support is nearly complete. Thread support is reliable on Darwin 6.x (MacOSX 10.2) and there have been reports of success on olderDarwin versions (MacOSX 10.1). Shared library support had also beenadded and the gc can be run from a shared library. There is currently onlysupport for Darwin/PPC although adding x86 support should be trivial.Thread support is implemented in terms of mach thread_suspend andthread_resume calls. These provide a very clean interface to threadsuspension. This implementation doesn't rely on pthread_kill so thecode works on Darwin < 6.0 (MacOSX 10.1). All the code to stop andstart the world is located in darwin_stop_world.c.Since not all uses of the GC enable clients to override pthread_create()before threads have been created, the code for stopping the world hasbeen rewritten to look for threads using Mach kernel calls. Eachthread identified in this way is suspended and resumed as above. Inaddition, since Mach kernel threads do not contain pointers to theirstacks, a stack-walking function has been written to find the stacklimits. Given an initial stack pointer (for the current thread, apointer to a stack-allocated local variable will do; for a non-activethread, we grab the value of register 1 (on PowerPC)), itwill walk the PPC Mach-O-ABI compliant stack chain until it reaches thetop of the stack. This appears to work correctly for GCC-compiled C,C++, Objective-C, and Objective-C++ code, as well as for Javaprograms that use JNI. If you run code that does not follow the stacklayout or stack pointer conventions laid out in the PPC Mach-O ABI,then this will likely crash the garbage collector. The original incremental collector support unfortunatelly no longer workson recent Darwin versions. It also relied on some undocumented kernelstructures. Mach, however, does have a very clean interface to exceptionhanding. The current implementation uses Mach's exception handling. Much thanks goes to Andrew Stone, Dietmar Planitzer, Andrew Begel, Jeff Sturm, and Jesse Rosenstock for all their work on the Darwin/OS X port.-Brian Allietbrian@brianweb.netgc_cpp.h usage==============Replacement of operator new and delete is apparently not supported withdynamic libraries. This means that applications using gc_cpp.h(including the built-in test) will probably not work correctly withthe collector in a dynamic library, unless special care is taken.Seehttp://article.gmane.org/gmane.comp.programming.garbage-collection.boehmgc/1421for some details.- Hans Boehm (based on information from Andrew Begel)Older Information (Most of this no longer applies to the current code)======================================================================While the GC should work on MacOS X Server, MacOS X and Darwin, I only testedit on MacOS X Server.I've added a PPC assembly version of GC_push_regs(), thus the setjmp() hack isno longer necessary. Incremental collection is supported via mprotect/signal.The current solution isn't really optimal because the signal handler must decodethe faulting PPC machine instruction in order to find the correct heap address.Further, it must poke around in the register state which the kernel saved awayin some obscure register state structure before it calls the signal handler -needless to say the layout of this structure is no where documented.Threads and dynamic libraries are not yet supported (adding dynamic librarysupport via the low-level dyld API shouldn't be that hard).The original MacOS X port was brought to you by Andrew Stone.June, 1 2000Dietmar Planitzerdave.pl@ping.atNote from Andrew Begel:One more fix to enable gc.a to link successfully into a shared library forMacOS X. You have to add -fno-common to the CFLAGS in the Makefile. MacOSXdisallows common symbols in anything that eventually finds its way into ashared library. (I don't completely understand why, but -fno-common seems towork and doesn't mess up the garbage collector's functionality).Feb 26, 2003Jeff Sturm and Jesse Rosenstock provided a patch that adds thread support.GC_MACOSX_THREADS should be defined in the build and in clients. Realdynamic library support is still missing, i.e. dynamic library data segmentsare still not scanned. Code that stores pointers to the garbage collectedheap in statically allocated variables should not reside in a dynamiclibrary. This still doesn't appear to be 100% reliable. Mar 10, 2003Brian Alliet contributed dynamic library support for MacOSX. It could alsouse more testing.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -