Skip to content

Commit

Permalink
Remove internal signed_word type
Browse files Browse the repository at this point in the history
(refactoring)

* allchblk.c (GC_unmap_old): Use `GC_signed_word` instead of
`signed_word`.
* alloc.c (GC_adj_bytes_allocd, GC_clear_fl_marks): Likewise.
* backgraph.c (back_edges_struct.height, backwards_height,
update_max_height): Likewise.
* dyn_load.c (sort_heap_sects): Likewise.
* gcj_mlc.c (GC_init_gcj_malloc_mp): Likewise.
* headers.c (GC_header_cache_miss, GC_apply_to_all_blocks,
GC_prev_block): Likewise.
* include/private/dbg_mlc.h (oh.oh_int): Likewise.
* include/private/gc_priv.h (_GC_arrays._num_unmapped_regions,
GC_bytes_found, GC_fl_builder_count): Likewise.
* mallocx.c (GC_generic_malloc_many): Likewise.
* mark.c (GC_mark_from, GC_wait_for_markers_init): Likewise.
* misc.c (fill_prof_stats, GC_init): Likewise.
* os_dep.c (GC_get_main_stack_base, GC_wince_get_mem, GC_dirty_init,
GC_handle_protected_regions_limit, GC_print_callers): Likewise.
* pthread_support.c (set_marker_thread_name,
GC_start_mark_threads_inner, GC_get_nprocs, GC_thr_init): Likewise.
* ptr_chck.c (GC_is_visible): Likewise.
* reclaim.c (GC_bytes_found, GC_fl_builder_count,
GC_disclaim_and_reclaim_or_free_small_block, GC_reclaim_block):
Likewise.
* typd_mlc.c (GC_add_ext_descriptor, GC_make_descriptor,
GC_calloc_typed_descr_s.alloc_lb, GC_calloc_typed_descr_s.descr_type,
GC_push_complex_descriptor): Likewise.
* win32_threads.c (GC_start_mark_threads_inner, GC_thr_init): Likewise.
* include/private/gc_priv.h (signed_word): Remove.
* include/private/gc_priv.h (WARN_PRIdPTR, _GC_arrays.hb_sz): Use
`GC_signed_word` instead of `signed_word` in comment.
  • Loading branch information
ivmai committed Nov 6, 2024
1 parent 7ef0dc2 commit a61cdae
Show file tree
Hide file tree
Showing 17 changed files with 79 additions and 80 deletions.
2 changes: 1 addition & 1 deletion allchblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ GC_unmap_old(unsigned threshold)
/* create too many unmapped regions, or if unmapping */
/* reduces the number of regions. */
int delta = calc_num_unmapped_regions_delta(h, hhdr);
signed_word regions = GC_num_unmapped_regions + delta;
GC_signed_word regions = GC_num_unmapped_regions + delta;

