diff options
author | (no author) <(no author)@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-07-28 03:46:21 +0000 |
---|---|---|
committer | (no author) <(no author)@138bc75d-0d04-0410-961f-82ee72b054a4> | 2003-07-28 03:46:21 +0000 |
commit | ae957486eda72a12531a7420941561882bc17b9b (patch) | |
tree | 3903711d680969b73432bbddb35b6ad14b2b8494 | |
parent | bd8ba8b8d3644c7765bead0d187676c91e316839 (diff) |
This commit was manufactured by cvs2svn to create tagGC_6_3_ALPHA_1
'GC_6_3_ALPHA_1'.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/tags/GC_6_3_ALPHA_1@69876 138bc75d-0d04-0410-961f-82ee72b054a4
28 files changed, 4869 insertions, 806 deletions
diff --git a/boehm-gc/irix_threads.c b/boehm-gc/aix_irix_threads.c index 12204fdabc2..d8ac3454af9 100644 --- a/boehm-gc/irix_threads.c +++ b/boehm-gc/aix_irix_threads.c @@ -1,7 +1,7 @@ /* * Copyright (c) 1991-1995 by Xerox Corporation. All rights reserved. * Copyright (c) 1996-1999 by Silicon Graphics. All rights reserved. - * Copyright (c) 1999 by Hewlett-Packard Company. All rights reserved. + * Copyright (c) 1999-2003 by Hewlett-Packard Company. All rights reserved. * * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. @@ -13,22 +13,24 @@ * modified is included with the above copyright notice. */ /* - * Support code for Irix (>=6.2) Pthreads. This relies on properties + * Support code for Irix (>=6.2) Pthreads and for AIX pthreads. + * This relies on properties * not guaranteed by the Pthread standard. It may or may not be portable * to other implementations. * - * This now also includes an initial attempt at thread support for - * HP/UX 11. + * Note that there is a lot of code duplication between this file and + * (pthread_support.c, pthread_stop_world.c). They should be merged. + * Pthread_support.c should be directly usable. * - * Note that there is a lot of code duplication between linux_threads.c - * and irix_threads.c; any changes made here may need to be reflected - * there too. + * Please avoid adding new ports here; use the generic pthread support + * as a base instead. */ -# if defined(GC_IRIX_THREADS) +# if defined(GC_IRIX_THREADS) || defined(GC_AIX_THREADS) # include "private/gc_priv.h" # include <pthread.h> +# include <assert.h> # include <semaphore.h> # include <time.h> # include <errno.h> @@ -39,7 +41,10 @@ #undef pthread_create #undef pthread_sigmask #undef pthread_join -#undef pthread_detach + +#if defined(GC_IRIX_THREADS) && !defined(MUTEX_RECURSIVE_NP) +#define MUTEX_RECURSIVE_NP PTHREAD_MUTEX_RECURSIVE +#endif void GC_thr_init(); @@ -82,13 +87,10 @@ typedef struct GC_Thread_Rep { word flags; # define FINISHED 1 /* Thread has exited. */ # define DETACHED 2 /* Thread is intended to be detached. */ -# define CLIENT_OWNS_STACK 4 - /* Stack was supplied by client. */ - ptr_t stack; - ptr_t stack_ptr; /* Valid only when stopped. */ + ptr_t stack_cold; /* cold end of the stack */ + ptr_t stack_hot; /* Valid only when stopped. */ /* But must be within stack region at */ /* all times. */ - size_t stack_size; /* 0 for original thread. */ void * status; /* Used only to avoid premature */ /* reclamation of any data it might */ /* reference. */ @@ -100,8 +102,14 @@ GC_thread GC_lookup_thread(pthread_t id); * The only way to suspend threads given the pthread interface is to send * signals. Unfortunately, this means we have to reserve * a signal, and intercept client calls to change the signal mask. - * We use SIG_SUSPEND, defined in gc_priv.h. */ +#if 0 /* DOB: 6.1 */ +# if defined(GC_AIX_THREADS) +# define SIG_SUSPEND SIGUSR1 +# else +# define SIG_SUSPEND (SIGRTMIN + 6) +# endif +#endif pthread_mutex_t GC_suspend_lock = PTHREAD_MUTEX_INITIALIZER; /* Number of threads stopped so far */ @@ -128,7 +136,7 @@ void GC_suspend_handler(int sig) return; } pthread_mutex_lock(&GC_suspend_lock); - me -> stack_ptr = (ptr_t)(&dummy); + me -> stack_hot = (ptr_t)(&dummy); me -> stop = STOPPED; pthread_cond_signal(&GC_suspend_ack_cv); pthread_cond_wait(&GC_continue_cv, &GC_suspend_lock); @@ -139,66 +147,6 @@ void GC_suspend_handler(int sig) GC_bool GC_thr_initialized = FALSE; -size_t GC_min_stack_sz; - -# define N_FREE_LISTS 25 -ptr_t GC_stack_free_lists[N_FREE_LISTS] = { 0 }; - /* GC_stack_free_lists[i] is free list for stacks of */ - /* size GC_min_stack_sz*2**i. */ - /* Free lists are linked through first word. */ - -/* Return a stack of size at least *stack_size. *stack_size is */ -/* replaced by the actual stack size. */ -/* Caller holds allocation lock. */ -ptr_t GC_stack_alloc(size_t * stack_size) -{ - register size_t requested_sz = *stack_size; - register size_t search_sz = GC_min_stack_sz; - register int index = 0; /* = log2(search_sz/GC_min_stack_sz) */ - register ptr_t result; - - while (search_sz < requested_sz) { - search_sz *= 2; - index++; - } - if ((result = GC_stack_free_lists[index]) == 0 - && (result = GC_stack_free_lists[index+1]) != 0) { - /* Try next size up. */ - search_sz *= 2; index++; - } - if (result != 0) { - GC_stack_free_lists[index] = *(ptr_t *)result; - } else { - result = (ptr_t) GC_scratch_alloc(search_sz + 2*GC_page_size); - result = (ptr_t)(((word)result + GC_page_size) & ~(GC_page_size - 1)); - /* Protect hottest page to detect overflow. */ -# ifdef STACK_GROWS_UP - /* mprotect(result + search_sz, GC_page_size, PROT_NONE); */ -# else - /* mprotect(result, GC_page_size, PROT_NONE); */ - result += GC_page_size; -# endif - } - *stack_size = search_sz; - return(result); -} - -/* Caller holds allocation lock. */ -void GC_stack_free(ptr_t stack, size_t size) -{ - register int index = 0; - register size_t search_sz = GC_min_stack_sz; - - while (search_sz < size) { - search_sz *= 2; - index++; - } - if (search_sz != size) ABORT("Bad stack size"); - *(ptr_t *)stack = GC_stack_free_lists[index]; - GC_stack_free_lists[index] = stack; -} - - # define THREAD_TABLE_SZ 128 /* Must be power of 2 */ volatile GC_thread GC_threads[THREAD_TABLE_SZ]; @@ -217,13 +165,14 @@ GC_thread GC_new_thread(pthread_t id) static struct GC_Thread_Rep first_thread; static GC_bool first_thread_used = FALSE; + GC_ASSERT(I_HOLD_LOCK()); if (!first_thread_used) { result = &first_thread; first_thread_used = TRUE; /* Dont acquire allocation lock, since we may already hold it. */ } else { result = (struct GC_Thread_Rep *) - GC_INTERNAL_MALLOC(sizeof(struct GC_Thread_Rep), NORMAL); + GC_generic_malloc_inner(sizeof(struct GC_Thread_Rep), NORMAL); } if (result == 0) return(0); result -> id = id; @@ -237,24 +186,8 @@ GC_thread GC_new_thread(pthread_t id) /* Delete a thread from GC_threads. We assume it is there. */ /* (The code intentionally traps if it wasn't.) */ /* Caller holds allocation lock. */ -void GC_delete_thread(pthread_t id) -{ - int hv = ((word)id) % THREAD_TABLE_SZ; - register GC_thread p = GC_threads[hv]; - register GC_thread prev = 0; - - while (!pthread_equal(p -> id, id)) { - prev = p; - p = p -> next; - } - if (prev == 0) { - GC_threads[hv] = p -> next; - } else { - prev -> next = p -> next; - } -} - -/* If a thread has been joined, but we have not yet */ +/* We explicitly pass in the GC_thread we're looking for, since */ +/* if a thread has been joined, but we have not yet */ /* been notified, then there may be more than one thread */ /* in the table with the same pthread id. */ /* This is OK, but we need a way to delete a specific one. */ @@ -264,6 +197,7 @@ void GC_delete_gc_thread(pthread_t id, GC_thread gc_id) register GC_thread p = GC_threads[hv]; register GC_thread prev = 0; + GC_ASSERT(I_HOLD_LOCK()); while (p != gc_id) { prev = p; p = p -> next; @@ -286,10 +220,53 @@ GC_thread GC_lookup_thread(pthread_t id) int hv = ((word)id) % THREAD_TABLE_SZ; register GC_thread p = GC_threads[hv]; + /* I either hold the lock, or i'm being called from the stop-the-world + * handler. */ +#if defined(GC_AIX_THREADS) + GC_ASSERT(I_HOLD_LOCK()); /* no stop-the-world handler needed on AIX */ +#endif while (p != 0 && !pthread_equal(p -> id, id)) p = p -> next; return(p); } +#if defined(GC_AIX_THREADS) +void GC_stop_world() +{ + pthread_t my_thread = pthread_self(); + register int i; + register GC_thread p; + register int result; + struct timespec timeout; + + GC_ASSERT(I_HOLD_LOCK()); + for (i = 0; i < THREAD_TABLE_SZ; i++) { + for (p = GC_threads[i]; p != 0; p = p -> next) { + if (p -> id != my_thread) { + pthread_suspend_np(p->id); + } + } + } + /* GC_printf1("World stopped 0x%x\n", pthread_self()); */ +} + +void GC_start_world() +{ + GC_thread p; + unsigned i; + pthread_t my_thread = pthread_self(); + + /* GC_printf0("World starting\n"); */ + GC_ASSERT(I_HOLD_LOCK()); + for (i = 0; i < THREAD_TABLE_SZ; i++) { + for (p = GC_threads[i]; p != 0; p = p -> next) { + if (p -> id != my_thread) { + pthread_continue_np(p->id); + } + } + } +} + +#else /* GC_AIX_THREADS */ /* Caller holds allocation lock. */ void GC_stop_world() @@ -300,6 +277,7 @@ void GC_stop_world() register int result; struct timespec timeout; + GC_ASSERT(I_HOLD_LOCK()); for (i = 0; i < THREAD_TABLE_SZ; i++) { for (p = GC_threads[i]; p != 0; p = p -> next) { if (p -> id != my_thread) { @@ -355,6 +333,7 @@ void GC_start_world() unsigned i; /* GC_printf0("World starting\n"); */ + GC_ASSERT(I_HOLD_LOCK()); for (i = 0; i < THREAD_TABLE_SZ; i++) { for (p = GC_threads[i]; p != 0; p = p -> next) { p -> stop = NOT_STOPPED; @@ -367,25 +346,8 @@ void GC_start_world() pthread_cond_broadcast(&GC_continue_cv); } -# ifdef MMAP_STACKS ---> not really supported yet. -int GC_is_thread_stack(ptr_t addr) -{ - register int i; - register GC_thread p; +#endif /* GC_AIX_THREADS */ - for (i = 0; i < THREAD_TABLE_SZ; i++) { - for (p = GC_threads[i]; p != 0; p = p -> next) { - if (p -> stack_size != 0) { - if (p -> stack <= addr && - addr < p -> stack + p -> stack_size) - return 1; - } - } - } - return 0; -} -# endif /* We hold allocation lock. Should do exactly the right thing if the */ /* world is stopped. Should not fail if it isn't. */ @@ -393,33 +355,59 @@ void GC_push_all_stacks() { register int i; register GC_thread p; - register ptr_t sp = GC_approx_sp(); register ptr_t hot, cold; pthread_t me = pthread_self(); - if (!GC_thr_initialized) GC_thr_init(); + /* GC_init() should have been called before GC_push_all_stacks is + * invoked, and GC_init calls GC_thr_init(), which sets + * GC_thr_initialized. */ + GC_ASSERT(GC_thr_initialized); + /* GC_printf1("Pushing stacks from thread 0x%x\n", me); */ + GC_ASSERT(I_HOLD_LOCK()); for (i = 0; i < THREAD_TABLE_SZ; i++) { for (p = GC_threads[i]; p != 0; p = p -> next) { if (p -> flags & FINISHED) continue; + cold = p->stack_cold; + if (!cold) cold=GC_stackbottom; /* 0 indicates 'original stack' */ if (pthread_equal(p -> id, me)) { hot = GC_approx_sp(); } else { - hot = p -> stack_ptr; +# ifdef GC_AIX_THREADS + /* AIX doesn't use signals to suspend, so we need to get an */ + /* accurate hot stack pointer. */ + /* See http://publib16.boulder.ibm.com/pseries/en_US/libs/basetrf1/pthread_getthrds_np.htm */ + pthread_t id = p -> id; + struct __pthrdsinfo pinfo; + int regbuf[64]; + int val = sizeof(regbuf); + int retval = pthread_getthrds_np(&id, PTHRDSINFO_QUERY_ALL, &pinfo, + sizeof(pinfo), regbuf, &val); + if (retval != 0) { + printf("ERROR: pthread_getthrds_np() failed in GC\n"); + abort(); + } + /* according to the AIX ABI, + "the lowest possible valid stack address is 288 bytes (144 + 144) + less than the current value of the stack pointer. Functions may + use this stack space as volatile storage which is not preserved + across function calls." + ftp://ftp.penguinppc64.org/pub/people/amodra/PPC-elf64abi.txt.gz + */ + hot = (ptr_t)(unsigned long)pinfo.__pi_ustk-288; + cold = (ptr_t)pinfo.__pi_stackend; /* more precise */ + /* push the registers too, because they won't be on stack */ + GC_push_all_eager((ptr_t)&pinfo.__pi_context, + (ptr_t)((&pinfo.__pi_context)+1)); + GC_push_all_eager((ptr_t)regbuf, ((ptr_t)regbuf)+val); +# else + hot = p -> stack_hot; +# endif } - if (p -> stack_size != 0) { -# ifdef STACK_GROWS_UP - cold = p -> stack; -# else - cold = p -> stack + p -> stack_size; -# endif - } else { - /* The original stack. */ - cold = GC_stackbottom; - } # ifdef STACK_GROWS_UP GC_push_all_stack(cold, hot); # else + /* printf("thread 0x%x: hot=0x%08x cold=0x%08x\n", p -> id, hot, cold); */ GC_push_all_stack(hot, cold); # endif } @@ -434,8 +422,14 @@ void GC_thr_init() struct sigaction act; if (GC_thr_initialized) return; +#if 0 + /* unfortunately, GC_init_inner calls us without the lock, so + * this assertion is not always true. */ + /* Why doesn't GC_init_inner hold the lock? - HB */ + GC_ASSERT(I_HOLD_LOCK()); +#endif GC_thr_initialized = TRUE; - GC_min_stack_sz = HBLKSIZE; +#ifndef GC_AIX_THREADS (void) sigaction(SIG_SUSPEND, 0, &act); if (act.sa_handler != SIG_DFL) ABORT("Previously installed SIG_SUSPEND handler"); @@ -445,10 +439,13 @@ void GC_thr_init() (void) sigemptyset(&act.sa_mask); if (0 != sigaction(SIG_SUSPEND, &act, 0)) ABORT("Failed to install SIG_SUSPEND handler"); +#endif /* Add the initial thread, so we can stop it. */ t = GC_new_thread(pthread_self()); - t -> stack_size = 0; - t -> stack_ptr = (ptr_t)(&t); + /* use '0' to indicate GC_stackbottom, since GC_init() has not + * completed by the time we are called (from GC_init_inner()) */ + t -> stack_cold = 0; /* the original stack. */ + t -> stack_hot = (ptr_t)(&t); t -> flags = DETACHED; } @@ -456,6 +453,10 @@ int GC_pthread_sigmask(int how, const sigset_t *set, sigset_t *oset) { sigset_t fudged_set; +#ifdef GC_AIX_THREADS + return(pthread_sigmask(how, set, oset)); +#endif + if (set != NULL && (how == SIG_BLOCK || how == SIG_SETMASK)) { fudged_set = *set; sigdelset(&fudged_set, SIG_SUSPEND); @@ -468,10 +469,9 @@ struct start_info { void *(*start_routine)(void *); void *arg; word flags; - ptr_t stack; - size_t stack_size; - sem_t registered; /* 1 ==> in our thread table, but */ - /* parent hasn't yet noticed. */ + pthread_mutex_t registeredlock; + pthread_cond_t registered; + int volatile registereddone; }; void GC_thread_exit_proc(void *arg) @@ -480,10 +480,10 @@ void GC_thread_exit_proc(void *arg) LOCK(); me = GC_lookup_thread(pthread_self()); + me -> flags |= FINISHED; + /* reclaim DETACHED thread right away; otherwise wait until join() */ if (me -> flags & DETACHED) { - GC_delete_thread(pthread_self()); - } else { - me -> flags |= FINISHED; + GC_delete_gc_thread(pthread_self(), me); } UNLOCK(); } @@ -498,42 +498,22 @@ int GC_pthread_join(pthread_t thread, void **retval) /* This is guaranteed to be the intended one, since the thread id */ /* cant have been recycled by pthreads. */ UNLOCK(); + GC_ASSERT(!(thread_gc_id->flags & DETACHED)); result = pthread_join(thread, retval); /* Some versions of the Irix pthreads library can erroneously */ /* return EINTR when the call succeeds. */ if (EINTR == result) result = 0; - if (result == 0) { - LOCK(); - /* Here the pthread thread id may have been recycled. */ - GC_delete_gc_thread(thread, thread_gc_id); - UNLOCK(); - } - return result; -} - -int GC_pthread_detach(pthread_t thread) -{ - int result; - GC_thread thread_gc_id; - + GC_ASSERT(thread_gc_id->flags & FINISHED); LOCK(); - thread_gc_id = GC_lookup_thread(thread); + /* Here the pthread thread id may have been recycled. */ + GC_delete_gc_thread(thread, thread_gc_id); UNLOCK(); - result = REAL_FUNC(pthread_detach)(thread); - if (result == 0) { - LOCK(); - thread_gc_id -> flags |= DETACHED; - /* Here the pthread thread id may have been recycled. */ - if (thread_gc_id -> flags & FINISHED) { - GC_delete_gc_thread(thread, thread_gc_id); - } - UNLOCK(); - } return result; } void * GC_start_routine(void * arg) { + int dummy; struct start_info * si = arg; void * result; GC_thread me; @@ -556,17 +536,21 @@ void * GC_start_routine(void * arg) /* doesn't try to do a pthread_join before we're registered. */ me = GC_new_thread(my_pthread); me -> flags = si -> flags; - me -> stack = si -> stack; - me -> stack_size = si -> stack_size; - me -> stack_ptr = (ptr_t)si -> stack + si -> stack_size - sizeof(word); + me -> stack_cold = (ptr_t) &dummy; /* this now the 'start of stack' */ + me -> stack_hot = me->stack_cold;/* this field should always be sensible */ UNLOCK(); start = si -> start_routine; start_arg = si -> arg; - sem_post(&(si -> registered)); + + pthread_mutex_lock(&(si->registeredlock)); + si->registereddone = 1; + pthread_cond_signal(&(si->registered)); + pthread_mutex_unlock(&(si->registeredlock)); + /* si went away as soon as we did this unlock */ + pthread_cleanup_push(GC_thread_exit_proc, 0); result = (*start)(start_arg); me -> status = result; - me -> flags |= FINISHED; pthread_cleanup_pop(1); /* This involves acquiring the lock, ensuring that we can't exit */ /* while a collection that thinks we're alive is trying to stop */ @@ -574,8 +558,6 @@ void * GC_start_routine(void * arg) return(result); } -# define copy_attr(pa_ptr, source) *(pa_ptr) = *(source) - int GC_pthread_create(pthread_t *new_thread, const pthread_attr_t *attr, @@ -583,69 +565,54 @@ GC_pthread_create(pthread_t *new_thread, { int result; GC_thread t; - void * stack; - size_t stacksize; - pthread_attr_t new_attr; int detachstate; word my_flags = 0; - struct start_info * si = GC_malloc(sizeof(struct start_info)); - /* This is otherwise saved only in an area mmapped by the thread */ - /* library, which isn't visible to the collector. */ + struct start_info * si; + /* This is otherwise saved only in an area mmapped by the thread */ + /* library, which isn't visible to the collector. */ + LOCK(); + /* GC_INTERNAL_MALLOC implicitly calls GC_init() if required */ + si = (struct start_info *)GC_INTERNAL_MALLOC(sizeof(struct start_info), + NORMAL); + GC_ASSERT(GC_thr_initialized); /* initialized by GC_init() */ + UNLOCK(); if (0 == si) return(ENOMEM); - if (0 != sem_init(&(si -> registered), 0, 0)) { - ABORT("sem_init failed"); - } + pthread_mutex_init(&(si->registeredlock), NULL); + pthread_cond_init(&(si->registered),NULL); + pthread_mutex_lock(&(si->registeredlock)); si -> start_routine = start_routine; si -> arg = arg; - LOCK(); - if (!GC_initialized) GC_init(); - if (NULL == attr) { - stack = 0; - (void) pthread_attr_init(&new_attr); - } else { - copy_attr(&new_attr, attr); - pthread_attr_getstackaddr(&new_attr, &stack); - } - pthread_attr_getstacksize(&new_attr, &stacksize); - pthread_attr_getdetachstate(&new_attr, &detachstate); - if (stacksize < GC_min_stack_sz) ABORT("Stack too small"); - if (0 == stack) { - stack = (void *)GC_stack_alloc(&stacksize); - if (0 == stack) { - UNLOCK(); - return(ENOMEM); - } - pthread_attr_setstackaddr(&new_attr, stack); - } else { - my_flags |= CLIENT_OWNS_STACK; - } + + pthread_attr_getdetachstate(attr, &detachstate); if (PTHREAD_CREATE_DETACHED == detachstate) my_flags |= DETACHED; si -> flags = my_flags; - si -> stack = stack; - si -> stack_size = stacksize; - result = pthread_create(new_thread, &new_attr, GC_start_routine, si); - if (0 == new_thread && !(my_flags & CLIENT_OWNS_STACK)) { - GC_stack_free(stack, stacksize); - } - UNLOCK(); + result = pthread_create(new_thread, attr, GC_start_routine, si); + /* Wait until child has been added to the thread table. */ /* This also ensures that we hold onto si until the child is done */ /* with it. Thus it doesn't matter whether it is otherwise */ /* visible to the collector. */ - while (0 != sem_wait(&(si -> registered))) { - if (errno != EINTR) { - GC_printf1("Sem_wait: errno = %ld\n", (unsigned long) errno); - ABORT("sem_wait failed"); - } - } - sem_destroy(&(si -> registered)); - pthread_attr_destroy(&new_attr); /* Probably unnecessary under Irix */ + + if (0 == result) { + si->registereddone = 0; + while (!si->registereddone) + pthread_cond_wait(&(si->registered), &(si->registeredlock)); + } + pthread_mutex_unlock(&(si->registeredlock)); + + pthread_cond_destroy(&(si->registered)); + pthread_mutex_destroy(&(si->registeredlock)); + LOCK(); + GC_INTERNAL_FREE(si); + UNLOCK(); + return(result); } -VOLATILE GC_bool GC_collecting = 0; - /* A hint that we're in the collector and */ +/* For now we use the pthreads locking primitives on HP/UX */ + +VOLATILE GC_bool GC_collecting = 0; /* A hint that we're in the collector and */ /* holding the allocation lock for an */ /* extended period. */ @@ -654,9 +621,9 @@ VOLATILE GC_bool GC_collecting = 0; #define SLEEP_THRESHOLD 3 -unsigned long GC_allocate_lock = 0; -# define GC_TRY_LOCK() !GC_test_and_set(&GC_allocate_lock,1) -# define GC_LOCK_TAKEN GC_allocate_lock +volatile unsigned int GC_allocate_lock = 0; +#define GC_TRY_LOCK() !GC_test_and_set(&GC_allocate_lock) +#define GC_LOCK_TAKEN GC_allocate_lock void GC_lock() { @@ -716,11 +683,11 @@ yield: } } -# else +# else /* !GC_IRIX_THREADS && !GC_AIX_THREADS */ #ifndef LINT int GC_no_Irix_threads; #endif -# endif /* GC_IRIX_THREADS */ +# endif /* IRIX_THREADS */ diff --git a/boehm-gc/alpha_mach_dep.s b/boehm-gc/alpha_mach_dep.S index 53547307a5d..53547307a5d 100644 --- a/boehm-gc/alpha_mach_dep.s +++ b/boehm-gc/alpha_mach_dep.S diff --git a/boehm-gc/backgraph.c b/boehm-gc/backgraph.c new file mode 100644 index 00000000000..0fe1c8f7d36 --- /dev/null +++ b/boehm-gc/backgraph.c @@ -0,0 +1,448 @@ +/* + * Copyright (c) 2001 by Hewlett-Packard Company. All rights reserved. + * + * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED + * OR IMPLIED. ANY USE IS AT YOUR OWN RISK. + * + * Permission is hereby granted to use or copy this program + * for any purpose, provided the above notices are retained on all copies. + * Permission to modify the code and to distribute modified code is granted, + * provided the above notices are retained, and a notice that the code was + * modified is included with the above copyright notice. + * + */ + +/* + * This implements a full, though not well-tuned, representation of the + * backwards points-to graph. This is used to test for non-GC-robust + * data structures; the code is not used during normal garbage collection. + * + * One restriction is that we drop all back-edges from nodes with very + * high in-degree, and simply add them add them to a list of such + * nodes. They are then treated as permanent roots. Id this by itself + * doesn't introduce a space leak, then such nodes can't contribute to + * a growing space leak. + */ + +#ifdef MAKE_BACK_GRAPH + +#define MAX_IN 10 /* Maximum in-degree we handle directly */ + +#include "private/dbg_mlc.h" +#include <unistd.h> + +#if !defined(DBG_HDRS_ALL) || (ALIGNMENT != CPP_WORDSZ/8) || !defined(UNIX_LIKE) +# error Configuration doesnt support MAKE_BACK_GRAPH +#endif + +/* We store single back pointers directly in the object's oh_bg_ptr field. */ +/* If there is more than one ptr to an object, we store q | FLAG_MANY, */ +/* where q is a pointer to a back_edges object. */ +/* Every once in a while we use a back_edges object even for a single */ +/* pointer, since we need the other fields in the back_edges structure to */ +/* be present in some fraction of the objects. Otherwise we get serious */ +/* performance issues. */ +#define FLAG_MANY 2 + +typedef struct back_edges_struct { + word n_edges; /* Number of edges, including those in continuation */ + /* structures. */ + unsigned short flags; +# define RETAIN 1 /* Directly points to a reachable object; */ + /* retain for next GC. */ + unsigned short height_gc_no; + /* If height > 0, then the GC_gc_no value when it */ + /* was computed. If it was computed this cycle, then */ + /* it is current. If it was computed during the */ + /* last cycle, then it represents the old height, */ + /* which is only saved for live objects referenced by */ + /* dead ones. This may grow due to refs from newly */ + /* dead objects. */ + signed_word height; + /* Longest path through unreachable nodes to this node */ + /* that we found using depth first search. */ + +# define HEIGHT_UNKNOWN ((signed_word)(-2)) +# define HEIGHT_IN_PROGRESS ((signed_word)(-1)) + ptr_t edges[MAX_IN]; + struct back_edges_struct *cont; + /* Pointer to continuation structure; we use only the */ + /* edges field in the continuation. */ + /* also used as free list link. */ +} back_edges; + +/* Allocate a new back edge structure. Should be more sophisticated */ +/* if this were production code. */ +#define MAX_BACK_EDGE_STRUCTS 100000 +static back_edges *back_edge_space = 0; +int GC_n_back_edge_structs = 0; /* Serves as pointer to never used */ + /* back_edges space. */ +static back_edges *avail_back_edges = 0; + /* Pointer to free list of deallocated */ + /* back_edges structures. */ + +static back_edges * new_back_edges(void) +{ + if (0 == back_edge_space) { + back_edge_space = (back_edges *) + sbrk(MAX_BACK_EDGE_STRUCTS*sizeof(back_edges)); + } + if (0 != avail_back_edges) { + back_edges * result = avail_back_edges; + avail_back_edges = result -> cont; + result -> cont = 0; + return result; + } + if (GC_n_back_edge_structs >= MAX_BACK_EDGE_STRUCTS - 1) { + ABORT("needed too much space for back edges: adjust " + "MAX_BACK_EDGE_STRUCTS"); + } + return back_edge_space + (GC_n_back_edge_structs++); +} + +/* Deallocate p and its associated continuation structures. */ +static void deallocate_back_edges(back_edges *p) +{ + back_edges *last = p; + + while (0 != last -> cont) last = last -> cont; + last -> cont = avail_back_edges; + avail_back_edges = p; +} + +/* Table of objects that are currently on the depth-first search */ +/* stack. Only objects with in-degree one are in this table. */ +/* Other objects are identified using HEIGHT_IN_PROGRESS. */ +/* This data structure NEEDS IMPROVEMENT. */ +#define MAX_IN_PROGRESS 10000 +static ptr_t * in_progress_space = 0; +static int n_in_progress = 0; + +static void push_in_progress(ptr_t p) +{ + if (in_progress_space == 0) + in_progress_space = sbrk(MAX_IN_PROGRESS * sizeof(ptr_t)); + if (n_in_progress == MAX_IN_PROGRESS) + ABORT("Exceeded MAX_IN_PROGRESS"); + in_progress_space[n_in_progress++] = p; +} + +static GC_bool is_in_progress(ptr_t p) +{ + int i; + for (i = 0; i < n_in_progress; ++i) { + if (in_progress_space[i] == p) return TRUE; + } + return FALSE; +} + +static void pop_in_progress(ptr_t p) +{ + --n_in_progress; + GC_ASSERT(in_progress_space[n_in_progress] == p); +} + +#define GET_OH_BG_PTR(p) \ + (ptr_t)REVEAL_POINTER(((oh *)(p)) -> oh_bg_ptr) +#define SET_OH_BG_PTR(p,q) (((oh *)(p)) -> oh_bg_ptr) = HIDE_POINTER(q) + +/* Execute s once for each predecessor q of p in the points-to graph. */ +/* s should be a bracketed statement. We declare q. */ +#define FOR_EACH_PRED(q, p, s) \ + { \ + ptr_t q = GET_OH_BG_PTR(p); \ + if (!((word)q & FLAG_MANY)) { \ + if (q && !((word)q & 1)) s \ + /* !((word)q & 1) checks for a misnterpreted freelist link */ \ + } else { \ + back_edges *orig_be_ = (back_edges *)((word)q & ~FLAG_MANY); \ + back_edges *be_ = orig_be_; \ + int total_, local_; \ + int n_edges_ = be_ -> n_edges; \ + for (total_ = 0, local_ = 0; total_ < n_edges_; ++local_, ++total_) { \ + if (local_ == MAX_IN) { \ + be_ = be_ -> cont; \ + local_ = 0; \ + } \ + q = be_ -> edges[local_]; s \ + } \ + } \ + } + +/* Ensure that p has a back_edges structure associated with it. */ +static void ensure_struct(ptr_t p) +{ + ptr_t old_back_ptr = GET_OH_BG_PTR(p); + + if (!((word)old_back_ptr & FLAG_MANY)) { + back_edges *be = new_back_edges(); + be -> flags = 0; + if (0 == old_back_ptr) { + be -> n_edges = 0; + } else { + be -> n_edges = 1; + be -> edges[0] = old_back_ptr; + } + be -> height = HEIGHT_UNKNOWN; + be -> height_gc_no = GC_gc_no - 1; + GC_ASSERT(be >= back_edge_space); + SET_OH_BG_PTR(p, (word)be | FLAG_MANY); + } +} + +/* Add the (forward) edge from p to q to the backward graph. Both p */ +/* q are pointers to the object base, i.e. pointers to an oh. */ +static void add_edge(ptr_t p, ptr_t q) +{ + ptr_t old_back_ptr = GET_OH_BG_PTR(q); + back_edges * be, *be_cont; + word i; + static unsigned random_number = 13; +# define GOT_LUCKY_NUMBER (((++random_number) & 0x7f) == 0) + /* A not very random number we use to occasionally allocate a */ + /* back_edges structure even for a single backward edge. This */ + /* prevents us from repeatedly tracing back through very long */ + /* chains, since we will have some place to store height and */ + /* in_progress flags along the way. */ + + GC_ASSERT(p == GC_base(p) && q == GC_base(q)); + if (!GC_HAS_DEBUG_INFO(q) || !GC_HAS_DEBUG_INFO(p)) { + /* This is really a misinterpreted free list link, since we saw */ + /* a pointer to a free list. Dont overwrite it! */ + return; + } + if (0 == old_back_ptr) { + SET_OH_BG_PTR(q, p); + if (GOT_LUCKY_NUMBER) ensure_struct(q); + return; + } + /* Check whether it was already in the list of predecessors. */ + FOR_EACH_PRED(pred, q, { if (p == pred) return; }); + ensure_struct(q); + old_back_ptr = GET_OH_BG_PTR(q); + be = (back_edges *)((word)old_back_ptr & ~FLAG_MANY); + for (i = be -> n_edges, be_cont = be; i > MAX_IN; + be_cont = be_cont -> cont, i -= MAX_IN) {} + if (i == MAX_IN) { + be_cont -> cont = new_back_edges(); + be_cont = be_cont -> cont; + i = 0; + } + be_cont -> edges[i] = p; + be -> n_edges++; + if (be -> n_edges == 100) { +# if 0 + if (GC_print_stats) { + GC_err_printf0("The following object has in-degree >= 100:\n"); + GC_print_heap_obj(q); + } +# endif + } +} + +typedef void (*per_object_func)(ptr_t p, word n_words, word gc_descr); + +static void per_object_helper(struct hblk *h, word fn) +{ + hdr * hhdr = HDR(h); + word sz = hhdr -> hb_sz; + word descr = hhdr -> hb_descr; + per_object_func f = (per_object_func)fn; + int i = 0; + + do { + f((ptr_t)(h -> hb_body + i), sz, descr); + i += sz; + } while (i + sz <= BYTES_TO_WORDS(HBLKSIZE)); +} + +void GC_apply_to_each_object(per_object_func f) +{ + GC_apply_to_all_blocks(per_object_helper, (word)f); +} + +static void reset_back_edge(ptr_t p, word n_words, word gc_descr) +{ + /* Skip any free list links, or dropped blocks */ + if (GC_HAS_DEBUG_INFO(p)) { + ptr_t old_back_ptr = GET_OH_BG_PTR(p); + if ((word)old_back_ptr & FLAG_MANY) { + back_edges *be = (back_edges *)((word)old_back_ptr & ~FLAG_MANY); + if (!(be -> flags & RETAIN)) { + deallocate_back_edges(be); + SET_OH_BG_PTR(p, 0); + } else { + word *currentp; + + GC_ASSERT(GC_is_marked(p)); + + /* Back edges may point to objects that will not be retained. */ + /* Delete them for now, but remember the height. */ + /* Some will be added back at next GC. */ + be -> n_edges = 0; + if (0 != be -> cont) { + deallocate_back_edges(be -> cont); + be -> cont = 0; + } + + GC_ASSERT(GC_is_marked(p)); + + /* We only retain things for one GC cycle at a time. */ + be -> flags &= ~RETAIN; + } + } else /* Simple back pointer */ { + /* Clear to avoid dangling pointer. */ + SET_OH_BG_PTR(p, 0); + } + } +} + +static void add_back_edges(ptr_t p, word n_words, word gc_descr) +{ + word *currentp = (word *)(p + sizeof(oh)); + + /* For now, fix up non-length descriptors conservatively. */ + if((gc_descr & GC_DS_TAGS) != GC_DS_LENGTH) { + gc_descr = WORDS_TO_BYTES(n_words); + } + while (currentp < (word *)(p + gc_descr)) { + word current = *currentp++; + FIXUP_POINTER(current); + if (current >= (word)GC_least_plausible_heap_addr && + current <= (word)GC_greatest_plausible_heap_addr) { + ptr_t target = GC_base((GC_PTR)current); + if (0 != target) { + add_edge(p, target); + } + } + } +} + +/* Rebuild the reprentation of the backward reachability graph. */ +/* Does not examine mark bits. Can be called before GC. */ +void GC_build_back_graph(void) +{ + GC_apply_to_each_object(add_back_edges); +} + +/* Return an approximation to the length of the longest simple path */ +/* through unreachable objects to p. We refer to this as the height */ +/* of p. */ +static word backwards_height(ptr_t p) +{ + word result; + ptr_t back_ptr = GET_OH_BG_PTR(p); + back_edges *be; + + if (0 == back_ptr) return 1; + if (!((word)back_ptr & FLAG_MANY)) { + if (is_in_progress(p)) return 0; /* DFS back edge, i.e. we followed */ + /* an edge to an object already */ + /* on our stack: ignore */ + push_in_progress(p); + result = backwards_height(back_ptr)+1; + pop_in_progress(p); + return result; + } + be = (back_edges *)((word)back_ptr & ~FLAG_MANY); + if (be -> height >= 0 && be -> height_gc_no == GC_gc_no) + return be -> height; + /* Ignore back edges in DFS */ + if (be -> height == HEIGHT_IN_PROGRESS) return 0; + result = (be -> height > 0? be -> height : 1); + be -> height = HEIGHT_IN_PROGRESS; + FOR_EACH_PRED(q, p, { + word this_height; + if (GC_is_marked(q) && !(FLAG_MANY & (word)GET_OH_BG_PTR(p))) { + if (GC_print_stats) + GC_printf2("Found bogus pointer from 0x%lx to 0x%lx\n", q, p); + /* Reachable object "points to" unreachable one. */ + /* Could be caused by our lax treatment of GC descriptors. */ + this_height = 1; + } else { + this_height = backwards_height(q); + } + if (this_height >= result) result = this_height + 1; + }); + be -> height = result; + be -> height_gc_no = GC_gc_no; + return result; +} + +word GC_max_height; +ptr_t GC_deepest_obj; + +/* Compute the maximum height of every unreachable predecessor p of a */ +/* reachable object. Arrange to save the heights of all such objects p */ +/* so that they can be used in calculating the height of objects in the */ +/* next GC. */ +/* Set GC_max_height to be the maximum height we encounter, and */ +/* GC_deepest_obj to be the corresponding object. */ +static void update_max_height(ptr_t p, word n_words, word gc_descr) +{ + if (GC_is_marked(p) && GC_HAS_DEBUG_INFO(p)) { + int i; + word p_height = 0; + ptr_t p_deepest_obj = 0; + ptr_t back_ptr; + back_edges *be = 0; + + /* If we remembered a height last time, use it as a minimum. */ + /* It may have increased due to newly unreachable chains pointing */ + /* to p, but it can't have decreased. */ + back_ptr = GET_OH_BG_PTR(p); + if (0 != back_ptr && ((word)back_ptr & FLAG_MANY)) { + be = (back_edges *)((word)back_ptr & ~FLAG_MANY); + if (be -> height != HEIGHT_UNKNOWN) p_height = be -> height; + } + FOR_EACH_PRED(q, p, { + if (!GC_is_marked(q) && GC_HAS_DEBUG_INFO(q)) { + word q_height; + + q_height = backwards_height(q); + if (q_height > p_height) { + p_height = q_height; + p_deepest_obj = q; + } + } + }); + if (p_height > 0) { + /* Remember the height for next time. */ + if (be == 0) { + ensure_struct(p); + back_ptr = GET_OH_BG_PTR(p); + be = (back_edges *)((word)back_ptr & ~FLAG_MANY); + } + be -> flags |= RETAIN; + be -> height = p_height; + be -> height_gc_no = GC_gc_no; + } + if (p_height > GC_max_height) { + GC_max_height = p_height; + GC_deepest_obj = p_deepest_obj; + } + } +} + +void GC_traverse_back_graph(void) +{ + static word max_max_height = 0; + GC_max_height = 0; + GC_apply_to_each_object(update_max_height); + GC_printf2("Maximum backwards height of reachable objects at GC %lu is %ld\n", + (unsigned long) GC_gc_no, GC_max_height); + if (GC_max_height > max_max_height) { + max_max_height = GC_max_height; + GC_printf0("The following unreachable object is last in a longest chain " + "of unreachable objects:\n"); + GC_print_heap_obj(GC_deepest_obj); + } + if (GC_print_stats) { + GC_printf1("Needed max total of %ld back-edge structs\n", + GC_n_back_edge_structs); + } + GC_apply_to_each_object(reset_back_edge); + GC_deepest_obj = 0; +} + +#endif /* MAKE_BACK_GRAPH */ diff --git a/boehm-gc/darwin_stop_world.c b/boehm-gc/darwin_stop_world.c new file mode 100644 index 00000000000..bc2247fa4e7 --- /dev/null +++ b/boehm-gc/darwin_stop_world.c @@ -0,0 +1,209 @@ +#include "private/pthread_support.h" + +# if defined(GC_DARWIN_THREADS) + +#define DEBUG_THREADS 0 + +/* From "Inside Mac OS X - Mach-O Runtime Architecture" published by Apple + Page 49: + "The space beneath the stack pointer, where a new stack frame would normally + be allocated, is called the red zone. This area as shown in Figure 3-2 may + be used for any purpose as long as a new stack frame does not need to be + added to the stack." + + Page 50: "If a leaf procedure's red zone usage would exceed 224 bytes, then + it must set up a stack frame just like routines that call other routines." +*/ +#define PPC_RED_ZONE_SIZE 224 + +void GC_push_all_stacks() { + int i; + kern_return_t r; + GC_thread p; + pthread_t me; + ptr_t lo, hi; +# if defined(POWERPC) + ppc_thread_state_t state; +# else +# error FIXME for non-ppc OS X +# endif + mach_msg_type_number_t thread_state_count = MACHINE_THREAD_STATE_COUNT; + + me = pthread_self(); + if (!GC_thr_initialized) GC_thr_init(); + + for(i=0;i<THREAD_TABLE_SZ;i++) { + for(p=GC_threads[i];p!=0;p=p->next) { + if(p -> flags & FINISHED) continue; + if(pthread_equal(p->id,me)) { + lo = GC_approx_sp(); + } else { + /* Get the thread state (registers, etc) */ + r = thread_get_state( + p->stop_info.mach_thread, + MACHINE_THREAD_STATE, + (natural_t*)&state, + &thread_state_count); + if(r != KERN_SUCCESS) ABORT("thread_get_state failed"); + + #ifdef POWERPC + lo = (void*)(state.r1 - PPC_RED_ZONE_SIZE); + + GC_push_one(state.r0); + GC_push_one(state.r2); + GC_push_one(state.r3); + GC_push_one(state.r4); + GC_push_one(state.r5); + GC_push_one(state.r6); + GC_push_one(state.r7); + GC_push_one(state.r8); + GC_push_one(state.r9); + GC_push_one(state.r10); + GC_push_one(state.r11); + GC_push_one(state.r12); + GC_push_one(state.r13); + GC_push_one(state.r14); + GC_push_one(state.r15); + GC_push_one(state.r16); + GC_push_one(state.r17); + GC_push_one(state.r18); + GC_push_one(state.r19); + GC_push_one(state.r20); + GC_push_one(state.r21); + GC_push_one(state.r22); + GC_push_one(state.r23); + GC_push_one(state.r24); + GC_push_one(state.r25); + GC_push_one(state.r26); + GC_push_one(state.r27); + GC_push_one(state.r28); + GC_push_one(state.r29); + GC_push_one(state.r30); + GC_push_one(state.r31); + #else + # error FIXME for non-PPC darwin + #endif /* !POWERPC */ + } /* p != me */ + if(p->flags & MAIN_THREAD) + hi = GC_stackbottom; + else + hi = p->stack_end; + #if DEBUG_THREADS + GC_printf3("Darwin: Stack for thread 0x%lx = [%lx,%lx)\n", + (unsigned long) p -> id, + (unsigned long) lo, + (unsigned long) hi + ); + #endif + GC_push_all_stack(lo,hi); + } /* for(p=GC_threads[i]...) */ + } /* for(i=0;i<THREAD_TABLE_SZ...) */ +} + +/* Caller holds allocation lock. */ +void GC_stop_world() +{ + int i; + GC_thread p; + pthread_t my_thread = pthread_self(); + kern_return_t kern_result; + + #if DEBUG_THREADS + GC_printf1("Stopping the world from 0x%lx\n", pthread_self()); + #endif + + /* Make sure all free list construction has stopped before we start. */ + /* No new construction can start, since free list construction is */ + /* required to acquire and release the GC lock before it starts, */ + /* and we have the lock. */ +# ifdef PARALLEL_MARK + GC_acquire_mark_lock(); + GC_ASSERT(GC_fl_builder_count == 0); + /* We should have previously waited for it to become zero. */ +# endif /* PARALLEL_MARK */ + + for (i = 0; i < THREAD_TABLE_SZ; i++) { + for (p = GC_threads[i]; p != 0; p = p -> next) { + if (p -> id == my_thread) continue; + if (p -> flags & FINISHED) continue; + if (p -> thread_blocked) /* Will wait */ continue; + + #if DEBUG_THREADS + GC_printf1("Suspending thread 0x%lx\n", p -> id); + #endif + + /* Suspend the thread */ + kern_result = thread_suspend(p->stop_info.mach_thread); + if(kern_result != KERN_SUCCESS) ABORT("thread_suspend failed"); + + /* This is only needed if we are modifying the threads + state. thread_abort_safely should also be used + if this code is ever added in again. + + kern_result = thread_abort(p->stop_info.mach_thread); + if(kern_result != KERN_SUCCESS) + ABORT("thread_abort failed (%ul)",kern_result); + */ + } + } + +# ifdef MPROTECT_VDB + if(GC_incremental) { + extern void GC_mprotect_stop(); + GC_mprotect_stop(); + } +# endif + +# ifdef PARALLEL_MARK + GC_release_mark_lock(); +# endif + #if DEBUG_THREADS + GC_printf1("World stopped from 0x%lx\n", pthread_self()); + #endif +} + +/* Caller holds allocation lock, and has held it continuously since */ +/* the world stopped. */ +void GC_start_world() +{ + pthread_t my_thread = pthread_self(); + int i; + GC_thread p; + kern_return_t kern_result; + +# if DEBUG_THREADS + GC_printf0("World starting\n"); +# endif + +# ifdef MPROTECT_VDB + if(GC_incremental) { + extern void GC_mprotect_resume(); + GC_mprotect_resume(); + } +# endif + + for (i = 0; i < THREAD_TABLE_SZ; i++) { + for (p = GC_threads[i]; p != 0; p = p -> next) { + if (p -> id == my_thread) continue; + if (p -> flags & FINISHED) continue; + if (p -> thread_blocked) continue; + + #if DEBUG_THREADS + GC_printf1("Resuming 0x%lx\n", p -> id); + #endif + + /* Resume the thread */ + kern_result = thread_resume(p->stop_info.mach_thread); + if(kern_result != KERN_SUCCESS) ABORT("thread_resume failed"); + } + } + #if DEBUG_THREADS + GC_printf0("World started\n"); + #endif +} + +void GC_stop_init() { + +} + +#endif diff --git a/boehm-gc/depcomp b/boehm-gc/depcomp new file mode 100755 index 00000000000..3480ce4e96d --- /dev/null +++ b/boehm-gc/depcomp @@ -0,0 +1,436 @@ +#! /bin/sh + +# depcomp - compile a program generating dependencies as side-effects +# Copyright 1999, 2000 Free Software Foundation, Inc. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +# Originally written by Alexandre Oliva <oliva@dcc.unicamp.br>. + +if test -z "$depmode" || test -z "$source" || test -z "$object"; then + echo "depcomp: Variables source, object and depmode must be set" 1>&2 + exit 1 +fi +# `libtool' can also be set to `yes' or `no'. + +if test -z "$depfile"; then + base=`echo "$object" | sed -e 's,^.*/,,' -e 's,\.\([^.]*\)$,.P\1,'` + dir=`echo "$object" | sed 's,/.*$,/,'` + if test "$dir" = "$object"; then + dir= + fi + # FIXME: should be _deps on DOS. + depfile="$dir.deps/$base" +fi + +tmpdepfile=${tmpdepfile-`echo "$depfile" | sed 's/\.\([^.]*\)$/.T\1/'`} + +rm -f "$tmpdepfile" + +# Some modes work just like other modes, but use different flags. We +# parameterize here, but still list the modes in the big case below, +# to make depend.m4 easier to write. Note that we *cannot* use a case +# here, because this file can only contain one case statement. +if test "$depmode" = hp; then + # HP compiler uses -M and no extra arg. + gccflag=-M + depmode=gcc +fi + +if test "$depmode" = dashXmstdout; then + # This is just like dashmstdout with a different argument. + dashmflag=-xM + depmode=dashmstdout +fi + +case "$depmode" in +gcc3) +## gcc 3 implements dependency tracking that does exactly what +## we want. Yay! Note: for some reason libtool 1.4 doesn't like +## it if -MD -MP comes after the -MF stuff. Hmm. + "$@" -MT "$object" -MD -MP -MF "$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + mv "$tmpdepfile" "$depfile" + ;; + +gcc) +## There are various ways to get dependency output from gcc. Here's +## why we pick this rather obscure method: +## - Don't want to use -MD because we'd like the dependencies to end +## up in a subdir. Having to rename by hand is ugly. +## (We might end up doing this anyway to support other compilers.) +## - The DEPENDENCIES_OUTPUT environment variable makes gcc act like +## -MM, not -M (despite what the docs say). +## - Using -M directly means running the compiler twice (even worse +## than renaming). + if test -z "$gccflag"; then + gccflag=-MD, + fi + "$@" -Wp,"$gccflag$tmpdepfile" + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + alpha=ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz +## The second -e expression handles DOS-style file names with drive letters. + sed -e 's/^[^:]*: / /' \ + -e 's/^['$alpha']:\/[^:]*: / /' < "$tmpdepfile" >> "$depfile" +## This next piece of magic avoids the `deleted header file' problem. +## The problem is that when a header file which appears in a .P file +## is deleted, the dependency causes make to die (because there is +## typically no way to rebuild the header). We avoid this by adding +## dummy dependencies for each header file. Too bad gcc doesn't do +## this for us directly. + tr ' ' ' +' < "$tmpdepfile" | +## Some versions of gcc put a space before the `:'. On the theory +## that the space means something, we add a space to the output as +## well. +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +hp) + # This case exists only to let depend.m4 do its work. It works by + # looking at the text of this script. This case will never be run, + # since it is checked for above. + exit 1 + ;; + +sgi) + if test "$libtool" = yes; then + "$@" "-Wp,-MDupdate,$tmpdepfile" + else + "$@" -MDupdate "$tmpdepfile" + fi + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + rm -f "$depfile" + + if test -f "$tmpdepfile"; then # yes, the sourcefile depend on other files + echo "$object : \\" > "$depfile" + + # Clip off the initial element (the dependent). Don't try to be + # clever and replace this with sed code, as IRIX sed won't handle + # lines with more than a fixed number of characters (4096 in + # IRIX 6.2 sed, 8192 in IRIX 6.5). We also remove comment lines; + # the IRIX cc adds comments like `#:fec' to the end of the + # dependency line. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' | \ + tr ' +' ' ' >> $depfile + echo >> $depfile + + # The second pass generates a dummy entry for each header file. + tr ' ' ' +' < "$tmpdepfile" \ + | sed -e 's/^.*\.o://' -e 's/#.*$//' -e '/^$/ d' -e 's/$/:/' \ + >> $depfile + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +aix) + # The C for AIX Compiler uses -M and outputs the dependencies + # in a .u file. This file always lives in the current directory. + # Also, the AIX compiler puts `$object:' at the start of each line; + # $object doesn't have directory information. + stripped=`echo "$object" | sed -e 's,^.*/,,' -e 's/\(.*\)\..*$/\1/'` + tmpdepfile="$stripped.u" + outname="$stripped.o" + if test "$libtool" = yes; then + "$@" -Wc,-M + else + "$@" -M + fi + + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile" + exit $stat + fi + + if test -f "$tmpdepfile"; then + # Each line is of the form `foo.o: dependent.h'. + # Do two passes, one to just change these to + # `$object: dependent.h' and one to simply `dependent.h:'. + sed -e "s,^$outname:,$object :," < "$tmpdepfile" > "$depfile" + sed -e "s,^$outname: \(.*\)$,\1:," < "$tmpdepfile" >> "$depfile" + else + # The sourcefile does not contain any dependencies, so just + # store a dummy comment line, to avoid errors with the Makefile + # "include basename.Plo" scheme. + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +tru64) + # The Tru64 compiler uses -MD to generate dependencies as a side + # effect. `cc -MD -o foo.o ...' puts the dependencies into `foo.o.d'. + # At least on Alpha/Redhat 6.1, Compaq CCC V6.2-504 seems to put + # dependencies in `foo.d' instead, so we check for that too. + # Subdirectories are respected. + + base=`echo "$object" | sed -e 's/\.o$//' -e 's/\.lo$//'` + tmpdepfile1="$base.o.d" + tmpdepfile2="$base.d" + if test "$libtool" = yes; then + "$@" -Wc,-MD + else + "$@" -MD + fi + + stat=$? + if test $stat -eq 0; then : + else + rm -f "$tmpdepfile1" "$tmpdepfile2" + exit $stat + fi + + if test -f "$tmpdepfile1"; then + tmpdepfile="$tmpdepfile1" + else + tmpdepfile="$tmpdepfile2" + fi + if test -f "$tmpdepfile"; then + sed -e "s,^.*\.[a-z]*:,$object:," < "$tmpdepfile" > "$depfile" + # That's a space and a tab in the []. + sed -e 's,^.*\.[a-z]*:[ ]*,,' -e 's,$,:,' < "$tmpdepfile" >> "$depfile" + else + echo "#dummy" > "$depfile" + fi + rm -f "$tmpdepfile" + ;; + +#nosideeffect) + # This comment above is used by automake to tell side-effect + # dependency tracking mechanisms from slower ones. + +dashmstdout) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o, + # because we must use -o when running libtool. + test -z "$dashmflag" && dashmflag=-M + ( IFS=" " + case " $* " in + *" --mode=compile "*) # this is libtool, let us make it quiet + for arg + do # cycle over the arguments + case "$arg" in + "--mode=compile") + # insert --quiet before "--mode=compile" + set fnord "$@" --quiet + shift # fnord + ;; + esac + set fnord "$@" "$arg" + shift # fnord + shift # "$arg" + done + ;; + esac + "$@" $dashmflag | sed 's:^[^:]*\:[ ]*:'"$object"'\: :' > "$tmpdepfile" + ) & + proc=$! + "$@" + stat=$? + wait "$proc" + if test "$stat" != 0; then exit $stat; fi + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + tr ' ' ' +' < "$tmpdepfile" | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +dashXmstdout) + # This case only exists to satisfy depend.m4. It is never actually + # run, as this mode is specially recognized in the preamble. + exit 1 + ;; + +makedepend) + # X makedepend + ( + shift + cleared=no + for arg in "$@"; do + case $cleared in no) + set ""; shift + cleared=yes + esac + case "$arg" in + -D*|-I*) + set fnord "$@" "$arg"; shift;; + -*) + ;; + *) + set fnord "$@" "$arg"; shift;; + esac + done + obj_suffix="`echo $object | sed 's/^.*\././'`" + touch "$tmpdepfile" + ${MAKEDEPEND-makedepend} 2>/dev/null -o"$obj_suffix" -f"$tmpdepfile" "$@" + ) & + proc=$! + "$@" + stat=$? + wait "$proc" + if test "$stat" != 0; then exit $stat; fi + rm -f "$depfile" + cat < "$tmpdepfile" > "$depfile" + sed '1,2d' "$tmpdepfile" | tr ' ' ' +' | \ +## Some versions of the HPUX 10.20 sed can't process this invocation +## correctly. Breaking it into two sed invocations is a workaround. + sed -e 's/^\\$//' -e '/^$/d' -e '/:$/d' | sed -e 's/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" "$tmpdepfile".bak + ;; + +cpp) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o, + # because we must use -o when running libtool. + ( IFS=" " + case " $* " in + *" --mode=compile "*) + for arg + do # cycle over the arguments + case $arg in + "--mode=compile") + # insert --quiet before "--mode=compile" + set fnord "$@" --quiet + shift # fnord + ;; + esac + set fnord "$@" "$arg" + shift # fnord + shift # "$arg" + done + ;; + esac + "$@" -E | + sed -n '/^# [0-9][0-9]* "\([^"]*\)".*/ s:: \1 \\:p' | + sed '$ s: \\$::' > "$tmpdepfile" + ) & + proc=$! + "$@" + stat=$? + wait "$proc" + if test "$stat" != 0; then exit $stat; fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + cat < "$tmpdepfile" >> "$depfile" + sed < "$tmpdepfile" '/^$/d;s/^ //;s/ \\$//;s/$/ :/' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +msvisualcpp) + # Important note: in order to support this mode, a compiler *must* + # always write the proprocessed file to stdout, regardless of -o, + # because we must use -o when running libtool. + ( IFS=" " + case " $* " in + *" --mode=compile "*) + for arg + do # cycle over the arguments + case $arg in + "--mode=compile") + # insert --quiet before "--mode=compile" + set fnord "$@" --quiet + shift # fnord + ;; + esac + set fnord "$@" "$arg" + shift # fnord + shift # "$arg" + done + ;; + esac + for arg + do + case "$arg" in + "-Gm"|"/Gm"|"-Gi"|"/Gi"|"-ZI"|"/ZI") + set fnord "$@" + shift + shift + ;; + *) + set fnord "$@" "$arg" + shift + shift + ;; + esac + done + "$@" -E | + sed -n '/^#line [0-9][0-9]* "\([^"]*\)"/ s::echo "`cygpath -u \\"\1\\"`":p' | sort | uniq > "$tmpdepfile" + ) & + proc=$! + "$@" + stat=$? + wait "$proc" + if test "$stat" != 0; then exit $stat; fi + rm -f "$depfile" + echo "$object : \\" > "$depfile" + . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s:: \1 \\:p' >> "$depfile" + echo " " >> "$depfile" + . "$tmpdepfile" | sed 's% %\\ %g' | sed -n '/^\(.*\)$/ s::\1\::p' >> "$depfile" + rm -f "$tmpdepfile" + ;; + +none) + exec "$@" + ;; + +*) + echo "Unknown depmode $depmode" 1>&2 + exit 1 + ;; +esac + +exit 0 diff --git a/boehm-gc/doc/Makefile.am b/boehm-gc/doc/Makefile.am new file mode 100644 index 00000000000..91446305581 --- /dev/null +++ b/boehm-gc/doc/Makefile.am @@ -0,0 +1,27 @@ +# +# +# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED +# OR IMPLIED. ANY USE IS AT YOUR OWN RISK. +# +# Permission is hereby granted to use or copy this program +# for any purpose, provided the above notices are retained on all copies. +# Permission to modify the code and to distribute modified code is granted, +# provided the above notices are retained, and a notice that the code was +# modified is included with the above copyright notice. +# +# Modified by: Grzegorz Jakacki <jakacki at acm dot org> + +## Process this file with automake to produce Makefile.in. + +# installed documentation +# +dist_pkgdata_DATA = barrett_diagram debugging.html gc.man \ + gcdescr.html README README.amiga README.arm.cross \ + README.autoconf README.changes README.contributors \ + README.cords README.DGUX386 README.dj README.environment \ + README.ews4800 README.hp README.linux README.Mac \ + README.MacOSX README.macros README.OS2 README.rs6000 \ + README.sgi README.solaris2 README.uts README.win32 \ + tree.html leak.html gcinterface.html scale.html \ + README.darwin + diff --git a/boehm-gc/doc/Makefile.in b/boehm-gc/doc/Makefile.in new file mode 100644 index 00000000000..9bf1ff5fead --- /dev/null +++ b/boehm-gc/doc/Makefile.in @@ -0,0 +1,282 @@ +# Makefile.in generated by automake 1.6.3 from Makefile.am. +# @configure_input@ + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 +# Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# +# +# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED +# OR IMPLIED. ANY USE IS AT YOUR OWN RISK. +# +# Permission is hereby granted to use or copy this program +# for any purpose, provided the above notices are retained on all copies. +# Permission to modify the code and to distribute modified code is granted, +# provided the above notices are retained, and a notice that the code was +# modified is included with the above copyright notice. +# +# Modified by: Grzegorz Jakacki <jakacki at acm dot org> +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_HEADER = $(INSTALL_DATA) +transform = @program_transform_name@ +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ + +EXEEXT = @EXEEXT@ +OBJEXT = @OBJEXT@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CFLAGS = @CFLAGS@ +CXX = @CXX@ +CXXFLAGS = @CXXFLAGS@ +CXXINCLUDES = @CXXINCLUDES@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +EXTRA_TEST_LIBS = @EXTRA_TEST_LIBS@ +GC_CFLAGS = @GC_CFLAGS@ +GC_VERSION = @GC_VERSION@ +INCLUDES = @INCLUDES@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAINT = @MAINT@ +MY_CFLAGS = @MY_CFLAGS@ +OBJDUMP = @OBJDUMP@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +STRIP = @STRIP@ +THREADLIBS = @THREADLIBS@ +VERSION = @VERSION@ +addincludes = @addincludes@ +addlibs = @addlibs@ +addobjs = @addobjs@ +addtests = @addtests@ +am__include = @am__include@ +am__quote = @am__quote@ +install_sh = @install_sh@ +target_all = @target_all@ + +# installed documentation +# +dist_pkgdata_DATA = barrett_diagram debugging.html gc.man \ + gcdescr.html README README.amiga README.arm.cross \ + README.autoconf README.changes README.contributors \ + README.cords README.DGUX386 README.dj README.environment \ + README.ews4800 README.hp README.linux README.Mac \ + README.MacOSX README.macros README.OS2 README.rs6000 \ + README.sgi README.solaris2 README.uts README.win32 \ + tree.html leak.html gcinterface.html scale.html \ + README.darwin + +subdir = doc +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_CLEAN_FILES = +DIST_SOURCES = +DATA = $(dist_pkgdata_DATA) + +DIST_COMMON = README $(dist_pkgdata_DATA) Makefile.am Makefile.in +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu doc/Makefile +Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +dist_pkgdataDATA_INSTALL = $(INSTALL_DATA) +install-dist_pkgdataDATA: $(dist_pkgdata_DATA) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(pkgdatadir) + @list='$(dist_pkgdata_DATA)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(dist_pkgdataDATA_INSTALL) $$d$$p $(DESTDIR)$(pkgdatadir)/$$f"; \ + $(dist_pkgdataDATA_INSTALL) $$d$$p $(DESTDIR)$(pkgdatadir)/$$f; \ + done + +uninstall-dist_pkgdataDATA: + @$(NORMAL_UNINSTALL) + @list='$(dist_pkgdata_DATA)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f $(DESTDIR)$(pkgdatadir)/$$f"; \ + rm -f $(DESTDIR)$(pkgdatadir)/$$f; \ + done +tags: TAGS +TAGS: + +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = .. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + @list='$(DISTFILES)'; for file in $$list; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkinstalldirs) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(DATA) + +installdirs: + $(mkinstalldirs) $(DESTDIR)$(pkgdatadir) + +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + +distclean-am: clean-am distclean-generic distclean-libtool + +dvi: dvi-am + +dvi-am: + +info: info-am + +info-am: + +install-data-am: install-dist_pkgdataDATA + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +uninstall-am: uninstall-dist_pkgdataDATA uninstall-info-am + +.PHONY: all all-am check check-am clean clean-generic clean-libtool \ + distclean distclean-generic distclean-libtool distdir dvi \ + dvi-am info info-am install install-am install-data \ + install-data-am install-dist_pkgdataDATA install-exec \ + install-exec-am install-info install-info-am install-man \ + install-strip installcheck installcheck-am installdirs \ + maintainer-clean maintainer-clean-generic mostlyclean \ + mostlyclean-generic mostlyclean-libtool uninstall uninstall-am \ + uninstall-dist_pkgdataDATA uninstall-info-am + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/boehm-gc/doc/README.DGUX386 b/boehm-gc/doc/README.DGUX386 new file mode 100644 index 00000000000..9d6d84788ef --- /dev/null +++ b/boehm-gc/doc/README.DGUX386 @@ -0,0 +1,215 @@ + Garbage Collector (parallel iversion) for ix86 DG/UX Release R4.20MU07 + + + *READ* the file README.QUICK. + + You need the GCC-3.0.3 rev (DG/UX) compiler to build this tree. + This compiler has the new "dgux386" threads package implemented. + It also supports the switch "-pthread" needed to link correctly + the DG/UX's -lrte -lthread with -lgcc and the system's -lc. + Finally we support parralleli-mark for the SMP DG/UX machines. + To build the garbage collector do: + + ./configure --enable-parallel-mark + make + make gctest + + Before you run "gctest" you need to set your LD_LIBRARY_PATH + correctly so that "gctest" can find the shared library libgc. + Alternatively you can do a configuration + + ./configure --enable-parallel-mark --disable-shared + + to build only the static version of libgc. + + To enable debugging messages please do: + 1) Add the "--enable-full-debug" flag during configuration. + 2) Edit the file linux-threads.c and uncommnect the line: + + /* #define DEBUG_THREADS 1 */ to ---> + + #define DEBUG_THREADS 1 + + Then give "make" as usual. + + In a machine with 4 CPUs (my own machine) the option parallel + mark (aka --enable-parallel-mark) makes a BIG difference. + + Takis Psarogiannakopoulos + University of Cambridge + Centre for Mathematical Sciences + Department of Pure Mathematics + Wilberforce Road + Cambridge CB3 0WB ,UK , <takis@XFree86.Org> + January 2002 + + +Note (HB): + The integration of this patch is currently not complete. + The following patches against 6.1alpha3 where hard to move + to alpha4, and are not integrated. There may also be minor + problems with stylistic corrections made by me. + + +--- ltconfig.ORIG Mon Jan 28 20:22:18 2002 ++++ ltconfig Mon Jan 28 20:44:00 2002 +@@ -689,6 +689,11 @@ + pic_flag=-Kconform_pic + fi + ;; ++ dgux*) ++ pic_flag='-fPIC' ++ link_static='-Bstatic' ++ wl='-Wl,' ++ ;; + *) + pic_flag='-fPIC' + ;; +@@ -718,6 +723,12 @@ + # We can build DLLs from non-PIC. + ;; + ++ dgux*) ++ pic_flag='-KPIC' ++ link_static='-Bstatic' ++ wl='-Wl,' ++ ;; ++ + osf3* | osf4* | osf5*) + # All OSF/1 code is PIC. + wl='-Wl,' +@@ -1154,6 +1165,22 @@ + fi + ;; + ++ dgux*) ++ ld_shlibs=yes ++ # For both C/C++ ommit the deplibs. This is because we relying on the fact ++ # that compilation of execitables will put them in correct order ++ # in any case and sometimes are wrong when listed as deplibs (or missing some deplibs) ++ # However when GNU ld and --whole-archive needs to be used we have the problem ++ # that if the -fPIC *_s.a archive is linked through deplibs list we ommiting crucial ++ # .lo/.o files from the created shared lib. This I think is not the case here. ++ archive_cmds='$CC -shared -h $soname -o $lib $libobjs $linkopts' ++ thread_safe_flag_spec='-pthread' ++ wlarc= ++ hardcode_libdir_flag_spec='-L$libdir' ++ hardcode_shlibpath_var=no ++ ac_cv_archive_cmds_needs_lc=no ++ ;; ++ + cygwin* | mingw*) + # hardcode_libdir_flag_spec is actually meaningless, as there is + # no search path for DLLs. +@@ -1497,7 +1524,7 @@ + ;; + + dgux*) +- archive_cmds='$LD -G -h $soname -o $lib $libobjs $deplibs $linkopts' ++ archive_cmds='$CC -shared -h $soname -o $lib $libobjs $linkopts' + hardcode_libdir_flag_spec='-L$libdir' + hardcode_shlibpath_var=no + ;; +@@ -2092,12 +2119,17 @@ + ;; + + dgux*) +- version_type=linux ++ version_type=dgux + need_lib_prefix=no + need_version=no +- library_names_spec='${libname}${release}.so$versuffix ${libname}${release}.so$major $libname.so' +- soname_spec='${libname}${release}.so$major' ++ library_names_spec='$libname.so$versuffix' ++ soname_spec='$libname.so$versuffix' + shlibpath_var=LD_LIBRARY_PATH ++ thread_safe_flag_spec='-pthread' ++ wlarc= ++ hardcode_libdir_flag_spec='-L$libdir' ++ hardcode_shlibpath_var=no ++ ac_cv_archive_cmds_needs_lc=no + ;; + + sysv4*MP*) + + +--- ltmain.sh.ORIG Mon Jan 28 20:31:18 2002 ++++ ltmain.sh Tue Jan 29 00:11:29 2002 +@@ -1072,11 +1072,38 @@ + esac + ;; + ++ -thread*) ++ # DG/UX GCC 2.95.x, 3.x.x rev (DG/UX) links -lthread ++ # with the switch -threads ++ if test "$arg" = "-threads"; then ++ case "$host" in ++ i[3456]86-*-dgux*) ++ deplibs="$deplibs $arg" ++ continue ++ ;; ++ esac ++ fi ++ ;; ++ ++ -pthread*) ++ # DG/UX GCC 2.95.x, 3.x.x rev (DG/UX) links -lthread ++ # with the switch -pthread ++ if test "$arg" = "-pthread"; then ++ case "$host" in ++ i[3456]86-*-dgux*) ++ deplibs="$deplibs $arg" ++ continue ++ ;; ++ esac ++ fi ++ ;; ++ + -l*) + if test "$arg" = "-lc"; then + case "$host" in +- *-*-cygwin* | *-*-mingw* | *-*-os2* | *-*-beos*) ++ *-*-cygwin* | *-*-mingw* | *-*-os2* | *-*-beos* | i[3456]86-*-dgux*) + # These systems don't actually have c library (as such) ++ # It is wrong in DG/UX to add -lc when creating shared/dynamic objs/libs + continue + ;; + esac +@@ -1248,6 +1275,12 @@ + temp_deplibs= + for deplib in $dependency_libs; do + case "$deplib" in ++ -thread*) ++ temp_deplibs="$temp_deplibs $deplib" ++ ;; ++ -pthread) ++ temp_deplibs="$temp_deplibs $deplib" ++ ;; + -R*) temp_xrpath=`$echo "X$deplib" | $Xsed -e 's/^-R//'` + case " $rpath $xrpath " in + *" $temp_xrpath "*) ;; +@@ -1709,6 +1742,13 @@ + done + ;; + ++ dgux) ++ # Leave mostly blank for DG/UX ++ major= ++ versuffix=".$current.$revision"; ++ verstring= ++ ;; ++ + linux) + major=.`expr $current - $age` + versuffix="$major.$age.$revision" +@@ -1792,8 +1832,9 @@ + + dependency_libs="$deplibs" + case "$host" in +- *-*-cygwin* | *-*-mingw* | *-*-os2* | *-*-beos*) ++ *-*-cygwin* | *-*-mingw* | *-*-os2* | *-*-beos* | i[3456]86-*-dgux*) + # these systems don't actually have a c library (as such)! ++ # It is wrong in DG/UX to add -lc when creating shared/dynamic objs/libs + ;; + *) + # Add libc to deplibs on all other systems. diff --git a/boehm-gc/doc/README.arm.cross b/boehm-gc/doc/README.arm.cross new file mode 100644 index 00000000000..96744edaf67 --- /dev/null +++ b/boehm-gc/doc/README.arm.cross @@ -0,0 +1,68 @@ +From: Margaret Fleck + +Here's the key details of what worked for me, in case anyone else needs them. +There may well be better ways to do some of this, but .... + -- Margaret + + +The badge4 has a StrongArm-1110 processor and a StrongArm-1111 coprocessor. + +Assume that the garbage collector distribution is unpacked into /home/arm/gc6.0, +which is visible to both the ARM machine and a linux desktop (e.g. via NFS mounting). + +Assume that you have a file /home/arm/config.site with contents something like the +example attached below. Notice that our local ARM toolchain lives in +/skiff/local. + +Go to /home/arm/gc6.0 directory. Do + CONFIG_SITE=/home/arm/config.site ./configure --target=arm-linux +--prefix=/home/arm/gc6.0 + +On your desktop, do: + make + make install +The main garbage collector library should now be in ../gc6.0/lib/libgc.so. + +To test the garbage collector, first do the following on your desktop + make gctest + ./gctest +Then do the following on the ARM machine + cd .libs + ./lt-gctest + +Do not try to do "make test" (the usual way of running the test +program). This does not work and seems to erase some of the important +files. + +The gctest program claims to have succeeded. Haven't run any further tests +with it, though I'll be doing so in the near future. + +------------------------------- +# config.site for configure + +# Modified from the one provided by Bradley D. LaRonde +# Edited by Andrej Cedilnik <acedil1@csee.umbc.edu> +# Used some of solutions by Tilman Vogel <Tilman.Vogel@web.de> +# Ported for iPAQ Familiar by Oliver Kurth <oliver.kurth@innominate.com> +# Further modified by Margaret Fleck for the badge4 + +HOSTCC=gcc + +# Names of the cross-compilers +CC=/skiff/local/bin/arm-linux-gcc +CXX=/skiff/local/bin/arm-linux-gcc + +# The cross compiler specific options +CFLAGS="-O2 -fno-exceptions" +CXXFLAGS="-O2 -fno-exceptions" +CPPFLAGS="-O2 -fno-exceptions" +LDFLAGS="" + +# Some other programs +AR=/skiff/local/bin/arm-linux-ar +RANLIB=/skiff/local/bin/arm-linux-ranlib +NM=/skiff/local/bin/arm-linux-nm +ac_cv_path_NM=/skiff/local/bin/arm-linux-nm +ac_cv_func_setpgrp_void=yes +x_includes=/skiff/local/arm-linux/include/X11 +x_libraries=/skiff/local/arm-linux/lib/X11 diff --git a/boehm-gc/doc/README.darwin b/boehm-gc/doc/README.darwin new file mode 100644 index 00000000000..3cd1b818b19 --- /dev/null +++ b/boehm-gc/doc/README.darwin @@ -0,0 +1,106 @@ +Darwin/MacOSX Support - July 22, 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. This +call is required even if you code does not use dynamic libraries as the +dyld code handles registering all data segments. + +When your use of the garbage collector is confined to dylibs and you +cannot call GC_init() before your libraries' static initializers have +run and perhaps called GC_malloc(), create an initialization routine +for each library to call GC_init(): + +#include <gc/gc.h> +void my_library_init() { GC_init(); } + +Compile this code into a my_library_init.o, and link it into your +dylib. 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.o +my_library_init.o -init _my_library_init). This causes +my_library_init() to be called before any static initializers, and +will 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 the +garbage collector, to create an initialization routine for each of +them 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 however +these workaround may not work correctly in all cases. There may also +be additional problems that I have not found. + +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 older +Darwin versions (MacOSX 10.1). Shared library support had also been +added and the gc can be run from a shared library. There is currently only +support for Darwin/PPC although adding x86 support should be trivial. + +Thread support is implemented in terms of mach thread_suspend and +thread_resume calls. These provide a very clean interface to thread +suspension. This implementation doesn't rely on pthread_kill so the +code works on Darwin < 6.0 (MacOSX 10.1). All the code to stop the +world is located in darwin_stop_world.c. + +The original incremental collector support unfortunatelly no longer works +on recent Darwin versions. It also relied on some undocumented kernel +structures. Mach, however, does have a very clean interface to exception +handing. 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 Alliet +brian@brianweb.net + + +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 tested +it on MacOS X Server. +I've added a PPC assembly version of GC_push_regs(), thus the setjmp() hack is +no longer necessary. Incremental collection is supported via mprotect/signal. +The current solution isn't really optimal because the signal handler must decode +the 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 away +in 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 library +support 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 2000 + +Dietmar Planitzer +dave.pl@ping.at + +Note from Andrew Begel: + +One more fix to enable gc.a to link successfully into a shared library for +MacOS X. You have to add -fno-common to the CFLAGS in the Makefile. MacOSX +disallows common symbols in anything that eventually finds its way into a +shared library. (I don't completely understand why, but -fno-common seems to +work and doesn't mess up the garbage collector's functionality). + +Feb 26, 2003 + +Jeff Sturm and Jesse Rosenstock provided a patch that adds thread support. +GC_MACOSX_THREADS should be defined in the build and in clients. Real +dynamic library support is still missing, i.e. dynamic library data segments +are still not scanned. Code that stores pointers to the garbage collected +heap in statically allocated variables should not reside in a dynamic +library. This still doesn't appear to be 100% reliable. + +Mar 10, 2003 +Brian Alliet contributed dynamic library support for MacOSX. It could also +use more testing. diff --git a/boehm-gc/doc/README.ews4800 b/boehm-gc/doc/README.ews4800 new file mode 100644 index 00000000000..80bca2b3d95 --- /dev/null +++ b/boehm-gc/doc/README.ews4800 @@ -0,0 +1,81 @@ +GC on EWS4800 +------------- + +1. About EWS4800 + EWS4800 is 32bit/64bit workstation. + + Vender: NEC Corporation + OS: UX/4800 R9.* - R13.* (SystemV R4.2) + CPU: R4000, R4400, R10000 (MIPS) + +2. Compiler + + 32bit: + Use ANSI C compiler. + CC = /usr/abiccs/bin/cc + + 64bit: + Use 64bit ANSI C compiler. + CC = /usr/ccs64/bin/cc + AR = /usr/ccs64/bin/ar + +3. ELF file format + *** Caution: The following infomation is empirical. *** + + 32bit: + ELF file has an unique format. (See a.out(4) and end(3C).) + + &_start + : text segment + &etext + DATASTART + : data segment (initialized) + &edata + DATASTART2 + : data segment (uninitialized) + &end + + Here, DATASTART and DATASTART2 are macros of GC, and are defined as + the following equations. (See include/private/gcconfig.h.) + The algorithm for DATASTART is similar with the function + GC_SysVGetDataStart() in os_dep.c. + + DATASTART = ((&etext + 0x3ffff) & ~0x3ffff) + (&etext & 0xffff) + + Dynamically linked: + DATASTART2 = (&_gp + 0x8000 + 0x3ffff) & ~0x3ffff + + Statically linked: + DATASTART2 = &edata + + GC has to check addresses both between DATASTART and &edata, and + between DATASTART2 and &end. If a program accesses between &etext + and DATASTART, or between &edata and DATASTART2, the segmentation + error occurs and the program stops. + + If a program is statically linked, there is not a gap between + &edata and DATASTART2. The global symbol &_DYNAMIC_LINKING is used + for the detection. + + 64bit: + ELF file has a simple format. (See end(3C).) + + _ftext + : text segment + _etext + _fdata = DATASTART + : data segment (initialized) + _edata + _fbss + : data segment (uninitialized) + _end = DATAEND + +-- +Hironori SAKAMOTO <hsaka@mth.biglobe.ne.jp> + + +When using the new "configure; make" build process, please +run configure with the --disable-shared option. "Make check" does not +yet pass with dynamic libraries. Ther reasons for that are not yet +understood. (HB, paraphrasing message from Hironori SAKAMOTO.) + diff --git a/boehm-gc/doc/gcinterface.html b/boehm-gc/doc/gcinterface.html new file mode 100644 index 00000000000..7b336ec811b --- /dev/null +++ b/boehm-gc/doc/gcinterface.html @@ -0,0 +1,203 @@ +<!DOCTYPE HTML> +<HEAD> +<TITLE>Garbage Collector Interface</TITLE> +</HEAD> +<BODY> +<H1>C Interface</h1> +On many platforms, a single-threaded garbage collector library can be built +to act as a plug-in malloc replacement. (Build with -DREDIRECT_MALLOC=GC_malloc +-DIGNORE_FREE.) This is often the best way to deal with third-party libraries +which leak or prematurely free objects. -DREDIRECT_MALLOC is intended +primarily as an easy way to adapt old code, not for new development. +<P> +New code should use the interface discussed below. +<P> +Code must be linked against the GC library. On most UNIX platforms, +this will be gc.a. +<P> +The following describes the standard C interface to the garbage collector. +It is not a complete definition of the interface. It describes only the +most commonly used functionality, approximately in decreasing order of +frequency of use. The description assumes an ANSI C compiler. +The full interface is described in +<A HREF="http://hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gch.txt">gc.h</a> +or <TT>gc.h</tt> in the distribution. +<P> +Clients should include gc.h. +<P> +In the case of multithreaded code, +gc.h should be included after the threads header file, and +after defining the appropriate GC_XXXX_THREADS macro. +(For 6.2alpha4 and later, simply defining GC_THREADS should suffice.) +Gc.h must be included +in files that use either GC or threads primitives, since threads primitives +will be redefined to cooperate with the GC on many platforms. +<DL> +<DT> <B>void * GC_MALLOC(size_t <I>nbytes</i>)</b> +<DD> +Allocates and clears <I>nbytes</i> of storage. +Requires (amortized) time proportional to <I>nbytes</i>. +The resulting object will be automatically deallocated when unreferenced. +References from objects allocated with the system malloc are usually not +considered by the collector. (See GC_MALLOC_UNCOLLECTABLE, however.) +GC_MALLOC is a macro which invokes GC_malloc by default or, if GC_DEBUG +is defined before gc.h is included, a debugging version that checks +occasionally for overwrite errors, and the like. +<DT> <B>void * GC_MALLOC_ATOMIC(size_t <I>nbytes</i>)</b> +<DD> +Allocates <I>nbytes</i> of storage. +Requires (amortized) time proportional to <I>nbytes</i>. +The resulting object will be automatically deallocated when unreferenced. +The client promises that the resulting object will never contain any pointers. +The memory is not cleared. +This is the preferred way to allocate strings, floating point arrays, +bitmaps, etc. +More precise information about pointer locations can be communicated to the +collector using the interface in +<A HREF="http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc_typedh.txt">gc_typed.h</a> in the distribution. +<DT> <B>void * GC_MALLOC_UNCOLLECTABLE(size_t <I>nbytes</i>)</b> +<DD> +Identical to GC_MALLOC, except that the resulting object is not automatically +deallocated. Unlike the system-provided malloc, the collector does +scan the object for pointers to garbage-collectable memory, even if the +block itself does not appear to be reachable. (Objects allocated in this way +are effectively treated as roots by the collector.) +<DT> <B> void * GC_REALLOC(void *old, size_t new_size) </b> +<DD> +Allocate a new object of the indicated size and copy (a prefix of) the +old object into the new object. The old object is reused in place if +convenient. If the original object was allocated with GC_malloc_atomic, +the new object is subject to the same constraints. If it was allocated +as an uncollectable object, then the new object is uncollectable, and +the old object (if different) is deallocated. +(Use GC_REALLOC with GC_MALLOC, etc.) +<DT> <B> void GC_FREE(void *dead) </b> +<DD> +Explicitly deallocate an object. Typically not useful for small +collectable objects. (Use GC_FREE with GC_MALLOC, etc.) +<DT> <B> void * GC_MALLOC_IGNORE_OFF_PAGE(size_t <I>nbytes</i>) </b> +<DD> +<DT> <B> void * GC_MALLOC_ATOMIC_IGNORE_OFF_PAGE(size_t <I>nbytes</i>) </b> +<DD> +Analogous to GC_MALLOC and GC_MALLOC_ATOMIC, except that the client +guarantees that as long +as the resulting object is of use, a pointer is maintained to someplace +inside the first 512 bytes of the object. This pointer should be declared +volatile to avoid interference from compiler optimizations. +(Other nonvolatile pointers to the object may exist as well.) +This is the +preferred way to allocate objects that are likely to be > 100KBytes in size. +It greatly reduces the risk that such objects will be accidentally retained +when they are no longer needed. Thus space usage may be significantly reduced. +<DT> <B> void GC_gcollect(void) </b> +<DD> +Explicitly force a garbage collection. +<DT> <B> void GC_enable_incremental(void) </b> +<DD> +Cause the garbage collector to perform a small amount of work +every few invocations of GC_malloc or the like, instead of performing +an entire collection at once. This is likely to increase total +running time. It will improve response on a platform that either has +suitable support in the garbage collector (Irix and most other Unix +versions, win32 if the collector was suitably built) or if "stubborn" +allocation is used (see <A HREF="http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gch.txt">gc.h</a>). +On many platforms this interacts poorly with system calls +that write to the garbage collected heap. +<DT> <B> GC_warn_proc GC_set_warn_proc(GC_warn_proc p) </b> +<DD> +Replace the default procedure used by the collector to print warnings. +The collector +may otherwise write to sterr, most commonly because GC_malloc was used +in a situation in which GC_malloc_ignore_off_page would have been more +appropriate. See <A HREF="http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gch.txt">gc.h</a> for details. +<DT> <B> void GC_register_finalizer(...) </b> +<DD> +Register a function to be called when an object becomes inaccessible. +This is often useful as a backup method for releasing system resources +(<I>e.g.</i> closing files) when the object referencing them becomes +inaccessible. +It is not an acceptable method to perform actions that must be performed +in a timely fashion. +See <A HREF="http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gch.txt">gc.h</a> for details of the interface. +See <A HREF="http://www.hpl.hp.com/personal/Hans_Boehm/gc/finalization.html">here</a> for a more detailed discussion +of the design. +<P> +Note that an object may become inaccessible before client code is done +operating on its fields. Suitable synchronization is usually required. +See <A HREF="http://portal.acm.org/citation.cfm?doid=604131.604153">here</a> +or <A HREF="http://www.hpl.hp.com/techreports/2002/HPL-2002-335.html">here</a> +for details. +</dl> +<P> +If you are concerned with multiprocessor performance and scalability, +you should consider enabling and using thread local allocation (<I>e.g.</i> +GC_LOCAL_MALLOC, see <TT>gc_local_alloc.h</tt>. If your platform +supports it, you should build the collector with parallel marking support +(-DPARALLEL_MARK, or --enable-parallel-mark). +<P> +If the collector is used in an environment in which pointer location +information for heap objects is easily available, this can be passed on +to the colllector using the interfaces in either <TT>gc_typed.h</tt> +or <TT>gc_gcj.h</tt>. +<P> +The collector distribution also includes a <B>string package</b> that takes +advantage of the collector. For details see +<A HREF="http://www.hpl.hp.com/personal/Hans_Boehm/gc/gc_source/cordh.txt">cord.h</a> + +<H1>C++ Interface</h1> +There are three distinct ways to use the collector from C++: +<DL> +<DT> <B> STL allocators </b> +<DD> +Users of the <A HREF="http://www.sgi.com/tech/stl">SGI extended STL</a> +can include <TT>new_gc_alloc.h</tt> before including +STL header files. +(<TT>gc_alloc.h</tt> corresponds to now obsolete versions of the +SGI STL.) +This defines SGI-style allocators +<UL> +<LI> alloc +<LI> single_client_alloc +<LI> gc_alloc +<LI> single_client_gc_alloc +</ul> +which may be used either directly to allocate memory or to instantiate +container templates. The first two allocate uncollectable but traced +memory, while the second two allocate collectable memory. +The single_client versions are not safe for concurrent access by +multiple threads, but are faster. +<P> +For an example, click <A HREF="http://hpl.hp.com/personal/Hans_Boehm/gc/gc_alloc_exC.txt">here</a>. +<P> +Recent versions of the collector also include a more standard-conforming +allocator implemention in <TT>gc_allocator.h</tt>. It defines +<UL> +<LI> traceable_allocator +<LI> gc_allocator +</ul> +Again the former allocates uncollectable but traced memory. +This should work with any fully standard-conforming C++ compiler. +<DT> <B> Class inheritance based interface </b> +<DD> +Users may include gc_cpp.h and then cause members of certain classes to +be allocated in garbage collectable memory by inheriting from class gc. +For details see <A HREF="http://hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gc_cpph.txt">gc_cpp.h</a>. +<DT> <B> C interface </b> +<DD> +It is also possible to use the C interface from +<A HREF="http://hpl.hp.com/personal/Hans_Boehm/gc/gc_source/gch.txt">gc.h</a> directly. +On platforms which use malloc to implement ::new, it should usually be possible +to use a version of the collector that has been compiled as a malloc +replacement. It is also possible to replace ::new and other allocation +functions suitably. +<P> +Note that user-implemented small-block allocation often works poorly with +an underlying garbage-collected large block allocator, since the collector +has to view all objects accessible from the user's free list as reachable. +This is likely to cause problems if GC_malloc is used with something like +the original HP version of STL. +This approach works with the SGI versions of the STL only if the +<TT>malloc_alloc</tt> allocator is used. +</dl> +</body> +</html> diff --git a/boehm-gc/doc/leak.html b/boehm-gc/doc/leak.html new file mode 100644 index 00000000000..91fa8ea8402 --- /dev/null +++ b/boehm-gc/doc/leak.html @@ -0,0 +1,197 @@ +<HTML> +<HEAD> +<TITLE>Using the Garbage Collector as Leak Detector</title> +</head> +<BODY> +<H1>Using the Garbage Collector as Leak Detector</h1> +The garbage collector may be used as a leak detector. +In this case, the primary function of the collector is to report +objects that were allocated (typically with <TT>GC_MALLOC</tt>), +not deallocated (normally with <TT>GC_FREE</tt>), but are +no longer accessible. Since the object is no longer accessible, +there in normally no way to deallocate the object at a later time; +thus it can safely be assumed that the object has been "leaked". +<P> +This is substantially different from counting leak detectors, +which simply verify that all allocated objects are eventually +deallocated. A garbage-collector based leak detector can provide +somewhat more precise information when an object was leaked. +More importantly, it does not report objects that are never +deallocated because they are part of "permanent" data structures. +Thus it does not require all objects to be deallocated at process +exit time, a potentially useless activity that often triggers +large amounts of paging. +<P> +All non-ancient versions of the garbage collector provide +leak detection support. Version 5.3 adds the following +features: +<OL> +<LI> Leak detection mode can be initiated at run-time by +setting GC_find_leak instead of building the collector with FIND_LEAK +defined. This variable should be set to a nonzero value +at program startup. +<LI> Leaked objects should be reported and then correctly garbage collected. +Prior versions either reported leaks or functioned as a garbage collector. +</ol> +For the rest of this description we will give instructions that work +with any reasonable version of the collector. +<P> +To use the collector as a leak detector, follow the following steps: +<OL> +<LI> Build the collector with -DFIND_LEAK. Otherwise use default +build options. +<LI> Change the program so that all allocation and deallocation goes +through the garbage collector. +<LI> Arrange to call <TT>GC_gcollect</tt> at appropriate points to check +for leaks. +(For sufficiently long running programs, this will happen implicitly, +but probably not with sufficient frequency.) +</ol> +The second step can usually be accomplished with the +<TT>-DREDIRECT_MALLOC=GC_malloc</tt> option when the collector is built, +or by defining <TT>malloc</tt>, <TT>calloc</tt>, +<TT>realloc</tt> and <TT>free</tt> +to call the corresponding garbage collector functions. +But this, by itself, will not yield very informative diagnostics, +since the collector does not keep track of information about +how objects were allocated. The error reports will include +only object addresses. +<P> +For more precise error reports, as much of the program as possible +should use the all uppercase variants of these functions, after +defining <TT>GC_DEBUG</tt>, and then including <TT>gc.h</tt>. +In this environment <TT>GC_MALLOC</tt> is a macro which causes +at least the file name and line number at the allocation point to +be saved as part of the object. Leak reports will then also include +this information. +<P> +Many collector features (<I>e.g</i> stubborn objects, finalization, +and disappearing links) are less useful in this context, and are not +fully supported. Their use will usually generate additional bogus +leak reports, since the collector itself drops some associated objects. +<P> +The same is generally true of thread support. However, as of 6.0alpha4, +correct leak reports should be generated with linuxthreads. +<P> +On a few platforms (currently Solaris/SPARC, Irix, and, with -DSAVE_CALL_CHAIN, +Linux/X86), <TT>GC_MALLOC</tt> +also causes some more information about its call stack to be saved +in the object. Such information is reproduced in the error +reports in very non-symbolic form, but it can be very useful with the +aid of a debugger. +<H2>An Example</h2> +The following header file <TT>leak_detector.h</tt> is included in the +"include" subdirectory of the distribution: +<PRE> +#define GC_DEBUG +#include "gc.h" +#define malloc(n) GC_MALLOC(n) +#define calloc(m,n) GC_MALLOC((m)*(n)) +#define free(p) GC_FREE(p) +#define realloc(p,n) GC_REALLOC((p),(n)) +#define CHECK_LEAKS() GC_gcollect() +</pre> +<P> +Assume the collector has been built with -DFIND_LEAK. (For very +new versions of the collector, we could instead add the statement +<TT>GC_find_leak = 1</tt> as the first statement in <TT>main</tt>. +<P> +The program to be tested for leaks can then look like: +<PRE> +#include "leak_detector.h" + +main() { + int *p[10]; + int i; + /* GC_find_leak = 1; for new collector versions not */ + /* compiled with -DFIND_LEAK. */ + for (i = 0; i < 10; ++i) { + p[i] = malloc(sizeof(int)+i); + } + for (i = 1; i < 10; ++i) { + free(p[i]); + } + for (i = 0; i < 9; ++i) { + p[i] = malloc(sizeof(int)+i); + } + CHECK_LEAKS(); +} +</pre> +<P> +On an Intel X86 Linux system this produces on the stderr stream: +<PRE> +Leaked composite object at 0x806dff0 (leak_test.c:8, sz=4) +</pre> +(On most unmentioned operating systems, the output is similar to this. +If the collector had been built on Linux/X86 with -DSAVE_CALL_CHAIN, +the output would be closer to the Solaris example. For this to work, +the program should not be compiled with -fomit_frame_pointer.) +<P> +On Irix it reports +<PRE> +Leaked composite object at 0x10040fe0 (leak_test.c:8, sz=4) + Caller at allocation: + ##PC##= 0x10004910 +</pre> +and on Solaris the error report is +<PRE> +Leaked composite object at 0xef621fc8 (leak_test.c:8, sz=4) + Call chain at allocation: + args: 4 (0x4), 200656 (0x30FD0) + ##PC##= 0x14ADC + args: 1 (0x1), -268436012 (0xEFFFFDD4) + ##PC##= 0x14A64 +</pre> +In the latter two cases some additional information is given about +how malloc was called when the leaked object was allocated. For +Solaris, the first line specifies the arguments to <TT>GC_debug_malloc</tt> +(the actual allocation routine), The second the program counter inside +main, the third the arguments to <TT>main</tt>, and finally the program +counter inside the caller to main (i.e. in the C startup code). +<P> +In the Irix case, only the address inside the caller to main is given. +<P> +In many cases, a debugger is needed to interpret the additional information. +On systems supporting the "adb" debugger, the <TT>callprocs</tt> script +can be used to replace program counter values with symbolic names. +As of version 6.1, the collector tries to generate symbolic names for +call stacks if it knows how to do so on the platform. This is true on +Linux/X86, but not on most other platforms. +<H2>Simplified leak detection under Linux</h2> +Since version 6.1, it should be possible to run the collector in leak +detection mode on a program a.out under Linux/X86 as follows: +<OL> +<LI> Ensure that a.out is a single-threaded executable. This doesn't yet work +for multithreaded programs. +<LI> If possible, ensure that the addr2line program is installed in +/usr/bin. (It comes with RedHat Linux.) +<LI> If possible, compile a.out with full debug information. +This will improve the quality of the leak reports. With this approach, it is +no longer necessary to call GC_ routines explicitly, though that can also +improve the quality of the leak reports. +<LI> Build the collector and install it in directory <I>foo</i> as follows: +<UL> +<LI> configure --prefix=<I>foo</i> --enable-full-debug --enable-redirect-malloc +--disable-threads +<LI> make +<LI> make install +</ul> +<LI> Set environment variables as follows: +<UL> +<LI> LD_PRELOAD=<I>foo</i>/lib/libgc.so +<LI> GC_FIND_LEAK +<LI> You may also want to set GC_PRINT_STATS (to confirm that the collector +is running) and/or GC_LOOP_ON_ABORT (to facilitate debugging from another +window if something goes wrong). +</ul +<LI> Simply run a.out as you normally would. Note that if you run anything +else (<I>e.g.</i> your editor) with those environment variables set, +it will also be leak tested. This may or may not be useful and/or +embarrassing. It can generate +mountains of leak reports if the application wasn't designed to avoid leaks, +<I>e.g.</i> because it's always short-lived. +</ol> +This has not yet been thropughly tested on large applications, but it's known +to do the right thing on at least some small ones. +</body> +</html> diff --git a/boehm-gc/doc/scale.html b/boehm-gc/doc/scale.html new file mode 100644 index 00000000000..2e70148dfb7 --- /dev/null +++ b/boehm-gc/doc/scale.html @@ -0,0 +1,210 @@ +<HTML> +<HEAD> +<TITLE>Garbage collector scalability</TITLE> +</HEAD> +<BODY> +<H1>Garbage collector scalability</h1> +In its default configuration, the Boehm-Demers-Weiser garbage collector +is not thread-safe. It can be made thread-safe for a number of environments +by building the collector with the appropriate +<TT>-D</tt><I>XXX</i><TT>-THREADS</tt> compilation +flag. This has primarily two effects: +<OL> +<LI> It causes the garbage collector to stop all other threads when +it needs to see a consistent memory state. +<LI> It causes the collector to acquire a lock around essentially all +allocation and garbage collection activity. +</ol> +Since a single lock is used for all allocation-related activity, only one +thread can be allocating or collecting at one point. This inherently +limits performance of multi-threaded applications on multiprocessors. +<P> +On most platforms, the allocator/collector lock is implemented as a +spin lock with exponential back-off. Longer wait times are implemented +by yielding and/or sleeping. If a collection is in progress, the pure +spinning stage is skipped. This has the advantage that uncontested and +thus most uniprocessor lock acquisitions are very cheap. It has the +disadvantage that the application may sleep for small periods of time +even when there is work to be done. And threads may be unnecessarily +woken up for short periods. Nonetheless, this scheme empirically +outperforms native queue-based mutual exclusion implementations in most +cases, sometimes drastically so. +<H2>Options for enhanced scalability</h2> +Version 6.0 of the collector adds two facilities to enhance collector +scalability on multiprocessors. As of 6.0alpha1, these are supported +only under Linux on X86 and IA64 processors, though ports to other +otherwise supported Pthreads platforms should be straightforward. +They are intended to be used together. +<UL> +<LI> +Building the collector with <TT>-DPARALLEL_MARK</tt> allows the collector to +run the mark phase in parallel in multiple threads, and thus on multiple +processors. The mark phase typically consumes the large majority of the +collection time. Thus this largely parallelizes the garbage collector +itself, though not the allocation process. Currently the marking is +performed by the thread that triggered the collection, together with +<I>N</i>-1 dedicated +threads, where <I>N</i> is the number of processors detected by the collector. +The dedicated threads are created once at initialization time. +<P> +A second effect of this flag is to switch to a more concurrent +implementation of <TT>GC_malloc_many</tt>, so that free lists can be +built, and memory can be cleared, by more than one thread concurrently. +<LI> +Building the collector with -DTHREAD_LOCAL_ALLOC adds support for thread +local allocation. It does not, by itself, cause thread local allocation +to be used. It simply allows the use of the interface in +<TT>gc_local_alloc.h</tt>. +<P> +Memory returned from thread-local allocators is completely interchangeable +with that returned by the standard allocators. It may be used by other +threads. The only difference is that, if the thread allocates enough +memory of a certain kind, it will build a thread-local free list for +objects of that kind, and allocate from that. This greatly reduces +locking. The thread-local free lists are refilled using +<TT>GC_malloc_many</tt>. +<P> +An important side effect of this flag is to replace the default +spin-then-sleep lock to be replace by a spin-then-queue based implementation. +This <I>reduces performance</i> for the standard allocation functions, +though it usually improves performance when thread-local allocation is +used heavily, and thus the number of short-duration lock acquisitions +is greatly reduced. +</ul> +<P> +The easiest way to switch an application to thread-local allocation is to +<OL> +<LI> Define the macro <TT>GC_REDIRECT_TO_LOCAL</tt>, +and then include the <TT>gc.h</tt> +header in each client source file. +<LI> Invoke <TT>GC_thr_init()</tt> before any allocation. +<LI> Allocate using <TT>GC_MALLOC</tt>, <TT>GC_MALLOC_ATOMIC</tt>, +and/or <TT>GC_GCJ_MALLOC</tt>. +</ol> +<H2>The Parallel Marking Algorithm</h2> +We use an algorithm similar to +<A HREF="http://www.yl.is.s.u-tokyo.ac.jp/gc/">that developed by +Endo, Taura, and Yonezawa</a> at the University of Tokyo. +However, the data structures and implementation are different, +and represent a smaller change to the original collector source, +probably at the expense of extreme scalability. Some of +the refinements they suggest, <I>e.g.</i> splitting large +objects, were also incorporated into out approach. +<P> +The global mark stack is transformed into a global work queue. +Unlike the usual case, it never shrinks during a mark phase. +The mark threads remove objects from the queue by copying them to a +local mark stack and changing the global descriptor to zero, indicating +that there is no more work to be done for this entry. +This removal +is done with no synchronization. Thus it is possible for more than +one worker to remove the same entry, resulting in some work duplication. +<P> +The global work queue grows only if a marker thread decides to +return some of its local mark stack to the global one. This +is done if the global queue appears to be running low, or if +the local stack is in danger of overflowing. It does require +synchronization, but should be relatively rare. +<P> +The sequential marking code is reused to process local mark stacks. +Hence the amount of additional code required for parallel marking +is minimal. +<P> +It should be possible to use generational collection in the presence of the +parallel collector, by calling <TT>GC_enable_incremental()</tt>. +This does not result in fully incremental collection, since parallel mark +phases cannot currently be interrupted, and doing so may be too +expensive. +<P> +Gcj-style mark descriptors do not currently mix with the combination +of local allocation and incremental collection. They should work correctly +with one or the other, but not both. +<P> +The number of marker threads is set on startup to the number of +available processors (or to the value of the <TT>GC_NPROCS</tt> +environment variable). If only a single processor is detected, +parallel marking is disabled. +<P> +Note that setting GC_NPROCS to 1 also causes some lock acquisitions inside +the collector to immediately yield the processor instead of busy waiting +first. In the case of a multiprocessor and a client with multiple +simultaneously runnable threads, this may have disastrous performance +consequences (e.g. a factor of 10 slowdown). +<H2>Performance</h2> +We conducted some simple experiments with a version of +<A HREF="gc_bench.html">our GC benchmark</a> that was slightly modified to +run multiple concurrent client threads in the same address space. +Each client thread does the same work as the original benchmark, but they share +a heap. +This benchmark involves very little work outside of memory allocation. +This was run with GC 6.0alpha3 on a dual processor Pentium III/500 machine +under Linux 2.2.12. +<P> +Running with a thread-unsafe collector, the benchmark ran in 9 +seconds. With the simple thread-safe collector, +built with <TT>-DLINUX_THREADS</tt>, the execution time +increased to 10.3 seconds, or 23.5 elapsed seconds with two clients. +(The times for the <TT>malloc</tt>/i<TT>free</tt> version +with glibc <TT>malloc</tt> +are 10.51 (standard library, pthreads not linked), +20.90 (one thread, pthreads linked), +and 24.55 seconds respectively. The benchmark favors a +garbage collector, since most objects are small.) +<P> +The following table gives execution times for the collector built +with parallel marking and thread-local allocation support +(<TT>-DGC_LINUX_THREADS -DPARALLEL_MARK -DTHREAD_LOCAL_ALLOC</tt>). We tested +the client using either one or two marker threads, and running +one or two client threads. Note that the client uses thread local +allocation exclusively. With -DTHREAD_LOCAL_ALLOC the collector +switches to a locking strategy that is better tuned to less frequent +lock acquisition. The standard allocation primitives thus peform +slightly worse than without -DTHREAD_LOCAL_ALLOC, and should be +avoided in time-critical code. +<P> +(The results using <TT>pthread_mutex_lock</tt> +directly for allocation locking would have been worse still, at +least for older versions of linuxthreads. +With THREAD_LOCAL_ALLOC, we first repeatedly try to acquire the +lock with pthread_mutex_try_lock(), busy_waiting between attempts. +After a fixed number of attempts, we use pthread_mutex_lock().) +<P> +These measurements do not use incremental collection, nor was prefetching +enabled in the marker. We used the C version of the benchmark. +All measurements are in elapsed seconds on an unloaded machine. +<P> +<TABLE BORDER ALIGN="CENTER"> +<TR><TH>Number of threads</th><TH>1 marker thread (secs.)</th> +<TH>2 marker threads (secs.)</th></tr> +<TR><TD>1 client</td><TD ALIGN="CENTER">10.45</td><TD ALIGN="CENTER">7.85</td> +<TR><TD>2 clients</td><TD ALIGN="CENTER">19.95</td><TD ALIGN="CENTER">12.3</td> +</table> +<PP> +The execution time for the single threaded case is slightly worse than with +simple locking. However, even the single-threaded benchmark runs faster than +even the thread-unsafe version if a second processor is available. +The execution time for two clients with thread local allocation time is +only 1.4 times the sequential execution time for a single thread in a +thread-unsafe environment, even though it involves twice the client work. +That represents close to a +factor of 2 improvement over the 2 client case with the old collector. +The old collector clearly +still suffered from some contention overhead, in spite of the fact that the +locking scheme had been fairly well tuned. +<P> +Full linear speedup (i.e. the same execution time for 1 client on one +processor as 2 clients on 2 processors) +is probably not achievable on this kind of +hardware even with such a small number of processors, +since the memory system is +a major constraint for the garbage collector, +the processors usually share a single memory bus, and thus +the aggregate memory bandwidth does not increase in +proportion to the number of processors. +<P> +These results are likely to be very sensitive to both hardware and OS +issues. Preliminary experiments with an older Pentium Pro machine running +an older kernel were far less encouraging. + +</body> +</html> diff --git a/boehm-gc/include/Makefile.am b/boehm-gc/include/Makefile.am new file mode 100644 index 00000000000..306026b0a8a --- /dev/null +++ b/boehm-gc/include/Makefile.am @@ -0,0 +1,35 @@ +# +# +# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED +# OR IMPLIED. ANY USE IS AT YOUR OWN RISK. +# +# Permission is hereby granted to use or copy this program +# for any purpose, provided the above notices are retained on all copies. +# Permission to modify the code and to distribute modified code is granted, +# provided the above notices are retained, and a notice that the code was +# modified is included with the above copyright notice. +# +# Modified by: Grzegorz Jakacki <jakacki at acm dot org> + +## Process this file with automake to produce Makefile.in. + +# installed headers +# +pkginclude_HEADERS = gc.h gc_typed.h gc_inl.h \ + gc_inline.h gc_mark.h gc_cpp.h \ + weakpointer.h gc_alloc.h new_gc_alloc.h \ + gc_allocator.h gc_backptr.h \ + gc_gcj.h gc_local_alloc.h leak_detector.h \ + gc_amiga_redirects.h gc_pthread_redirects.h \ + gc_config_macros.h + +# headers which are not installed +# +dist_noinst_HEADERS = private/gc_hdrs.h \ + private/gc_priv.h private/gcconfig.h \ + private/gc_pmark.h private/gc_locks.h \ + private/solaris_threads.h private/dbg_mlc.h \ + private/specific.h private/cord_pos.h \ + private/pthread_support.h private/pthread_stop_world.h \ + private/darwin_semaphore.h private/darwin_stop_world.h \ + cord.h ec.h javaxfc.h diff --git a/boehm-gc/include/Makefile.in b/boehm-gc/include/Makefile.in new file mode 100644 index 00000000000..9ade270b5ee --- /dev/null +++ b/boehm-gc/include/Makefile.in @@ -0,0 +1,329 @@ +# Makefile.in generated by automake 1.6.3 from Makefile.am. +# @configure_input@ + +# Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 +# Free Software Foundation, Inc. +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + +@SET_MAKE@ + +# +# +# THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED +# OR IMPLIED. ANY USE IS AT YOUR OWN RISK. +# +# Permission is hereby granted to use or copy this program +# for any purpose, provided the above notices are retained on all copies. +# Permission to modify the code and to distribute modified code is granted, +# provided the above notices are retained, and a notice that the code was +# modified is included with the above copyright notice. +# +# Modified by: Grzegorz Jakacki <jakacki at acm dot org> +SHELL = @SHELL@ + +srcdir = @srcdir@ +top_srcdir = @top_srcdir@ +VPATH = @srcdir@ +prefix = @prefix@ +exec_prefix = @exec_prefix@ + +bindir = @bindir@ +sbindir = @sbindir@ +libexecdir = @libexecdir@ +datadir = @datadir@ +sysconfdir = @sysconfdir@ +sharedstatedir = @sharedstatedir@ +localstatedir = @localstatedir@ +libdir = @libdir@ +infodir = @infodir@ +mandir = @mandir@ +includedir = @includedir@ +oldincludedir = /usr/include +pkgdatadir = $(datadir)/@PACKAGE@ +pkglibdir = $(libdir)/@PACKAGE@ +pkgincludedir = $(includedir)/@PACKAGE@ +top_builddir = .. + +ACLOCAL = @ACLOCAL@ +AUTOCONF = @AUTOCONF@ +AUTOMAKE = @AUTOMAKE@ +AUTOHEADER = @AUTOHEADER@ + +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +INSTALL = @INSTALL@ +INSTALL_PROGRAM = @INSTALL_PROGRAM@ +INSTALL_DATA = @INSTALL_DATA@ +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_SCRIPT = @INSTALL_SCRIPT@ +INSTALL_HEADER = $(INSTALL_DATA) +transform = @program_transform_name@ +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +host_alias = @host_alias@ +host_triplet = @host@ + +EXEEXT = @EXEEXT@ +OBJEXT = @OBJEXT@ +PATH_SEPARATOR = @PATH_SEPARATOR@ +AMTAR = @AMTAR@ +AR = @AR@ +AS = @AS@ +AWK = @AWK@ +CC = @CC@ +CCAS = @CCAS@ +CCASFLAGS = @CCASFLAGS@ +CFLAGS = @CFLAGS@ +CXX = @CXX@ +CXXFLAGS = @CXXFLAGS@ +CXXINCLUDES = @CXXINCLUDES@ +DEPDIR = @DEPDIR@ +DLLTOOL = @DLLTOOL@ +ECHO = @ECHO@ +EXTRA_TEST_LIBS = @EXTRA_TEST_LIBS@ +GC_CFLAGS = @GC_CFLAGS@ +GC_VERSION = @GC_VERSION@ +INCLUDES = @INCLUDES@ +INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@ +LIBTOOL = @LIBTOOL@ +LN_S = @LN_S@ +MAINT = @MAINT@ +MY_CFLAGS = @MY_CFLAGS@ +OBJDUMP = @OBJDUMP@ +PACKAGE = @PACKAGE@ +RANLIB = @RANLIB@ +STRIP = @STRIP@ +THREADLIBS = @THREADLIBS@ +VERSION = @VERSION@ +addincludes = @addincludes@ +addlibs = @addlibs@ +addobjs = @addobjs@ +addtests = @addtests@ +am__include = @am__include@ +am__quote = @am__quote@ +install_sh = @install_sh@ +target_all = @target_all@ + +# installed headers +# +pkginclude_HEADERS = gc.h gc_typed.h gc_inl.h \ + gc_inline.h gc_mark.h gc_cpp.h \ + weakpointer.h gc_alloc.h new_gc_alloc.h \ + gc_allocator.h gc_backptr.h \ + gc_gcj.h gc_local_alloc.h leak_detector.h \ + gc_amiga_redirects.h gc_pthread_redirects.h \ + gc_config_macros.h + + +# headers which are not installed +# +dist_noinst_HEADERS = private/gc_hdrs.h \ + private/gc_priv.h private/gcconfig.h \ + private/gc_pmark.h private/gc_locks.h \ + private/solaris_threads.h private/dbg_mlc.h \ + private/specific.h private/cord_pos.h \ + private/pthread_support.h private/pthread_stop_world.h \ + private/darwin_semaphore.h private/darwin_stop_world.h \ + cord.h ec.h javaxfc.h + +subdir = include +mkinstalldirs = $(SHELL) $(top_srcdir)/mkinstalldirs +CONFIG_CLEAN_FILES = +DIST_SOURCES = +HEADERS = $(dist_noinst_HEADERS) $(pkginclude_HEADERS) + +DIST_COMMON = $(dist_noinst_HEADERS) $(pkginclude_HEADERS) Makefile.am \ + Makefile.in +all: all-am + +.SUFFIXES: +$(srcdir)/Makefile.in: @MAINTAINER_MODE_TRUE@ Makefile.am $(top_srcdir)/configure.in $(ACLOCAL_M4) + cd $(top_srcdir) && \ + $(AUTOMAKE) --gnu include/Makefile +Makefile: @MAINTAINER_MODE_TRUE@ $(srcdir)/Makefile.in $(top_builddir)/config.status + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe) + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +distclean-libtool: + -rm -f libtool +uninstall-info-am: +pkgincludeHEADERS_INSTALL = $(INSTALL_HEADER) +install-pkgincludeHEADERS: $(pkginclude_HEADERS) + @$(NORMAL_INSTALL) + $(mkinstalldirs) $(DESTDIR)$(pkgincludedir) + @list='$(pkginclude_HEADERS)'; for p in $$list; do \ + if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " $(pkgincludeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(pkgincludedir)/$$f"; \ + $(pkgincludeHEADERS_INSTALL) $$d$$p $(DESTDIR)$(pkgincludedir)/$$f; \ + done + +uninstall-pkgincludeHEADERS: + @$(NORMAL_UNINSTALL) + @list='$(pkginclude_HEADERS)'; for p in $$list; do \ + f="`echo $$p | sed -e 's|^.*/||'`"; \ + echo " rm -f $(DESTDIR)$(pkgincludedir)/$$f"; \ + rm -f $(DESTDIR)$(pkgincludedir)/$$f; \ + done + +ETAGS = etags +ETAGSFLAGS = + +tags: TAGS + +ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES) + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + mkid -fID $$unique + +TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \ + $(TAGS_FILES) $(LISP) + tags=; \ + here=`pwd`; \ + list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | \ + $(AWK) ' { files[$$0] = 1; } \ + END { for (i in files) print i; }'`; \ + test -z "$(ETAGS_ARGS)$$tags$$unique" \ + || $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$tags $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && cd $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) $$here + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) + +top_distdir = .. +distdir = $(top_distdir)/$(PACKAGE)-$(VERSION) + +distdir: $(DISTFILES) + $(mkinstalldirs) $(distdir)/private + @list='$(DISTFILES)'; for file in $$list; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test "$$dir" != "$$file" && test "$$dir" != "."; then \ + dir="/$$dir"; \ + $(mkinstalldirs) "$(distdir)$$dir"; \ + else \ + dir=''; \ + fi; \ + if test -d $$d/$$file; then \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \ + fi; \ + cp -pR $$d/$$file $(distdir)$$dir || exit 1; \ + else \ + test -f $(distdir)/$$file \ + || cp -p $$d/$$file $(distdir)/$$file \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(HEADERS) + +installdirs: + $(mkinstalldirs) $(DESTDIR)$(pkgincludedir) + +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + INSTALL_STRIP_FLAG=-s \ + `test -z '$(STRIP)' || \ + echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -rm -f Makefile $(CONFIG_CLEAN_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool mostlyclean-am + +distclean: distclean-am + +distclean-am: clean-am distclean-generic distclean-libtool \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +info: info-am + +info-am: + +install-data-am: install-pkgincludeHEADERS + +install-exec-am: + +install-info: install-info-am + +install-man: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-generic mostlyclean-libtool + +uninstall-am: uninstall-info-am uninstall-pkgincludeHEADERS + +.PHONY: GTAGS all all-am check check-am clean clean-generic \ + clean-libtool distclean distclean-generic distclean-libtool \ + distclean-tags distdir dvi dvi-am info info-am install \ + install-am install-data install-data-am install-exec \ + install-exec-am install-info install-info-am install-man \ + install-pkgincludeHEADERS install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-generic \ + mostlyclean-libtool tags uninstall uninstall-am \ + uninstall-info-am uninstall-pkgincludeHEADERS + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/boehm-gc/include/gc_allocator.h b/boehm-gc/include/gc_allocator.h new file mode 100644 index 00000000000..87c85099381 --- /dev/null +++ b/boehm-gc/include/gc_allocator.h @@ -0,0 +1,232 @@ +/* + * Copyright (c) 1996-1997 + * Silicon Graphics Computer Systems, Inc. + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Silicon Graphics makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * Copyright (c) 2002 + * Hewlett-Packard Company + * + * Permission to use, copy, modify, distribute and sell this software + * and its documentation for any purpose is hereby granted without fee, + * provided that the above copyright notice appear in all copies and + * that both that copyright notice and this permission notice appear + * in supporting documentation. Hewlett-Packard Company makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + */ + +/* + * This implements standard-conforming allocators that interact with + * the garbage collector. Gc_alloctor<T> allocates garbage-collectable + * objects of type T. Traceable_allocator<T> allocates objects that + * are not temselves garbage collected, but are scanned by the + * collector for pointers to collectable objects. Traceable_alloc + * should be used for explicitly managed STL containers that may + * point to collectable objects. + * + * This code was derived from an earlier version of the GNU C++ standard + * library, which itself was derived from the SGI STL implementation. + */ + +#include "gc.h" // For size_t + +/* First some helpers to allow us to dispatch on whether or not a type + * is known to be pointerfree. + * These are private, except that the client may invoke the + * GC_DECLARE_PTRFREE macro. + */ + +struct GC_true_type {}; +struct GC_false_type {}; + +template <class GC_tp> +struct GC_type_traits { + GC_false_type GC_is_ptr_free; +}; + +# define GC_DECLARE_PTRFREE(T) \ +template<> struct GC_type_traits<T> { GC_true_type GC_is_ptr_free; } + +GC_DECLARE_PTRFREE(signed char); +GC_DECLARE_PTRFREE(unsigned char); +GC_DECLARE_PTRFREE(signed short); +GC_DECLARE_PTRFREE(unsigned short); +GC_DECLARE_PTRFREE(signed int); +GC_DECLARE_PTRFREE(unsigned int); +GC_DECLARE_PTRFREE(signed long); +GC_DECLARE_PTRFREE(unsigned long); +GC_DECLARE_PTRFREE(float); +GC_DECLARE_PTRFREE(double); +/* The client may want to add others. */ + +// In the following GC_Tp is GC_true_type iff we are allocating a +// pointerfree object. +template <class GC_Tp> +inline void * GC_selective_alloc(size_t n, GC_Tp) { + return GC_MALLOC(n); +} + +template <> +inline void * GC_selective_alloc<GC_true_type>(size_t n, GC_true_type) { + return GC_MALLOC_ATOMIC(n); +} + +/* Now the public gc_allocator<T> class: + */ +template <class GC_Tp> +class gc_allocator { +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef GC_Tp* pointer; + typedef const GC_Tp* const_pointer; + typedef GC_Tp& reference; + typedef const GC_Tp& const_reference; + typedef GC_Tp value_type; + + template <class GC_Tp1> struct rebind { + typedef gc_allocator<GC_Tp1> other; + }; + + gc_allocator() {} +# ifndef _MSC_VER + // I'm not sure why this is needed here in addition to the following. + // The standard specifies it for the standard allocator, but VC++ rejects + // it. -HB + gc_allocator(const gc_allocator&) throw() {} +# endif + template <class GC_Tp1> gc_allocator(const gc_allocator<GC_Tp1>&) throw() {} + ~gc_allocator() throw() {} + + pointer address(reference GC_x) const { return &GC_x; } + const_pointer address(const_reference GC_x) const { return &GC_x; } + + // GC_n is permitted to be 0. The C++ standard says nothing about what + // the return value is when GC_n == 0. + GC_Tp* allocate(size_type GC_n, const void* = 0) { + GC_type_traits<GC_Tp> traits; + return static_cast<GC_Tp *> + (GC_selective_alloc(GC_n * sizeof(GC_Tp), + traits.GC_is_ptr_free)); + } + + // __p is not permitted to be a null pointer. + void deallocate(pointer __p, size_type GC_n) + { GC_FREE(__p); } + + size_type max_size() const throw() + { return size_t(-1) / sizeof(GC_Tp); } + + void construct(pointer __p, const GC_Tp& __val) { new(__p) GC_Tp(__val); } + void destroy(pointer __p) { __p->~GC_Tp(); } +}; + +template<> +class gc_allocator<void> { + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template <class GC_Tp1> struct rebind { + typedef gc_allocator<GC_Tp1> other; + }; +}; + + +template <class GC_T1, class GC_T2> +inline bool operator==(const gc_allocator<GC_T1>&, const gc_allocator<GC_T2>&) +{ + return true; +} + +template <class GC_T1, class GC_T2> +inline bool operator!=(const gc_allocator<GC_T1>&, const gc_allocator<GC_T2>&) +{ + return false; +} + +/* + * And the public traceable_allocator class. + */ + +// Note that we currently don't specialize the pointer-free case, since a +// pointer-free traceable container doesn't make that much sense, +// though it could become an issue due to abstraction boundaries. +template <class GC_Tp> +class traceable_allocator { +public: + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef GC_Tp* pointer; + typedef const GC_Tp* const_pointer; + typedef GC_Tp& reference; + typedef const GC_Tp& const_reference; + typedef GC_Tp value_type; + + template <class GC_Tp1> struct rebind { + typedef traceable_allocator<GC_Tp1> other; + }; + + traceable_allocator() throw() {} +# ifndef _MSC_VER + traceable_allocator(const traceable_allocator&) throw() {} +# endif + template <class GC_Tp1> traceable_allocator + (const traceable_allocator<GC_Tp1>&) throw() {} + ~traceable_allocator() throw() {} + + pointer address(reference GC_x) const { return &GC_x; } + const_pointer address(const_reference GC_x) const { return &GC_x; } + + // GC_n is permitted to be 0. The C++ standard says nothing about what + // the return value is when GC_n == 0. + GC_Tp* allocate(size_type GC_n, const void* = 0) { + return static_cast<GC_Tp*>(GC_MALLOC_UNCOLLECTABLE(GC_n * sizeof(GC_Tp))); + } + + // __p is not permitted to be a null pointer. + void deallocate(pointer __p, size_type GC_n) + { GC_FREE(__p); } + + size_type max_size() const throw() + { return size_t(-1) / sizeof(GC_Tp); } + + void construct(pointer __p, const GC_Tp& __val) { new(__p) GC_Tp(__val); } + void destroy(pointer __p) { __p->~GC_Tp(); } +}; + +template<> +class traceable_allocator<void> { + typedef size_t size_type; + typedef ptrdiff_t difference_type; + typedef void* pointer; + typedef const void* const_pointer; + typedef void value_type; + + template <class GC_Tp1> struct rebind { + typedef traceable_allocator<GC_Tp1> other; + }; +}; + + +template <class GC_T1, class GC_T2> +inline bool operator==(const traceable_allocator<GC_T1>&, const traceable_allocator<GC_T2>&) +{ + return true; +} + +template <class GC_T1, class GC_T2> +inline bool operator!=(const traceable_allocator<GC_T1>&, const traceable_allocator<GC_T2>&) +{ + return false; +} + diff --git a/boehm-gc/include/gc_config_macros.h b/boehm-gc/include/gc_config_macros.h new file mode 100644 index 00000000000..0c836d876c8 --- /dev/null +++ b/boehm-gc/include/gc_config_macros.h @@ -0,0 +1,147 @@ +/* + * This should never be included directly. It is included only from gc.h. + * We separate it only to make gc.h more suitable as documentation. + * + * Some tests for old macros. These violate our namespace rules and will + * disappear shortly. Use the GC_ names. + */ +#if defined(SOLARIS_THREADS) || defined(_SOLARIS_THREADS) +# define GC_SOLARIS_THREADS +#endif +#if defined(_SOLARIS_PTHREADS) +# define GC_SOLARIS_PTHREADS +#endif +#if defined(IRIX_THREADS) +# define GC_IRIX_THREADS +#endif +#if defined(DGUX_THREADS) +# if !defined(GC_DGUX386_THREADS) +# define GC_DGUX386_THREADS +# endif +#endif +#if defined(AIX_THREADS) +# define GC_AIX_THREADS +#endif +#if defined(HPUX_THREADS) +# define GC_HPUX_THREADS +#endif +#if defined(OSF1_THREADS) +# define GC_OSF1_THREADS +#endif +#if defined(LINUX_THREADS) +# define GC_LINUX_THREADS +#endif +#if defined(WIN32_THREADS) +# define GC_WIN32_THREADS +#endif +#if defined(USE_LD_WRAP) +# define GC_USE_LD_WRAP +#endif + +#if !defined(_REENTRANT) && (defined(GC_SOLARIS_THREADS) \ + || defined(GC_SOLARIS_PTHREADS) \ + || defined(GC_HPUX_THREADS) \ + || defined(GC_AIX_THREADS) \ + || defined(GC_LINUX_THREADS)) +# define _REENTRANT + /* Better late than never. This fails if system headers that */ + /* depend on this were previously included. */ +#endif + +#if defined(GC_DGUX386_THREADS) && !defined(_POSIX4A_DRAFT10_SOURCE) +# define _POSIX4A_DRAFT10_SOURCE 1 +#endif + +# if defined(GC_SOLARIS_PTHREADS) || defined(GC_FREEBSD_THREADS) || \ + defined(GC_IRIX_THREADS) || defined(GC_LINUX_THREADS) || \ + defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS) || \ + defined(GC_DGUX386_THREADS) || defined(GC_DARWIN_THREADS) || \ + defined(GC_AIX_THREADS) || \ + (defined(GC_WIN32_THREADS) && defined(__CYGWIN32__)) +# define GC_PTHREADS +# endif + +#if defined(GC_THREADS) && !defined(GC_PTHREADS) +# if defined(__linux__) +# define GC_LINUX_THREADS +# define GC_PTHREADS +# endif +# if !defined(LINUX) && (defined(_PA_RISC1_1) || defined(_PA_RISC2_0) \ + || defined(hppa) || defined(__HPPA)) +# define GC_HPUX_THREADS +# define GC_PTHREADS +# endif +# if !defined(__linux__) && (defined(__alpha) || defined(__alpha__)) +# define GC_OSF1_THREADS +# define GC_PTHREADS +# endif +# if defined(__mips) && !defined(__linux__) +# define GC_IRIX_THREADS +# define GC_PTHREADS +# endif +# if defined(__sparc) && !defined(__linux__) +# define GC_SOLARIS_PTHREADS +# define GC_PTHREADS +# endif +# if defined(__APPLE__) && defined(__MACH__) && defined(__ppc__) +# define GC_DARWIN_THREADS +# define GC_PTHREADS +# endif +# if !defined(GC_PTHREADS) && defined(__FreeBSD__) +# define GC_FREEBSD_THREADS +# define GC_PTHREADS +# endif +# if defined(DGUX) && (defined(i386) || defined(__i386__)) +# define GC_DGUX386_THREADS +# define GC_PTHREADS +# endif +#endif /* GC_THREADS */ + +#if defined(GC_THREADS) && !defined(GC_PTHREADS) && defined(MSWIN32) +# define GC_WIN32_THREADS +#endif + +#if defined(GC_SOLARIS_PTHREADS) && !defined(GC_SOLARIS_THREADS) +# define GC_SOLARIS_THREADS +#endif + +# define __GC +# include <stddef.h> +# ifdef _WIN32_WCE +/* Yet more kluges for WinCE */ +# include <stdlib.h> /* size_t is defined here */ + typedef long ptrdiff_t; /* ptrdiff_t is not defined */ +# endif + +#if defined(_DLL) && !defined(GC_NOT_DLL) && !defined(GC_DLL) +# define GC_DLL +#endif + +#if defined(__MINGW32__) && defined(GC_DLL) +# ifdef GC_BUILD +# define GC_API __declspec(dllexport) +# else +# define GC_API __declspec(dllimport) +# endif +#endif + +#if (defined(__DMC__) || defined(_MSC_VER)) && defined(GC_DLL) +# ifdef GC_BUILD +# define GC_API extern __declspec(dllexport) +# else +# define GC_API __declspec(dllimport) +# endif +#endif + +#if defined(__WATCOMC__) && defined(GC_DLL) +# ifdef GC_BUILD +# define GC_API extern __declspec(dllexport) +# else +# define GC_API extern __declspec(dllimport) +# endif +#endif + +#ifndef GC_API +#define GC_API extern +#endif + diff --git a/boehm-gc/include/private/darwin_semaphore.h b/boehm-gc/include/private/darwin_semaphore.h new file mode 100644 index 00000000000..0f43982d5c1 --- /dev/null +++ b/boehm-gc/include/private/darwin_semaphore.h @@ -0,0 +1,68 @@ +#ifndef GC_DARWIN_SEMAPHORE_H +#define GC_DARWIN_SEMAPHORE_H + +#if !defined(GC_DARWIN_THREADS) +#error darwin_semaphore.h included with GC_DARWIN_THREADS not defined +#endif + +/* + This is a very simple semaphore implementation for darwin. It + is implemented in terms of pthreads calls so it isn't async signal + safe. This isn't a problem because signals aren't used to + suspend threads on darwin. +*/ + +typedef struct { + pthread_mutex_t mutex; + pthread_cond_t cond; + int value; +} sem_t; + +static int sem_init(sem_t *sem, int pshared, int value) { + int ret; + if(pshared) + GC_abort("sem_init with pshared set"); + sem->value = value; + + ret = pthread_mutex_init(&sem->mutex,NULL); + if(ret < 0) return -1; + ret = pthread_cond_init(&sem->cond,NULL); + if(ret < 0) return -1; + return 0; +} + +static int sem_post(sem_t *sem) { + if(pthread_mutex_lock(&sem->mutex) < 0) + return -1; + sem->value++; + if(pthread_cond_signal(&sem->cond) < 0) { + pthread_mutex_unlock(&sem->mutex); + return -1; + } + if(pthread_mutex_unlock(&sem->mutex) < 0) + return -1; + return 0; +} + +static int sem_wait(sem_t *sem) { + if(pthread_mutex_lock(&sem->mutex) < 0) + return -1; + while(sem->value == 0) { + pthread_cond_wait(&sem->cond,&sem->mutex); + } + sem->value--; + if(pthread_mutex_unlock(&sem->mutex) < 0) + return -1; + return 0; +} + +static int sem_destroy(sem_t *sem) { + int ret; + ret = pthread_cond_destroy(&sem->cond); + if(ret < 0) return -1; + ret = pthread_mutex_destroy(&sem->mutex); + if(ret < 0) return -1; + return 0; +} + +#endif diff --git a/boehm-gc/include/private/darwin_stop_world.h b/boehm-gc/include/private/darwin_stop_world.h new file mode 100644 index 00000000000..9924297ec77 --- /dev/null +++ b/boehm-gc/include/private/darwin_stop_world.h @@ -0,0 +1,15 @@ +#ifndef GC_DARWIN_STOP_WORLD_H +#define GC_DARWIN_STOP_WORLD_H + +#if !defined(GC_DARWIN_THREADS) +#error darwin_stop_world.h included without GC_DARWIN_THREADS defined +#endif + +#include <mach/mach.h> +#include <mach/thread_act.h> + +struct thread_stop_info { + mach_port_t mach_thread; +}; + +#endif diff --git a/boehm-gc/include/private/pthread_stop_world.h b/boehm-gc/include/private/pthread_stop_world.h new file mode 100644 index 00000000000..054c7a0eacd --- /dev/null +++ b/boehm-gc/include/private/pthread_stop_world.h @@ -0,0 +1,12 @@ +#ifndef GC_PTHREAD_STOP_WORLD_H +#define GC_PTHREAD_STOP_WORLD_H + +struct thread_stop_info { + int signal; + word last_stop_count; /* GC_last_stop_count value when thread */ + /* last successfully handled a suspend */ + /* signal. */ + ptr_t stack_ptr; /* Valid only when stopped. */ +}; + +#endif diff --git a/boehm-gc/include/private/pthread_support.h b/boehm-gc/include/private/pthread_support.h new file mode 100644 index 00000000000..0ef917e7ef0 --- /dev/null +++ b/boehm-gc/include/private/pthread_support.h @@ -0,0 +1,97 @@ +#ifndef GC_PTHREAD_SUPPORT_H +#define GC_PTHREAD_SUPPORT_H + +# include "private/gc_priv.h" + +# if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \ + && !defined(GC_IRIX_THREADS) && !defined(GC_WIN32_THREADS) + +#if defined(GC_DARWIN_THREADS) +# include "private/darwin_stop_world.h" +#else +# include "private/pthread_stop_world.h" +#endif + +/* We use the allocation lock to protect thread-related data structures. */ + +/* The set of all known threads. We intercept thread creation and */ +/* joins. */ +/* Protected by allocation/GC lock. */ +/* Some of this should be declared volatile, but that's inconsistent */ +/* with some library routine declarations. */ +typedef struct GC_Thread_Rep { + struct GC_Thread_Rep * next; /* More recently allocated threads */ + /* with a given pthread id come */ + /* first. (All but the first are */ + /* guaranteed to be dead, but we may */ + /* not yet have registered the join.) */ + pthread_t id; + /* Extra bookkeeping information the stopping code uses */ + struct thread_stop_info stop_info; + + short flags; +# define FINISHED 1 /* Thread has exited. */ +# define DETACHED 2 /* Thread is intended to be detached. */ +# define MAIN_THREAD 4 /* True for the original thread only. */ + short thread_blocked; /* Protected by GC lock. */ + /* Treated as a boolean value. If set, */ + /* thread will acquire GC lock before */ + /* doing any pointer manipulations, and */ + /* has set its sp value. Thus it does */ + /* not need to be sent a signal to stop */ + /* it. */ + ptr_t stack_end; /* Cold end of the stack. */ +# ifdef IA64 + ptr_t backing_store_end; + ptr_t backing_store_ptr; +# endif + void * status; /* The value returned from the thread. */ + /* Used only to avoid premature */ + /* reclamation of any data it might */ + /* reference. */ +# ifdef THREAD_LOCAL_ALLOC +# if CPP_WORDSZ == 64 && defined(ALIGN_DOUBLE) +# define GRANULARITY 16 +# define NFREELISTS 49 +# else +# define GRANULARITY 8 +# define NFREELISTS 65 +# endif + /* The ith free list corresponds to size i*GRANULARITY */ +# define INDEX_FROM_BYTES(n) ((ADD_SLOP(n) + GRANULARITY - 1)/GRANULARITY) +# define BYTES_FROM_INDEX(i) ((i) * GRANULARITY - EXTRA_BYTES) +# define SMALL_ENOUGH(bytes) (ADD_SLOP(bytes) <= \ + (NFREELISTS-1)*GRANULARITY) + ptr_t ptrfree_freelists[NFREELISTS]; + ptr_t normal_freelists[NFREELISTS]; +# ifdef GC_GCJ_SUPPORT + ptr_t gcj_freelists[NFREELISTS]; +# endif + /* Free lists contain either a pointer or a small count */ + /* reflecting the number of granules allocated at that */ + /* size. */ + /* 0 ==> thread-local allocation in use, free list */ + /* empty. */ + /* > 0, <= DIRECT_GRANULES ==> Using global allocation, */ + /* too few objects of this size have been */ + /* allocated by this thread. */ + /* >= HBLKSIZE => pointer to nonempty free list. */ + /* > DIRECT_GRANULES, < HBLKSIZE ==> transition to */ + /* local alloc, equivalent to 0. */ +# define DIRECT_GRANULES (HBLKSIZE/GRANULARITY) + /* Don't use local free lists for up to this much */ + /* allocation. */ +# endif +} * GC_thread; + +# define THREAD_TABLE_SZ 128 /* Must be power of 2 */ +extern volatile GC_thread GC_threads[THREAD_TABLE_SZ]; + +extern GC_bool GC_thr_initialized; + +GC_thread GC_lookup_thread(pthread_t id); + +void GC_stop_init(); + +#endif /* GC_PTHREADS && !GC_SOLARIS_THREADS.... etc */ +#endif /* GC_PTHREAD_SUPPORT_H */ diff --git a/boehm-gc/missing b/boehm-gc/missing new file mode 100755 index 00000000000..dd583709f53 --- /dev/null +++ b/boehm-gc/missing @@ -0,0 +1,336 @@ +#! /bin/sh +# Common stub for a few missing GNU programs while installing. +# Copyright 1996, 1997, 1999, 2000 Free Software Foundation, Inc. +# Originally by Fran,cois Pinard <pinard@iro.umontreal.ca>, 1996. + +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. + +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +# 02111-1307, USA. + +# As a special exception to the GNU General Public License, if you +# distribute this file as part of a program that contains a +# configuration script generated by Autoconf, you may include it under +# the same distribution terms that you use for the rest of that program. + +if test $# -eq 0; then + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 +fi + +run=: + +# In the cases where this matters, `missing' is being run in the +# srcdir already. +if test -f configure.ac; then + configure_ac=configure.ac +else + configure_ac=configure.in +fi + +case "$1" in +--run) + # Try to run requested program, and just exit if it succeeds. + run= + shift + "$@" && exit 0 + ;; +esac + +# If it does not exist, or fails to run (possibly an outdated version), +# try to emulate it. +case "$1" in + + -h|--h|--he|--hel|--help) + echo "\ +$0 [OPTION]... PROGRAM [ARGUMENT]... + +Handle \`PROGRAM [ARGUMENT]...' for when PROGRAM is missing, or return an +error status if there is no known handling for PROGRAM. + +Options: + -h, --help display this help and exit + -v, --version output version information and exit + --run try to run the given command, and emulate it if it fails + +Supported PROGRAM values: + aclocal touch file \`aclocal.m4' + autoconf touch file \`configure' + autoheader touch file \`config.h.in' + automake touch all \`Makefile.in' files + bison create \`y.tab.[ch]', if possible, from existing .[ch] + flex create \`lex.yy.c', if possible, from existing .c + help2man touch the output file + lex create \`lex.yy.c', if possible, from existing .c + makeinfo touch the output file + tar try tar, gnutar, gtar, then tar without non-portable flags + yacc create \`y.tab.[ch]', if possible, from existing .[ch]" + ;; + + -v|--v|--ve|--ver|--vers|--versi|--versio|--version) + echo "missing 0.4 - GNU automake" + ;; + + -*) + echo 1>&2 "$0: Unknown \`$1' option" + echo 1>&2 "Try \`$0 --help' for more information" + exit 1 + ;; + + aclocal*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acinclude.m4' or \`${configure_ac}'. You might want + to install the \`Automake' and \`Perl' packages. Grab them from + any GNU archive site." + touch aclocal.m4 + ;; + + autoconf) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`${configure_ac}'. You might want to install the + \`Autoconf' and \`GNU m4' packages. Grab them from any GNU + archive site." + touch configure + ;; + + autoheader) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`acconfig.h' or \`${configure_ac}'. You might want + to install the \`Autoconf' and \`GNU m4' packages. Grab them + from any GNU archive site." + files=`sed -n 's/^[ ]*A[CM]_CONFIG_HEADER(\([^)]*\)).*/\1/p' ${configure_ac}` + test -z "$files" && files="config.h" + touch_files= + for f in $files; do + case "$f" in + *:*) touch_files="$touch_files "`echo "$f" | + sed -e 's/^[^:]*://' -e 's/:.*//'`;; + *) touch_files="$touch_files $f.in";; + esac + done + touch $touch_files + ;; + + automake*) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified \`Makefile.am', \`acinclude.m4' or \`${configure_ac}'. + You might want to install the \`Automake' and \`Perl' packages. + Grab them from any GNU archive site." + find . -type f -name Makefile.am -print | + sed 's/\.am$/.in/' | + while read f; do touch "$f"; done + ;; + + autom4te) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. + You can get \`$1Help2man' as part of \`Autoconf' from any GNU + archive site." + + file=`echo "$*" | sed -n 's/.*--output[ =]*\([^ ]*\).*/\1/p'` + test -z "$file" && file=`echo "$*" | sed -n 's/.*-o[ ]*\([^ ]*\).*/\1/p'` + if test -f "$file"; then + touch $file + else + test -z "$file" || exec >$file + echo "#! /bin/sh" + echo "# Created by GNU Automake missing as a replacement of" + echo "# $ $@" + echo "exit 0" + chmod +x $file + exit 1 + fi + ;; + + bison|yacc) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.y' file. You may need the \`Bison' package + in order for those modifications to take effect. You can get + \`Bison' from any GNU archive site." + rm -f y.tab.c y.tab.h + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.y) + SRCFILE=`echo "$LASTARG" | sed 's/y$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.c + fi + SRCFILE=`echo "$LASTARG" | sed 's/y$/h/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" y.tab.h + fi + ;; + esac + fi + if [ ! -f y.tab.h ]; then + echo >y.tab.h + fi + if [ ! -f y.tab.c ]; then + echo 'main() { return 0; }' >y.tab.c + fi + ;; + + lex|flex) + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.l' file. You may need the \`Flex' package + in order for those modifications to take effect. You can get + \`Flex' from any GNU archive site." + rm -f lex.yy.c + if [ $# -ne 1 ]; then + eval LASTARG="\${$#}" + case "$LASTARG" in + *.l) + SRCFILE=`echo "$LASTARG" | sed 's/l$/c/'` + if [ -f "$SRCFILE" ]; then + cp "$SRCFILE" lex.yy.c + fi + ;; + esac + fi + if [ ! -f lex.yy.c ]; then + echo 'main() { return 0; }' >lex.yy.c + fi + ;; + + help2man) + if test -z "$run" && ($1 --version) > /dev/null 2>&1; then + # We have it, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a dependency of a manual page. You may need the + \`Help2man' package in order for those modifications to take + effect. You can get \`Help2man' from any GNU archive site." + + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed -n 's/.*--output=\([^ ]*\).*/\1/p'` + fi + if [ -f "$file" ]; then + touch $file + else + test -z "$file" || exec >$file + echo ".ab help2man is required to generate this page" + exit 1 + fi + ;; + + makeinfo) + if test -z "$run" && (makeinfo --version) > /dev/null 2>&1; then + # We have makeinfo, but it failed. + exit 1 + fi + + echo 1>&2 "\ +WARNING: \`$1' is missing on your system. You should only need it if + you modified a \`.texi' or \`.texinfo' file, or any other file + indirectly affecting the aspect of the manual. The spurious + call might also be the consequence of using a buggy \`make' (AIX, + DU, IRIX). You might want to install the \`Texinfo' package or + the \`GNU make' package. Grab either from any GNU archive site." + file=`echo "$*" | sed -n 's/.*-o \([^ ]*\).*/\1/p'` + if test -z "$file"; then + file=`echo "$*" | sed 's/.* \([^ ]*\) *$/\1/'` + file=`sed -n '/^@setfilename/ { s/.* \([^ ]*\) *$/\1/; p; q; }' $file` + fi + touch $file + ;; + + tar) + shift + if test -n "$run"; then + echo 1>&2 "ERROR: \`tar' requires --run" + exit 1 + fi + + # We have already tried tar in the generic part. + # Look for gnutar/gtar before invocation to avoid ugly error + # messages. + if (gnutar --version > /dev/null 2>&1); then + gnutar ${1+"$@"} && exit 0 + fi + if (gtar --version > /dev/null 2>&1); then + gtar ${1+"$@"} && exit 0 + fi + firstarg="$1" + if shift; then + case "$firstarg" in + *o*) + firstarg=`echo "$firstarg" | sed s/o//` + tar "$firstarg" ${1+"$@"} && exit 0 + ;; + esac + case "$firstarg" in + *h*) + firstarg=`echo "$firstarg" | sed s/h//` + tar "$firstarg" ${1+"$@"} && exit 0 + ;; + esac + fi + + echo 1>&2 "\ +WARNING: I can't seem to be able to run \`tar' with the given arguments. + You may want to install GNU tar or Free paxutils, or check the + command line arguments." + exit 1 + ;; + + *) + echo 1>&2 "\ +WARNING: \`$1' is needed, and you do not seem to have it handy on your + system. You might have modified some files without having the + proper tools for further handling them. Check the \`README' file, + it often tells you about the needed prerequirements for installing + this package. You may also peek at any GNU archive site, in case + some other package would contain this missing \`$1' program." + exit 1 + ;; +esac + +exit 0 diff --git a/boehm-gc/powerpc_darwin_mach_dep.s b/boehm-gc/powerpc_darwin_mach_dep.s new file mode 100644 index 00000000000..92f2c93ca8d --- /dev/null +++ b/boehm-gc/powerpc_darwin_mach_dep.s @@ -0,0 +1,84 @@ + +; GC_push_regs function. Under some optimization levels GCC will clobber +; some of the non-volatile registers before we get a chance to save them +; therefore, this can't be inline asm. + +.text + .align 2 + .globl _GC_push_regs +_GC_push_regs: + + ; Prolog + mflr r0 + stw r0,8(r1) + stwu r1,-80(r1) + + ; Push r13-r31 + mr r3,r13 + bl L_GC_push_one$stub + mr r3,r14 + bl L_GC_push_one$stub + mr r3,r15 + bl L_GC_push_one$stub + mr r3,r16 + bl L_GC_push_one$stub + mr r3,r17 + bl L_GC_push_one$stub + mr r3,r18 + bl L_GC_push_one$stub + mr r3,r19 + bl L_GC_push_one$stub + mr r3,r20 + bl L_GC_push_one$stub + mr r3,r21 + bl L_GC_push_one$stub + mr r3,r22 + bl L_GC_push_one$stub + mr r3,r23 + bl L_GC_push_one$stub + mr r3,r24 + bl L_GC_push_one$stub + mr r3,r25 + bl L_GC_push_one$stub + mr r3,r26 + bl L_GC_push_one$stub + mr r3,r27 + bl L_GC_push_one$stub + mr r3,r28 + bl L_GC_push_one$stub + mr r3,r29 + bl L_GC_push_one$stub + mr r3,r30 + bl L_GC_push_one$stub + mr r3,r31 + bl L_GC_push_one$stub + + ; + lwz r0,88(r1) + addi r1,r1,80 + mtlr r0 + + ; Return + blr + +; PIC stuff, generated by GCC + +.data +.picsymbol_stub +L_GC_push_one$stub: + .indirect_symbol _GC_push_one + mflr r0 + bcl 20,31,L0$_GC_push_one +L0$_GC_push_one: + mflr r11 + addis r11,r11,ha16(L_GC_push_one$lazy_ptr-L0$_GC_push_one) + mtlr r0 + lwz r12,lo16(L_GC_push_one$lazy_ptr-L0$_GC_push_one)(r11) + mtctr r12 + addi r11,r11,lo16(L_GC_push_one$lazy_ptr-L0$_GC_push_one) + bctr +.data +.lazy_symbol_pointer +L_GC_push_one$lazy_ptr: + .indirect_symbol _GC_push_one + .long dyld_stub_binding_helper diff --git a/boehm-gc/powerpc_macosx_mach_dep.s b/boehm-gc/powerpc_macosx_mach_dep.s deleted file mode 100644 index 92f06286e73..00000000000 --- a/boehm-gc/powerpc_macosx_mach_dep.s +++ /dev/null @@ -1,95 +0,0 @@ - -.text - - .set linkageArea,24 - .set params,4 - .set alignment,4 - - .set spaceToSave,linkageArea+params+alignment - .set spaceToSave8,spaceToSave+8 - -; Mark from machine registers that are saved by C compiler - .globl _GC_push_regs -_GC_push_regs: - ; PROLOG - mflr r0 ; get return address - stw r0,8(r1) ; save return address - stwu r1,-spaceToSave(r1) ; skip over caller save area - ; - mr r3,r2 ; mark from r2. Well Im not really sure - ; that this is necessary or even the right - ; thing to do - at least it doesnt harm... - ; According to Apples docs it points to - ; the direct data area, whatever that is... - bl L_GC_push_one$stub - mr r3,r13 ; mark from r13-r31 - bl L_GC_push_one$stub - mr r3,r14 - bl L_GC_push_one$stub - mr r3,r15 - bl L_GC_push_one$stub - mr r3,r16 - bl L_GC_push_one$stub - mr r3,r17 - bl L_GC_push_one$stub - mr r3,r18 - bl L_GC_push_one$stub - mr r3,r19 - bl L_GC_push_one$stub - mr r3,r20 - bl L_GC_push_one$stub - mr r3,r21 - bl L_GC_push_one$stub - mr r3,r22 - bl L_GC_push_one$stub - mr r3,r23 - bl L_GC_push_one$stub - mr r3,r24 - bl L_GC_push_one$stub - mr r3,r25 - bl L_GC_push_one$stub - mr r3,r26 - bl L_GC_push_one$stub - mr r3,r27 - bl L_GC_push_one$stub - mr r3,r28 - bl L_GC_push_one$stub - mr r3,r29 - bl L_GC_push_one$stub - mr r3,r30 - bl L_GC_push_one$stub - mr r3,r31 - bl L_GC_push_one$stub - ; EPILOG - lwz r0,spaceToSave8(r1) ; get return address back - mtlr r0 ; reset link register - addic r1,r1,spaceToSave ; restore stack pointer - blr - -.data -.picsymbol_stub -L_GC_push_one$stub: - .indirect_symbol _GC_push_one - mflr r0 - bcl 20,31,L0$_GC_push_one -L0$_GC_push_one: - mflr r11 - addis r11,r11,ha16(L_GC_push_one$lazy_ptr-L0$_GC_push_one) - mtlr r0 - lwz r12,lo16(L_GC_push_one$lazy_ptr-L0$_GC_push_one)(r11) - mtctr r12 - addi r11,r11,lo16(L_GC_push_one$lazy_ptr-L0$_GC_push_one) - bctr -.data -.lazy_symbol_pointer -L_GC_push_one$lazy_ptr: - .indirect_symbol _GC_push_one - .long dyld_stub_binding_helper -.non_lazy_symbol_pointer -L_GC_push_one$non_lazy_ptr: - .indirect_symbol _GC_push_one - .long 0 - - - - diff --git a/boehm-gc/pthread_stop_world.c b/boehm-gc/pthread_stop_world.c new file mode 100644 index 00000000000..5dfd26d319a --- /dev/null +++ b/boehm-gc/pthread_stop_world.c @@ -0,0 +1,445 @@ +#include "private/pthread_support.h" + +#if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \ + && !defined(GC_IRIX_THREADS) && !defined(GC_WIN32_THREADS) \ + && !defined(GC_DARWIN_THREADS) && !defined(GC_AIX_THREADS) + +#include <signal.h> +#include <semaphore.h> +#include <errno.h> +#include <unistd.h> + +#if DEBUG_THREADS + +#ifndef NSIG +# if defined(MAXSIG) +# define NSIG (MAXSIG+1) +# elif defined(_NSIG) +# define NSIG _NSIG +# elif defined(__SIGRTMAX) +# define NSIG (__SIGRTMAX+1) +# else + --> please fix it +# endif +#endif + +void GC_print_sig_mask() +{ + sigset_t blocked; + int i; + + if (pthread_sigmask(SIG_BLOCK, NULL, &blocked) != 0) + ABORT("pthread_sigmask"); + GC_printf0("Blocked: "); + for (i = 1; i < NSIG; i++) { + if (sigismember(&blocked, i)) { GC_printf1("%ld ",(long) i); } + } + GC_printf0("\n"); +} + +#endif + +word GC_stop_count; /* Incremented at the beginning of GC_stop_world. */ + +#ifdef GC_OSF1_THREADS + GC_bool GC_retry_signals = TRUE; +#else + GC_bool GC_retry_signals = FALSE; +#endif + +/* + * We use signals to stop threads during GC. + * + * Suspended threads wait in signal handler for SIG_THR_RESTART. + * That's more portable than semaphores or condition variables. + * (We do use sem_post from a signal handler, but that should be portable.) + * + * The thread suspension signal SIG_SUSPEND is now defined in gc_priv.h. + * Note that we can't just stop a thread; we need it to save its stack + * pointer(s) and acknowledge. + */ + +#ifndef SIG_THR_RESTART +# if defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS) +# ifdef _SIGRTMIN +# define SIG_THR_RESTART _SIGRTMIN + 5 +# else +# define SIG_THR_RESTART SIGRTMIN + 5 +# endif +# else +# define SIG_THR_RESTART SIGXCPU +# endif +#endif + +sem_t GC_suspend_ack_sem; + +void GC_suspend_handler(int sig) +{ + int dummy; + pthread_t my_thread = pthread_self(); + GC_thread me; + sigset_t mask; +# ifdef PARALLEL_MARK + word my_mark_no = GC_mark_no; + /* Marker can't proceed until we acknowledge. Thus this is */ + /* guaranteed to be the mark_no correspending to our */ + /* suspension, i.e. the marker can't have incremented it yet. */ +# endif + word my_stop_count = GC_stop_count; + + if (sig != SIG_SUSPEND) ABORT("Bad signal in suspend_handler"); + +#if DEBUG_THREADS + GC_printf1("Suspending 0x%lx\n", my_thread); +#endif + + me = GC_lookup_thread(my_thread); + /* The lookup here is safe, since I'm doing this on behalf */ + /* of a thread which holds the allocation lock in order */ + /* to stop the world. Thus concurrent modification of the */ + /* data structure is impossible. */ + if (me -> stop_info.last_stop_count == my_stop_count) { + /* Duplicate signal. OK if we are retrying. */ + if (!GC_retry_signals) { + WARN("Duplicate suspend signal in thread %lx\n", + pthread_self()); + } + return; + } +# ifdef SPARC + me -> stop_info.stack_ptr = (ptr_t)GC_save_regs_in_stack(); +# else + me -> stop_info.stack_ptr = (ptr_t)(&dummy); +# endif +# ifdef IA64 + me -> backing_store_ptr = (ptr_t)GC_save_regs_in_stack(); +# endif + + /* Tell the thread that wants to stop the world that this */ + /* thread has been stopped. Note that sem_post() is */ + /* the only async-signal-safe primitive in LinuxThreads. */ + sem_post(&GC_suspend_ack_sem); + me -> stop_info.last_stop_count = my_stop_count; + + /* Wait until that thread tells us to restart by sending */ + /* this thread a SIG_THR_RESTART signal. */ + /* SIG_THR_RESTART should be masked at this point. Thus there */ + /* is no race. */ + if (sigfillset(&mask) != 0) ABORT("sigfillset() failed"); + if (sigdelset(&mask, SIG_THR_RESTART) != 0) ABORT("sigdelset() failed"); +# ifdef NO_SIGNALS + if (sigdelset(&mask, SIGINT) != 0) ABORT("sigdelset() failed"); + if (sigdelset(&mask, SIGQUIT) != 0) ABORT("sigdelset() failed"); + if (sigdelset(&mask, SIGTERM) != 0) ABORT("sigdelset() failed"); + if (sigdelset(&mask, SIGABRT) != 0) ABORT("sigdelset() failed"); +# endif + do { + me->stop_info.signal = 0; + sigsuspend(&mask); /* Wait for signal */ + } while (me->stop_info.signal != SIG_THR_RESTART); + /* If the RESTART signal gets lost, we can still lose. That should be */ + /* less likely than losing the SUSPEND signal, since we don't do much */ + /* between the sem_post and sigsuspend. */ + /* We'd need more handshaking to work around that, since we don't want */ + /* to accidentally leave a RESTART signal pending, thus causing us to */ + /* continue prematurely in a future round. */ + +#if DEBUG_THREADS + GC_printf1("Continuing 0x%lx\n", my_thread); +#endif +} + +void GC_restart_handler(int sig) +{ + pthread_t my_thread = pthread_self(); + GC_thread me; + + if (sig != SIG_THR_RESTART) ABORT("Bad signal in suspend_handler"); + + /* Let the GC_suspend_handler() know that we got a SIG_THR_RESTART. */ + /* The lookup here is safe, since I'm doing this on behalf */ + /* of a thread which holds the allocation lock in order */ + /* to stop the world. Thus concurrent modification of the */ + /* data structure is impossible. */ + me = GC_lookup_thread(my_thread); + me->stop_info.signal = SIG_THR_RESTART; + + /* + ** Note: even if we didn't do anything useful here, + ** it would still be necessary to have a signal handler, + ** rather than ignoring the signals, otherwise + ** the signals will not be delivered at all, and + ** will thus not interrupt the sigsuspend() above. + */ + +#if DEBUG_THREADS + GC_printf1("In GC_restart_handler for 0x%lx\n", pthread_self()); +#endif +} + +# ifdef IA64 +# define IF_IA64(x) x +# else +# define IF_IA64(x) +# endif +/* We hold allocation lock. Should do exactly the right thing if the */ +/* world is stopped. Should not fail if it isn't. */ +void GC_push_all_stacks() +{ + int i; + GC_thread p; + ptr_t lo, hi; + /* On IA64, we also need to scan the register backing store. */ + IF_IA64(ptr_t bs_lo; ptr_t bs_hi;) + pthread_t me = pthread_self(); + + if (!GC_thr_initialized) GC_thr_init(); + #if DEBUG_THREADS + GC_printf1("Pushing stacks from thread 0x%lx\n", (unsigned long) me); + #endif + for (i = 0; i < THREAD_TABLE_SZ; i++) { + for (p = GC_threads[i]; p != 0; p = p -> next) { + if (p -> flags & FINISHED) continue; + if (pthread_equal(p -> id, me)) { +# ifdef SPARC + lo = (ptr_t)GC_save_regs_in_stack(); +# else + lo = GC_approx_sp(); +# endif + IF_IA64(bs_hi = (ptr_t)GC_save_regs_in_stack();) + } else { + lo = p -> stop_info.stack_ptr; + IF_IA64(bs_hi = p -> backing_store_ptr;) + } + if ((p -> flags & MAIN_THREAD) == 0) { + hi = p -> stack_end; + IF_IA64(bs_lo = p -> backing_store_end); + } else { + /* The original stack. */ + hi = GC_stackbottom; + IF_IA64(bs_lo = BACKING_STORE_BASE;) + } + #if DEBUG_THREADS + GC_printf3("Stack for thread 0x%lx = [%lx,%lx)\n", + (unsigned long) p -> id, + (unsigned long) lo, (unsigned long) hi); + #endif + if (0 == lo) ABORT("GC_push_all_stacks: sp not set!\n"); +# ifdef STACK_GROWS_UP + /* We got them backwards! */ + GC_push_all_stack(hi, lo); +# else + GC_push_all_stack(lo, hi); +# endif +# ifdef IA64 + if (pthread_equal(p -> id, me)) { + GC_push_all_eager(bs_lo, bs_hi); + } else { + GC_push_all_stack(bs_lo, bs_hi); + } +# endif + } + } +} + +/* There seems to be a very rare thread stopping problem. To help us */ +/* debug that, we save the ids of the stopping thread. */ +pthread_t GC_stopping_thread; +int GC_stopping_pid; + +/* We hold the allocation lock. Suspend all threads that might */ +/* still be running. Return the number of suspend signals that */ +/* were sent. */ +int GC_suspend_all() +{ + int n_live_threads = 0; + int i; + GC_thread p; + int result; + pthread_t my_thread = pthread_self(); + + GC_stopping_thread = my_thread; /* debugging only. */ + GC_stopping_pid = getpid(); /* debugging only. */ + for (i = 0; i < THREAD_TABLE_SZ; i++) { + for (p = GC_threads[i]; p != 0; p = p -> next) { + if (p -> id != my_thread) { + if (p -> flags & FINISHED) continue; + if (p -> stop_info.last_stop_count == GC_stop_count) continue; + if (p -> thread_blocked) /* Will wait */ continue; + n_live_threads++; + #if DEBUG_THREADS + GC_printf1("Sending suspend signal to 0x%lx\n", p -> id); + #endif + + result = pthread_kill(p -> id, SIG_SUSPEND); + switch(result) { + case ESRCH: + /* Not really there anymore. Possible? */ + n_live_threads--; + break; + case 0: + break; + default: + ABORT("pthread_kill failed"); + } + } + } + } + return n_live_threads; +} + +/* Caller holds allocation lock. */ +void GC_stop_world() +{ + int i; + int n_live_threads; + int code; + + #if DEBUG_THREADS + GC_printf1("Stopping the world from 0x%lx\n", pthread_self()); + #endif + + /* Make sure all free list construction has stopped before we start. */ + /* No new construction can start, since free list construction is */ + /* required to acquire and release the GC lock before it starts, */ + /* and we have the lock. */ +# ifdef PARALLEL_MARK + GC_acquire_mark_lock(); + GC_ASSERT(GC_fl_builder_count == 0); + /* We should have previously waited for it to become zero. */ +# endif /* PARALLEL_MARK */ + ++GC_stop_count; + n_live_threads = GC_suspend_all(); + + if (GC_retry_signals) { + unsigned long wait_usecs = 0; /* Total wait since retry. */ +# define WAIT_UNIT 3000 +# define RETRY_INTERVAL 100000 + for (;;) { + int ack_count; + + sem_getvalue(&GC_suspend_ack_sem, &ack_count); + if (ack_count == n_live_threads) break; + if (wait_usecs > RETRY_INTERVAL) { + int newly_sent = GC_suspend_all(); + +# ifdef CONDPRINT + if (GC_print_stats) { + GC_printf1("Resent %ld signals after timeout\n", + newly_sent); + } +# endif + sem_getvalue(&GC_suspend_ack_sem, &ack_count); + if (newly_sent < n_live_threads - ack_count) { + WARN("Lost some threads during GC_stop_world?!\n",0); + n_live_threads = ack_count + newly_sent; + } + wait_usecs = 0; + } + usleep(WAIT_UNIT); + wait_usecs += WAIT_UNIT; + } + } + for (i = 0; i < n_live_threads; i++) { + if (0 != (code = sem_wait(&GC_suspend_ack_sem))) { + GC_err_printf1("Sem_wait returned %ld\n", (unsigned long)code); + ABORT("sem_wait for handler failed"); + } + } +# ifdef PARALLEL_MARK + GC_release_mark_lock(); +# endif + #if DEBUG_THREADS + GC_printf1("World stopped from 0x%lx\n", pthread_self()); + #endif + GC_stopping_thread = 0; /* debugging only */ +} + +/* Caller holds allocation lock, and has held it continuously since */ +/* the world stopped. */ +void GC_start_world() +{ + pthread_t my_thread = pthread_self(); + register int i; + register GC_thread p; + register int n_live_threads = 0; + register int result; + +# if DEBUG_THREADS + GC_printf0("World starting\n"); +# endif + + for (i = 0; i < THREAD_TABLE_SZ; i++) { + for (p = GC_threads[i]; p != 0; p = p -> next) { + if (p -> id != my_thread) { + if (p -> flags & FINISHED) continue; + if (p -> thread_blocked) continue; + n_live_threads++; + #if DEBUG_THREADS + GC_printf1("Sending restart signal to 0x%lx\n", p -> id); + #endif + + result = pthread_kill(p -> id, SIG_THR_RESTART); + switch(result) { + case ESRCH: + /* Not really there anymore. Possible? */ + n_live_threads--; + break; + case 0: + break; + default: + ABORT("pthread_kill failed"); + } + } + } + } + #if DEBUG_THREADS + GC_printf0("World started\n"); + #endif +} + +void GC_stop_init() { + struct sigaction act; + + if (sem_init(&GC_suspend_ack_sem, 0, 0) != 0) + ABORT("sem_init failed"); + + act.sa_flags = SA_RESTART; + if (sigfillset(&act.sa_mask) != 0) { + ABORT("sigfillset() failed"); + } +# ifdef NO_SIGNALS + if (sigdelset(&act.sa_mask, SIGINT) != 0 + || sigdelset(&act.sa_mask, SIGQUIT != 0) + || sigdelset(&act.sa_mask, SIGABRT != 0) + || sigdelset(&act.sa_mask, SIGTERM != 0)) { + ABORT("sigdelset() failed"); + } +# endif + + /* SIG_THR_RESTART is unmasked by the handler when necessary. */ + act.sa_handler = GC_suspend_handler; + if (sigaction(SIG_SUSPEND, &act, NULL) != 0) { + ABORT("Cannot set SIG_SUSPEND handler"); + } + + act.sa_handler = GC_restart_handler; + if (sigaction(SIG_THR_RESTART, &act, NULL) != 0) { + ABORT("Cannot set SIG_THR_RESTART handler"); + } + + /* Check for GC_RETRY_SIGNALS. */ + if (0 != GETENV("GC_RETRY_SIGNALS")) { + GC_retry_signals = TRUE; + } + if (0 != GETENV("GC_NO_RETRY_SIGNALS")) { + GC_retry_signals = FALSE; + } +# ifdef CONDPRINT + if (GC_print_stats && GC_retry_signals) { + GC_printf0("Will retry suspend signal if necessary.\n"); + } +# endif +} + +#endif diff --git a/boehm-gc/linux_threads.c b/boehm-gc/pthread_support.c index b63dfb7fd7e..b302817bfdf 100644 --- a/boehm-gc/linux_threads.c +++ b/boehm-gc/pthread_support.c @@ -26,13 +26,11 @@ * and thread support for some of the other Posix platforms; any changes * made here may need to be reflected there too. */ + /* DG/UX ix86 support <takis@xfree86.org> */ /* * Linux_threads.c now also includes some code to support HPUX and - * OSF1 (Compaq Tru64 Unix, really). The OSF1 support is not yet - * functional. The OSF1 code is based on Eric Benson's - * patch, though that was originally against hpux_irix_threads. The code - * here is completely untested. With 0.0000001% probability, it might - * actually work. + * OSF1 (Compaq Tru64 Unix, really). The OSF1 support is based on Eric Benson's + * patch. * * Eric also suggested an alternate basis for a lock implementation in * his code: @@ -46,22 +44,33 @@ * + # define GC_LOCK_TAKEN GC_allocate_lock */ -/* #define DEBUG_THREADS 1 */ +/*#define DEBUG_THREADS 1*/ +/*#define GC_ASSERTIONS*/ -/* ANSI C requires that a compilation unit contains something */ - -# include "gc.h" +# include "private/pthread_support.h" # if defined(GC_PTHREADS) && !defined(GC_SOLARIS_THREADS) \ - && !defined(GC_IRIX_THREADS) - -# include "private/gc_priv.h" + && !defined(GC_IRIX_THREADS) && !defined(GC_WIN32_THREADS) \ + && !defined(GC_AIX_THREADS) # if defined(GC_HPUX_THREADS) && !defined(USE_PTHREAD_SPECIFIC) \ && !defined(USE_HPUX_TLS) # define USE_HPUX_TLS # endif +# if (defined(GC_DGUX386_THREADS) || defined(GC_OSF1_THREADS) || \ + defined(GC_DARWIN_THREADS)) && !defined(USE_PTHREAD_SPECIFIC) +# define USE_PTHREAD_SPECIFIC +# endif + +# if defined(GC_DGUX386_THREADS) && !defined(_POSIX4A_DRAFT10_SOURCE) +# define _POSIX4A_DRAFT10_SOURCE 1 +# endif + +# if defined(GC_DGUX386_THREADS) && !defined(_USING_POSIX4A_DRAFT10) +# define _USING_POSIX4A_DRAFT10 1 +# endif + # ifdef THREAD_LOCAL_ALLOC # if !defined(USE_PTHREAD_SPECIFIC) && !defined(USE_HPUX_TLS) # include "private/specific.h" @@ -87,12 +96,29 @@ # include <unistd.h> # include <sys/mman.h> # include <sys/time.h> -# include <semaphore.h> -# include <signal.h> # include <sys/types.h> # include <sys/stat.h> # include <fcntl.h> +#if defined(GC_DARWIN_THREADS) +# include "private/darwin_semaphore.h" +#else +# include <semaphore.h> +#endif /* !GC_DARWIN_THREADS */ + +#if defined(GC_DARWIN_THREADS) +# include <sys/sysctl.h> +#endif /* GC_DARWIN_THREADS */ + + + +#if defined(GC_DGUX386_THREADS) +# include <sys/dg_sys_info.h> +# include <sys/_int_psem.h> + /* sem_t is an uint in DG/UX */ + typedef unsigned int sem_t; +#endif /* GC_DGUX386_THREADS */ + #ifndef __GNUC__ # define __inline__ #endif @@ -102,113 +128,31 @@ # define REAL_FUNC(f) __real_##f #else # define WRAP_FUNC(f) GC_##f -# define REAL_FUNC(f) f +# if !defined(GC_DGUX386_THREADS) +# define REAL_FUNC(f) f +# else /* GC_DGUX386_THREADS */ +# define REAL_FUNC(f) __d10_##f +# endif /* GC_DGUX386_THREADS */ # undef pthread_create -# undef pthread_sigmask +# if !defined(GC_DARWIN_THREADS) +# undef pthread_sigmask +# endif # undef pthread_join # undef pthread_detach +# if defined(GC_OSF1_THREADS) && defined(_PTHREAD_USE_MANGLED_NAMES_) \ + && !defined(_PTHREAD_USE_PTDNAM_) +/* Restore the original mangled names on Tru64 UNIX. */ +# define pthread_create __pthread_create +# define pthread_join __pthread_join +# define pthread_detach __pthread_detach +# endif #endif - void GC_thr_init(); -#if 0 -void GC_print_sig_mask() -{ - sigset_t blocked; - int i; - - if (pthread_sigmask(SIG_BLOCK, NULL, &blocked) != 0) - ABORT("pthread_sigmask"); - GC_printf0("Blocked: "); - for (i = 1; i <= MAXSIG; i++) { - if (sigismember(&blocked, i)) { GC_printf1("%ld ",(long) i); } - } - GC_printf0("\n"); -} -#endif - - -/* We use the allocation lock to protect thread-related data structures. */ - -/* The set of all known threads. We intercept thread creation and */ -/* joins. */ -/* Protected by allocation/GC lock. */ -/* Some of this should be declared volatile, but that's inconsistent */ -/* with some library routine declarations. */ -typedef struct GC_Thread_Rep { - struct GC_Thread_Rep * next; /* More recently allocated threads */ - /* with a given pthread id come */ - /* first. (All but the first are */ - /* guaranteed to be dead, but we may */ - /* not yet have registered the join.) */ - pthread_t id; - short flags; -# define FINISHED 1 /* Thread has exited. */ -# define DETACHED 2 /* Thread is intended to be detached. */ -# define MAIN_THREAD 4 /* True for the original thread only. */ - short thread_blocked; /* Protected by GC lock. */ - /* Treated as a boolean value. If set, */ - /* thread will acquire GC lock before */ - /* doing any pointer manipulations, and */ - /* has set its sp value. Thus it does */ - /* not need to be sent a signal to stop */ - /* it. */ - ptr_t stack_end; /* Cold end of the stack. */ - ptr_t stack_ptr; /* Valid only when stopped. */ -# ifdef IA64 - ptr_t backing_store_end; - ptr_t backing_store_ptr; -# endif - int signal; - void * status; /* The value returned from the thread. */ - /* Used only to avoid premature */ - /* reclamation of any data it might */ - /* reference. */ -# ifdef THREAD_LOCAL_ALLOC -# if CPP_WORDSZ == 64 && defined(ALIGN_DOUBLE) -# define GRANULARITY 16 -# define NFREELISTS 49 -# else -# define GRANULARITY 8 -# define NFREELISTS 65 -# endif - /* The ith free list corresponds to size i*GRANULARITY */ -# define INDEX_FROM_BYTES(n) ((ADD_SLOP(n) + GRANULARITY - 1)/GRANULARITY) -# define BYTES_FROM_INDEX(i) ((i) * GRANULARITY - EXTRA_BYTES) -# define SMALL_ENOUGH(bytes) (ADD_SLOP(bytes) <= \ - (NFREELISTS-1)*GRANULARITY) - ptr_t ptrfree_freelists[NFREELISTS]; - ptr_t normal_freelists[NFREELISTS]; -# ifdef GC_GCJ_SUPPORT - ptr_t gcj_freelists[NFREELISTS]; -# endif - /* Free lists contain either a pointer or a small count */ - /* reflecting the number of granules allocated at that */ - /* size. */ - /* 0 ==> thread-local allocation in use, free list */ - /* empty. */ - /* > 0, <= DIRECT_GRANULES ==> Using global allocation, */ - /* too few objects of this size have been */ - /* allocated by this thread. */ - /* >= HBLKSIZE => pointer to nonempty free list. */ - /* > DIRECT_GRANULES, < HBLKSIZE ==> transition to */ - /* local alloc, equivalent to 0. */ -# define DIRECT_GRANULES (HBLKSIZE/GRANULARITY) - /* Don't use local free lists for up to this much */ - /* allocation. */ -# endif -} * GC_thread; - -GC_thread GC_lookup_thread(pthread_t id); - static GC_bool parallel_initialized = FALSE; -# if defined(__GNUC__) - void GC_init_parallel() __attribute__ ((constructor)); -# else - void GC_init_parallel(); -# endif +void GC_init_parallel(); # if defined(THREAD_LOCAL_ALLOC) && !defined(DBG_HDRS_ALL) @@ -235,15 +179,16 @@ static void return_freelists(ptr_t *fl, ptr_t *gfl) nwords = i * (GRANULARITY/sizeof(word)); qptr = fl + i; q = *qptr; - if ((word)q < HBLKSIZE) continue; - if (gfl[nwords] == 0) { + if ((word)q >= HBLKSIZE) { + if (gfl[nwords] == 0) { gfl[nwords] = q; - } else { + } else { /* Concatenate: */ for (; (word)q >= HBLKSIZE; qptr = &(obj_link(q)), q = *qptr); GC_ASSERT(0 == q); *qptr = gfl[nwords]; gfl[nwords] = fl[i]; + } } /* Clear fl[i], since the thread structure may hang around. */ /* Do it in a way that is likely to trap if we access it. */ @@ -295,8 +240,11 @@ void GC_init_thread_local(GC_thread p) /* We hold the allocator lock. */ void GC_destroy_thread_local(GC_thread p) { - /* We currently only do this from the thread itself. */ - GC_ASSERT(GC_getspecific(GC_thread_key) == (void *)p); + /* We currently only do this from the thread itself or from */ + /* the fork handler for a child process. */ +# ifndef HANDLE_FORK + GC_ASSERT(GC_getspecific(GC_thread_key) == (void *)p); +# endif return_freelists(p -> ptrfree_freelists, GC_aobjfreelist); return_freelists(p -> normal_freelists, GC_objfreelist); # ifdef GC_GCJ_SUPPORT @@ -314,11 +262,12 @@ GC_PTR GC_local_malloc(size_t bytes) int index = INDEX_FROM_BYTES(bytes); ptr_t * my_fl; ptr_t my_entry; +# if defined(REDIRECT_MALLOC) && !defined(USE_PTHREAD_SPECIFIC) GC_key_t k = GC_thread_key; +# endif void * tsd; -# if defined(REDIRECT_MALLOC) && !defined(USE_PTHREAD_SPECIFIC) \ - || !defined(__GNUC__) +# if defined(REDIRECT_MALLOC) && !defined(USE_PTHREAD_SPECIFIC) if (EXPECT(0 == k, 0)) { /* This can happen if we get called when the world is */ /* being initialized. Whether we can actually complete */ @@ -362,13 +311,14 @@ GC_PTR GC_local_malloc_atomic(size_t bytes) ptr_t * my_fl = ((GC_thread)GC_getspecific(GC_thread_key)) -> ptrfree_freelists + index; ptr_t my_entry = *my_fl; + if (EXPECT((word)my_entry >= HBLKSIZE, 1)) { GC_PTR result = (GC_PTR)my_entry; *my_fl = obj_link(my_entry); return result; } else if ((word)my_entry - 1 < DIRECT_GRANULES) { *my_fl = my_entry + index + 1; - return GC_malloc_atomic(bytes); + return GC_malloc_atomic(bytes); } else { GC_generic_malloc_many(BYTES_FROM_INDEX(index), PTRFREE, my_fl); /* *my_fl is updated while the collector is excluded; */ @@ -416,10 +366,13 @@ GC_PTR GC_local_gcj_malloc(size_t bytes, /* A memory barrier is probably never needed, since the */ /* action of stopping this thread will cause prior writes */ /* to complete. */ + GC_ASSERT(((void * volatile *)result)[1] == 0); *(void * volatile *)result = ptr_to_struct_containing_descr; return result; } else if ((word)my_entry - 1 < DIRECT_GRANULES) { - *my_fl = my_entry + index + 1; + if (!GC_incremental) *my_fl = my_entry + index + 1; + /* In the incremental case, we always have to take this */ + /* path. Thus we leave the counter alone. */ return GC_gcj_malloc(bytes, ptr_to_struct_containing_descr); } else { GC_generic_malloc_many(BYTES_FROM_INDEX(index), GC_gcj_kind, my_fl); @@ -437,28 +390,6 @@ GC_PTR GC_local_gcj_malloc(size_t bytes, # endif /* !THREAD_LOCAL_ALLOC */ -/* - * We use signals to stop threads during GC. - * - * Suspended threads wait in signal handler for SIG_THR_RESTART. - * That's more portable than semaphores or condition variables. - * (We do use sem_post from a signal handler, but that should be portable.) - * - * The thread suspension signal SIG_SUSPEND is now defined in gc_priv.h. - * Note that we can't just stop a thread; we need it to save its stack - * pointer(s) and acknowledge. - */ - -#ifndef SIG_THR_RESTART -# if defined(GC_HPUX_THREADS) || defined(GC_OSF1_THREADS) -# define SIG_THR_RESTART _SIGRTMIN + 5 -# else -# define SIG_THR_RESTART SIGXCPU -# endif -#endif - -sem_t GC_suspend_ack_sem; - #if 0 /* To make sure that we're using LinuxThreads and not some other thread @@ -473,10 +404,6 @@ actually work for something else. void (*dummy_var_to_force_linux_threads)() = pthread_kill_other_threads_np; #endif /* 0 */ -#if defined(SPARC) || defined(IA64) - extern word GC_save_regs_in_stack(); -#endif - long GC_nprocs = 1; /* Number of processors. We may not have */ /* access to all of them, but this is as good */ /* a guess as any ... */ @@ -535,7 +462,7 @@ static void start_mark_threads() if (0 != pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED)) ABORT("pthread_attr_setdetachstate failed"); -# ifdef HPUX +# if defined(HPUX) || defined(GC_DGUX386_THREADS) /* Default stack size is usually too small: fix it. */ /* Otherwise marker threads or GC may run out of */ /* space. */ @@ -548,10 +475,10 @@ static void start_mark_threads() ABORT("pthread_attr_getstacksize failed\n"); if (old_size < MIN_STACK_SIZE) { if (pthread_attr_setstacksize(&attr, MIN_STACK_SIZE) != 0) - ABORT("pthread_attr_getstacksize failed\n"); + ABORT("pthread_attr_setstacksize failed\n"); } } -# endif /* HPUX */ +# endif /* HPUX || GC_DGUX386_THREADS */ # ifdef CONDPRINT if (GC_print_stats) { GC_printf1("Starting %ld marker threads\n", GC_markers - 1); @@ -573,96 +500,6 @@ static __inline__ void start_mark_threads() #endif /* !PARALLEL_MARK */ -void GC_suspend_handler(int sig) -{ - int dummy; - pthread_t my_thread = pthread_self(); - GC_thread me; - sigset_t all_sigs; - sigset_t old_sigs; - int i; - sigset_t mask; -# ifdef PARALLEL_MARK - word my_mark_no = GC_mark_no; - /* Marker can't proceed until we acknowledge. Thus this is */ - /* guaranteed to be the mark_no correspending to our */ - /* suspension, i.e. the marker can't have incremented it yet. */ -# endif - - if (sig != SIG_SUSPEND) ABORT("Bad signal in suspend_handler"); - -#if DEBUG_THREADS - GC_printf1("Suspending 0x%x\n", my_thread); -#endif - - me = GC_lookup_thread(my_thread); - /* The lookup here is safe, since I'm doing this on behalf */ - /* of a thread which holds the allocation lock in order */ - /* to stop the world. Thus concurrent modification of the */ - /* data structure is impossible. */ -# ifdef SPARC - me -> stack_ptr = (ptr_t)GC_save_regs_in_stack(); -# else - me -> stack_ptr = (ptr_t)(&dummy); -# endif -# ifdef IA64 - me -> backing_store_ptr = (ptr_t)GC_save_regs_in_stack(); -# endif - - /* Tell the thread that wants to stop the world that this */ - /* thread has been stopped. Note that sem_post() is */ - /* the only async-signal-safe primitive in LinuxThreads. */ - sem_post(&GC_suspend_ack_sem); - - /* Wait until that thread tells us to restart by sending */ - /* this thread a SIG_THR_RESTART signal. */ - /* SIG_THR_RESTART should be masked at this point. Thus there */ - /* is no race. */ - if (sigfillset(&mask) != 0) ABORT("sigfillset() failed"); - if (sigdelset(&mask, SIG_THR_RESTART) != 0) ABORT("sigdelset() failed"); -# ifdef NO_SIGNALS - if (sigdelset(&mask, SIGINT) != 0) ABORT("sigdelset() failed"); - if (sigdelset(&mask, SIGQUIT) != 0) ABORT("sigdelset() failed"); - if (sigdelset(&mask, SIGTERM) != 0) ABORT("sigdelset() failed"); - if (sigdelset(&mask, SIGABRT) != 0) ABORT("sigdelset() failed"); -# endif - do { - me->signal = 0; - sigsuspend(&mask); /* Wait for signal */ - } while (me->signal != SIG_THR_RESTART); - -#if DEBUG_THREADS - GC_printf1("Continuing 0x%x\n", my_thread); -#endif -} - -void GC_restart_handler(int sig) -{ - GC_thread me; - - if (sig != SIG_THR_RESTART) ABORT("Bad signal in suspend_handler"); - - /* Let the GC_suspend_handler() know that we got a SIG_THR_RESTART. */ - /* The lookup here is safe, since I'm doing this on behalf */ - /* of a thread which holds the allocation lock in order */ - /* to stop the world. Thus concurrent modification of the */ - /* data structure is impossible. */ - me = GC_lookup_thread(pthread_self()); - me->signal = SIG_THR_RESTART; - - /* - ** Note: even if we didn't do anything useful here, - ** it would still be necessary to have a signal handler, - ** rather than ignoring the signals, otherwise - ** the signals will not be delivered at all, and - ** will thus not interrupt the sigsuspend() above. - */ - -#if DEBUG_THREADS - GC_printf1("In GC_restart_handler for 0x%x\n", pthread_self()); -#endif -} - /* Defining INSTALL_LOOPING_SEGV_HANDLER causes SIGSEGV and SIGBUS to */ /* result in an infinite loop in a signal handler. This can be very */ /* useful for debugging, since (as of RH7) gdb still seems to have */ @@ -678,12 +515,15 @@ void GC_looping_handler(int sig) GC_bool GC_thr_initialized = FALSE; -# define THREAD_TABLE_SZ 128 /* Must be power of 2 */ volatile GC_thread GC_threads[THREAD_TABLE_SZ]; void GC_push_thread_structures GC_PROTO((void)) { GC_push_all((ptr_t)(GC_threads), (ptr_t)(GC_threads)+sizeof(GC_threads)); +# if defined(THREAD_LOCAL_ALLOC) && !defined(DBG_HDRS_ALL) + GC_push_all((ptr_t)(&GC_thread_key), + (ptr_t)(&GC_thread_key)+sizeof(&GC_thread_key)); +# endif } #ifdef THREAD_LOCAL_ALLOC @@ -714,13 +554,14 @@ void GC_mark_thread_local_free_lists(void) } #endif /* THREAD_LOCAL_ALLOC */ +static struct GC_Thread_Rep first_thread; + /* Add a thread to GC_threads. We assume it wasn't already there. */ /* Caller holds allocation lock. */ GC_thread GC_new_thread(pthread_t id) { int hv = ((word)id) % THREAD_TABLE_SZ; GC_thread result; - static struct GC_Thread_Rep first_thread; static GC_bool first_thread_used = FALSE; if (!first_thread_used) { @@ -796,174 +637,37 @@ GC_thread GC_lookup_thread(pthread_t id) return(p); } -/* There seems to be a very rare thread stopping problem. To help us */ -/* debug that, we save the ids of the stopping thread. */ -pthread_t GC_stopping_thread; -int GC_stopping_pid; - -/* Caller holds allocation lock. */ -void GC_stop_world() +#ifdef HANDLE_FORK +/* Remove all entries from the GC_threads table, except the */ +/* one for the current thread. We need to do this in the child */ +/* process after a fork(), since only the current thread */ +/* survives in the child. */ +void GC_remove_all_threads_but_me(void) { - pthread_t my_thread = pthread_self(); - register int i; - register GC_thread p; - register int n_live_threads = 0; - register int result; - - GC_stopping_thread = my_thread; /* debugging only. */ - GC_stopping_pid = getpid(); /* debugging only. */ - /* Make sure all free list construction has stopped before we start. */ - /* No new construction can start, since free list construction is */ - /* required to acquire and release the GC lock before it starts, */ - /* and we have the lock. */ -# ifdef PARALLEL_MARK - GC_acquire_mark_lock(); - GC_ASSERT(GC_fl_builder_count == 0); - /* We should have previously waited for it to become zero. */ -# endif /* PARALLEL_MARK */ - for (i = 0; i < THREAD_TABLE_SZ; i++) { - for (p = GC_threads[i]; p != 0; p = p -> next) { - if (p -> id != my_thread) { - if (p -> flags & FINISHED) continue; - if (p -> thread_blocked) /* Will wait */ continue; - n_live_threads++; - #if DEBUG_THREADS - GC_printf1("Sending suspend signal to 0x%x\n", p -> id); - #endif - result = pthread_kill(p -> id, SIG_SUSPEND); - switch(result) { - case ESRCH: - /* Not really there anymore. Possible? */ - n_live_threads--; - break; - case 0: - break; - default: - ABORT("pthread_kill failed"); - } - } - } - } - for (i = 0; i < n_live_threads; i++) { - if (0 != sem_wait(&GC_suspend_ack_sem)) - ABORT("sem_wait in handler failed"); - } -# ifdef PARALLEL_MARK - GC_release_mark_lock(); -# endif - #if DEBUG_THREADS - GC_printf1("World stopped 0x%x\n", pthread_self()); - #endif - GC_stopping_thread = 0; /* debugging only */ -} - -/* Caller holds allocation lock, and has held it continuously since */ -/* the world stopped. */ -void GC_start_world() -{ - pthread_t my_thread = pthread_self(); - register int i; - register GC_thread p; - register int n_live_threads = 0; - register int result; - -# if DEBUG_THREADS - GC_printf0("World starting\n"); -# endif - - for (i = 0; i < THREAD_TABLE_SZ; i++) { - for (p = GC_threads[i]; p != 0; p = p -> next) { - if (p -> id != my_thread) { - if (p -> flags & FINISHED) continue; - if (p -> thread_blocked) continue; - n_live_threads++; - #if DEBUG_THREADS - GC_printf1("Sending restart signal to 0x%x\n", p -> id); - #endif - result = pthread_kill(p -> id, SIG_THR_RESTART); - switch(result) { - case ESRCH: - /* Not really there anymore. Possible? */ - n_live_threads--; - break; - case 0: - break; - default: - ABORT("pthread_kill failed"); - } - } - } - } - #if DEBUG_THREADS - GC_printf0("World started\n"); - #endif -} - -# ifdef IA64 -# define IF_IA64(x) x -# else -# define IF_IA64(x) -# endif -/* We hold allocation lock. Should do exactly the right thing if the */ -/* world is stopped. Should not fail if it isn't. */ -void GC_push_all_stacks() -{ - int i; - GC_thread p; - ptr_t sp = GC_approx_sp(); - ptr_t lo, hi; - /* On IA64, we also need to scan the register backing store. */ - IF_IA64(ptr_t bs_lo; ptr_t bs_hi;) - pthread_t me = pthread_self(); - - if (!GC_thr_initialized) GC_thr_init(); - #if DEBUG_THREADS - GC_printf1("Pushing stacks from thread 0x%lx\n", (unsigned long) me); - #endif - for (i = 0; i < THREAD_TABLE_SZ; i++) { - for (p = GC_threads[i]; p != 0; p = p -> next) { - if (p -> flags & FINISHED) continue; - if (pthread_equal(p -> id, me)) { -# ifdef SPARC - lo = (ptr_t)GC_save_regs_in_stack(); -# else - lo = GC_approx_sp(); -# endif - IF_IA64(bs_hi = (ptr_t)GC_save_regs_in_stack();) + pthread_t self = pthread_self(); + int hv; + GC_thread p, next, me; + + for (hv = 0; hv < THREAD_TABLE_SZ; ++hv) { + me = 0; + for (p = GC_threads[hv]; 0 != p; p = next) { + next = p -> next; + if (p -> id == self) { + me = p; + p -> next = 0; } else { - lo = p -> stack_ptr; - IF_IA64(bs_hi = p -> backing_store_ptr;) +# ifdef THREAD_LOCAL_ALLOC + if (!(p -> flags & FINISHED)) { + GC_destroy_thread_local(p); + } +# endif /* THREAD_LOCAL_ALLOC */ + if (p != &first_thread) GC_INTERNAL_FREE(p); } - if ((p -> flags & MAIN_THREAD) == 0) { - hi = p -> stack_end; - IF_IA64(bs_lo = p -> backing_store_end); - } else { - /* The original stack. */ - hi = GC_stackbottom; - IF_IA64(bs_lo = BACKING_STORE_BASE;) - } - #if DEBUG_THREADS - GC_printf3("Stack for thread 0x%lx = [%lx,%lx)\n", - (unsigned long) p -> id, - (unsigned long) lo, (unsigned long) hi); - #endif - if (0 == lo) ABORT("GC_push_all_stacks: sp not set!\n"); -# ifdef STACK_GROWS_UP - /* We got them backwards! */ - GC_push_all_stack(hi, lo); -# else - GC_push_all_stack(lo, hi); -# endif -# ifdef IA64 - if (pthread_equal(p -> id, me)) { - GC_push_all_eager(bs_lo, bs_hi); - } else { - GC_push_all_stack(bs_lo, bs_hi); - } -# endif } + GC_threads[hv] = me; } } +#endif /* HANDLE_FORK */ #ifdef USE_PROC_FOR_LIBRARIES int GC_segment_is_thread_stack(ptr_t lo, ptr_t hi) @@ -999,14 +703,11 @@ int GC_get_nprocs() /* appears to be buggy in many cases. */ /* We look for lines "cpu<n>" in /proc/stat. */ # define STAT_BUF_SIZE 4096 -# if defined(GC_USE_LD_WRAP) -# define STAT_READ __real_read -# else -# define STAT_READ read -# endif +# define STAT_READ read + /* If read is wrapped, this may need to be redefined to call */ + /* the real one. */ char stat_buf[STAT_BUF_SIZE]; int f; - char c; word result = 1; /* Some old kernels only have a single "cpu nnnn ..." */ /* entry in /proc/stat. We identify those as */ @@ -1025,59 +726,144 @@ int GC_get_nprocs() if (cpu_no >= result) result = cpu_no + 1; } } + close(f); return result; } #endif /* GC_LINUX_THREADS */ -/* We hold the allocation lock. */ -void GC_thr_init() +/* We hold the GC lock. Wait until an in-progress GC has finished. */ +/* Repeatedly RELEASES GC LOCK in order to wait. */ +/* If wait_for_all is true, then we exit with the GC lock held and no */ +/* collection in progress; otherwise we just wait for the current GC */ +/* to finish. */ +extern GC_bool GC_collection_in_progress(); +void GC_wait_for_gc_completion(GC_bool wait_for_all) { - int dummy; - GC_thread t; - struct sigaction act; + if (GC_incremental && GC_collection_in_progress()) { + int old_gc_no = GC_gc_no; - if (GC_thr_initialized) return; - GC_thr_initialized = TRUE; + /* Make sure that no part of our stack is still on the mark stack, */ + /* since it's about to be unmapped. */ + while (GC_incremental && GC_collection_in_progress() + && (wait_for_all || old_gc_no == GC_gc_no)) { + ENTER_GC(); + GC_collect_a_little_inner(1); + EXIT_GC(); + UNLOCK(); + sched_yield(); + LOCK(); + } + } +} - if (sem_init(&GC_suspend_ack_sem, 0, 0) != 0) - ABORT("sem_init failed"); +#ifdef HANDLE_FORK +/* Procedures called before and after a fork. The goal here is to make */ +/* it safe to call GC_malloc() in a forked child. It's unclear that is */ +/* attainable, since the single UNIX spec seems to imply that one */ +/* should only call async-signal-safe functions, and we probably can't */ +/* quite guarantee that. But we give it our best shot. (That same */ +/* spec also implies that it's not safe to call the system malloc */ +/* between fork() and exec(). Thus we're doing no worse than it. */ + +/* Called before a fork() */ +void GC_fork_prepare_proc(void) +{ + /* Acquire all relevant locks, so that after releasing the locks */ + /* the child will see a consistent state in which monitor */ + /* invariants hold. Unfortunately, we can't acquire libc locks */ + /* we might need, and there seems to be no guarantee that libc */ + /* must install a suitable fork handler. */ + /* Wait for an ongoing GC to finish, since we can't finish it in */ + /* the (one remaining thread in) the child. */ + LOCK(); +# if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC) + GC_wait_for_reclaim(); +# endif + GC_wait_for_gc_completion(TRUE); +# if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC) + GC_acquire_mark_lock(); +# endif +} - act.sa_flags = SA_RESTART; - if (sigfillset(&act.sa_mask) != 0) { - ABORT("sigfillset() failed"); - } -# ifdef NO_SIGNALS - if (sigdelset(&act.sa_mask, SIGINT) != 0 - || sigdelset(&act.sa_mask, SIGQUIT != 0) - || sigdelset(&act.sa_mask, SIGABRT != 0) - || sigdelset(&act.sa_mask, SIGTERM != 0)) { - ABORT("sigdelset() failed"); - } +/* Called in parent after a fork() */ +void GC_fork_parent_proc(void) +{ +# if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC) + GC_release_mark_lock(); # endif + UNLOCK(); +} - /* SIG_THR_RESTART is unmasked by the handler when necessary. */ - act.sa_handler = GC_suspend_handler; - if (sigaction(SIG_SUSPEND, &act, NULL) != 0) { - ABORT("Cannot set SIG_SUSPEND handler"); - } +/* Called in child after a fork() */ +void GC_fork_child_proc(void) +{ + /* Clean up the thread table, so that just our thread is left. */ +# if defined(PARALLEL_MARK) || defined(THREAD_LOCAL_ALLOC) + GC_release_mark_lock(); +# endif + GC_remove_all_threads_but_me(); +# ifdef PARALLEL_MARK + /* Turn off parallel marking in the child, since we are probably */ + /* just going to exec, and we would have to restart mark threads. */ + GC_markers = 1; + GC_parallel = FALSE; +# endif /* PARALLEL_MARK */ + UNLOCK(); +} +#endif /* HANDLE_FORK */ - act.sa_handler = GC_restart_handler; - if (sigaction(SIG_THR_RESTART, &act, NULL) != 0) { - ABORT("Cannot set SIG_THR_RESTART handler"); - } -# ifdef INSTALL_LOOPING_SEGV_HANDLER - act.sa_handler = GC_looping_handler; - if (sigaction(SIGSEGV, &act, NULL) != 0 - || sigaction(SIGBUS, &act, NULL) != 0) { - ABORT("Cannot set SIGSEGV or SIGBUS looping handler"); - } -# endif /* INSTALL_LOOPING_SEGV_HANDLER */ +#if defined(GC_DGUX386_THREADS) +/* Return the number of processors, or i<= 0 if it can't be determined. */ +int GC_get_nprocs() +{ + /* <takis@XFree86.Org> */ + int numCpus; + struct dg_sys_info_pm_info pm_sysinfo; + int status =0; + + status = dg_sys_info((long int *) &pm_sysinfo, + DG_SYS_INFO_PM_INFO_TYPE, DG_SYS_INFO_PM_CURRENT_VERSION); + if (status < 0) + /* set -1 for error */ + numCpus = -1; + else + /* Active CPUs */ + numCpus = pm_sysinfo.idle_vp_count; + +# ifdef DEBUG_THREADS + GC_printf1("Number of active CPUs in this system: %d\n", numCpus); +# endif + return(numCpus); +} +#endif /* GC_DGUX386_THREADS */ + +/* We hold the allocation lock. */ +void GC_thr_init() +{ +# ifndef GC_DARWIN_THREADS + int dummy; +# endif + GC_thread t; + if (GC_thr_initialized) return; + GC_thr_initialized = TRUE; + +# ifdef HANDLE_FORK + /* Prepare for a possible fork. */ + pthread_atfork(GC_fork_prepare_proc, GC_fork_parent_proc, + GC_fork_child_proc); +# endif /* HANDLE_FORK */ /* Add the initial thread, so we can stop it. */ t = GC_new_thread(pthread_self()); - t -> stack_ptr = (ptr_t)(&dummy); +# ifdef GC_DARWIN_THREADS + t -> stop_info.mach_thread = mach_thread_self(); +# else + t -> stop_info.stack_ptr = (ptr_t)(&dummy); +# endif t -> flags = DETACHED | MAIN_THREAD; + GC_stop_init(); + /* Set GC_nprocs. */ { char * nprocs_string = GETENV("GC_NPROCS"); @@ -1088,10 +874,20 @@ void GC_thr_init() # if defined(GC_HPUX_THREADS) GC_nprocs = pthread_num_processors_np(); # endif -# if defined(GC_OSF1_THREADS) || defined(GC_FREEBSD_THREADS) +# if defined(GC_OSF1_THREADS) + GC_nprocs = sysconf(_SC_NPROCESSORS_ONLN); + if (GC_nprocs <= 0) GC_nprocs = 1; +# endif +# if defined(GC_FREEBSD_THREADS) GC_nprocs = 1; # endif -# if defined(GC_LINUX_THREADS) +# if defined(GC_DARWIN_THREADS) + int ncpus = 1; + size_t len = sizeof(ncpus); + sysctl((int[2]) {CTL_HW, HW_NCPU}, 2, &ncpus, &len, NULL, 0); + GC_nprocs = ncpus; +# endif +# if defined(GC_LINUX_THREADS) || defined(GC_DGUX386_THREADS) GC_nprocs = GC_get_nprocs(); # endif } @@ -1103,7 +899,14 @@ void GC_thr_init() # endif } else { # ifdef PARALLEL_MARK - GC_markers = GC_nprocs; + { + char * markers_string = GETENV("GC_MARKERS"); + if (markers_string != NULL) { + GC_markers = atoi(markers_string); + } else { + GC_markers = GC_nprocs; + } + } # endif } # ifdef PARALLEL_MARK @@ -1122,6 +925,8 @@ void GC_thr_init() # endif } else { GC_parallel = TRUE; + /* Disable true incremental collection, but generational is OK. */ + GC_time_limit = GC_TIME_UNLIMITED; } # endif } @@ -1129,14 +934,15 @@ void GC_thr_init() /* Perform all initializations, including those that */ /* may require allocation. */ -/* Called as constructor without allocation lock. */ +/* Called without allocation lock. */ /* Must be called before a second thread is created. */ /* Called without allocation lock. */ void GC_init_parallel() { if (parallel_initialized) return; parallel_initialized = TRUE; - /* GC_init() calls us back, so set flag first. */ + + /* GC_init() calls us back, so set flag first. */ if (!GC_is_initialized) GC_init(); /* If we are using a parallel marker, start the helper threads. */ # ifdef PARALLEL_MARK @@ -1151,6 +957,7 @@ void GC_init_parallel() } +#if !defined(GC_DARWIN_THREADS) int WRAP_FUNC(pthread_sigmask)(int how, const sigset_t *set, sigset_t *oset) { sigset_t fudged_set; @@ -1162,6 +969,7 @@ int WRAP_FUNC(pthread_sigmask)(int how, const sigset_t *set, sigset_t *oset) } return(REAL_FUNC(pthread_sigmask)(how, set, oset)); } +#endif /* !GC_DARWIN_THREADS */ /* Wrappers for functions that are likely to block for an appreciable */ /* length of time. Must be called in pairs, if at all. */ @@ -1175,25 +983,29 @@ void GC_start_blocking(void) { me = GC_lookup_thread(pthread_self()); GC_ASSERT(!(me -> thread_blocked)); # ifdef SPARC - me -> stack_ptr = (ptr_t)GC_save_regs_in_stack(); + me -> stop_info.stack_ptr = (ptr_t)GC_save_regs_in_stack(); # else - me -> stack_ptr = (ptr_t)GC_approx_sp(); +# ifndef GC_DARWIN_THREADS + me -> stop_info.stack_ptr = (ptr_t)GC_approx_sp(); +# endif # endif # ifdef IA64 me -> backing_store_ptr = (ptr_t)GC_save_regs_in_stack() + SP_SLOP; # endif /* Add some slop to the stack pointer, since the wrapped call may */ /* end up pushing more callee-save registers. */ +# ifndef GC_DARWIN_THREADS # ifdef STACK_GROWS_UP - me -> stack_ptr += SP_SLOP; + me -> stop_info.stack_ptr += SP_SLOP; # else - me -> stack_ptr -= SP_SLOP; + me -> stop_info.stack_ptr -= SP_SLOP; +# endif # endif me -> thread_blocked = TRUE; UNLOCK(); } -GC_end_blocking(void) { +void GC_end_blocking(void) { GC_thread me; LOCK(); /* This will block if the world is stopped. */ me = GC_lookup_thread(pthread_self()); @@ -1202,6 +1014,10 @@ GC_end_blocking(void) { UNLOCK(); } +#if defined(GC_DGUX386_THREADS) +#define __d10_sleep sleep +#endif /* GC_DGUX386_THREADS */ + /* A wrapper for the standard C sleep function */ int WRAP_FUNC(sleep) (unsigned int seconds) { @@ -1242,21 +1058,7 @@ void GC_thread_exit_proc(void *arg) && !defined(USE_HPUX_TLS) && !defined(DBG_HDRS_ALL) GC_remove_specific(GC_thread_key); # endif - if (GC_incremental && GC_collection_in_progress()) { - int old_gc_no = GC_gc_no; - - /* Make sure that no part of our stack is still on the mark stack, */ - /* since it's about to be unmapped. */ - while (GC_incremental && GC_collection_in_progress() - && old_gc_no == GC_gc_no) { - ENTER_GC(); - GC_collect_a_little_inner(1); - EXIT_GC(); - UNLOCK(); - sched_yield(); - LOCK(); - } - } + GC_wait_for_gc_completion(FALSE); UNLOCK(); } @@ -1331,8 +1133,12 @@ void * GC_start_routine(void * arg) # endif LOCK(); me = GC_new_thread(my_pthread); +#ifdef GC_DARWIN_THREADS + me -> stop_info.mach_thread = mach_thread_self(); +#else + me -> stop_info.stack_ptr = 0; +#endif me -> flags = si -> flags; - me -> stack_ptr = 0; /* me -> stack_end = GC_linux_stack_base(); -- currently (11/99) */ /* doesn't work because the stack base in /proc/self/stat is the */ /* one for the main thread. There is a strong argument that that's */ @@ -1340,12 +1146,14 @@ void * GC_start_routine(void * arg) # ifdef STACK_GROWS_DOWN me -> stack_end = (ptr_t)(((word)(&dummy) + (GC_page_size - 1)) & ~(GC_page_size - 1)); - me -> stack_ptr = me -> stack_end - 0x10; +# ifndef GC_DARWIN_THREADS + me -> stop_info.stack_ptr = me -> stack_end - 0x10; +# endif /* Needs to be plausible, since an asynchronous stack mark */ /* should not crash. */ # else me -> stack_end = (ptr_t)((word)(&dummy) & ~(GC_page_size - 1)); - me -> stack_ptr = me -> stack_end + 0x10; + me -> stop_info.stack_ptr = me -> stack_end + 0x10; # endif /* This is dubious, since we may be more than a page into the stack, */ /* and hence skip some of it, though it's not clear that matters. */ @@ -1374,7 +1182,6 @@ void * GC_start_routine(void * arg) GC_printf1("Finishing thread 0x%x\n", pthread_self()); #endif me -> status = result; - me -> flags |= FINISHED; pthread_cleanup_pop(1); /* Cleanup acquires lock, ensuring that we can't exit */ /* while a collection that thinks we're alive is trying to stop */ @@ -1388,16 +1195,19 @@ WRAP_FUNC(pthread_create)(pthread_t *new_thread, void *(*start_routine)(void *), void *arg) { int result; - GC_thread t; - pthread_t my_new_thread; int detachstate; word my_flags = 0; struct start_info * si; /* This is otherwise saved only in an area mmapped by the thread */ /* library, which isn't visible to the collector. */ + /* We resist the temptation to muck with the stack size here, */ + /* even if the default is unreasonably small. That's the client's */ + /* responsibility. */ + LOCK(); - si = (struct start_info *)GC_INTERNAL_MALLOC(sizeof(struct start_info), NORMAL); + si = (struct start_info *)GC_INTERNAL_MALLOC(sizeof(struct start_info), + NORMAL); UNLOCK(); if (!parallel_initialized) GC_init_parallel(); if (0 == si) return(ENOMEM); @@ -1406,9 +1216,25 @@ WRAP_FUNC(pthread_create)(pthread_t *new_thread, si -> arg = arg; LOCK(); if (!GC_thr_initialized) GC_thr_init(); +# ifdef GC_ASSERTIONS + { + int stack_size; + if (NULL == attr) { + pthread_attr_t my_attr; + pthread_attr_init(&my_attr); + pthread_attr_getstacksize(&my_attr, &stack_size); + } else { + pthread_attr_getstacksize(attr, &stack_size); + } + GC_ASSERT(stack_size >= (8*HBLKSIZE*sizeof(word))); + /* Our threads may need to do some work for the GC. */ + /* Ridiculously small threads won't work, and they */ + /* probably wouldn't work anyway. */ + } +# endif if (NULL == attr) { detachstate = PTHREAD_CREATE_JOINABLE; - } else { + } else { pthread_attr_getdetachstate(attr, &detachstate); } if (PTHREAD_CREATE_DETACHED == detachstate) my_flags |= DETACHED; @@ -1418,7 +1244,9 @@ WRAP_FUNC(pthread_create)(pthread_t *new_thread, GC_printf1("About to start new thread from thread 0x%X\n", pthread_self()); # endif + result = REAL_FUNC(pthread_create)(new_thread, attr, GC_start_routine, si); + # ifdef DEBUG_THREADS GC_printf1("Started thread 0x%X\n", *new_thread); # endif @@ -1426,13 +1254,16 @@ WRAP_FUNC(pthread_create)(pthread_t *new_thread, /* This also ensures that we hold onto si until the child is done */ /* with it. Thus it doesn't matter whether it is otherwise */ /* visible to the collector. */ - while (0 != sem_wait(&(si -> registered))) { - if (EINTR != errno) ABORT("sem_wait failed"); + if (0 == result) { + while (0 != sem_wait(&(si -> registered))) { + if (EINTR != errno) ABORT("sem_wait failed"); } - sem_destroy(&(si -> registered)); - LOCK(); - GC_INTERNAL_FREE(si); - UNLOCK(); + } + sem_destroy(&(si -> registered)); + LOCK(); + GC_INTERNAL_FREE(si); + UNLOCK(); + return(result); } @@ -1470,7 +1301,9 @@ WRAP_FUNC(pthread_create)(pthread_t *new_thread, void GC_pause() { int i; - volatile word dummy = 0; +# ifndef __GNUC__ + volatile word dummy = 0; +# endif for (i = 0; i < 10; ++i) { # ifdef __GNUC__ @@ -1509,6 +1342,7 @@ VOLATILE GC_bool GC_collecting = 0; void GC_generic_lock(pthread_mutex_t * lock) { +#ifndef NO_PTHREAD_TRYLOCK unsigned pause_length = 1; unsigned i; @@ -1526,6 +1360,7 @@ void GC_generic_lock(pthread_mutex_t * lock) ABORT("Unexpected error from pthread_mutex_trylock"); } } +#endif /* !NO_PTHREAD_TRYLOCK */ pthread_mutex_lock(lock); } @@ -1581,8 +1416,12 @@ yield: return; } # define SLEEP_THRESHOLD 12 - /* nanosleep(<= 2ms) just spins under Linux. We */ - /* want to be careful to avoid that behavior. */ + /* Under Linux very short sleeps tend to wait until */ + /* the current time quantum expires. On old Linux */ + /* kernels nanosleep(<= 2ms) just spins under Linux. */ + /* (Under 2.4, this happens only for real-time */ + /* processes.) We want to minimize both behaviors */ + /* here. */ if (i < SLEEP_THRESHOLD) { sched_yield(); } else { @@ -1599,14 +1438,17 @@ yield: } #else /* !USE_SPINLOCK */ - void GC_lock() { +#ifndef NO_PTHREAD_TRYLOCK if (1 == GC_nprocs || GC_collecting) { pthread_mutex_lock(&GC_allocate_ml); } else { GC_generic_lock(&GC_allocate_ml); } +#else /* !NO_PTHREAD_TRYLOCK */ + pthread_mutex_lock(&GC_allocate_ml); +#endif /* !NO_PTHREAD_TRYLOCK */ } #endif /* !USE_SPINLOCK */ diff --git a/boehm-gc/sparc_mach_dep.S b/boehm-gc/sparc_mach_dep.S new file mode 100644 index 00000000000..06a0f3b4673 --- /dev/null +++ b/boehm-gc/sparc_mach_dep.S @@ -0,0 +1,67 @@ +! SPARCompiler 3.0 and later apparently no longer handles +! asm outside functions. So we need a separate .s file +! This is only set up for SunOS 5, not SunOS 4. +! Assumes this is called before the stack contents are +! examined. + + .seg "text" + .globl GC_save_regs_in_stack + .globl GC_push_regs +GC_save_regs_in_stack: +GC_push_regs: +#if defined(__arch64__) || defined(__sparcv9) + save %sp,-128,%sp + flushw + ret + restore %sp,2047+128,%o0 +#else /* 32 bit SPARC */ + ta 0x3 ! ST_FLUSH_WINDOWS + mov %sp,%o0 + retl + nop +#endif /* 32 bit SPARC */ +.GC_save_regs_in_stack_end: + .size GC_save_regs_in_stack,.GC_save_regs_in_stack_end-GC_save_regs_in_stack + + + .globl GC_clear_stack_inner +GC_clear_stack_inner: +#if defined(__arch64__) || defined(__sparcv9) + mov %sp,%o2 ! Save sp + add %sp,2047-8,%o3 ! p = sp+bias-8 + add %o1,-2047-192,%sp ! Move sp out of the way, + ! so that traps still work. + ! Includes some extra words + ! so we can be sloppy below. +loop: + stx %g0,[%o3] ! *(long *)p = 0 + cmp %o3,%o1 + bgu,pt %xcc, loop ! if (p > limit) goto loop + add %o3,-8,%o3 ! p -= 8 (delay slot) + retl + mov %o2,%sp ! Restore sp., delay slot +#else /* 32 bit SPARC */ + mov %sp,%o2 ! Save sp + add %sp,-8,%o3 ! p = sp-8 + clr %g1 ! [g0,g1] = 0 + add %o1,-0x60,%sp ! Move sp out of the way, + ! so that traps still work. + ! Includes some extra words + ! so we can be sloppy below. +loop: + std %g0,[%o3] ! *(long long *)p = 0 + cmp %o3,%o1 + bgu loop ! if (p > limit) goto loop + add %o3,-8,%o3 ! p -= 8 (delay slot) + retl + mov %o2,%sp ! Restore sp., delay slot +#endif /* 32 bit SPARC */ +.GC_clear_stack_inner_end: + .size GC_clear_stack_inner,.GC_clear_stack_inner_end-GC_clear_stack_inner + + + + + + + |