2010-10-05 Ivan Maidanski <ivmai@mail.ru>
authorivmai <ivmai>
Tue, 5 Oct 2010 07:07:06 +0000 (07:07 +0000)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 26 Jul 2011 17:06:55 +0000 (21:06 +0400)
* finalize.c (GC_check_finalizer_nested): Change return type to
char pointer (instead of int pointer); use explicit cast for
GC_finalizer_nested assignment.
* pthread_support.c (GC_check_finalizer_nested): Ditto.
* win32_threads.c (GC_check_finalizer_nested): Ditto.
* finalize.c (GC_finalizer_nested): Change type to unsigned char.
* finalize.c (GC_notify_or_invoke_finalizers): Change type of
"pnested" local variable to char pointer.
* pthread_support.c (GC_do_blocking_inner,
GC_call_with_gc_active): Use explicit cast for "thread_blocked"
field assignment.
* win32_threads.c (GC_lookup_pthread): Use explicit cast for
"suspended" field assignment.
* win32_threads.c (GC_Thread_Rep): Use short type for
finalizer_skipped; use char type for finalizer_nested and flags
fields and reorder some fields (to minimize GC_Thread_Rep
structure size).
* include/private/pthread_support.h (GC_Thread_Rep): Ditto.
* win32_threads.c (GC_Thread_Rep): Use char type for suspended
field (instead of GC_bool).
* include/private/pthread_support.h (GC_Thread_Rep): Use char type
for thread_blocked field (instead of short).

ChangeLog
finalize.c
include/private/pthread_support.h
pthread_support.c
win32_threads.c

