Skip to content

Commit

Permalink
Change type of internal variables from word to size_t where applicable
Browse files Browse the repository at this point in the history
(refactoring)

* allchblk.c (GC_dump_regions, GC_remove_from_fl, GC_add_to_fl,
GC_get_first_part, drop_hblk_in_chunks, GC_allochblk_nth,
GC_freehblk): Remove casts to size_t.
* blacklst.c (GC_is_black_listed): Likewise.
* dbg_mlc.c (GC_debug_free): Likewise.
* finalize.c (GC_grow_table): Likewise.
* allchblk.c (GC_merge_unmapped): Rename nextsize local variable to
next_size.
* allchblk.c (GC_merge_unmapped, next_hblk_fits_better, GC_freehblk):
Change type of size, next_size local variables from word to size_t.
* allchblk.c (GC_get_first_part): Rename bytes argument to size_needed.
* allchblk.c (GC_split_block): Change type of h_size local variable
from word to size_t.
* allchblk.c (next_hblk_fits_better): Change type of size_avail,
size_needed arguments from word to size_t.
* allchblk.c (find_nonbl_hblk):  Change type of size_remain,
eff_size_needed arguments from word to size_t.
* allchblk.c (GC_allochblk_nth): Change type of size_needed, size_avail
local variables from word to size_t.
* allchblk.c (GC_merge_unmapped, GC_freehblk): Use SIZET_SIGNB instead
of SIGNB.
* alloc.c (GC_set_fl_marks, GC_clear_fl_marks): Change type of bit_no
local variable from unsigned to size_t.
* alloc.c (GC_add_to_heap, GC_scratch_recycle_inner): Rename bytes
argument to sz; update comment.
* include/private/gc_priv.h (GC_scratch_recycle_inner): Likewise.
* alloc.c (GC_expand_hp_inner): Rename bytes local variable to sz.
* backgraph.c (per_object_func, reset_back_edge, add_back_edges,
update_max_height): Rename n_bytes argument to sz; rename gc_descr
argument to descr.
* blacklst.c (GC_unpromote_black_lists, GC_add_to_black_list_stack,
GC_number_stack_black_listed): Change type of index local variable from
word to size_t.
* os_dep.c [MPROTECT_VDB] (GC_write_fault_handler,
GC_remove_protection): Likewise.
* os_dep.c [PROC_VDB] (GC_proc_read_dirty): Likewise.
* os_dep.c [SOFT_VDB] (soft_set_grungy_pages): Likewise.
* os_dep.c [!NO_MANUAL_VDB] (GC_dirty_inner): Likewise.
* os_dep.c [!GC_DISABLE_INCREMENTAL] (GC_page_was_dirty): Likewise.
* os_dep.c [GWW_VDB || PROC_VDB || SOFT_VDB] (GC_page_was_ever_dirty):
Likewise.
* os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise): Likewise.
* dbg_mlc.c (GC_has_other_debug_info, GC_debug_free): Change type of sz
local variable from word to size_t.
* misc.c (GC_base): Likewise.
* ptr_chck.c (GC_same_obj, GC_is_valid_displacement): Likewise.
* dbg_mlc.c (GC_store_debug_info_inner): Change type of sz argument
from word to size_t.
* dbg_mlc.c (store_debug_info, GC_start_debugging_inner,
GC_debug_register_displacement, GC_debug_generic_malloc): Remove cast
to word.
* gcj_mlc.c (GC_debug_gcj_malloc): Likewise.
* include/private/gc_priv.h (GC_store_debug_info_inner): Likewise.
* reclaim.c (GC_clear_block): Likewise.
* dbg_mlc.c (GC_check_annotated_obj): Change type of gc_sz local
variable from word to size_t.
* finalize.c (HASH3): Add a cast to have result of size_t type.
* include/private/gc_priv.h (PHT_HASH): Likewise.
* include/private/specific.h (ts_quick_thread_id): Likewise.
* finalize.c (HASH2, GC_grow_table): Cast to size_t instead of word.
* include/private/specific.h (INVALID_QTID): Likewise.
* mark.c (GC_set_mark_bit, GC_clear_mark_bit, GC_is_marked,
GC_push_marked): Likewise.
* typd_mlc.c (GC_make_descriptor): Likewise.
* finalize.c (hash_chain_entry.fo_object_size): Rename to fo_object_sz
and change its type from word to size_t.
* finalize.c (GC_grow_table): Change type of entries_ptr argument to
const size_t*.
* finalize.c (GC_grow_table): Change type for i local variable from
word to size_t.
* os_dep.c [MSWINCE] (GC_wince_get_mem): Likewise.
* os_dep.c [GWW_VDB] (GC_gww_read_dirty, GC_gww_read_dirty): Likewise.
* os_dep.c [SOFT_VDB] (GC_soft_read_dirty): Likewise.
* finalize.c (GC_grow_table): Change type for old_size, new_size local
variables from word to size_t.
* finalize.c (GC_old_dl_entries, GC_old_ll_entries): Change type from
word to size_t.
* include/private/gc_priv.h (dl_hashtbl_s.entries,
_GC_arrays._n_heap_bases, _GC_arrays._n_root_sets): Likewise.
* typd_mlc.c (LeafDescriptor.ld_size, LeafDescriptor.ld_nelements,
ComplexArrayDescriptor.ad_nelements):
* finalize.c (GC_finalize, GC_enqueue_all_finalizers): Cast
curr_fo->fo_object_sz to word.
* headers.c (GC_next_block): Change type of j local variable from word
to size_t.
* include/private/gc_priv.h (SIZET_SIGNB): New macro.
* include/private/gc_priv.h (GC_SQRT_SIZE_MAX): Replace CPP_WORDSZ to
sizeof(size_t)*8.
* include/private/gc_priv.h [IA64] (GC_push_all_register_sections):
Change type of eager argument from int to GC_bool.
* mark_rts.c [IA64] (GC_push_all_register_sections): Likewise.
* include/private/gc_priv.h (MARK_BIT_NO): Remove cast to unsigned.
* include/private/gc_priv.h (GC_remove_protection): Change type of
nblocks argument from word to size_t.
* os_dep.c [MPROTECT_VDB] (GC_remove_protection): Likewise.
* include/private/pthread_support.h [E2K] (GC_StackContext_Rep.ps_ofs):
Adjust comment.
* include/private/pthread_support.h [GC_ENABLE_SUSPEND_THREAD
&& SIGNAL_BASED_STOP_WORLD] (GC_suspend_self_inner): Change type of
suspend_cnt argument from word to size_t.
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD]
(GC_suspend_self_inner): Likewise.
* include/private/specific.h (GC_slow_getspecific): Change type of qtid
argument from word to size_t.
* specific.c (GC_slow_getspecific): Likewise.
* include/private/specific.h (GC_getspecific): Change type of qtid
local variable from word to size_t.
* mark.c (GC_set_hdr_marks): Change type of i, n_marks local variables
from unsigned to size_t; remove cast to unsigned.
* os_dep.c [CHECKSUMS && GWW_VDB || PROC_VDB] (GC_or_pages): Likewise.
* os_dep.c [MPROTECT_VDB] (GC_protect_heap, GC_unprotect_all_heap):
Likewise.
* mark.c (GC_set_mark_bit, GC_clear_mark_bit, GC_is_marked,
GC_push_marked): Change type of bit_no local variable from word to
size_t.
* reclaim.c (GC_reclaim_clear, GC_reclaim_uninit,
GC_disclaim_and_reclaim, GC_reclaim_check, GC_reclaim_block): Likewise.
* mark.c (GC_steal_mark_stack): Rename max argument to n_to_get and
change its type from unsigned to size_t; update comment; change type of
i local variable from unsigned to size_t.
* mark.c (GC_mark_local): Change type of n_to_get local variable from
unsigned to size_t.
* mark_rts.c (GC_compute_root_size, GC_print_static_roots,
GC_is_static_root, GC_add_roots_inner, GC_rebuild_root_index,
GC_remove_tmp_roots, GC_remove_roots_inner, GC_remove_roots_subregion,
GC_remove_roots_inner, GC_is_tmp_root, GC_push_roots): Change type of
i, j local variables from int to size_t.
* os_dep.c [!OS2 && MSWIN32] (GC_register_data_segments): Likewise.
* mark_rts.c (GC_is_static_root, GC_is_tmp_root): Change type of
last_root_set static variable from int to size_t.
* mark_rts.c (rt_hash): Change type of result from int to size_t.
* mark_rts.c (GC_roots_present, add_roots_to_index): Change type of h
local variable from int to size_t.
* mark_rts.c [DEBUG_ADD_DEL_ROOTS] (GC_add_roots_inner): Change printf
format specifier for n_root_sets from %d to %u.
* mark_rts.c (GC_remove_root_at_pos, swap_static_roots): Change type of
i, j arguments from int to size_t; add assertion that i<n_root_sets.
* mark_rts.c [!ANY_MSWIN](GC_remove_tmp_roots, GC_remove_roots_inner):
Change type of old_n_roots local variable from int to size_t.
* mark_rts.c [AO_HAVE_load && HAS_REAL_READER_LOCK] (GC_is_tmp_root):
Remove cast to int, unsigned and AO_t.
* misc.c [!THREADS] (GC_bytes_allocd_at_reset): Move static variable
definition upper (to be near GC_stack_last_cleared).
* misc.c [!CPPCHECK] (GC_init): Add static assertion about size of
size_t.
* misc.c (GC_init): Pass 0 instead of 0L to
GC_register_displacement_inner().
* misc.c [!THREADS] (GC_call_with_gc_active): Adjust indentation.
* os_dep.c [!OS2 && MSWIN32] (GC_no_win32_dlls, GC_wnt, GC_init_win32,
GC_register_data_segments, GC_least_described_address): Reformat
comment.
* os_dep.c [!OS2 && ANY_MSWIN] (GC_max_root_size,
GC_is_malloc_heap_base, GC_free_malloc_heap_list): Likewise.
* os_dep.c [DATASTART_USES_BSDGETDATASTART] (GC_FreeBSDGetDataStart):
Likewise.
* os_dep.c [!OS2 && !ANY_MSWIN && !AMIGA && !OPENBSD]
(GC_register_data_segments): Likewise.
* reclaim.c [!NO_DEBUGGING] (Print_stats): Likewise.
* typd_mlc.c (GC_make_descriptor): Likewise.
* os_dep.c [!OS2 && MSWIN32] (GC_least_described_address): Change a
(name of the variable) to p in comment; move buf local variable to the
nested block.
* os_dep.c [!OS2 && MSWIN32] (GC_register_root_section): Move
definition upper to be near GC_least_described_address(); remove
protect local variable.
* os_dep.c [MSWINCE] (GC_wince_get_mem): Do not decrement
GC_n_heap_bases if it is zero.
* os_dep.c [GWW_VDB] (GC_gww_read_dirty): Rename hash local variable to
index and change its type from word to size_t.
* os_dep.c [MPROTECT_VDB] (GC_protect_heap): Change type of nblocks
from word to size_t.
* os_dep.c [PROC_VDB] (GC_proc_read_dirty): Change type of i, nmaps
local variables from int to size_t.
* os_dep.c [!GC_DISABLE_INCREMENTAL && PCR_VDB] (GC_read_dirty): Change
type of onhs, nhs variables from int to size_t.
* os_dep.c [MPROTECT_VDB && DARWIN] (catch_exception_raise): Change
type for i local variable from unsigned int to size_t.
* pthread_support.c [USE_SPIN_LOCK] (GC_lock): Likewise.
* pthread_stop_world.c [GC_ENABLE_SUSPEND_THREAD]
(GC_suspend_handler_inner, GC_suspend_thread, GC_resume_thread): Change
type of suspend_cnt local variable from word to AO_t; remove casts to
word and AO_t.
* pthread_support.c [GC_ENABLE_SUSPEND_THREAD
&& SIGNAL_BASED_STOP_WORLD] (GC_do_blocking_inner,
GC_suspend_self_blocked, GC_call_with_gc_active): Likewise.
* pthread_support.c [!USE_SPIN_LOCK && !NO_PTHREAD_TRYLOCK
&& USE_PTHREAD_LOCKS || GC_PTHREADS_PARAMARK] (GC_generic_lock): Cast
SPIN_MAX to unsigned.
* pthread_support.c [USE_SPIN_LOCK] (GC_lock): Replace my_last_spins
local variable to my_last_spins_half; change type of my_spin_max,
my_last_spins_half local variables from unsigned to AO_t; remove casts
to AO_t.
* ptr_chck.c (GC_same_obj, GC_is_valid_displacement): Remove pdispl
local variable.
* ptr_chck.c (GC_is_valid_displacement): Change type of offset local
variable from word to size_t; change the expression (in an invariant
way) for computing descr to use signed_word type.
* reclaim.c (GC_reclaim_small_nonempty_block,
GC_disclaim_and_reclaim_or_free_small_block): Add comment for the cast.
* reclaim.c (GC_reclaim_block): Cast sz to word.
* reclaim.c [!NO_DEBUGGING && !USE_MARK_BYTES] (count_ones): Rename n
argument to v; adjust indentation.
* reclaim.c [!NO_DEBUGGING] (GC_print_block_descr): Change type
of n_marks, n_objs from unsigned to size_t and cast them to unsigned
in printf call; remove casts to word.
* typd_mlc.c: Reformat comment.
* typd_mlc.c (GC_add_ext_descriptor): Change type of nbits argument
from word to size_t; change tpe of ed_size local variable from word to
size_t.
* typd_mlc.c (GC_init_explicit_typing): Replace (word)-1 to
GC_WORD_MAX.
* typd_mlc.c (GC_make_leaf_descriptor): Change type of nelements
argument from word to size_t; reformat code.
* typd_mlc.c (GC_calloc_prepare_explicitly_typed): Remove casts to
word.
* typd_mlc.c (GC_descr_obj_size): Change type of result from word to
size_t; change type of i, nelements, sz local variables from word to
size_t.
  • Loading branch information
