diff options
author | Ivan Maidanski <ivmai@mail.ru> | 2018-11-07 23:34:04 +0300 |
---|---|---|
committer | Ivan Maidanski <ivmai@mail.ru> | 2018-11-07 23:34:04 +0300 |
commit | 93374170974aba0e9992c5acedb52d887f237a93 (patch) | |
tree | 35d345fc070dd3d5cbbc68b2dd60e886c7aad900 | |
parent | 36a6d79e182861a70c53a604e36bb34a8bad7bd1 (diff) | |
download | bdwgc-93374170974aba0e9992c5acedb52d887f237a93.tar.gz |
Use GC_WORD_MAX macro across all C source files
(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.
-rw-r--r-- | alloc.c | 12 | ||||
-rw-r--r-- | dyn_load.c | 4 | ||||
-rw-r--r-- | finalize.c | 2 | ||||
-rw-r--r-- | headers.c | 10 | ||||
-rw-r--r-- | include/private/gc_priv.h | 4 | ||||
-rw-r--r-- | include/private/thread_local_alloc.h | 2 | ||||
-rw-r--r-- | mark.c | 2 | ||||
-rw-r--r-- | os_dep.c | 4 | ||||
-rw-r--r-- | pthread_support.c | 2 | ||||
-rw-r--r-- | win32_threads.c | 4 |
10 files changed, 23 insertions, 23 deletions
@@ -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 */ @@ -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; @@ -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. */ @@ -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 */ diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 728e74ea..d6c782f2 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -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 < diff --git a/include/private/thread_local_alloc.h b/include/private/thread_local_alloc.h index 276de402..1ffa28b0 100644 --- a/include/private/thread_local_alloc.h +++ b/include/private/thread_local_alloc.h @@ -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 @@ -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 @@ -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; diff --git a/pthread_support.c b/pthread_support.c index 8a78efed..b301e720 100644 --- a/pthread_support.c +++ b/pthread_support.c @@ -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. */ diff --git a/win32_threads.c b/win32_threads.c index cec6729e..a2a8203e 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -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(); |