diff --git a/allchblk.c b/allchblk.c index c780fa001..2f78d18b9 100644 --- a/allchblk.c +++ b/allchblk.c @@ -506,7 +506,7 @@ GC_INNER void GC_unmap_old(unsigned threshold) /* Check that the interval is not smaller than the threshold. */ /* The truncated counter value wrapping is handled correctly. */ - if ((unsigned short)(GC_gc_no - hhdr->hb_last_reclaimed) + if ((unsigned short)(GC_gc_no - hhdr -> hb_last_reclaimed) >= (unsigned short)threshold) { # ifdef COUNT_UNMAPPED_REGIONS /* Continue with unmapping the block only if it will not */ @@ -629,6 +629,7 @@ STATIC struct hblk * GC_get_first_part(struct hblk *h, hdr *hhdr, WARN("Header allocation failed: dropping block\n", 0); return NULL; } + rest_hdr -> hb_block = rest; rest_hdr -> hb_sz = total_size - size_needed; rest_hdr -> hb_flags = 0; # ifdef GC_ASSERTIONS diff --git a/dbg_mlc.c b/dbg_mlc.c index 05341657a..bfecb536e 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -939,6 +939,7 @@ GC_API GC_ATTR_MALLOC void * GC_CALL size_t bit_no; UNUSED_ARG(dummy); + GC_ASSERT((ptr_t)(hhdr -> hb_block) == p); plim = sz > MAXOBJBYTES ? p : p + HBLKSIZE - sz; /* Go through all objects in block. */ for (bit_no = 0; ADDR_GE(plim, p); diff --git a/headers.c b/headers.c index e85836901..dbde84545 100644 --- a/headers.c +++ b/headers.c @@ -343,7 +343,8 @@ GC_API void GC_CALL GC_apply_to_all_blocks(GC_walk_hblk_fn fn, j -= (signed_word)(hhdr != NULL ? ADDR(hhdr) : 1); } else { if (!HBLK_IS_FREE(hhdr)) { - fn((struct hblk *)HBLK_ADDR(bi, j), client_data); + GC_ASSERT(HBLK_ADDR(bi, j) == ADDR(hhdr -> hb_block)); + fn(hhdr -> hb_block, client_data); } j--; } @@ -374,7 +375,8 @@ GC_INNER struct hblk * GC_next_block(struct hblk *h, GC_bool allow_free) j++; } else { if (allow_free || !HBLK_IS_FREE(hhdr)) { - return (struct hblk *)HBLK_ADDR(bi, j); + GC_ASSERT(HBLK_ADDR(bi, j) == ADDR(hhdr -> hb_block)); + return hhdr -> hb_block; } j += divHBLKSZ(hhdr -> hb_sz); } @@ -408,6 +410,7 @@ GC_INNER struct hblk * GC_prev_block(struct hblk *h) } else if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) { j -= (signed_word)ADDR(hhdr); } else { + /* TODO: return hhdr -> hb_block instead */ return (struct hblk *)HBLK_ADDR(bi, j); } } diff --git a/malloc.c b/malloc.c index 1287fcb5b..36ba6138b 100644 --- a/malloc.c +++ b/malloc.c @@ -634,7 +634,8 @@ static void free_internal(void *p, const hdr *hhdr) if (lb > HBLKSIZE) { GC_large_allocd_bytes -= HBLKSIZE * OBJ_SZ_TO_BLOCKS(lb); } - GC_freehblk(HBLKPTR(p)); + GC_ASSERT(ADDR(HBLKPTR(p)) == ADDR(hhdr -> hb_block)); + GC_freehblk(hhdr -> hb_block); } } diff --git a/reclaim.c b/reclaim.c index 4ad2998c4..c5d8ae033 100644 --- a/reclaim.c +++ b/reclaim.c @@ -375,6 +375,7 @@ STATIC void GC_reclaim_small_nonempty_block(struct hblk *hbp, size_t sz, if (hhdr -> hb_n_marks) { *flh = flh_next; } else { + GC_ASSERT(hbp == hhdr -> hb_block); GC_bytes_found += (signed_word)HBLKSIZE; GC_freehblk(hbp); } @@ -410,6 +411,7 @@ STATIC void GC_CALLBACK GC_reclaim_block(struct hblk *hbp, if (sz > MAXOBJBYTES) { /* 1 big object */ if (!mark_bit_from_hdr(hhdr, 0)) { if (report_if_found) { + GC_ASSERT(hbp == hhdr -> hb_block); GC_add_leaked((ptr_t)hbp); } else { # ifdef ENABLE_DISCLAIM @@ -421,6 +423,7 @@ STATIC void GC_CALLBACK GC_reclaim_block(struct hblk *hbp, } } # endif + GC_ASSERT(hbp == hhdr -> hb_block); if (sz > HBLKSIZE) { GC_large_allocd_bytes -= HBLKSIZE * OBJ_SZ_TO_BLOCKS(sz); } @@ -468,6 +471,7 @@ STATIC void GC_CALLBACK GC_reclaim_block(struct hblk *hbp, } } # endif + GC_ASSERT(hbp == hhdr -> hb_block); if (report_if_found) { GC_reclaim_small_nonempty_block(hbp, sz, TRUE /* report_if_found */);