if (delta >= 0 && regions >= GC_UNMAPPED_REGIONS_SOFT_LIMIT) {
GC_COND_LOG_PRINTF("Unmapped regions limit reached!\n");
Expand Down
24 changes: 12 additions & 12 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,32 +408,32 @@ STATIC word GC_non_gc_bytes_at_gc = 0;
STATIC word
GC_adj_bytes_allocd(void)
{
signed_word result;
signed_word expl_managed
= (signed_word)GC_non_gc_bytes - (signed_word)GC_non_gc_bytes_at_gc;
GC_signed_word result;
GC_signed_word expl_managed = (GC_signed_word)GC_non_gc_bytes
- (GC_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 */
/* managed object should not alter result, assuming the client */
/* is playing by the rules. */
result = (signed_word)GC_bytes_allocd + (signed_word)GC_bytes_dropped
- (signed_word)GC_bytes_freed
+ (signed_word)GC_finalizer_bytes_freed - expl_managed;
if (result > (signed_word)GC_bytes_allocd) {
result = (GC_signed_word)GC_bytes_allocd + (GC_signed_word)GC_bytes_dropped
- (GC_signed_word)GC_bytes_freed
+ (GC_signed_word)GC_finalizer_bytes_freed - expl_managed;
if (result > (GC_signed_word)GC_bytes_allocd) {
/* Probably a client bug or unfortunate scheduling. */
result = (signed_word)GC_bytes_allocd;
result = (GC_signed_word)GC_bytes_allocd;
}
/* We count objects enqueued for finalization as though they had */
/* been reallocated this round. Finalization is user visible */
/* progress. And if we do not count this, we have stability */
/* problems for programs that finalize all objects. */
result += (signed_word)GC_bytes_finalized;
if (result < (signed_word)(GC_bytes_allocd >> 3)) {
result += (GC_signed_word)GC_bytes_finalized;
if (result < (GC_signed_word)(GC_bytes_allocd >> 3)) {
/* Always count at least 1/8 of the allocations. We don't want */
/* to collect too infrequently, since that would inhibit */
/* coalescing of free storage blocks. */
/* This also makes us partially robust against client bugs. */
result = (signed_word)(GC_bytes_allocd >> 3);
result = (GC_signed_word)(GC_bytes_allocd >> 3);
}
return (word)result;
}
Expand Down Expand Up @@ -1180,7 +1180,7 @@ GC_clear_fl_marks(ptr_t q)
hhdr->hb_n_marks = n_marks;
#endif
}
GC_bytes_found -= (signed_word)sz;
GC_bytes_found -= (GC_signed_word)sz;

q = (ptr_t)obj_link(q);
if (NULL == q)
Expand Down
6 changes: 3 additions & 3 deletions backgraph.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ typedef struct back_edges_struct {

/* Longest path through unreachable nodes to this node that we found */
/* using depth first search. */
signed_word height;
GC_signed_word height;
# define HEIGHT_UNKNOWN (-2)
# define HEIGHT_IN_PROGRESS (-1)

Expand Down Expand Up @@ -475,7 +475,7 @@ backwards_height(ptr_t p)
}
}

be->height = (signed_word)result;
be->height = (GC_signed_word)result;
be->height_gc_no = (unsigned short)GC_gc_no;
return result;
}
Expand Down Expand Up @@ -559,7 +559,7 @@ update_max_height(ptr_t p, size_t sz, word descr)
be = (back_edges *)CPTR_CLEAR_FLAGS(back_ptr, FLAG_MANY);
}
be->flags |= RETAIN;
be->height = (signed_word)p_height;
be->height = (GC_signed_word)p_height;
be->height_gc_no = (unsigned short)GC_gc_no;
}
if (p_height > GC_max_height) {
Expand Down
6 changes: 3 additions & 3 deletions dyn_load.c
Original file line number Diff line number Diff line change
Expand Up @@ -407,11 +407,11 @@ GC_register_dynamic_libraries(void)
static void
sort_heap_sects(struct HeapSect *base, size_t number_of_elements)
{
signed_word n = (signed_word)number_of_elements;
signed_word nsorted = 1;
GC_signed_word n = (GC_signed_word)number_of_elements;
GC_signed_word nsorted = 1;

while (nsorted < n) {
signed_word i;
GC_signed_word i;

while (nsorted < n
&& ADDR_LT(base[nsorted - 1].hs_start, base[nsorted].hs_start)) {
Expand Down
2 changes: 1 addition & 1 deletion gcj_mlc.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ GC_init_gcj_malloc_mp(unsigned mp_index, GC_mark_proc mp, size_t descr_offset)
} else {
GC_gcj_kind = (int)GC_new_kind_inner(
(void **)GC_gcjobjfreelist,
(((word)(-(signed_word)GC_GCJ_MARK_DESCR_OFFSET
(((word)(-(GC_signed_word)GC_GCJ_MARK_DESCR_OFFSET
- GC_INDIR_PER_OBJ_BIAS))
| GC_DS_PER_OBJECT),
FALSE, TRUE);
Expand Down
10 changes: 5 additions & 5 deletions headers.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ GC_header_cache_miss(ptr_t p, hdr_cache_entry *hce)

if (hhdr->hb_flags & IGNORE_OFF_PAGE)
return 0;
if (HBLK_IS_FREE(hhdr) || p - current >= (signed_word)hhdr->hb_sz) {
if (HBLK_IS_FREE(hhdr) || p - current >= (GC_signed_word)hhdr->hb_sz) {
GC_ADD_TO_BLACK_LIST_NORMAL(p, source);
/* The pointer is past the end of the block. */
return 0;
Expand Down Expand Up @@ -350,13 +350,13 @@ GC_apply_to_all_blocks(GC_walk_hblk_fn fn, void *client_data)
bottom_index *bi;

for (bi = GC_all_bottom_indices; bi != NULL; bi = bi->asc_link) {
signed_word j;
GC_signed_word j;

for (j = BOTTOM_SZ - 1; j >= 0;) {
hdr *hhdr = bi->index[j];

if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
j -= (signed_word)(hhdr != NULL ? ADDR(hhdr) : 1);
j -= (GC_signed_word)(hhdr != NULL ? ADDR(hhdr) : 1);
} else {
if (!HBLK_IS_FREE(hhdr)) {
GC_ASSERT(HBLK_ADDR(bi, j) == ADDR(hhdr->hb_block));
Expand Down Expand Up @@ -408,7 +408,7 @@ GC_INNER struct hblk *
GC_prev_block(struct hblk *h)
{
bottom_index *bi;
signed_word j = (ADDR(h) >> LOG_HBLKSIZE) & (BOTTOM_SZ - 1);
GC_signed_word j = (ADDR(h) >> LOG_HBLKSIZE) & (BOTTOM_SZ - 1);

GC_ASSERT(I_HOLD_READER_LOCK());
GET_BI(h, bi);
Expand All @@ -427,7 +427,7 @@ GC_prev_block(struct hblk *h)
if (NULL == hhdr) {
--j;
} else if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
j -= (signed_word)ADDR(hhdr);
j -= (GC_signed_word)ADDR(hhdr);
} else {
/* TODO: return hhdr -> hb_block instead */
return (struct hblk *)MAKE_CPTR(HBLK_ADDR(bi, j));
Expand Down
2 changes: 1 addition & 1 deletion include/private/dbg_mlc.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ typedef struct {
GC_hidden_pointer oh_bg_ptr;
#endif
const char *oh_string; /* object descriptor string (file name) */
signed_word oh_int; /* object descriptor integer (line number) */
GC_signed_word oh_int; /* object descriptor integer (line number) */
#ifdef NEED_CALLINFO
struct callinfo oh_ci[NFRAMES];
#endif
Expand Down
19 changes: 9 additions & 10 deletions include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@
#include "gc/gc_tiny_fl.h"

typedef GC_word word;
typedef GC_signed_word signed_word;

typedef int GC_bool;
#define TRUE 1
Expand Down Expand Up @@ -764,11 +763,11 @@ GC_API_PRIV GC_abort_func GC_on_abort;
GC_current_warn_proc("GC Warning: " msg, (GC_uintptr_t)(arg))
GC_EXTERN GC_warn_proc GC_current_warn_proc;

/* Print format type macro for decimal signed_word value passed WARN(). */
/* This could be redefined for Win64 or LLP64, but typically should */
/* not be done as the WARN format string is, possibly, processed on the */
/* client side, so non-standard print type modifiers (like MS "I64d") */
/* should be avoided here if possible. */
/* Print format type macro for decimal GC_signed_word value passed */
/* WARN(). This could be redefined for Win64 or LLP64, but typically */
/* should not be done as the WARN format string is, possibly, processed */
/* on the client side, so non-standard print type modifiers (like MS */
/* "I64d") should be avoided here if possible. */
/* TODO: Assuming sizeof(void*) == sizeof(long) or a little-endian machine. */
#ifndef WARN_PRIdPTR
# define WARN_PRIdPTR "ld"
Expand Down Expand Up @@ -1137,7 +1136,7 @@ struct hblkhdr {

/* If in use, size in bytes, of objects in the block. */
/* Otherwise, the size of the whole free block. We assume that */
/* this is convertible to signed_word without generating */
/* this is convertible to GC_signed_word without generating */
/* a negative result. We avoid generating free blocks larger */
/* than that. */
size_t hb_sz;
Expand Down Expand Up @@ -1485,7 +1484,7 @@ struct _GC_arrays {
#endif
#if defined(COUNT_UNMAPPED_REGIONS) && defined(USE_MUNMAP)
# define GC_num_unmapped_regions GC_arrays._num_unmapped_regions
signed_word _num_unmapped_regions;
GC_signed_word _num_unmapped_regions;
#else
# define GC_num_unmapped_regions 0
#endif
Expand Down Expand Up @@ -2815,7 +2814,7 @@ GC_EXTERN long GC_large_alloc_warn_interval; /* defined in misc.c */

/* Number of reclaimed bytes after garbage collection; protected by the */
/* allocator lock. */
GC_EXTERN signed_word GC_bytes_found;
GC_EXTERN GC_signed_word GC_bytes_found;

#ifndef GC_GET_HEAP_USAGE_NOT_NEEDED
/* Number of bytes reclaimed before this collection cycle; used for */
Expand Down Expand Up @@ -3122,7 +3121,7 @@ GC_INNER void GC_release_mark_lock(void);
GC_INNER void GC_notify_all_builder(void);
GC_INNER void GC_wait_for_reclaim(void);

GC_EXTERN signed_word GC_fl_builder_count; /* protected by the mark lock */
GC_EXTERN GC_signed_word GC_fl_builder_count; /* protected by the mark lock */

GC_INNER void GC_notify_all_marker(void);
GC_INNER void GC_wait_marker(void);
Expand Down
10 changes: 5 additions & 5 deletions mallocx.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,8 +314,8 @@ GC_generic_malloc_many(size_t lb_adjusted, int k, void **result)
hhdr->hb_last_reclaimed = (unsigned short)GC_gc_no;
#ifdef PARALLEL_MARK
if (GC_parallel) {
signed_word my_bytes_allocd_tmp
= (signed_word)AO_load(&GC_bytes_allocd_tmp);
GC_signed_word my_bytes_allocd_tmp
= (GC_signed_word)AO_load(&GC_bytes_allocd_tmp);
GC_ASSERT(my_bytes_allocd_tmp >= 0);
/* We only decrement it while holding the allocator */
/* lock. Thus, we cannot accidentally adjust it down */
Expand Down Expand Up @@ -345,19 +345,19 @@ GC_generic_malloc_many(size_t lb_adjusted, int k, void **result)
# ifdef THREAD_SANITIZER
GC_release_mark_lock();
LOCK();
GC_bytes_found += (signed_word)my_bytes_allocd;
GC_bytes_found += (GC_signed_word)my_bytes_allocd;
UNLOCK();
# else
/* The resulting GC_bytes_found may be inaccurate. */
GC_bytes_found += (signed_word)my_bytes_allocd;
GC_bytes_found += (GC_signed_word)my_bytes_allocd;
GC_release_mark_lock();
# endif
(void)GC_clear_stack(0);
return;
}
#endif
/* We also reclaimed memory, so we need to adjust that count. */
GC_bytes_found += (signed_word)my_bytes_allocd;
GC_bytes_found += (GC_signed_word)my_bytes_allocd;
GC_bytes_allocd += my_bytes_allocd;
goto out;
}
Expand Down
8 changes: 4 additions & 4 deletions mark.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,7 @@ GC_ATTR_NO_SANITIZE_ADDR_MEM_THREAD
GC_INNER mse *
GC_mark_from(mse *mark_stack_top, mse *mark_stack, mse *mark_stack_limit)
{
signed_word credit = HBLKSIZE; /* remaining credit for marking work */
GC_signed_word credit = HBLKSIZE; /* remaining credit for marking work */
word descr;
ptr_t current_p; /* pointer to current candidate ptr */
ptr_t q; /* the candidate pointer */
Expand Down Expand Up @@ -776,7 +776,7 @@ GC_mark_from(mse *mark_stack_top, mse *mark_stack, mse *mark_stack_limit)
}
#endif
descr &= ~(word)GC_DS_TAGS;
credit -= (signed_word)PTRS_TO_BYTES(CPP_PTRSZ / 2); /* guess */
credit -= (GC_signed_word)PTRS_TO_BYTES(CPP_PTRSZ / 2); /* guess */
for (; descr != 0; descr <<= 1, current_p += sizeof(ptr_t)) {
if ((descr & SIGNB) == 0)
continue;
Expand Down Expand Up @@ -833,7 +833,7 @@ GC_mark_from(mse *mark_stack_top, mse *mark_stack, mse *mark_stack_limit)
continue;
}
descr = *(word *)(type_descr
- ((signed_word)descr
- ((GC_signed_word)descr
+ (GC_INDIR_PER_OBJ_BIAS - GC_DS_PER_OBJECT)));
}
if (0 == descr) {
Expand Down Expand Up @@ -971,7 +971,7 @@ GC_INNER word GC_mark_no = 0;
GC_INNER void
GC_wait_for_markers_init(void)
{
signed_word count;
GC_signed_word count;

GC_ASSERT(I_HOLD_LOCK());
if (GC_markers_m1 == 0)
Expand Down
6 changes: 3 additions & 3 deletions misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ fill_prof_stats(struct GC_prof_stats_s *pstats)
pstats->non_gc_bytes = GC_non_gc_bytes;
pstats->gc_no = GC_gc_no; /* could be -1 */
# ifdef PARALLEL_MARK
pstats->markers_m1 = (word)((signed_word)GC_markers_m1);
pstats->markers_m1 = (word)((GC_signed_word)GC_markers_m1);
# else
/* A single marker. */
pstats->markers_m1 = 0;
Expand Down Expand Up @@ -1407,7 +1407,7 @@ GC_init(void)
GC_STATIC_ASSERT(sizeof(AO_t) == sizeof(word));
# endif
GC_STATIC_ASSERT(sizeof(ptrdiff_t) == sizeof(word));
GC_STATIC_ASSERT(sizeof(signed_word) == sizeof(word));
GC_STATIC_ASSERT(sizeof(GC_signed_word) == sizeof(word));
GC_STATIC_ASSERT(sizeof(word) * 8 == CPP_WORDSZ);
GC_STATIC_ASSERT(sizeof(ptr_t) * 8 == CPP_PTRSZ);
GC_STATIC_ASSERT(sizeof(ptr_t) == sizeof(GC_uintptr_t));
Expand All @@ -1421,7 +1421,7 @@ GC_init(void)
# endif
/* We no longer check for ((void*)(-1) > NULL) since all pointers */
/* are explicitly cast to word in every less/greater comparison. */
GC_STATIC_ASSERT((signed_word)(-1) < (signed_word)0);
GC_STATIC_ASSERT((GC_signed_word)(-1) < (GC_signed_word)0);
#endif
GC_STATIC_ASSERT(sizeof(struct hblk) == HBLKSIZE);
#ifndef THREADS
Expand Down
16 changes: 8 additions & 8 deletions os_dep.c
Original file line number Diff line number Diff line change
Expand Up @@ -1413,7 +1413,7 @@ GC_get_main_stack_base(void)
# endif
# if !defined(STACK_GROWS_UP) && !defined(CPPCHECK)
if (NULL == result)
result = MAKE_CPTR((signed_word)(-sizeof(ptr_t)));
result = MAKE_CPTR((GC_signed_word)(-sizeof(ptr_t)));
# endif
# endif
# if !defined(CPPCHECK)
Expand Down Expand Up @@ -2454,7 +2454,7 @@ GC_wince_get_mem(size_t bytes)

/* Try to find reserved, uncommitted pages. */
for (i = 0; i < GC_n_heap_bases; i++) {
if (((word)(-(signed_word)GC_heap_lengths[i])
if (((word)(-(GC_signed_word)GC_heap_lengths[i])
& (GC_sysinfo.dwAllocationGranularity - 1))
>= bytes) {
result = GC_heap_bases[i] + GC_heap_lengths[i];
Expand Down Expand Up @@ -3472,8 +3472,8 @@ GC_dirty_init(void)
GC_ASSERT(I_HOLD_LOCK());
# ifdef COUNT_PROTECTED_REGIONS
GC_ASSERT(GC_page_size != 0);
if ((signed_word)(GC_heapsize / (word)GC_page_size)
>= ((signed_word)GC_UNMAPPED_REGIONS_SOFT_LIMIT
if ((GC_signed_word)(GC_heapsize / (word)GC_page_size)
>= ((GC_signed_word)GC_UNMAPPED_REGIONS_SOFT_LIMIT
- GC_num_unmapped_regions)
* 2) {
GC_COND_LOG_PRINTF("Cannot turn on GC incremental mode"
Expand Down Expand Up @@ -3676,8 +3676,8 @@ GC_handle_protected_regions_limit(void)
/* incremental collection mode (based on mprotect) once the */
/* number of pages in the heap reaches that limit. */
if (GC_auto_incremental && !GC_GWW_AVAILABLE()
&& (signed_word)(GC_heapsize / (word)GC_page_size)
>= ((signed_word)GC_UNMAPPED_REGIONS_SOFT_LIMIT
&& (GC_signed_word)(GC_heapsize / (word)GC_page_size)
>= ((GC_signed_word)GC_UNMAPPED_REGIONS_SOFT_LIMIT
- GC_num_unmapped_regions)
* 2) {
GC_unprotect_all_heap();
Expand Down Expand Up @@ -5446,7 +5446,7 @@ GC_print_callers(struct callinfo info[NFRAMES])
/* but practically this has little sense because printing is done */
/* into a single output stream. */
GC_ASSERT(I_DONT_HOLD_LOCK());
reent_cnt = (int)(signed_word)AO_fetch_and_add1(&reentry_count);
reent_cnt = (int)(GC_signed_word)AO_fetch_and_add1(&reentry_count);
# else
static int reentry_count = 0;

Expand Down Expand Up @@ -5477,7 +5477,7 @@ GC_print_callers(struct callinfo info[NFRAMES])

if (j != 0)
GC_err_printf(", ");
GC_err_printf("%ld (%p)", (long)(signed_word)ADDR(p), p);
GC_err_printf("%ld (%p)", (long)(GC_signed_word)ADDR(p), p);
}
GC_err_printf("\n");
}
Expand Down
Loading

0 comments on commit a61cdae

Please sign in to comment.