Use GC_WORD_MAX macro across all C source files
authorIvan Maidanski <ivmai@mail.ru>
Wed, 7 Nov 2018 20:34:04 +0000 (23:34 +0300)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 7 Nov 2018 20:34:04 +0000 (23:34 +0300)
(code refactoring)

* alloc.c (GC_collect_at_heapsize, GC_compute_heap_usage_percent,
GC_add_to_heap, GC_expand_hp_inner): Use GC_WORD_MAX instead of
(word)-1.
* dyn_load.c [DATASTART_IS_FUNC]
(GC_register_dynamic_libraries_dl_iterate_phdr): Likewise.
* finalize.c [KEEP_BACK_PTRS] (GC_notify_or_invoke_finalizers):
Likewise.
* headers.c (GC_install_counts): Likewise.
* include/private/thread_local_alloc.h [GC_GCJ_SUPPORT] (ERROR_FL):
Likewise.
* os_dep.c [NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES] (GC_find_limit):
Likewise.
* os_dep.c [MPROTECT_VDB && DARWIN] (GC_mprotect_thread): Likewise.
* pthread_support.c [PARALLEL_MARK] (GC_mark_thread): Likewise.
* win32_threads.c (ADDR_LIMIT): Likewise.
* win32_threads.c [PARALLEL_MARK] (GC_mark_thread): Likewise.
* alloc.c (GC_least_plausible_heap_addr): Use GC_WORD_MAX instead of
ONES macro.
* include/private/gc_priv.h [STACK_GROWS_DOWN] (MAKE_COOLER): Likewise.
* mark.c (GC_set_hdr_marks): Likewise.
* alloc.c (GC_WORD_MAX): Remove definition (in this file).
* headers.c (GC_install_counts): Reformat code.
* include/private/gc_priv.h (ONES): Rename to GC_WORD_MAX.

alloc.c
dyn_load.c
finalize.c
headers.c
include/private/gc_priv.h
include/private/thread_local_alloc.h
mark.c
os_dep.c
pthread_support.c
win32_threads.c

diff --git a/alloc.c b/alloc.c
index 86c9ac8..846879b 100644 (file)
--- a/alloc.c
+++ b/alloc.c
@@ -349,7 +349,7 @@ STATIC void GC_clear_a_few_frames(void)
 
 /* Heap size at which we need a collection to avoid expanding past      */
 /* limits used by blacklisting.                                         */
-STATIC word GC_collect_at_heapsize = (word)(-1);
+STATIC word GC_collect_at_heapsize = GC_WORD_MAX;
 
 /* Have we allocated enough to amortize a collection? */
 GC_INNER GC_bool GC_should_collect(void)
@@ -984,7 +984,7 @@ GC_INLINE int GC_compute_heap_usage_percent(void)
 {
   word used = GC_composite_in_use + GC_atomic_in_use;
   word heap_sz = GC_heapsize - GC_unmapped_bytes;
-  return used >= heap_sz ? 0 : used < ((word)-1) / 100 ?
+  return used >= heap_sz ? 0 : used < GC_WORD_MAX / 100 ?
                 (int)((used * 100) / heap_sz) : (int)(used / (heap_sz / 100));
 }
 
@@ -1267,7 +1267,7 @@ GC_INNER void GC_add_to_heap(struct hblk *p, size_t bytes)
      */
     GC_collect_at_heapsize += bytes;
     if (GC_collect_at_heapsize < GC_heapsize /* wrapped */)
-       GC_collect_at_heapsize = (word)(-1);
+       GC_collect_at_heapsize = GC_WORD_MAX;
 
     if ((word)p <= (word)GC_least_plausible_heap_addr
         || GC_least_plausible_heap_addr == 0) {
@@ -1307,7 +1307,7 @@ GC_INNER void GC_add_to_heap(struct hblk *p, size_t bytes)
   }
 #endif
 
-void * GC_least_plausible_heap_addr = (void *)ONES;
+void * GC_least_plausible_heap_addr = (void *)GC_WORD_MAX;
 void * GC_greatest_plausible_heap_addr = 0;
 
 GC_INLINE word GC_max(word x, word y)
