From e794f1e7a4ef7ebd14621473420010c0db210235 Mon Sep 17 00:00:00 2001 From: Ivan Maidanski Date: Thu, 8 Feb 2018 11:41:45 +0300 Subject: [PATCH] Change type of hb_sz field (of hblkhdr) from size_t to word This is needed to make the size of hb_sz to be the same as of AO_t. * allchblk.c [USE_MUNMAP] (GC_unmap_old): Cast hhdr->hb_sz to size_t when passed to GC_unmap(). * allchblk.c (GC_allochblk_nth): Cast hhdr->hb_sz to signed_word when assigned to size_avail. * allchblk.c [USE_MUNMAP] (GC_allochblk_nth): Cast hhdr->hb_sz to size_t when passed to GC_remap(). * alloc.c (GC_set_fl_marks, GC_clear_fl_marks): Change type of sz and bit_no local variables from size_t/unsigned to word. * dbg_mlc.c (GC_check_heap_block): Likewise. * backgraph.c [MAKE_BACK_GRAPH] (per_object_helper): Cast hhdr->hb_sz to size_t; change type of i local variables from int to size_t. * checksums.c [CHECKSUMS] (GC_on_free_list): Change type of sz local variable from size_t to word. * mark.c (GC_push_marked, GC_push_unconditionally, GC_block_was_dirty): Likewise. * reclaim.c (GC_reclaim_small_nonempty_block, GC_disclaim_and_reclaim_or_free_small_block, GC_reclaim_block, GC_n_set_marks): Likewise. * checksums.c [CHECKSUMS] (GC_add_block): Remove bytes local variable (to avoid casting of hhdr->hb_sz). * dbg_mlc.c (GC_debug_free): Change type of i and obj_sz local variables from size_t to word. * dbg_mlc.c (GC_check_leaked): Likewise. * extra/pcr_interface.c (GC_enumerate_block): Change type of sz local variable from int to size_t. * extra/pcr_interface.c (GC_enumerate_block): Cast hhdr->hb_sz to size_t when assigned to sz. * mallocx.c (GC_realloc): Likewise. * mark.c (GC_set_hdr_marks): Likewise. * reclaim.c (GC_do_enumerate_reachable_objects): Likewise. * include/private/gc_pmark.h [MARK_BIT_PER_OBJ] (PUSH_CONTENTS_HDR): Cast hhdr->hb_sz to size_t in assignment of obj_displ. * include/private/gc_priv.h (struct hblkhdr): Change type of hb_sz from size_t to word. * include/private/gc_priv.h (MARK_BIT_NO): Cast offset argument to word instead of unsigned. * malloc.c (GC_free): Cast hhdr->hb_sz to size_t. * mallocx.c (GC_get_kind_and_size): Likewise. * mark.c (GC_clear_hdr_marks): Likewise. * misc.c (GC_size): Likewise. * misc.c (GC_do_blocking): Remove redundant cast of hhdr->hb_sz. * reclaim.c (GC_reclaim_clear, GC_reclaim_uninit, GC_disclaim_and_reclaim, GC_continue_reclaim): Change type of sz argument from size_t to word. * typd_mlc.c (GC_array_mark_proc): Change type of sz and nwords local variables from size_t to word. --- allchblk.c | 8 ++++---- alloc.c | 8 ++++---- backgraph.c | 8 ++++---- checksums.c | 7 ++----- dbg_mlc.c | 12 ++++++------ extra/pcr_interface.c | 4 ++-- include/private/gc_pmark.h | 2 +- include/private/gc_priv.h | 14 +++++++------- malloc.c | 4 ++-- mallocx.c | 4 ++-- mark.c | 10 +++++----- misc.c | 4 ++-- reclaim.c | 20 ++++++++++---------- typd_mlc.c | 4 ++-- 14 files changed, 53 insertions(+), 56 deletions(-) diff --git a/allchblk.c b/allchblk.c index c8d03b19..010fb8a5 100644 --- a/allchblk.c +++ b/allchblk.c @@ -413,7 +413,7 @@ GC_INNER void GC_unmap_old(void) /* truncated counter value wrapping is handled correctly). */ if ((unsigned short)(GC_gc_no - hhdr->hb_last_reclaimed) > (unsigned short)GC_unmap_threshold) { - GC_unmap((ptr_t)h, hhdr -> hb_sz); + GC_unmap((ptr_t)h, (size_t)hhdr->hb_sz); hhdr -> hb_flags |= WAS_UNMAPPED; } } @@ -680,7 +680,7 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, int may_split) if (NULL == hbp) return NULL; GET_HDR(hbp, hhdr); /* set hhdr value */ - size_avail = hhdr->hb_sz; + size_avail = (signed_word)hhdr->hb_sz; if (size_avail < size_needed) continue; if (size_avail != size_needed) { if (!may_split) continue; @@ -728,7 +728,7 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, int may_split) /* Make sure it's mapped before we mangle it. */ # ifdef USE_MUNMAP if (!IS_MAPPED(hhdr)) { - GC_remap((ptr_t)hbp, hhdr -> hb_sz); + GC_remap((ptr_t)hbp, (size_t)hhdr->hb_sz); hhdr -> hb_flags &= ~WAS_UNMAPPED; } # endif @@ -801,7 +801,7 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, int may_split) if( size_avail >= size_needed ) { # ifdef USE_MUNMAP if (!IS_MAPPED(hhdr)) { - GC_remap((ptr_t)hbp, hhdr -> hb_sz); + GC_remap((ptr_t)hbp, (size_t)hhdr->hb_sz); hhdr -> hb_flags &= ~WAS_UNMAPPED; /* Note: This may leave adjacent, mapped free blocks. */ } diff --git a/alloc.c b/alloc.c index 7247336c..26201cd5 100644 --- a/alloc.c +++ b/alloc.c @@ -807,10 +807,10 @@ GC_INNER void GC_set_fl_marks(ptr_t q) struct hblk *h = HBLKPTR(q); struct hblk *last_h = h; hdr *hhdr = HDR(h); - IF_PER_OBJ(size_t sz = hhdr->hb_sz;) + IF_PER_OBJ(word sz = hhdr->hb_sz;) for (;;) { - unsigned bit_no = MARK_BIT_NO((ptr_t)q - (ptr_t)h, sz); + word bit_no = MARK_BIT_NO((ptr_t)q - (ptr_t)h, sz); if (!mark_bit_from_hdr(hhdr, bit_no)) { set_mark_bit_from_hdr(hhdr, bit_no); @@ -883,10 +883,10 @@ STATIC void GC_clear_fl_marks(ptr_t q) struct hblk *h = HBLKPTR(q); struct hblk *last_h = h; hdr *hhdr = HDR(h); - size_t sz = hhdr->hb_sz; /* Normally set only once. */ + word sz = hhdr->hb_sz; /* Normally set only once. */ for (;;) { - unsigned bit_no = MARK_BIT_NO((ptr_t)q - (ptr_t)h, sz); + word bit_no = MARK_BIT_NO((ptr_t)q - (ptr_t)h, sz); if (mark_bit_from_hdr(hhdr, bit_no)) { size_t n_marks = hhdr -> hb_n_marks; diff --git a/backgraph.c b/backgraph.c index 675df1f5..24beaa43 100644 --- a/backgraph.c +++ b/backgraph.c @@ -280,15 +280,15 @@ typedef void (*per_object_func)(ptr_t p, size_t n_bytes, word gc_descr); static void per_object_helper(struct hblk *h, word fn) { hdr * hhdr = HDR(h); - size_t sz = hhdr -> hb_sz; + size_t sz = (size_t)hhdr->hb_sz; word descr = hhdr -> hb_descr; per_object_func f = (per_object_func)fn; - int i = 0; + size_t i = 0; do { f((ptr_t)(h -> hb_body + i), sz, descr); - i += (int)sz; - } while ((word)i + sz <= BYTES_TO_WORDS(HBLKSIZE)); + i += sz; + } while (i + sz <= BYTES_TO_WORDS(HBLKSIZE)); } GC_INLINE void GC_apply_to_each_object(per_object_func f) diff --git a/checksums.c b/checksums.c index 4847661a..3af11a19 100644 --- a/checksums.c +++ b/checksums.c @@ -79,7 +79,7 @@ STATIC word GC_checksum(struct hblk *h) STATIC GC_bool GC_on_free_list(struct hblk *h) { hdr * hhdr = HDR(h); - size_t sz = BYTES_TO_WORDS(hhdr -> hb_sz); + word sz = BYTES_TO_WORDS(hhdr -> hb_sz); ptr_t p; if (sz > MAXOBJWORDS) return(FALSE); @@ -148,11 +148,8 @@ word GC_bytes_in_used_blocks = 0; STATIC void GC_add_block(struct hblk *h, word dummy GC_ATTR_UNUSED) { hdr * hhdr = HDR(h); - size_t bytes = hhdr -> hb_sz; - bytes += HBLKSIZE-1; - bytes &= ~(HBLKSIZE-1); - GC_bytes_in_used_blocks += bytes; + GC_bytes_in_used_blocks += (hhdr->hb_sz + HBLKSIZE-1) & ~(HBLKSIZE-1); } STATIC void GC_check_blocks(void) diff --git a/dbg_mlc.c b/dbg_mlc.c index 085ba2e7..69b671c6 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -895,8 +895,8 @@ GC_API void GC_CALL GC_debug_free(void * p) ) { GC_free(base); } else { - size_t i; - size_t obj_sz = BYTES_TO_WORDS(hhdr -> hb_sz - sizeof(oh)); + word i; + word obj_sz = BYTES_TO_WORDS(hhdr->hb_sz - sizeof(oh)); for (i = 0; i < obj_sz; ++i) ((word *)p)[i] = GC_FREED_MEM_MARKER; @@ -1062,8 +1062,8 @@ STATIC void GC_print_all_smashed_proc(void) STATIC void GC_check_heap_block(struct hblk *hbp, word dummy GC_ATTR_UNUSED) { struct hblkhdr * hhdr = HDR(hbp); - size_t sz = hhdr -> hb_sz; - size_t bit_no; + word sz = hhdr -> hb_sz; + word bit_no; char *p, *plim; p = hbp->hb_body; @@ -1094,8 +1094,8 @@ STATIC void GC_check_heap_proc(void) GC_INNER GC_bool GC_check_leaked(ptr_t base) { - size_t i; - size_t obj_sz; + word i; + word obj_sz; word *p; if ( diff --git a/extra/pcr_interface.c b/extra/pcr_interface.c index c7033055..b0256410 100644 --- a/extra/pcr_interface.c +++ b/extra/pcr_interface.c @@ -66,7 +66,7 @@ typedef struct { void GC_enumerate_block(struct hblk *h; enumerate_data * ed) { register hdr * hhdr; - register int sz; + register size_t sz; ptr_t p; ptr_t lim; word descr; @@ -77,7 +77,7 @@ void GC_enumerate_block(struct hblk *h; enumerate_data * ed) # endif hhdr = HDR(h); descr = hhdr -> hb_descr; - sz = hhdr -> hb_sz; + sz = (size_t)hhdr->hb_sz; if (descr != 0 && ed -> ed_pointerfree || descr == 0 && !(ed -> ed_pointerfree)) return; lim = (ptr_t)(h+1) - sz; diff --git a/include/private/gc_pmark.h b/include/private/gc_pmark.h index 280cffec..c327ad60 100644 --- a/include/private/gc_pmark.h +++ b/include/private/gc_pmark.h @@ -330,7 +330,7 @@ GC_INNER mse * GC_signal_mark_stack_overflow(mse *msp); size_t obj_displ; \ /* Accurate enough if HBLKSIZE <= 2**15. */ \ GC_STATIC_ASSERT(HBLKSIZE <= (1 << 15)); \ - obj_displ = (((low_prod >> 16) + 1) * hhdr->hb_sz) >> 16; \ + obj_displ = (((low_prod >> 16) + 1) * (size_t)hhdr->hb_sz) >> 16; \ if (do_offset_check && !GC_valid_offsets[obj_displ]) { \ GC_ADD_TO_BLACK_LIST_NORMAL(current, source); \ break; \ diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h index 7efc8bf9..7364dafe 100644 --- a/include/private/gc_priv.h +++ b/include/private/gc_priv.h @@ -1067,11 +1067,11 @@ struct hblkhdr { /* LARGE_INV_SZ. */ # define LARGE_INV_SZ (1 << 16) # endif - size_t hb_sz; /* If in use, size in bytes, of objects in the block. */ - /* if free, the size in bytes of the whole block */ - /* We assume that this is convertible to signed_word */ - /* without generating a negative result. We avoid */ - /* generating free blocks larger than that. */ + word hb_sz; /* If in use, size in bytes, of objects in the block. */ + /* if free, the size in bytes of the whole block. */ + /* We assume that this is convertible to signed_word */ + /* without generating a negative result. We avoid */ + /* generating free blocks larger than that. */ word hb_descr; /* object descriptor for marking. See */ /* gc_mark.h. */ # ifdef MARK_BIT_PER_GRANULE @@ -1671,7 +1671,7 @@ struct GC_traced_stack_sect_s { #endif /* !USE_MARK_BYTES */ #ifdef MARK_BIT_PER_OBJ -# define MARK_BIT_NO(offset, sz) (((unsigned)(offset))/(sz)) +# define MARK_BIT_NO(offset, sz) (((word)(offset))/(sz)) /* Get the mark bit index corresponding to the given byte */ /* offset and size (in bytes). */ # define MARK_BIT_OFFSET(sz) 1 @@ -1680,7 +1680,7 @@ struct GC_traced_stack_sect_s { # define FINAL_MARK_BIT(sz) ((sz) > MAXOBJBYTES? 1 : HBLK_OBJS(sz)) /* Position of final, always set, mark bit. */ #else /* MARK_BIT_PER_GRANULE */ -# define MARK_BIT_NO(offset, sz) BYTES_TO_GRANULES((unsigned)(offset)) +# define MARK_BIT_NO(offset, sz) BYTES_TO_GRANULES((word)(offset)) # define MARK_BIT_OFFSET(sz) BYTES_TO_GRANULES(sz) # define IF_PER_OBJ(x) # define FINAL_MARK_BIT(sz) \ diff --git a/malloc.c b/malloc.c index eb0e80f1..b62fd3ea 100644 --- a/malloc.c +++ b/malloc.c @@ -600,7 +600,7 @@ GC_API void GC_CALL GC_free(void * p) if (0 == hhdr) return; # endif GC_ASSERT(GC_base(p) == p); - sz = hhdr -> hb_sz; + sz = (size_t)hhdr->hb_sz; ngranules = BYTES_TO_GRANULES(sz); knd = hhdr -> hb_obj_kind; ok = &GC_obj_kinds[knd]; @@ -650,7 +650,7 @@ GC_API void GC_CALL GC_free(void * p) h = HBLKPTR(p); hhdr = HDR(h); knd = hhdr -> hb_obj_kind; - sz = hhdr -> hb_sz; + sz = (size_t)hhdr->hb_sz; ngranules = BYTES_TO_GRANULES(sz); ok = &GC_obj_kinds[knd]; if (ngranules <= MAXOBJGRANULES) { diff --git a/mallocx.c b/mallocx.c index 6440311d..5d42392f 100644 --- a/mallocx.c +++ b/mallocx.c @@ -52,7 +52,7 @@ GC_API int GC_CALL GC_get_kind_and_size(const void * p, size_t * psize) hdr * hhdr = HDR(p); if (psize != NULL) { - *psize = hhdr -> hb_sz; + *psize = (size_t)hhdr->hb_sz; } return hhdr -> hb_obj_kind; } @@ -112,7 +112,7 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb) } h = HBLKPTR(p); hhdr = HDR(h); - sz = hhdr -> hb_sz; + sz = (size_t)hhdr->hb_sz; obj_kind = hhdr -> hb_obj_kind; orig_sz = sz; diff --git a/mark.c b/mark.c index 705c4a41..5a23366f 100644 --- a/mark.c +++ b/mark.c @@ -145,7 +145,7 @@ GC_INNER GC_bool GC_collection_in_progress(void) /* clear all mark bits in the header */ GC_INNER void GC_clear_hdr_marks(hdr *hhdr) { - size_t last_bit = FINAL_MARK_BIT(hhdr -> hb_sz); + size_t last_bit = FINAL_MARK_BIT((size_t)hhdr->hb_sz); BZERO(hhdr -> hb_marks, sizeof(hhdr->hb_marks)); set_mark_bit_from_hdr(hhdr, last_bit); hhdr -> hb_n_marks = 0; @@ -155,7 +155,7 @@ GC_INNER void GC_clear_hdr_marks(hdr *hhdr) GC_INNER void GC_set_hdr_marks(hdr *hhdr) { unsigned i; - size_t sz = hhdr -> hb_sz; + size_t sz = (size_t)hhdr->hb_sz; unsigned n_marks = (unsigned)FINAL_MARK_BIT(sz); # ifdef USE_MARK_BYTES @@ -1858,7 +1858,7 @@ STATIC void GC_push_marked4(struct hblk *h, hdr *hhdr) /* Push all objects reachable from marked objects in the given block */ STATIC void GC_push_marked(struct hblk *h, hdr *hhdr) { - size_t sz = hhdr -> hb_sz; + word sz = hhdr -> hb_sz; word descr = hhdr -> hb_descr; ptr_t p; word bit_no; @@ -1920,7 +1920,7 @@ STATIC void GC_push_marked(struct hblk *h, hdr *hhdr) /* first word. */ STATIC void GC_push_unconditionally(struct hblk *h, hdr *hhdr) { - size_t sz = hhdr -> hb_sz; + word sz = hhdr -> hb_sz; word descr = hhdr -> hb_descr; ptr_t p; ptr_t lim; @@ -1951,7 +1951,7 @@ STATIC void GC_push_marked(struct hblk *h, hdr *hhdr) /* Test whether any page in the given block is dirty. */ STATIC GC_bool GC_block_was_dirty(struct hblk *h, hdr *hhdr) { - size_t sz = hhdr -> hb_sz; + word sz = hhdr -> hb_sz; if (sz <= MAXOBJBYTES) { return(GC_page_was_dirty(h)); diff --git a/misc.c b/misc.c index 6e38c0ca..0c857cbb 100644 --- a/misc.c +++ b/misc.c @@ -457,7 +457,7 @@ GC_API size_t GC_CALL GC_size(const void * p) { hdr * hhdr = HDR(p); - return hhdr -> hb_sz; + return (size_t)hhdr->hb_sz; } @@ -2209,7 +2209,7 @@ GC_API void * GC_CALL GC_do_blocking(GC_fn_type fn, void * client_data) static void block_add_size(struct hblk *h, word pbytes) { hdr *hhdr = HDR(h); - *(word *)pbytes += (WORDS_TO_BYTES((word)hhdr->hb_sz) + (HBLKSIZE - 1)) + *(word *)pbytes += (WORDS_TO_BYTES(hhdr->hb_sz) + (HBLKSIZE - 1)) & ~(word)(HBLKSIZE - 1); } diff --git a/reclaim.c b/reclaim.c index ec20a17a..6b9fe7d1 100644 --- a/reclaim.c +++ b/reclaim.c @@ -146,7 +146,7 @@ STATIC GC_bool GC_block_nearly_full(hdr *hhdr) * free list. Returns the new list. * Clears unmarked objects. Sz is in bytes. */ -STATIC ptr_t GC_reclaim_clear(struct hblk *hbp, hdr *hhdr, size_t sz, +STATIC ptr_t GC_reclaim_clear(struct hblk *hbp, hdr *hhdr, word sz, ptr_t list, signed_word *count) { word bit_no = 0; @@ -193,7 +193,7 @@ STATIC ptr_t GC_reclaim_clear(struct hblk *hbp, hdr *hhdr, size_t sz, } /* The same thing, but don't clear objects: */ -STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, hdr *hhdr, size_t sz, +STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, hdr *hhdr, word sz, ptr_t list, signed_word *count) { word bit_no = 0; @@ -222,7 +222,7 @@ STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, hdr *hhdr, size_t sz, #ifdef ENABLE_DISCLAIM /* Call reclaim notifier for block's kind on each unmarked object in */ /* block, all within a pair of corresponding enter/leave callbacks. */ - STATIC ptr_t GC_disclaim_and_reclaim(struct hblk *hbp, hdr *hhdr, size_t sz, + STATIC ptr_t GC_disclaim_and_reclaim(struct hblk *hbp, hdr *hhdr, word sz, ptr_t list, signed_word *count) { word bit_no = 0; @@ -331,7 +331,7 @@ STATIC void GC_reclaim_small_nonempty_block(struct hblk *hbp, GC_bool report_if_found) { hdr *hhdr = HDR(hbp); - size_t sz = hhdr -> hb_sz; + word sz = hhdr -> hb_sz; struct obj_kind * ok = &GC_obj_kinds[hhdr -> hb_obj_kind]; void **flh = &(ok -> ok_freelist[BYTES_TO_GRANULES(sz)]); @@ -349,7 +349,7 @@ STATIC void GC_reclaim_small_nonempty_block(struct hblk *hbp, STATIC void GC_disclaim_and_reclaim_or_free_small_block(struct hblk *hbp) { hdr *hhdr = HDR(hbp); - size_t sz = hhdr -> hb_sz; + word sz = hhdr -> hb_sz; struct obj_kind * ok = &GC_obj_kinds[hhdr -> hb_obj_kind]; void **flh = &(ok -> ok_freelist[BYTES_TO_GRANULES(sz)]); void *flh_next; @@ -377,7 +377,7 @@ STATIC void GC_reclaim_small_nonempty_block(struct hblk *hbp, STATIC void GC_reclaim_block(struct hblk *hbp, word report_if_found) { hdr * hhdr = HDR(hbp); - size_t sz = hhdr -> hb_sz; /* size of objects in current block */ + word sz = hhdr -> hb_sz; /* size of objects in current block */ struct obj_kind * ok = &GC_obj_kinds[hhdr -> hb_obj_kind]; if( sz > MAXOBJBYTES ) { /* 1 big object */ @@ -385,7 +385,7 @@ STATIC void GC_reclaim_block(struct hblk *hbp, word report_if_found) if (report_if_found) { GC_add_leaked((ptr_t)hbp); } else { - size_t blocks; + word blocks; # ifdef ENABLE_DISCLAIM if (EXPECT(hhdr->hb_flags & HAS_DISCLAIM, 0)) { @@ -481,7 +481,7 @@ int GC_n_set_marks(hdr *hhdr) { int result = 0; int i; - size_t sz = hhdr -> hb_sz; + word sz = hhdr -> hb_sz; int offset = (int)MARK_BIT_OFFSET(sz); int limit = (int)FINAL_MARK_BIT(sz); @@ -675,7 +675,7 @@ GC_INNER void GC_start_reclaim(GC_bool report_if_found) * appropriate free list is nonempty, or there are no more blocks to * sweep. */ -GC_INNER void GC_continue_reclaim(size_t sz /* granules */, int kind) +GC_INNER void GC_continue_reclaim(word sz /* granules */, int kind) { hdr * hhdr; struct hblk * hbp; @@ -793,7 +793,7 @@ struct enumerate_reachable_s { STATIC void GC_do_enumerate_reachable_objects(struct hblk *hbp, word ped) { struct hblkhdr *hhdr = HDR(hbp); - size_t sz = hhdr -> hb_sz; + size_t sz = (size_t)hhdr->hb_sz; size_t bit_no; char *p, *plim; diff --git a/typd_mlc.c b/typd_mlc.c index 94a003a2..05079f14 100644 --- a/typd_mlc.c +++ b/typd_mlc.c @@ -476,8 +476,8 @@ STATIC mse * GC_array_mark_proc(word * addr, mse * mark_stack_ptr, word env GC_ATTR_UNUSED) { hdr * hhdr = HDR(addr); - size_t sz = hhdr -> hb_sz; - size_t nwords = BYTES_TO_WORDS(sz); + word sz = hhdr -> hb_sz; + word nwords = BYTES_TO_WORDS(sz); complex_descriptor * descr = (complex_descriptor *)(addr[nwords-1]); mse * orig_mark_stack_ptr = mark_stack_ptr; mse * new_mark_stack_ptr; -- 2.40.0