]> granicus.if.org Git - gc/commitdiff
2007-06-19 Hans Boehm <Hans.Boehm@hp.com>
authorhboehm <hboehm>
Tue, 19 Jun 2007 18:27:41 +0000 (18:27 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:40 +0000 (21:06 +0400)
* 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.

ChangeLog
alloc.c
include/gc_config_macros.h
include/gc_inline.h
tests/test.c
thread_local_alloc.c
win32_threads.c

index 62dcb6ea972e73de3463be34dea40ab8356c68ad..cd62f6d11536d7acc5898f5283c191a6ece6d727 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2007-06-19  Hans Boehm <Hans.Boehm@hp.com>
+
+       * 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 <Hans.Boehm@hp.com>
 
        * aclocal.m4: Regenerate to update date.
diff --git a/alloc.c b/alloc.c
index 2c51873ecbc2a99354d9f2284ea163aa4d5f393c..6a6c9982cbdd7feb684f18c3056007e4a402a124 100644 (file)
--- 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;
         
index 4b37b1c7ba777aaba6d9e95745093d96af494859..3587ed60093284cbf15cedee8a37ab27fff61545 100644 (file)
 # define __GC
 # ifndef _WIN32_WCE
 #   include <stddef.h>
+#   if defined(__MINGW32__)
+#     include <stdint.h>
+      /* 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 <stdlib.h>         /* size_t is defined here */
index 95044fd4e82d2720c6325dded617bab686b10db6..da7e2e91f020e8d120506f42c5493cf1e6f1734b 100644 (file)
         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; \
                } \
            } \
         } \
-        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: ; \
    } \
 }
index 6c7a6ce89438e3b2a1bd9cf9f590afddfbaa4432..47cf99b596701dd49f54a87c43b9e5d3f4f51deb 100644 (file)
@@ -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;
index 9acd3046db269df74398f6a14a7d23adb73032e5..843700fe8ad82c5fcf32cc65ce92939145c053b8 100644 (file)
@@ -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 <pthread.h>
   extern char * GC_lookup_thread(int id);
 #endif
index fa62c568edbc4294c410b07f6f7dea5036935ffd..ac579719000cf38edfee2d4f411facf0faae74be 100644 (file)
@@ -1,13 +1,6 @@
 #include "private/gc_priv.h"
 
-#if defined(GC_WIN32_THREADS) 
-
-#if defined( _MINGW_VER ) || defined( __MINGW32__ )
-# include <stdint.h>
-       /* We mention uintptr_t.                                        */
-       /* Perhaps this should be included in pure msft environments    */
-       /* as well?                                                     */
-#endif
+#if defined(GC_WIN32_THREADS)
 
 #include <windows.h>
 
 # 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);
 
 #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 <process.h>  /* 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;