summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Maidanski <ivmai@mail.ru>2022-08-03 07:53:47 +0300
committerIvan Maidanski <ivmai@mail.ru>2022-08-03 21:26:18 +0300
commita7b3a08d30e0498de3ad44c5e75bc21600ef9ff8 (patch)
tree5b9b28d7894dfdc9875ddd9967db4fe06a4da6dc
parent89308bed1754cafe54e713ef950ef04727c17299 (diff)
downloadbdwgc-a7b3a08d30e0498de3ad44c5e75bc21600ef9ff8.tar.gz
Use modHBLKSZ where possible
(refactoring) * allchblk.c (GC_remove_from_fl_at, GC_add_to_fl, GC_get_first_part): Replace v&(HBLKSIZE-1) to modHBLKSZ(v). * allchblk.c [!GC_DISABLE_INCREMENTAL] (GC_allochblk_nth): Likewise. * include/private/gc_priv.h (HBLKDISPL): Likewise. * include/private/gc_hdrs.h (MAX_JUMP): Remove spaces in HBLKSIZE-1 (to match similar expressions). * include/private/gc_priv.h (OBJ_SZ_TO_BLOCKS_CHECKED): Likewise. * misc.c (block_add_size): Likewise. * os_dep.c [!MSWIN_XBOX1 && !MSWINCE && (USE_WINALLOC || CYGWIN32)] (GC_win32_get_mem): Likewise. * include/private/gc_priv.h (HBLKMASK): Remove. * include/private/gc_priv.h (obj_link): Remove extra space in the expression. * malloc.c (GC_generic_malloc_uncollectable): Replace (word)op&(HBLKSIZE-1) to HBLKDISPL(op). * mallocx.c (GC_realloc): Replace HBLKMASK to (HBLKSIZE-1).
-rw-r--r--allchblk.c8
-rw-r--r--include/private/gc_hdrs.h2
-rw-r--r--include/private/gc_priv.h9
-rw-r--r--malloc.c2
-rw-r--r--mallocx.c2
-rw-r--r--misc.c4
-rw-r--r--os_dep.c4
7 files changed, 14 insertions, 17 deletions
diff --git a/allchblk.c b/allchblk.c
index e3f54522..4be830da 100644
--- a/allchblk.c
+++ b/allchblk.c
@@ -301,7 +301,7 @@ static GC_bool setup_header(hdr * hhdr, struct hblk *block, size_t byte_sz,
/* Remove hhdr from the free list (it is assumed to specified by index). */
STATIC void GC_remove_from_fl_at(hdr *hhdr, int index)
{
- GC_ASSERT(((hhdr -> hb_sz) & (HBLKSIZE-1)) == 0);
+ GC_ASSERT(modHBLKSZ(hhdr -> hb_sz) == 0);
if (hhdr -> hb_prev == 0) {
GC_ASSERT(HDR(GC_hblkfreelist[index]) == hhdr);
GC_hblkfreelist[index] = hhdr -> hb_next;
@@ -385,7 +385,7 @@ STATIC void GC_add_to_fl(struct hblk *h, hdr *hhdr)
GC_ASSERT(prev == 0 || !HBLK_IS_FREE(prevhdr)
|| (GC_heapsize & SIGNB) != 0);
# endif
- GC_ASSERT(((hhdr -> hb_sz) & (HBLKSIZE-1)) == 0);
+ GC_ASSERT(modHBLKSZ(hhdr -> hb_sz) == 0);
GC_hblkfreelist[index] = h;
GC_free_bytes[index] += hhdr -> hb_sz;
GC_ASSERT(GC_free_bytes[index] <= GC_large_free_bytes);
@@ -590,7 +590,7 @@ STATIC struct hblk * GC_get_first_part(struct hblk *h, hdr *hhdr,
GC_ASSERT(I_HOLD_LOCK());
total_size = hhdr -> hb_sz;
- GC_ASSERT((total_size & (HBLKSIZE-1)) == 0);
+ GC_ASSERT(modHBLKSZ(total_size) == 0);
GC_remove_from_fl_at(hhdr, index);
if (total_size == bytes) return h;
rest = (struct hblk *)((word)h + bytes);
@@ -908,7 +908,7 @@ GC_allochblk_nth(size_t sz, int kind, unsigned flags, int n, int may_split)
/* if it is avoidable. This also ensures that newly allocated */
/* blocks are treated as dirty. Necessary since we don't */
/* protect free blocks. */
- GC_ASSERT((size_needed & (HBLKSIZE-1)) == 0);
+ GC_ASSERT(modHBLKSZ(size_needed) == 0);
GC_remove_protection(hbp, divHBLKSZ(size_needed),
(hhdr -> hb_descr == 0) /* pointer-free */);
# endif
diff --git a/include/private/gc_hdrs.h b/include/private/gc_hdrs.h
index e3bdfd63..58113f92 100644
--- a/include/private/gc_hdrs.h
+++ b/include/private/gc_hdrs.h
@@ -152,7 +152,7 @@ typedef struct bi {
/* GC_all_nils. */
-#define MAX_JUMP (HBLKSIZE - 1)
+#define MAX_JUMP (HBLKSIZE-1)
#define HDR_FROM_BI(bi, p) \
(bi)->index[((word)(p) >> LOG_HBLKSIZE) & (BOTTOM_SZ - 1)]
diff --git a/include/private/gc_priv.h b/include/private/gc_priv.h
index 7f56db1f..6b731313 100644
--- a/include/private/gc_priv.h
+++ b/include/private/gc_priv.h
@@ -984,7 +984,7 @@ EXTERN_C_BEGIN
# define HBLKPTR(objptr) ((struct hblk *)(((word)(objptr)) \
& ~(word)(HBLKSIZE-1)))
-# define HBLKDISPL(objptr) (((size_t) (objptr)) & (HBLKSIZE-1))
+# define HBLKDISPL(objptr) modHBLKSZ((size_t)(objptr))
/* Round up allocation size (in bytes) to a multiple of a granule. */
#define ROUNDUP_GRANULE_SIZE(lb) /* lb should have no side-effect */ \
@@ -1073,9 +1073,6 @@ typedef word page_hash_table[PHT_SIZE];
/* */
/********************************************/
-/* heap block header */
-#define HBLKMASK (HBLKSIZE-1)
-
#define MARK_BITS_PER_HBLK (HBLKSIZE/GRANULE_BYTES)
/* upper bound */
/* We allocate 1 bit per allocation granule. */
@@ -1222,12 +1219,12 @@ struct hblk {
# define OBJ_SZ_TO_BLOCKS(lb) divHBLKSZ((lb) + HBLKSIZE-1)
# define OBJ_SZ_TO_BLOCKS_CHECKED(lb) /* lb should have no side-effect */ \
- divHBLKSZ(SIZET_SAT_ADD(lb, HBLKSIZE - 1))
+ divHBLKSZ(SIZET_SAT_ADD(lb, HBLKSIZE-1))
/* Size of block (in units of HBLKSIZE) needed to hold objects of */
/* given lb (in bytes). The checked variant prevents wrap around. */
/* Object free list link */
-# define obj_link(p) (*(void **)(p))
+# define obj_link(p) (*(void **)(p))
# define LOG_MAX_MARK_PROCS 6
# define MAX_MARK_PROCS (1 << LOG_MAX_MARK_PROCS)
diff --git a/malloc.c b/malloc.c
index 7714e5dd..65434f2d 100644
--- a/malloc.c
+++ b/malloc.c
@@ -389,7 +389,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_generic_malloc_uncollectable(
if (op /* != NULL */) { /* CPPCHECK */
hdr * hhdr = HDR(op);
- GC_ASSERT(((word)op & (HBLKSIZE - 1)) == 0); /* large block */
+ GC_ASSERT(HBLKDISPL(op) == 0); /* large block */
/* We don't need the lock here, since we have an undisguised */
/* pointer. We do need to hold the lock while we adjust */
/* mark bits. */
diff --git a/mallocx.c b/mallocx.c
index eb97947b..a5e2856e 100644
--- a/mallocx.c
+++ b/mallocx.c
@@ -106,7 +106,7 @@ GC_API void * GC_CALL GC_realloc(void * p, size_t lb)
/* Round it up to the next whole heap block */
word descr = GC_obj_kinds[obj_kind].ok_descriptor;
- sz = (sz + HBLKSIZE-1) & ~HBLKMASK;
+ sz = (sz + HBLKSIZE-1) & ~(HBLKSIZE-1);
if (GC_obj_kinds[obj_kind].ok_relocate_descr)
descr += sz;
/* GC_realloc might be changing the block size while */
diff --git a/misc.c b/misc.c
index abb803f5..a3589d11 100644
--- a/misc.c
+++ b/misc.c
@@ -2350,8 +2350,8 @@ 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(hhdr->hb_sz) + (HBLKSIZE - 1))
- & ~(word)(HBLKSIZE - 1);
+ *(word *)pbytes += (WORDS_TO_BYTES(hhdr->hb_sz) + HBLKSIZE-1)
+ & ~(word)(HBLKSIZE-1);
}
GC_API size_t GC_CALL GC_get_memory_use(void)
diff --git a/os_dep.c b/os_dep.c
index ce91b30d..61b8d53c 100644
--- a/os_dep.c
+++ b/os_dep.c
@@ -2454,8 +2454,8 @@ void * os2_alloc(size_t bytes)
/* problems, so we dodge the issue. */
result = (ptr_t)GlobalAlloc(0, SIZET_SAT_ADD(bytes, HBLKSIZE));
/* Align it at HBLKSIZE boundary. */
- result = (ptr_t)(((word)result + HBLKSIZE - 1)
- & ~(word)(HBLKSIZE - 1));
+ result = (ptr_t)(((word)result + HBLKSIZE-1)
+ & ~(word)(HBLKSIZE-1));
} else
# endif
/* else */ {