ivmai committed Jul 10, 2024
1 parent 0354e65 commit 642a4d1
Show file tree
Hide file tree
Showing 21 changed files with 760 additions and 755 deletions.
117 changes: 57 additions & 60 deletions allchblk.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@
* Adjacent free blocks are coalesced.
*/


# define MAX_BLACK_LIST_ALLOC (2*HBLKSIZE)
#define MAX_BLACK_LIST_ALLOC (2*HBLKSIZE)
/* largest block we will allocate starting on a black */
/* listed block. Must be >= HBLKSIZE. */


# define UNIQUE_THRESHOLD 32
#define UNIQUE_THRESHOLD 32
/* Sizes up to this many HBLKs each have their own free list */
# define HUGE_THRESHOLD 256
#define HUGE_THRESHOLD 256
/* Sizes of at least this many heap blocks are mapped to a */
/* single free list. */
# define FL_COMPRESSION 8
#define FL_COMPRESSION 8
/* In between sizes map this many distinct sizes to a single */
/* bin. */

# define N_HBLK_FLS ((HUGE_THRESHOLD - UNIQUE_THRESHOLD) / FL_COMPRESSION \
#define N_HBLK_FLS ((HUGE_THRESHOLD - UNIQUE_THRESHOLD) / FL_COMPRESSION \
+ UNIQUE_THRESHOLD)

