From 2c5ab1802c1d530829670037a111a786c5e9193e Mon Sep 17 00:00:00 2001 From: ivmai Date: Sun, 1 Nov 2009 09:44:56 +0000 Subject: [PATCH] 2009-11-01 Ivan Maidanski * alloc.c (min_bytes_allocd): Use GC_stackbottom value to compute stack_size even if THREADS. * doc/README.macros (DEBUG_THREADS): Document. * pthread_support.c (DEBUG_THREADS): Remove the commented out definition. * win32_threads.c (DEBUG_WIN32_THREADS): Remove duplicate definition. * win32_threads.c: Include errno.h (except for WinCE). * win32_threads.c (GC_win32_start_inner): Copy "start" and "param" to local variables, and free "arg" parameter before "start" invocation. * win32_threads.c (GC_beginthreadex): Set errno to EAGAIN on error (instead of calling SetLastError(ERROR_NOT_ENOUGH_MEMORY)). * win32_threads.c (GC_beginthreadex): Return 0 on error (instead of -1). --- ChangeLog | 20 +++++++++++++++++++- alloc.c | 18 +++++++++++------- doc/README.macros | 3 +++ pthread_support.c | 2 -- win32_threads.c | 25 +++++++++++++------------ 5 files changed, 46 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8c66c142..b4ab4d9a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,21 @@ +2009-11-01 Ivan Maidanski + + * alloc.c (min_bytes_allocd): Use GC_stackbottom value to compute + stack_size even if THREADS. + * doc/README.macros (DEBUG_THREADS): Document. + * pthread_support.c (DEBUG_THREADS): Remove the commented out + definition. + * win32_threads.c (DEBUG_WIN32_THREADS): Remove duplicate + definition. + * win32_threads.c: Include errno.h (except for WinCE). + * win32_threads.c (GC_win32_start_inner): Copy "start" and "param" + to local variables, and free "arg" parameter before "start" + invocation. + * win32_threads.c (GC_beginthreadex): Set errno to EAGAIN on error + (instead of calling SetLastError(ERROR_NOT_ENOUGH_MEMORY)). + * win32_threads.c (GC_beginthreadex): Return 0 on error (instead + of -1). + 2009-10-23 Ivan Maidanski * darwin_stop_world.c (GC_darwin_register_mach_handler_thread): @@ -4075,7 +4093,7 @@ * cord/cord.am, tests/tests.am: Add better library dependencies. Remove now unnecessary dependencies. * Makefile.in: Regenerate. - * include/gc.h (GC_begin_thread_ex, GC_endthreadex, GC_ExitThread): + * include/gc.h (GC_beginthreadex, GC_endthreadex, GC_ExitThread): Move to define on all Windows platforms. (_beginthread): define to generate error if used. diff --git a/alloc.c b/alloc.c index 3efbde7f..56d565a9 100644 --- a/alloc.c +++ b/alloc.c @@ -190,13 +190,9 @@ GC_API GC_stop_func GC_CALL GC_get_stop_func(void) /* collections to amortize the collection cost. */ static word min_bytes_allocd(void) { -# ifdef THREADS - /* We punt, for now. */ - signed_word stack_size = 10000; -# else - int dummy; - signed_word stack_size = (ptr_t)(&dummy) - GC_stackbottom; -# endif + int dummy; + signed_word stack_size = (ptr_t)(&dummy) - GC_stackbottom; + word total_root_size; /* includes double stack size, */ /* since the stack is expensive */ /* to scan. */ @@ -204,6 +200,14 @@ static word min_bytes_allocd(void) /* during normal GC. */ if (stack_size < 0) stack_size = -stack_size; + +# ifdef THREADS + if (GC_need_to_lock) { + /* We are multi-threaded. */ + if (stack_size < 10000) stack_size = 10000; /* We punt, for now. */ + } +# endif + total_root_size = 2 * stack_size + GC_root_size; scan_size = 2 * GC_composite_in_use + GC_atomic_in_use/4 + total_root_size; diff --git a/doc/README.macros b/doc/README.macros index dcea97c9..74e3247d 100644 --- a/doc/README.macros +++ b/doc/README.macros @@ -205,6 +205,9 @@ IGNORE_FREE Turns calls to free into a no-op. Only useful with NO_DEBUGGING Removes GC_dump and the debugging routines it calls. Reduces code size slightly at the expense of debuggability. +DEBUG_THREADS Turn on printing additional thread-support debugging + information. + JAVA_FINALIZATION Makes it somewhat safer to finalize objects out of order by specifying a nonstandard finalization mark procedure (see finalize.c). Objects reachable from finalizable objects will be marked diff --git a/pthread_support.c b/pthread_support.c index 636c3932..84aa89fe 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -46,8 +46,6 @@ #if defined(GC_PTHREADS) && !defined(GC_WIN32_THREADS) -/*#define DEBUG_THREADS 1*/ - # include # include # include diff --git a/win32_threads.c b/win32_threads.c index 6fe4febe..1f771cbb 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -64,12 +64,6 @@ #else -# ifdef DEBUG_THREADS -# define DEBUG_WIN32_THREADS 1 -# else -# define DEBUG_WIN32_THREADS 0 -# endif - # undef CreateThread # undef ExitThread # undef _beginthreadex @@ -89,6 +83,7 @@ # endif # else # include /* For _beginthreadex, _endthreadex */ +# include /* for errno, EAGAIN */ # endif #endif @@ -1939,7 +1934,8 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, void *arg) { void * ret; - thread_args *args = (thread_args *)arg; + LPTHREAD_START_ROUTINE start = ((thread_args *)arg)->start; + LPVOID param = ((thread_args *)arg)->param; GC_register_my_thread(sb); /* This waits for an in-progress GC. */ @@ -1947,6 +1943,8 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, GC_printf("thread 0x%x starting...\n", (unsigned)GetCurrentThreadId()); # endif + GC_free(arg); + /* Clear the thread entry even if we exit with an exception. */ /* This is probably pointless, since an uncaught exception is */ /* supposed to result in the process being killed. */ @@ -1954,14 +1952,13 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, __try # endif { - ret = (void *)(word)args->start(args->param); + ret = (void *)(word)(*start)(param); } # ifndef __GNUC__ __finally # endif { GC_unregister_my_thread(); - GC_free(args); } # if DEBUG_WIN32_THREADS @@ -2047,10 +2044,14 @@ GC_INNER void GC_get_next_stack(char *start, char *limit, arglist, initflag, thrdaddr); } else { args = GC_malloc_uncollectable(sizeof(thread_args)); - /* Handed off to and deallocated by child thread. */ + /* Handed off to and deallocated by child thread. */ if (0 == args) { - SetLastError(ERROR_NOT_ENOUGH_MEMORY); - return (GC_uintptr_t)(-1L); + /* MSDN docs say _beginthreadex() returns 0 on error and sets */ + /* errno to either EAGAIN (too many threads) or EINVAL (the */ + /* argument is invalid or the stack size is incorrect), so we */ + /* set errno to EAGAIN on "not enough memory". */ + errno = EAGAIN; + return 0; } /* set up thread arguments */ -- 2.40.0