Skip to content

Commit

Permalink
Use ADDR_GE/LT() in reclaim.c
Browse files Browse the repository at this point in the history
(fix of commit e37ab2a)

Issue #627 (bdwgc).

* reclaim.c (GC_clear_block, GC_start_reclaim): Use ADDR_LT().
* win32_threads.c (GC_push_stack_for): Likewise.
* reclaim.c (GC_reclaim_clear, GC_reclaim_uninit, GC_reclaim_check,
GC_do_enumerate_reachable_objects): Use ADDR_GE().
* reclaim.c [ENABLE_DISCLAIM] (GC_disclaim_and_reclaim): Likewise.
* reclaim.c [VALGRIND_TRACKING] (GC_reclaim_block): Likewise.
* tests/gctest.c [!VERY_SMALL_CONFIG] (cons): Replace ptr_t to char*
casts for GC_ADDR_LT() arguments.
  • Loading branch information
ivmai committed Apr 21, 2024
1 parent 7b34b7e commit fec152c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
19 changes: 9 additions & 10 deletions reclaim.c
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ GC_INLINE word *GC_clear_block(word *p, word sz, word *pcount)
GC_ASSERT(((word)p & (2 * sizeof(word) - 1)) == 0);
p[1] = 0;
p += 2;
while ((word)p < (word)q) {
while (ADDR_LT((ptr_t)p, (ptr_t)q)) {
CLEAR_DOUBLE(p);
p += 2;
}
# else
p++; /* Skip link field */
while ((word)p < (word)q) {
while (ADDR_LT((ptr_t)p, (ptr_t)q)) {
*p++ = 0;
}
# endif
Expand Down Expand Up @@ -192,7 +192,7 @@ STATIC ptr_t GC_reclaim_clear(struct hblk *hbp, const hdr *hhdr, word sz,
/* Go through all objects in the block. */
p = hbp -> hb_body;
plim = p + HBLKSIZE - sz;
for (bit_no = 0; (word)p <= (word)plim; bit_no += MARK_BIT_OFFSET(sz)) {
for (bit_no = 0; ADDR_GE(plim, p); bit_no += MARK_BIT_OFFSET(sz)) {
if (mark_bit_from_hdr(hhdr, bit_no)) {
p += sz;
} else {
Expand Down Expand Up @@ -221,7 +221,7 @@ STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, const hdr *hhdr, word sz,
/* Go through all objects in the block. */
p = hbp -> hb_body;
plim = (ptr_t)hbp + HBLKSIZE - sz;
for (bit_no = 0; (word)p <= (word)plim;
for (bit_no = 0; ADDR_GE(plim, p);
bit_no += MARK_BIT_OFFSET(sz), p += sz) {
if (!mark_bit_from_hdr(hhdr, bit_no)) {
n_bytes_found += sz;
Expand Down Expand Up @@ -253,7 +253,7 @@ STATIC ptr_t GC_reclaim_uninit(struct hblk *hbp, const hdr *hhdr, word sz,
p = hbp -> hb_body;
plim = p + HBLKSIZE - sz;

for (bit_no = 0; (word)p <= (word)plim; bit_no += MARK_BIT_OFFSET(sz)) {
for (bit_no = 0; ADDR_GE(plim, p); bit_no += MARK_BIT_OFFSET(sz)) {
if (mark_bit_from_hdr(hhdr, bit_no)) {
p += sz;
} else if (disclaim(p)) {
Expand Down Expand Up @@ -283,7 +283,7 @@ STATIC void GC_reclaim_check(struct hblk *hbp, const hdr *hhdr, word sz)
/* Go through all objects in the block. */
p = hbp -> hb_body;
plim = p + HBLKSIZE - sz;
for (bit_no = 0; (word)p <= (word)plim;
for (bit_no = 0; ADDR_GE(plim, p);
bit_no += MARK_BIT_OFFSET(sz), p += sz) {
if (!mark_bit_from_hdr(hhdr, bit_no))
GC_add_leaked(p);
Expand Down Expand Up @@ -463,7 +463,7 @@ STATIC void GC_CALLBACK GC_reclaim_block(struct hblk *hbp,
ptr_t plim = p + HBLKSIZE - sz;
word bit_no;

for (bit_no = 0; (word)p <= (word)plim;
for (bit_no = 0; ADDR_GE(plim, p);
bit_no += MARK_BIT_OFFSET(sz), p += sz) {
if (!mark_bit_from_hdr(hhdr, bit_no))
FREE_PROFILER_HOOK(p);
Expand Down Expand Up @@ -688,7 +688,7 @@ GC_INNER void GC_start_reclaim(GC_bool report_if_found)
void **lim = &GC_obj_kinds[k].ok_freelist[MAXOBJGRANULES+1];

for (fop = GC_obj_kinds[k].ok_freelist;
(word)fop < (word)lim; (*(word **)&fop)++) {
ADDR_LT((ptr_t)fop, (ptr_t)lim); (*(word **)&fop)++) {
if (*fop != NULL) {
if (should_clobber) {
GC_clear_fl_links(fop);
Expand Down Expand Up @@ -857,8 +857,7 @@ STATIC void GC_CALLBACK GC_do_enumerate_reachable_objects(struct hblk *hbp,
plim = p + HBLKSIZE - sz;
}
/* Go through all objects in the block. */
for (bit_no = 0; (word)p <= (word)plim;
bit_no += MARK_BIT_OFFSET(sz), p += sz) {
for (bit_no = 0; ADDR_GE(plim, p); bit_no += MARK_BIT_OFFSET(sz), p += sz) {
if (mark_bit_from_hdr(hhdr, bit_no)) {
((struct enumerate_reachable_s *)ped)->proc(p, sz,
((struct enumerate_reachable_s *)ped)->client_data);
Expand Down
2 changes: 1 addition & 1 deletion tests/gctest.c
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ static sexpr cons(sexpr x, sexpr y)
r = (sexpr)checkOOM(GC_MALLOC(sizeof(struct SEXPR) + my_extra));
AO_fetch_and_add1(&collectable_count);
for (p = (int *)r;
GC_ADDR_LT((ptr_t)p, (ptr_t)r + my_extra + sizeof(struct SEXPR));
GC_ADDR_LT((char *)p, (char *)r + my_extra + sizeof(struct SEXPR));
p++) {
if (*p) {
GC_printf("Found nonzero at %p - allocator is broken\n",
Expand Down
2 changes: 1 addition & 1 deletion win32_threads.c
Original file line number Diff line number Diff line change
Expand Up @@ -916,7 +916,7 @@ STATIC word GC_push_stack_for(GC_thread thread, thread_id_t self_id,
stack_min = sp;
} else {
/* In the current thread it is always safe to use sp value. */
if (may_be_in_stack(is_self && (word)sp < (word)(crtn -> last_stack_min)
if (may_be_in_stack(is_self && ADDR_LT(sp, crtn -> last_stack_min)
? sp : crtn -> last_stack_min)) {
stack_min = (ptr_t)last_info.BaseAddress;
/* Do not probe rest of the stack if sp is correct. */
Expand Down

0 comments on commit fec152c

Please sign in to comment.