#ifndef GC_GCJ_SUPPORT
Expand Down Expand Up @@ -102,14 +101,14 @@ STATIC int GC_hblk_fl_from_blocks(size_t blocks_needed)
+ UNIQUE_THRESHOLD;
}

# define PHDR(hhdr) HDR((hhdr) -> hb_prev)
# define NHDR(hhdr) HDR((hhdr) -> hb_next)
#define PHDR(hhdr) HDR((hhdr) -> hb_prev)
#define NHDR(hhdr) HDR((hhdr) -> hb_next)

# ifdef USE_MUNMAP
#ifdef USE_MUNMAP
# define IS_MAPPED(hhdr) (((hhdr) -> hb_flags & WAS_UNMAPPED) == 0)
# else
#else
# define IS_MAPPED(hhdr) TRUE
# endif /* !USE_MUNMAP */
#endif /* !USE_MUNMAP */

#if !defined(NO_DEBUGGING) || defined(GC_ASSERTIONS)
static void GC_CALLBACK add_hb_sz(struct hblk *h, int i,
Expand All @@ -132,7 +131,7 @@ STATIC int GC_hblk_fl_from_blocks(size_t blocks_needed)
}
#endif /* !NO_DEBUGGING || GC_ASSERTIONS */

# if !defined(NO_DEBUGGING)
#if !defined(NO_DEBUGGING)
static void GC_CALLBACK print_hblkfreelist_item(struct hblk *h, int i,
void *prev_index_ptr)
{
Expand Down Expand Up @@ -168,10 +167,10 @@ STATIC int GC_hblk_fl_from_blocks(size_t blocks_needed)
(unsigned long)total);
}