@@ -1389,7 +1389,7 @@ GC_INNER GC_bool GC_expand_hp_inner(word n)
       GC_collect_at_heapsize =
          GC_heapsize + expansion_slop - 2*MAXHINCR*HBLKSIZE;
       if (GC_collect_at_heapsize < GC_heapsize /* wrapped */)
-         GC_collect_at_heapsize = (word)(-1);
+         GC_collect_at_heapsize = GC_WORD_MAX;
     if (GC_on_heap_resize)
       (*GC_on_heap_resize)(GC_heapsize);
 
@@ -1420,8 +1420,6 @@ GC_INNER unsigned GC_fail_count = 0;
 static word last_fo_entries = 0;
 static word last_bytes_finalized = 0;
 
-#define GC_WORD_MAX (~(word)0)
-
 /* Collect or expand heap in an attempt make the indicated number of    */
 /* free blocks available.  Should be called until the blocks are        */
 /* available (setting retry value to TRUE unless this is the first call */
index 6692321..1fc9308 100644 (file)
@@ -619,10 +619,10 @@ STATIC GC_bool GC_register_dynamic_libraries_dl_iterate_phdr(void)
   } else {
       ptr_t datastart, dataend;
 #     ifdef DATASTART_IS_FUNC
-        static ptr_t datastart_cached = (ptr_t)(word)-1;
+        static ptr_t datastart_cached = (ptr_t)GC_WORD_MAX;
 
         /* Evaluate DATASTART only once.  */
-        if (datastart_cached == (ptr_t)(word)-1) {
+        if (datastart_cached == (ptr_t)GC_WORD_MAX) {
           datastart_cached = DATASTART;
         }
         datastart = datastart_cached;
index 64a0ec2..978639e 100644 (file)
@@ -1326,7 +1326,7 @@ GC_INNER void GC_notify_or_invoke_finalizers(void)
 #       ifdef KEEP_BACK_PTRS
           long i;
           /* Stops when GC_gc_no wraps; that's OK.      */
-          last_back_trace_gc_no = (word)(-1);  /* disable others. */
+          last_back_trace_gc_no = GC_WORD_MAX;  /* disable others. */
           for (i = 0; i < GC_backtraces; ++i) {
               /* FIXME: This tolerates concurrent heap mutation,        */
               /* which may cause occasional mysterious results.         */
index 462da89..1b3b3eb 100644 (file)
--- a/headers.c
+++ b/headers.c
@@ -283,17 +283,19 @@ GC_INNER GC_bool GC_install_counts(struct hblk *h, size_t sz/* bytes */)
     struct hblk * hbp;
 
     for (hbp = h; (word)hbp < (word)h + sz; hbp += BOTTOM_SZ) {
-        if (!get_index((word) hbp)) return(FALSE);
-        if ((word)hbp > (~(word)0) - (word)BOTTOM_SZ * HBLKSIZE)
+        if (!get_index((word)hbp))
+            return FALSE;
+        if ((word)hbp > GC_WORD_MAX - (word)BOTTOM_SZ * HBLKSIZE)
             break; /* overflow of hbp+=BOTTOM_SZ is expected */
     }
-    if (!get_index((word)h + sz - 1)) return(FALSE);
+    if (!get_index((word)h + sz - 1))
+        return FALSE;
     for (hbp = h + 1; (word)hbp < (word)h + sz; hbp += 1) {
         word i = HBLK_PTR_DIFF(hbp, h);
 
         SET_HDR(hbp, (hdr *)(i > MAX_JUMP? MAX_JUMP : i));
     }
-    return(TRUE);
+    return TRUE;
 }
 
 /* Remove the header for block h */
index 728e74e..d6c782f 100644 (file)
@@ -263,13 +263,13 @@ typedef char * ptr_t;   /* A generic pointer to which we can add        */
 # include "gc_locks.h"
 #endif
 
-#define ONES ((word)(signed_word)(-1))
+#define GC_WORD_MAX (~(word)0)
 
 # ifdef STACK_GROWS_DOWN
 #   define COOLER_THAN >
 #   define HOTTER_THAN <
 #   define MAKE_COOLER(x,y) if ((word)((x) + (y)) > (word)(x)) {(x) += (y);} \
-                            else (x) = (ptr_t)ONES
+                            else (x) = (ptr_t)GC_WORD_MAX
 #   define MAKE_HOTTER(x,y) (x) -= (y)
 # else
 #   define COOLER_THAN <
index 276de40..1ffa28b 100644 (file)
@@ -95,7 +95,7 @@ typedef struct thread_local_freelists {
         /* Note: Preserve *_freelists names for some clients.   */
 # ifdef GC_GCJ_SUPPORT
     void * gcj_freelists[TINY_FREELISTS];
-#   define ERROR_FL ((void *)(word)-1)
+#   define ERROR_FL ((void *)GC_WORD_MAX)
         /* Value used for gcj_freelists[-1]; allocation is      */
         /* erroneous.                                           */
 # endif
diff --git a/mark.c b/mark.c
index b1d5902..0ee0a57 100644 (file)
--- a/mark.c
+++ b/mark.c
@@ -161,7 +161,7 @@ GC_INNER void GC_set_hdr_marks(hdr *hhdr)
       }
 #   else
       for (i = 0; i < divWORDSZ(n_marks + WORDSZ); ++i) {
-        hhdr -> hb_marks[i] = ONES;
+        hhdr -> hb_marks[i] = GC_WORD_MAX;
       }
 #   endif
 #   ifdef MARK_BIT_PER_OBJ
index 6eee61a..5900f9c 100644 (file)
--- a/os_dep.c
+++ b/os_dep.c
@@ -1029,7 +1029,7 @@ GC_INNER size_t GC_page_size = 0;
 
     ptr_t GC_find_limit(ptr_t p, GC_bool up)
     {
-        return GC_find_limit_with_bound(p, up, up ? (ptr_t)(word)(-1) : 0);
+        return GC_find_limit_with_bound(p, up, up ? (ptr_t)GC_WORD_MAX : 0);
     }
 # endif /* NEED_FIND_LIMIT || USE_PROC_FOR_LIBRARIES */
 
@@ -4042,7 +4042,7 @@ STATIC void *GC_mprotect_thread(void *arg)
   } msg;
   mach_msg_id_t id;
 
-  if ((word)arg == (word)-1) return 0; /* to make compiler happy */
+  if ((word)arg == GC_WORD_MAX) return 0; /* to prevent a compiler warning */
 # if defined(CPPCHECK)
     reply.data[0] = 0; /* to prevent "field unused" warnings */
     msg.data[0] = 0;
index 8a78efe..b301e72 100644 (file)
@@ -340,7 +340,7 @@ STATIC void * GC_mark_thread(void * id)
   word my_mark_no = 0;
   IF_CANCEL(int cancel_state;)
 
-  if ((word)id == (word)-1) return 0; /* to make compiler happy */
+  if ((word)id == GC_WORD_MAX) return 0; /* to prevent a compiler warning */
   DISABLE_CANCEL(cancel_state);
                          /* Mark threads are not cancellable; they      */
                          /* should be invisible to client.              */
index cec6729..a2a8203 100644 (file)
@@ -168,7 +168,7 @@ GC_API void GC_CALL GC_use_threads_discovery(void)
 
 STATIC DWORD GC_main_thread = 0;
 
-#define ADDR_LIMIT ((ptr_t)(word)-1)
+#define ADDR_LIMIT ((ptr_t)GC_WORD_MAX)
 
 struct GC_Thread_Rep {
   union {
@@ -1744,7 +1744,7 @@ GC_INNER void GC_get_next_stack(char *start, char *limit,
   {
     word my_mark_no = 0;
 
-    if ((word)id == (word)-1) return 0; /* to make compiler happy */
+    if ((word)id == GC_WORD_MAX) return 0; /* to prevent a compiler warning */
     marker_sp[(word)id] = GC_approx_sp();
 #   ifdef IA64
       marker_bsp[(word)id] = GC_save_regs_in_stack();