From: hboehm Date: Tue, 19 Jun 2007 18:27:41 +0000 (+0000) Subject: 2007-06-19 Hans Boehm X-Git-Tag: gc7_0~8 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=154eb2b0d0ca1ca5932cd597dc09f810b61ce946;p=gc 2007-06-19 Hans Boehm * alloc.c (GC_adj_bytes_allocd): Avoid (long) casts, fix comment. (GC_print_heap_sects): Use size_t instead of unsigned long. * thread_local_alloc.c (GC_lookup_thread): Define in the correct context. * win32_threads.c, include/gc_config_macros.h: The last of Romano Paolo Tenca's patch. Move stdint.h include to gc_config_macros.h. * include/gc_inline.h: Avoid gc_priv.h dependencies. * tests/test.c (check_heap_stats): Replace unsigned long with size_t. --- diff --git a/ChangeLog b/ChangeLog index 62dcb6ea..cd62f6d1 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2007-06-19 Hans Boehm + + * alloc.c (GC_adj_bytes_allocd): Avoid (long) casts, fix comment. + (GC_print_heap_sects): Use size_t instead of unsigned long. + * thread_local_alloc.c (GC_lookup_thread): Define in the correct + context. + * win32_threads.c, include/gc_config_macros.h: The last of Romano + Paolo Tenca's patch. Move stdint.h include to gc_config_macros.h. + * include/gc_inline.h: Avoid gc_priv.h dependencies. + * tests/test.c (check_heap_stats): Replace unsigned long with size_t. + 2007-06-12 Hans Boehm * aclocal.m4: Regenerate to update date. diff --git a/alloc.c b/alloc.c index 2c51873e..6a6c9982 100644 --- a/alloc.c +++ b/alloc.c @@ -166,14 +166,15 @@ static word min_bytes_allocd() } } -/* Return the number of words allocated, adjusted for explicit storage */ +/* Return the number of bytes allocated, adjusted for explicit storage */ /* management, etc.. This number is used in deciding when to trigger */ /* collections. */ word GC_adj_bytes_allocd(void) { signed_word result; signed_word expl_managed = - (long)GC_non_gc_bytes - (long)GC_non_gc_bytes_at_gc; + (signed_word)GC_non_gc_bytes + - (signed_word)GC_non_gc_bytes_at_gc; /* Don't count what was explicitly freed, or newly allocated for */ /* explicit management. Note that deallocating an explicitly */ @@ -801,7 +802,7 @@ void GC_print_heap_sects(void) GC_printf("Total heap size: %lu\n", (unsigned long) GC_heapsize); for (i = 0; i < GC_n_heap_sects; i++) { ptr_t start = GC_heap_sects[i].hs_start; - unsigned long len = (unsigned long) GC_heap_sects[i].hs_bytes; + size_t len = GC_heap_sects[i].hs_bytes; struct hblk *h; unsigned nbl = 0; diff --git a/include/gc_config_macros.h b/include/gc_config_macros.h index 4b37b1c7..3587ed60 100644 --- a/include/gc_config_macros.h +++ b/include/gc_config_macros.h @@ -132,6 +132,12 @@ # define __GC # ifndef _WIN32_WCE # include +# if defined(__MINGW32__) +# include + /* We mention uintptr_t. */ + /* Perhaps this should be included in pure msft environments */ + /* as well? */ +# endif # else /* ! _WIN32_WCE */ /* Yet more kluges for WinCE */ # include /* size_t is defined here */ diff --git a/include/gc_inline.h b/include/gc_inline.h index 95044fd4..da7e2e91 100644 --- a/include/gc_inline.h +++ b/include/gc_inline.h @@ -59,10 +59,10 @@ void *my_entry=*my_fl; \ void *next; \ \ - while (GC_EXPECT((word)my_entry \ + while (GC_EXPECT((GC_word)my_entry \ <= num_direct + GC_TINY_FREELISTS + 1, 0)) { \ /* Entry contains counter or NULL */ \ - if ((word)my_entry - 1 < num_direct) { \ + if ((GC_word)my_entry - 1 < num_direct) { \ /* Small counter value, not NULL */ \ *my_fl = (ptr_t)my_entry + granules + 1; \ result = default_expr; \ @@ -79,13 +79,13 @@ } \ } \ } \ - next = obj_link(my_entry); \ + next = *(void **)(my_entry); \ result = (void *)my_entry; \ *my_fl = next; \ init; \ PREFETCH_FOR_WRITE(next); \ GC_ASSERT(GC_size(result) >= bytes + EXTRA_BYTES); \ - GC_ASSERT((kind) == PTRFREE || ((word *)result)[1] == 0); \ + GC_ASSERT((kind) == PTRFREE || ((GC_word *)result)[1] == 0); \ out: ; \ } \ } diff --git a/tests/test.c b/tests/test.c index 6c7a6ce8..47cf99b5 100644 --- a/tests/test.c +++ b/tests/test.c @@ -1169,7 +1169,7 @@ void run_one_test() void check_heap_stats() { - unsigned long max_heap_sz; + size_t max_heap_sz; int i; int still_live; int late_finalize_count = 0; diff --git a/thread_local_alloc.c b/thread_local_alloc.c index 9acd3046..843700fe 100644 --- a/thread_local_alloc.c +++ b/thread_local_alloc.c @@ -130,7 +130,7 @@ void GC_destroy_thread_local(GC_tlfs p) extern char * GC_lookup_thread(pthread_t id); #endif -#if defined(GC_ASSERTIONS) && defined(GC_WIN32_THREADS) +#if defined(GC_ASSERTIONS) && !defined(GC_WIN32_THREADS) # include extern char * GC_lookup_thread(int id); #endif diff --git a/win32_threads.c b/win32_threads.c index fa62c568..ac579719 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -1,13 +1,6 @@ #include "private/gc_priv.h" -#if defined(GC_WIN32_THREADS) - -#if defined( _MINGW_VER ) || defined( __MINGW32__ ) -# include - /* We mention uintptr_t. */ - /* Perhaps this should be included in pure msft environments */ - /* as well? */ -#endif +#if defined(GC_WIN32_THREADS) #include @@ -47,15 +40,18 @@ # undef pthread_detach # undef dlopen -# define DEBUG_CYGWIN_THREADS 0 -# define DEBUG_WIN32_PTHREADS 0 -# define DEBUG_WIN32_PTHREADS_STACK 0 - -# if DEBUG_WIN32_PTHREADS_STACK - /* It seems that is not safe to call GC_printf() if any threads */ - /* are suspended while executing GC_printf(). */ +# ifdef DEBUG_THREADS +# ifdef CYGWIN32 +# define DEBUG_CYGWIN_THREADS 1 +# define DEBUG_WIN32_PTHREADS 0 +# else +# define DEBUG_WIN32_PTHREADS 1 +# define DEBUG_CYGWIN_THREADS 0 +# endif +# else +# define DEBUG_CYGWIN_THREADS 0 # define DEBUG_WIN32_PTHREADS 0 -# endif +# endif void * GC_pthread_start(void * arg); void GC_thread_exit_proc(void *arg); @@ -64,11 +60,23 @@ #else +# ifdef DEBUG_THREADS +# define DEBUG_WIN32_THREADS 1 +# else +# define DEBUG_WIN32_THREADS 0 +# endif + # undef CreateThread # undef ExitThread # undef _beginthreadex -# undef _beginthread # undef _endthreadex +# undef _beginthread +# ifdef DEBUG_THREADS +# define DEBUG_WIN32_THREADS 1 +# else +# define DEBUG_WIN32_THREADS 0 +# endif + # include /* For _beginthreadex, _endthreadex */ #endif @@ -290,6 +298,8 @@ extern LONG WINAPI GC_write_fault_handler(struct _EXCEPTION_POINTERS *exc_info); /* may be called repeatedly. */ #endif +GC_bool GC_in_thread_creation = FALSE; /* Protected by allocation lock. */ + /* * This may be called from DllMain, and hence operates under unusual * constraints. In particular, it must be lock-free if GC_win32_dll_threads @@ -356,11 +366,13 @@ static GC_thread GC_register_my_thread_inner(struct GC_stack_base *sb, me = dll_thread_table + i; } else /* Not using DllMain */ { GC_ASSERT(I_HOLD_LOCK()); + GC_in_thread_creation = TRUE; /* OK to collect from unknown thread. */ me = GC_new_thread(thread_id); + GC_in_thread_creation = FALSE; } # ifdef GC_PTHREADS - /* me can be NULL -> segfault */ - me -> pthread_id = pthread_self(); + /* me can be NULL -> segfault */ + me -> pthread_id = pthread_self(); # endif if (!DuplicateHandle(GetCurrentProcess(), @@ -704,7 +716,7 @@ void GC_suspend(GC_thread t) } /* Defined in misc.c */ -#ifndef GC_PTHREADS +#ifndef CYGWIN32 extern CRITICAL_SECTION GC_write_cs; #endif @@ -717,7 +729,7 @@ void GC_stop_world(void) GC_ASSERT(I_HOLD_LOCK()); GC_please_stop = TRUE; -# ifndef GC_PTHREADS +# ifndef CYGWIN32 EnterCriticalSection(&GC_write_cs); # endif if (GC_win32_dll_threads) { @@ -747,7 +759,7 @@ void GC_stop_world(void) } } } -# ifndef GC_PTHREADS +# ifndef CYGWIN32 LeaveCriticalSection(&GC_write_cs); # endif } @@ -869,11 +881,8 @@ void GC_push_stack_for(GC_thread thread) stack_min = GC_get_stack_min(thread->stack_base); if (sp >= stack_min && sp < thread->stack_base) { -# if DEBUG_CYGWIN_THREADS - GC_printf("Pushing thread from %p to %p for %d from %d\n", - sp, thread -> stack_base, thread -> id, me); -# endif -# if DEBUG_WIN32_PTHREADS_STACK +# if DEBUG_WIN32_PTHREADS || DEBUG_WIN32_THREADS \ + || DEBUG_CYGWIN_THREADS GC_printf("Pushing thread from %p to %p for 0x%x from 0x%x\n", sp, thread -> stack_base, thread -> id, me); # endif @@ -924,7 +933,8 @@ void GC_push_all_stacks(void) GC_log_printf("\n"); } } - if (!found_me) ABORT("Collecting from unknown thread."); + if (!found_me && !GC_in_thread_creation) + ABORT("Collecting from unknown thread."); } void GC_get_next_stack(char *start, char **lo, char **hi) @@ -982,6 +992,10 @@ void * GC_win32_start_inner(struct GC_stack_base *sb, LPVOID arg) void * ret; thread_args *args = (thread_args *)arg; +# if DEBUG_WIN32_THREADS + GC_printf("thread 0x%x starting...\n", GetCurrentThreadId()); +# endif + GC_register_my_thread(sb); /* This waits for an in-progress GC. */ /* Clear the thread entry even if we exit with an exception. */ @@ -1000,6 +1014,10 @@ void * GC_win32_start_inner(struct GC_stack_base *sb, LPVOID arg) } #endif /* __GNUC__ */ +# if DEBUG_WIN32_THREADS + GC_printf("thread 0x%x returned from start routine.\n", + GetCurrentThreadId()); +# endif return ret; } @@ -1021,6 +1039,9 @@ GC_API HANDLE WINAPI GC_CreateThread( /* make sure GC is initialized (i.e. main thread is attached, tls initialized) */ +# if DEBUG_WIN32_THREADS + GC_printf("About to create a thread from 0x%x\n", GetCurrentThreadId()); +# endif if (GC_win32_dll_threads) { return CreateThread(lpThreadAttributes, dwStackSize, lpStartAddress, lpParameter, dwCreationFlags, lpThreadId); @@ -1064,6 +1085,9 @@ uintptr_t GC_beginthreadex( if (!parallel_initialized) GC_init_parallel(); /* make sure GC is initialized (i.e. main thread is attached, tls initialized) */ +# if DEBUG_WIN32_THREADS + GC_printf("About to create a thread from 0x%x\n", GetCurrentThreadId()); +# endif if (GC_win32_dll_threads) { return _beginthreadex(security, stack_size, start_address, @@ -1077,11 +1101,12 @@ uintptr_t GC_beginthreadex( } /* set up thread arguments */ - args -> start = start_address; + args -> start = (LPTHREAD_START_ROUTINE)start_address; args -> param = arglist; GC_need_to_lock = TRUE; - thread_h = _beginthreadex(security, stack_size, GC_win32_start, + thread_h = _beginthreadex(security, stack_size, + (unsigned (__stdcall *) (void *))GC_win32_start, args, initflag, thrdaddr); if( thread_h == 0 ) GC_free( args ); return thread_h;