/* Return the free-list index on which the block described by the header */
/* appears, or -1 if it appears nowhere. */
static int free_list_index_of(const hdr *wanted)
{
/* Return the free-list index on which the block described by the header */
/* appears, or -1 if it appears nowhere. */
static int free_list_index_of(const hdr *wanted)
{
int i;

for (i = 0; i <= N_HBLK_FLS; ++i) {
Expand All @@ -184,10 +183,10 @@ static int free_list_index_of(const hdr *wanted)
}
}
return -1;
}
}

GC_API void GC_CALL GC_dump_regions(void)
{
GC_API void GC_CALL GC_dump_regions(void)
{
unsigned i;

for (i = 0; i < GC_n_heap_sects; ++i) {
Expand All @@ -213,7 +212,7 @@ GC_API void GC_CALL GC_dump_regions(void)
}
if (HBLK_IS_FREE(hhdr)) {
int correct_index = GC_hblk_fl_from_blocks(
(size_t)divHBLKSZ(hhdr -> hb_sz));
divHBLKSZ(hhdr -> hb_sz));
int actual_index;

GC_printf("\t%p\tfree block of size 0x%lx bytes%s\n",
Expand All @@ -235,9 +234,8 @@ GC_API void GC_CALL GC_dump_regions(void)
}
}
}
}