index 20baeb1..441e678 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,28 @@
+2010-10-05  Ivan Maidanski <ivmai@mail.ru>
+
+       * finalize.c (GC_check_finalizer_nested): Change return type to
+       char pointer (instead of int pointer); use explicit cast for
+       GC_finalizer_nested assignment.
+       * pthread_support.c (GC_check_finalizer_nested): Ditto.
+       * win32_threads.c (GC_check_finalizer_nested): Ditto.
+       * finalize.c (GC_finalizer_nested): Change type to unsigned char.
+       * finalize.c (GC_notify_or_invoke_finalizers): Change type of
+       "pnested" local variable to char pointer.
+       * pthread_support.c (GC_do_blocking_inner,
+       GC_call_with_gc_active): Use explicit cast for "thread_blocked"
+       field assignment.
+       * win32_threads.c (GC_lookup_pthread): Use explicit cast for
+       "suspended" field assignment.
+       * win32_threads.c (GC_Thread_Rep): Use short type for
+       finalizer_skipped; use char type for finalizer_nested and flags
+       fields and reorder some fields (to minimize GC_Thread_Rep
+       structure size).
+       * include/private/pthread_support.h (GC_Thread_Rep): Ditto.
+       * win32_threads.c (GC_Thread_Rep): Use char type for suspended
+       field (instead of GC_bool).
+       * include/private/pthread_support.h (GC_Thread_Rep): Use char type
+       for thread_blocked field (instead of short).
+
 2010-09-30  Ivan Maidanski <ivmai@mail.ru>
 
        * darwin_stop_world.c (GC_query_task_threads): New variable (or
index 294f80b..0683d3b 100644 (file)
@@ -495,18 +495,18 @@ GC_API void GC_CALL GC_register_finalizer_unreachable(void * obj,
   /* Defined in pthread_support.c or win32_threads.c.  Called with the  */
   /* allocation lock held.                                              */
   GC_INNER void GC_reset_finalizer_nested(void);
-  GC_INNER unsigned *GC_check_finalizer_nested(void);
+  GC_INNER unsigned char *GC_check_finalizer_nested(void);
 #else
   /* Global variables to minimize the level of recursion when a client  */
   /* finalizer allocates memory.                                        */
-  STATIC unsigned GC_finalizer_nested = 0;
+  STATIC unsigned char GC_finalizer_nested = 0;
   STATIC unsigned GC_finalizer_skipped = 0;
 
   /* Checks and updates the level of finalizers recursion.              */
   /* Returns NULL if GC_invoke_finalizers() should not be called by the */
   /* collector (to minimize the risk of a deep finalizers recursion),   */
   /* otherwise returns a pointer to GC_finalizer_nested.                */
-  STATIC unsigned *GC_check_finalizer_nested(void)
+  STATIC unsigned char *GC_check_finalizer_nested(void)
   {
     unsigned nesting_level = GC_finalizer_nested;
     if (nesting_level) {
@@ -516,7 +516,7 @@ GC_API void GC_CALL GC_register_finalizer_unreachable(void * obj,
       if (++GC_finalizer_skipped < (1U << nesting_level)) return NULL;
       GC_finalizer_skipped = 0;
     }
-    GC_finalizer_nested = nesting_level + 1;
+    GC_finalizer_nested = (unsigned char)(nesting_level + 1);
     return &GC_finalizer_nested;
   }
 #endif /* THREADS */
@@ -888,7 +888,7 @@ GC_INNER void GC_notify_or_invoke_finalizers(void)
     }
 
     if (!GC_finalize_on_demand) {
-      unsigned *pnested = GC_check_finalizer_nested();
+      unsigned char *pnested = GC_check_finalizer_nested();
       UNLOCK();
       /* Skip GC_invoke_finalizers() if nested */
       if (pnested != NULL) {
index 5dca50c..3c804a5 100644 (file)
@@ -49,7 +49,7 @@ typedef struct GC_Thread_Rep {
     /* Extra bookkeeping information the stopping code uses */
     struct thread_stop_info stop_info;
 
-    short flags;
+    unsigned char flags;
 #       define FINISHED 1       /* Thread has exited.   */
 #       define DETACHED 2       /* Thread is treated as detached.       */
                                 /* Thread may really be detached, or    */
@@ -62,13 +62,22 @@ typedef struct GC_Thread_Rep {
 #       define DISABLED_GC 8    /* Collections are disabled while the   */
                                 /* thread is exiting.                   */
 
-    short thread_blocked;       /* Protected by GC lock.                */
+    unsigned char 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.                                  */
+
+    unsigned short finalizer_skipped;
+    unsigned char finalizer_nested;
+                                /* Used by GC_check_finalizer_nested()  */
+                                /* to minimize the level of recursion   */
+                                /* when a client finalizer allocates    */
+                                /* memory (initially both are 0).       */
+
     ptr_t stack_end;            /* Cold end of the stack (except for    */
                                 /* main thread).                        */
 #   ifdef IA64
@@ -89,12 +98,6 @@ typedef struct GC_Thread_Rep {
                                 /* reason we need to intercept join     */
                                 /* and detach.                          */
 
-    unsigned finalizer_nested;
-    unsigned finalizer_skipped; /* Used by GC_check_finalizer_nested()  */
-                                /* to minimize the level of recursion   */
-                                /* when a client finalizer allocates    */
-                                /* memory (initially both are 0).       */
-
 #   ifdef THREAD_LOCAL_ALLOC
         struct thread_local_freelists tlfs;
 #   endif
index 7610ce2..6c20209 100644 (file)
@@ -547,7 +547,7 @@ GC_INNER void GC_reset_finalizer_nested(void)
 /* collector (to minimize the risk of a deep finalizers recursion),     */
 /* otherwise returns a pointer to the thread-local finalizer_nested.    */
 /* Called by GC_notify_or_invoke_finalizers() only (the lock is held).  */
-GC_INNER unsigned *GC_check_finalizer_nested(void)
+GC_INNER unsigned char *GC_check_finalizer_nested(void)
 {
   GC_thread me = GC_lookup_thread(pthread_self());
   unsigned nesting_level = me->finalizer_nested;
@@ -558,7 +558,7 @@ GC_INNER unsigned *GC_check_finalizer_nested(void)
     if (++me->finalizer_skipped < (1U << nesting_level)) return NULL;
     me->finalizer_skipped = 0;
   }
-  me->finalizer_nested = nesting_level + 1;
+  me->finalizer_nested = (unsigned char)(nesting_level + 1);
   return &me->finalizer_nested;
 }
 
@@ -1019,7 +1019,7 @@ GC_INNER void GC_do_blocking_inner(ptr_t data, void * context)
 #   ifdef IA64
         me -> backing_store_ptr = GC_save_regs_in_stack();
 #   endif
-    me -> thread_blocked = TRUE;
+    me -> thread_blocked = (unsigned char)TRUE;
     /* Save context here if we want to support precise stack marking */
     UNLOCK();
     d -> client_data = (d -> fn)(d -> client_data);
@@ -1054,7 +1054,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn,
         GC_stackbottom = (ptr_t)(&stacksect);
     }
 
-    if (me -> thread_blocked == FALSE) {
+    if (!me->thread_blocked) {
       /* We are not inside GC_do_blocking() - do nothing more.  */
       UNLOCK();
       return fn(client_data);
@@ -1084,7 +1084,7 @@ GC_API void * GC_CALL GC_call_with_gc_active(GC_fn_type fn,
 #   ifdef IA64
       me -> backing_store_ptr = stacksect.saved_backing_store_ptr;
 #   endif
-    me -> thread_blocked = TRUE;
+    me -> thread_blocked = (unsigned char)TRUE;
     me -> stop_info.stack_ptr = stacksect.saved_stack_ptr;
     UNLOCK();
 
index f3a4830..40f3915 100644 (file)
@@ -224,24 +224,26 @@ struct GC_Thread_Rep {
                                 /* GC_call_with_gc_active() of this     */
                                 /* thread.  May be NULL.                */
 
-  unsigned finalizer_nested;
-  unsigned finalizer_skipped;   /* Used by GC_check_finalizer_nested()  */
+  unsigned short finalizer_skipped;
+  unsigned char finalizer_nested;
+                                /* Used by GC_check_finalizer_nested()  */
                                 /* to minimize the level of recursion   */
                                 /* when a client finalizer allocates    */
                                 /* memory (initially both are 0).       */
 
-  GC_bool suspended;
+  unsigned char suspended; /* really of GC_bool type */
 
 # ifdef GC_PTHREADS
-    void *status; /* hold exit value until join in case it's a pointer */
-    pthread_t pthread_id;
-    short flags;                /* Protected by GC lock.                */
+    unsigned char flags;        /* Protected by GC lock.                */
 #   define FINISHED 1           /* Thread has exited.                   */
 #   define DETACHED 2           /* Thread is intended to be detached.   */
 #   define KNOWN_FINISHED(t) (((t) -> flags) & FINISHED)
+    pthread_t pthread_id;
+    void *status;  /* hold exit value until join in case it's a pointer */
 # else
 #   define KNOWN_FINISHED(t) 0
 # endif
+
 # ifdef THREAD_LOCAL_ALLOC
     struct thread_local_freelists tlfs;
 # endif
@@ -551,7 +553,7 @@ GC_INNER void GC_reset_finalizer_nested(void)
 /* otherwise returns a pointer to the thread-local finalizer_nested.    */
 /* Called by GC_notify_or_invoke_finalizers() only (the lock is held).  */
 /* GC_check_finalizer_nested() is the same as in pthread_support.c.     */
-GC_INNER unsigned *GC_check_finalizer_nested(void)
+GC_INNER unsigned char *GC_check_finalizer_nested(void)
 {
   GC_thread me = GC_lookup_thread_inner(GetCurrentThreadId());
   unsigned nesting_level = me->finalizer_nested;
@@ -562,7 +564,7 @@ GC_INNER unsigned *GC_check_finalizer_nested(void)
     if (++me->finalizer_skipped < (1U << nesting_level)) return NULL;
     me->finalizer_skipped = 0;
   }
-  me->finalizer_nested = nesting_level + 1;
+  me->finalizer_nested = (unsigned char)(nesting_level + 1);
   return &me->finalizer_nested;
 }
 
@@ -974,7 +976,7 @@ STATIC void GC_suspend(GC_thread t)
     if (SuspendThread(t -> handle) == (DWORD)-1)
       ABORT("SuspendThread failed");
 # endif /* !MSWINCE */
-  t -> suspended = TRUE;
+  t -> suspended = (unsigned char)TRUE;
 # if defined(MPROTECT_VDB)
     AO_CLEAR(&GC_fault_handler_lock);
 # endif