Re: [Gc] patch for support of GC_THREAD GC_PTHREAD on iPhone

Ivan Maidanski ivmai at mail.ru
Mon May 23 03:57:26 PDT 2011


Hi. 

Try GC from today's cvs. I've tested it on iPhone 3GS. No special macro is required. Number of CPUs is obtained via sysctl. Semaphores are emulated. I have not noticed any problems with CAS instruction.  WriteFaultHandler is not used. 

Regards. 

>Greetings,   I am a sometimes developer of the XMLVM project (http://xmlvm.org/overview/).  We make use of the Boehm garbage collector on the iPhone.  In order to have it compile and work on the iPhone we have had to make some minor modifications that we thought you might be interested in incorporating back into the main GC source tree so that others do not have to repeat our work to use the GC on the iPhone.  
>Below I have described the changes.  If you could please suggest a course of action for me I would applicate it.  Please note that these changes are required for threading support, the Boehm GC already functions correctly for single threaded apps. 
>Regards, 
>-- Joshua Melcon
>
>We made the following changes:
>Introduced a define called IPHONEGC to handle iPhone platform differences.  It must be defined for the GC to work on the iPhone
>
>By file:pthread_support.cGC_nprocs forced to 1 if iPhonesem_t* registered instead of sem_t registered, use sem_open instead of sem_init because it is more portable (or so I read).  sem_init doesn't work on the iphone
>pthread_stop_world.csame sem_t* replacement as pthread_support.c
>os_dep.cForce an undef of DARWINForce CODE_OK TRUE in  GC_write_fault_handler
>gc_priv.h
>#ifdef IPHONEGC#define SIG_SUSPEND SIGUSR1  #endif 
>gc_config_macros.h
>#ifdef IPHONEGC #define GC_THREADS#define GC_PTHREADS#elseThe existing code for defining those preprocessor vars.#endif
>dyn_load.c
>don't call _dyld_bind_fully_image_containing_address
>as it doesn't exist on the iphone
>atomic_ops\sysdeps\gcc\arm.h
>undef AO_HAVE_compare_and_swap for iphone because it occasionally generates invalid instructions that won't compile.
>
>
>Diffs from today's cvs version:
>
>C:\tmp>"c:\program files (x86)\gnuwin32\bin\diff" -E -b -w -B C:\tmp\xmlvm\lib\boehmgc\pthread_support.c C:\bdwgcraw\bdwgc\pthread_support.c 938,940c938< #ifdef IPHONEGC<   GC_nprocs = 1;< #else---> 947d944< #endif1444,1447d1440< #if IPHONEGC<     sem_t *registered;           /* 1 ==> in our thread table, but       */<                                 /* parent hasn't yet noticed.           */< #else 1450,1451d1442< #endif< 1482,1485d1472< #if IPHONEGC<     sem_post((si -> registered));      /* Last action on si.   */<                                         /* OK to deallocate.    */< #else1488,1489d1474< #endif< 1545,1550d1529< #ifdef IPHONEGC< < si->registered = sem_open("GCSEMTHREAD", O_CREAT, S_IRWXU, 0);< if(si->registered  == SEM_FAILED)< ABORT("thread sem fail"< #else  1553d1531< #endif1617,1621d1594< #if IPHONEGC<         while (0 != sem_wait((si -> registered))) {<             if (EINTR != errno) ABORT("sem_wait failed"<         }< #else 1625d1597< #endif 1628,1630!
d1599< #if IPHONEGC<     sem_destroy((si -> registered));< #else 1632d1600< #endif
>C:\tmp>"c:\program files (x86)\gnuwin32\bin\diff" -E -b -w -B  C:\tmp\xmlvm\lib\boehmgc\pthread_stop_world.c C:\bdwgcraw\bdwgc\pthread_stop_world.c 158,164c158< #ifdef IPHONEGC< STATIC sem_t* GC_suspend_ack_sem_real;< #define GC_suspend_ack_sem GC_suspend_ack_sem_real< #else < STATIC sem_t GC_suspend_ack_sem_real;< #define GC_suspend_ack_sem &GC_suspend_ack_sem_real< #endif ---> STATIC sem_t GC_suspend_ack_sem;247c241<   sem_post(GC_suspend_ack_sem);--->   sem_post(&GC_suspend_ack_sem);563c557<         sem_getvalue(GC_suspend_ack_sem, &ack_count);--->         sem_getvalue(&GC_suspend_ack_sem, &ack_count);571c565<           sem_getvalue(GC_suspend_ack_sem, &ack_count);--->           sem_getvalue(&GC_suspend_ack_sem, &ack_count);585c579<         if (0 != (code = sem_wait(GC_suspend_ack_sem))) {--->         if (0 != (code = sem_wait(&GC_suspend_ack_sem))) {817,822c811,812< #ifdef IPHONEGC< GC_suspend_ack_sem = sem_open("GCSEM", O_CREAT, S_IRWXU, 0);< if(GC_suspend_ack_sem == S!
EM_FAILED)<  ABORT("sem_open failed"< #else <     if (sem_init(GC_suspend_ack_sem, GC_SEM_INIT_PSHARED, 0) != 0)---> >     if (sem_init(&GC_suspend_ack_sem, GC_SEM_INIT_PSHARED, 0) != 0)824d813< #endif 
>C:\tmp>"c:\program files (x86)\gnuwin32\bin\diff" -E -b -w -B C:\tmp\xmlvm\lib\boehmgc\os_dep.c C:\bdwgcraw\bdwgc\os_dep.c 116,119d115< #ifdef IPHONEGC< #undef DARWIN< #endif < 3124,3126c3120< #ifdef IPHONEGC < #define CODE_OK TRUE< #endif---> 
>C:\tmp>"c:\program files (x86)\gnuwin32\bin\diff" -E -b -w -B C:\tmp\xmlvm\lib\boehmgc\include\private\gc_priv.h C:\bdwgcraw\bdwgc\include\private\gc_priv.h 2110,2113d2109< #ifdef IPHONEGC< #define SIG_SUSPEND SIGUSR1< #endif < 
>C:\tmp>"c:\program files (x86)\gnuwin32\bin\diff" -E -b -w -B C:\tmp\xmlvm\lib\boehmgc\include\gc_config_macros.h C:\bdwgcraw\bdwgc\include\gc_config_macros.h 62,65d61< #ifdef IPHONEGC < #define GC_THREADS< #define GC_PTHREADS< #else130,131d125< #endif // ELSE IPHONEGC< 
>C:\tmp>"c:\program files (x86)\gnuwin32\bin\diff" -E -b -w -B C:\tmp\xmlvm\lib\boehmgc\dyn_load.c C:\bdwgcraw\bdwgc\dyn_load.c 1413c1413< # ifdef NO_DYLD_BIND_FULLY_IMAGE || IPHONEGC---> # ifdef NO_DYLD_BIND_FULLY_IMAGE
>C:\tmp>"c:\program files (x86)\gnuwin32\bin\diff" -E -b -w -B C:\tmp\xmlvm\lib\boehmgc\libatomic_ops\src\atomic_ops\sysdeps\gcc\arm.h C:\bdwgcraw\bdwgc\libatomic_ops\src\atomic_ops\sysdeps\gcc\arm.h 231,232d230< #ifndef IPHONEGC < 234,235c232< // Generates invalid instructions on the iphone with the gcc compiler in the< // apple sdk -- avoid it for now. ---> 263d259< #endif
>


More information about the Gc mailing list