# endif /* NO_DEBUGGING */
}
#endif /* NO_DEBUGGING */

/* Initialize hdr for a block containing the indicated size and */
/* kind of objects. Return FALSE on failure. */
Expand Down Expand Up @@ -352,8 +350,7 @@ STATIC void GC_remove_from_fl_at(hdr *hhdr, int index)
/* size-appropriate free list). */
GC_INLINE void GC_remove_from_fl(hdr *hhdr)
{
GC_remove_from_fl_at(hhdr, GC_hblk_fl_from_blocks(
(size_t)divHBLKSZ(hhdr -> hb_sz)));
GC_remove_from_fl_at(hhdr, GC_hblk_fl_from_blocks(divHBLKSZ(hhdr -> hb_sz)));
}

/* Return a pointer to the block ending just before h, if any. */
Expand Down Expand Up @@ -395,7 +392,7 @@ STATIC struct hblk * GC_free_block_ending_at(struct hblk *h)
/* We maintain individual free lists sorted by address. */
STATIC void GC_add_to_fl(struct hblk *h, hdr *hhdr)
{
int index = GC_hblk_fl_from_blocks((size_t)divHBLKSZ(hhdr -> hb_sz));
int index = GC_hblk_fl_from_blocks(divHBLKSZ(hhdr -> hb_sz));
struct hblk *second = GC_hblkfreelist[index];

# if defined(GC_ASSERTIONS) && !defined(USE_MUNMAP)
Expand Down Expand Up @@ -543,15 +540,15 @@ GC_INNER void GC_merge_unmapped(void)
while (h != 0) {
struct hblk *next;
hdr *hhdr, *nexthdr;
word size, nextsize;
size_t size, next_size;

GET_HDR(h, hhdr);
size = hhdr -> hb_sz;
next = (struct hblk *)((word)h + size);
GET_HDR(next, nexthdr);
/* Coalesce with successor, if possible. */
if (nexthdr != NULL && HBLK_IS_FREE(nexthdr)
&& !((size + (nextsize = nexthdr -> hb_sz)) & SIGNB)
&& ((size + (next_size = nexthdr -> hb_sz)) & SIZET_SIGNB) == 0
/* no overflow */) {
/* Note that we usually try to avoid adjacent free blocks */
/* that are either both mapped or both unmapped. But that */
Expand All @@ -560,20 +557,20 @@ GC_INNER void GC_merge_unmapped(void)
/* not hold if the merged block would be too big. */
if (IS_MAPPED(hhdr) && !IS_MAPPED(nexthdr)) {
/* Make both consistent, so that we can merge. */
if (size > nextsize) {
if (size > next_size) {
GC_adjust_num_unmapped(next, nexthdr);
GC_remap((ptr_t)next, nextsize);
GC_remap((ptr_t)next, next_size);
} else {
GC_adjust_num_unmapped(h, hhdr);
GC_unmap((ptr_t)h, size);
GC_unmap_gap((ptr_t)h, size, (ptr_t)next, nextsize);
GC_unmap_gap((ptr_t)h, size, (ptr_t)next, next_size);
hhdr -> hb_flags |= WAS_UNMAPPED;
}
} else if (IS_MAPPED(nexthdr) && !IS_MAPPED(hhdr)) {
if (size > nextsize) {
if (size > next_size) {
GC_adjust_num_unmapped(next, nexthdr);
GC_unmap((ptr_t)next, nextsize);
GC_unmap_gap((ptr_t)h, size, (ptr_t)next, nextsize);
GC_unmap((ptr_t)next, next_size);
GC_unmap_gap((ptr_t)h, size, (ptr_t)next, next_size);
} else {
GC_adjust_num_unmapped(h, hhdr);
GC_remap((ptr_t)h, size);
Expand All @@ -582,7 +579,7 @@ GC_INNER void GC_merge_unmapped(void)
}
} else if (!IS_MAPPED(hhdr) && !IS_MAPPED(nexthdr)) {
/* Unmap any gap in the middle */
GC_unmap_gap((ptr_t)h, size, (ptr_t)next, nextsize);
GC_unmap_gap((ptr_t)h, size, (ptr_t)next, next_size);
}
/* If they are both unmapped, we merge, but leave unmapped. */
GC_remove_from_fl_at(hhdr, i);
Expand Down Expand Up @@ -611,27 +608,27 @@ GC_INNER void GC_merge_unmapped(void)
* If the return value is not 0, then hhdr is the header for it.
*/
STATIC struct hblk * GC_get_first_part(struct hblk *h, hdr *hhdr,
size_t bytes, int index)
size_t size_needed, int index)
{
size_t total_size;
struct hblk * rest;
hdr * rest_hdr;

GC_ASSERT(I_HOLD_LOCK());
GC_ASSERT(modHBLKSZ(bytes) == 0);
total_size = (size_t)(hhdr -> hb_sz);
GC_ASSERT(modHBLKSZ(size_needed) == 0);
total_size = hhdr -> hb_sz;
GC_ASSERT(modHBLKSZ(total_size) == 0);
GC_remove_from_fl_at(hhdr, index);
if (total_size == bytes) return h;
if (total_size == size_needed) return h;

rest = (struct hblk *)((word)h + bytes);
rest = (struct hblk *)((word)h + size_needed);
rest_hdr = GC_install_header(rest);
if (EXPECT(NULL == rest_hdr, FALSE)) {
/* FIXME: This is likely to be very bad news ... */
WARN("Header allocation failed: dropping block\n", 0);
return NULL;
}
rest_hdr -> hb_sz = total_size - bytes;
rest_hdr -> hb_sz = total_size - size_needed;
rest_hdr -> hb_flags = 0;
# ifdef GC_ASSERTIONS
/* Mark h not free, to avoid assertion about adjacent free blocks. */
Expand All @@ -654,15 +651,14 @@ STATIC struct hblk * GC_get_first_part(struct hblk *h, hdr *hhdr,
STATIC void GC_split_block(struct hblk *hbp, hdr *hhdr, struct hblk *last_hbp,
hdr *last_hdr, int index /* of free list */)
{
word total_size = hhdr -> hb_sz;
word h_size = (word)((ptr_t)last_hbp - (ptr_t)hbp);
size_t h_size = (size_t)((ptr_t)last_hbp - (ptr_t)hbp);
struct hblk *prev = hhdr -> hb_prev;
struct hblk *next = hhdr -> hb_next;

/* Replace hbp with last_hbp on its free list. */
last_hdr -> hb_prev = prev;
last_hdr -> hb_next = next;
last_hdr -> hb_sz = total_size - h_size;
last_hdr -> hb_sz = hhdr -> hb_sz - h_size;
last_hdr -> hb_flags = 0;
if (prev /* != NULL */) { /* CPPCHECK */
HDR(prev) -> hb_next = last_hbp;
Expand Down Expand Up @@ -759,11 +755,11 @@ STATIC unsigned GC_drop_blacklisted_count = 0;
#define ALIGN_PAD_SZ(p, align_m1) \
(((align_m1) + 1 - (size_t)ADDR(p)) & (align_m1))

static GC_bool next_hblk_fits_better(const hdr *hhdr, word size_avail,
word size_needed, size_t align_m1)
static GC_bool next_hblk_fits_better(const hdr *hhdr, size_t size_avail,
size_t size_needed, size_t align_m1)
{
const hdr *nexthdr;
word next_size;
size_t next_size;
size_t next_ofs;
struct hblk *next_hbp = hhdr -> hb_next;

Expand All @@ -777,8 +773,8 @@ static GC_bool next_hblk_fits_better(const hdr *hhdr, word size_avail,
&& !GC_is_black_listed(next_hbp + divHBLKSZ(next_ofs), size_needed);
}

static struct hblk *find_nonbl_hblk(struct hblk *last_hbp, word size_remain,
word eff_size_needed, size_t align_m1)
static struct hblk *find_nonbl_hblk(struct hblk *last_hbp, size_t size_remain,
size_t eff_size_needed, size_t align_m1)
{
ptr_t search_end = PTR_ALIGN_DOWN((ptr_t)last_hbp + size_remain,
align_m1 + 1);
Expand All @@ -798,7 +794,7 @@ static struct hblk *find_nonbl_hblk(struct hblk *last_hbp, word size_remain,
/* that we will recover some later. hhdr should correspond to hbp. */
static void drop_hblk_in_chunks(int n, struct hblk *hbp, hdr *hhdr)
{
size_t total_size = (size_t)(hhdr -> hb_sz);
size_t total_size = hhdr -> hb_sz;
const struct hblk *limit = hbp + divHBLKSZ(total_size);

GC_ASSERT(HDR(hbp) == hhdr);
Expand Down Expand Up @@ -852,7 +848,7 @@ STATIC struct hblk *GC_allochblk_nth(size_t lb_adjusted, int k,
{
struct hblk *hbp, *last_hbp;
hdr *hhdr; /* header corresponding to hbp */
word size_needed = HBLKSIZE * OBJ_SZ_TO_BLOCKS_CHECKED(lb_adjusted);
size_t size_needed = HBLKSIZE * OBJ_SZ_TO_BLOCKS_CHECKED(lb_adjusted);
/* number of bytes in requested objects */

GC_ASSERT(I_HOLD_LOCK());
Expand All @@ -861,7 +857,7 @@ STATIC struct hblk *GC_allochblk_nth(size_t lb_adjusted, int k,
retry:
/* Search for a big enough block in free list. */
for (hbp = GC_hblkfreelist[index];; hbp = hhdr -> hb_next) {
word size_avail; /* bytes available in this block */
size_t size_avail; /* bytes available in this block */
size_t align_ofs;

if (hbp /* != NULL */) {
Expand Down Expand Up @@ -978,11 +974,11 @@ STATIC struct hblk *GC_allochblk_nth(size_t lb_adjusted, int k,
}
# endif
/* hbp may be on the wrong free list; the parameter index is important. */
hbp = GC_get_first_part(hbp, hhdr, (size_t)size_needed, index);
hbp = GC_get_first_part(hbp, hhdr, size_needed, index);
if (EXPECT(NULL == hbp, FALSE)) return NULL;

/* Add it to map of valid blocks. */
if (EXPECT(!GC_install_counts(hbp, (size_t)size_needed), FALSE))
if (EXPECT(!GC_install_counts(hbp, size_needed), FALSE))
return NULL; /* This leaks memory under very rare conditions. */

/* Set up the header. */
Expand All @@ -992,7 +988,7 @@ STATIC struct hblk *GC_allochblk_nth(size_t lb_adjusted, int k,
/* Result is always true, not checked to avoid a cppcheck warning. */
# else
if (EXPECT(!setup_header(hhdr, hbp, lb_adjusted, k, flags), FALSE)) {
GC_remove_counts(hbp, (size_t)size_needed);
GC_remove_counts(hbp, size_needed);
return NULL; /* ditto */
}
# endif
Expand Down Expand Up @@ -1040,17 +1036,17 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
{
struct hblk *next, *prev;
hdr *hhdr, *prevhdr, *nexthdr;
word size;
size_t size;

GET_HDR(hbp, hhdr);
size = HBLKSIZE * OBJ_SZ_TO_BLOCKS(hhdr -> hb_sz);
if ((size & SIGNB) != 0)
if ((size & SIZET_SIGNB) != 0)
ABORT("Deallocating excessively large block. Too large an allocation?");
/* Probably possible if we try to allocate more than half the address */
/* space at once. If we don't catch it here, strange things happen */
/* later. */

GC_remove_counts(hbp, (size_t)size);
GC_remove_counts(hbp, size);
hhdr -> hb_sz = size;
# ifdef USE_MUNMAP
hhdr -> hb_last_reclaimed = (unsigned short)GC_gc_no;
Expand All @@ -1069,7 +1065,8 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
prev = GC_free_block_ending_at(hbp);
/* Coalesce with successor, if possible. */
if (nexthdr != NULL && HBLK_IS_FREE(nexthdr) && IS_MAPPED(nexthdr)
&& !((hhdr -> hb_sz + nexthdr -> hb_sz) & SIGNB) /* no overflow */) {
&& ((hhdr -> hb_sz + nexthdr -> hb_sz) & SIZET_SIGNB) == 0
/* no overflow */) {
GC_remove_from_fl(nexthdr);
hhdr -> hb_sz += nexthdr -> hb_sz;
GC_remove_header(next);
Expand All @@ -1079,7 +1076,7 @@ GC_INNER void GC_freehblk(struct hblk *hbp)
if (prev /* != NULL */) { /* CPPCHECK */
prevhdr = HDR(prev);
if (IS_MAPPED(prevhdr)
&& !((hhdr -> hb_sz + prevhdr -> hb_sz) & SIGNB)) {
&& ((hhdr -> hb_sz + prevhdr -> hb_sz) & SIZET_SIGNB) == 0) {
GC_remove_from_fl(prevhdr);
prevhdr -> hb_sz += hhdr -> hb_sz;
# ifdef USE_MUNMAP
Expand Down
Loading

0 comments on commit 642a4d1

Please sign in to comment.