Skip to content

Commit

Permalink
Revert "Change type of argument of set/clear_fl_marks() to that of fr…
Browse files Browse the repository at this point in the history
…eelist"

This reverts commit 8697096.
  • Loading branch information
ivmai committed Mar 4, 2024
1 parent a85c6b1 commit 0e3cf6d
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 59 deletions.
81 changes: 36 additions & 45 deletions alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -978,36 +978,32 @@ STATIC GC_bool GC_stopped_mark(GC_stop_func stop_func)
return TRUE;
}

GC_INNER void GC_set_fl_marks(void **fl)
/* Set all mark bits for the free list whose first entry is q */
GC_INNER void GC_set_fl_marks(ptr_t q)
{
ptr_t q = (ptr_t)fl;
# ifdef GC_ASSERTIONS
if (q /* != NULL */) { /* CPPCHECK */
# ifdef GC_ASSERTIONS
ptr_t q2;
# endif
struct hblk *h = HBLKPTR(q);
struct hblk *last_h = h;
hdr *hhdr;
# ifdef MARK_BIT_PER_OBJ
word sz;
# endif
# endif
struct hblk *h = HBLKPTR(q);
struct hblk *last_h = h;
hdr *hhdr = HDR(h);
IF_PER_OBJ(word sz = hhdr->hb_sz;)

GC_ASSERT(fl != NULL);
hhdr = HDR(h);
# ifdef MARK_BIT_PER_OBJ
sz = hhdr -> hb_sz;
# endif
# ifdef GC_ASSERTIONS
# ifdef GC_ASSERTIONS
q2 = (ptr_t)obj_link(q);
# endif
for (;;) {
# endif
for (;;) {
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);
INCR_MARKS(hhdr);
}

q = (ptr_t)obj_link(q);
if (NULL == q) break;
if (q == NULL)
break;
# ifdef GC_ASSERTIONS
/* Detect a cycle in the freelist. The algorithm is to */
/* have a second "twice faster" iterator over the list - */
Expand All @@ -1024,14 +1020,12 @@ GC_INNER void GC_set_fl_marks(void **fl)
# endif

h = HBLKPTR(q);
if (EXPECT(h != last_h, FALSE)) {
if (h != last_h) {
last_h = h;
/* Update hhdr and sz. */
hhdr = HDR(h);
# ifdef MARK_BIT_PER_OBJ
sz = hhdr -> hb_sz;
# endif
IF_PER_OBJ(sz = hhdr->hb_sz;)
}
}
}
}

Expand Down Expand Up @@ -1080,15 +1074,14 @@ GC_INNER void GC_set_fl_marks(void **fl)
}
#endif /* GC_ASSERTIONS && THREAD_LOCAL_ALLOC */

/* Clear all mark bits for the free list (specified by the first */
/* entry). Decrement GC_bytes_found by number of bytes on free list. */
STATIC void GC_clear_fl_marks(void **fl)
/* Clear all mark bits for the free list whose first entry is q */
/* Decrement GC_bytes_found by number of bytes on free list. */
STATIC void GC_clear_fl_marks(ptr_t q)
{
ptr_t q = (ptr_t)fl;
struct hblk *h = HBLKPTR(q);
struct hblk *last_h = h;
hdr *hhdr = HDR(h);
word sz = hhdr -> hb_sz; /* Normally set only once. */
word sz = hhdr->hb_sz; /* Normally set only once. */

for (;;) {
word bit_no = MARK_BIT_NO((ptr_t)q - (ptr_t)h, sz);
Expand All @@ -1111,14 +1104,14 @@ STATIC void GC_clear_fl_marks(void **fl)
GC_bytes_found -= (signed_word)sz;

q = (ptr_t)obj_link(q);
if (NULL == q) break;
if (q == NULL)
break;

h = HBLKPTR(q);
if (EXPECT(h != last_h, FALSE)) {
if (h != last_h) {
last_h = h;
/* Update hhdr and sz. */
hhdr = HDR(h);
sz = hhdr -> hb_sz;
sz = hhdr->hb_sz;
}
}
}
Expand Down Expand Up @@ -1188,16 +1181,15 @@ STATIC void GC_finish_collection(void)
if (GC_find_leak) {
/* Mark all objects on the free list. All objects should be */
/* marked when we're done. */
word size; /* current object size */
unsigned kind;
ptr_t q;

for (kind = 0; kind < GC_n_kinds; kind++) {
word size; /* current object size */

for (size = 1; size <= MAXOBJGRANULES; size++) {
void **fl = GC_obj_kinds[kind].ok_freelist[size];

if (fl != NULL)
GC_set_fl_marks(fl);
q = (ptr_t)GC_obj_kinds[kind].ok_freelist[size];
if (q != NULL)
GC_set_fl_marks(q);
}
}
GC_start_reclaim(TRUE);
Expand Down Expand Up @@ -1228,16 +1220,15 @@ STATIC void GC_finish_collection(void)
/* Thus accidentally marking a free list is not a problem; only */
/* objects on the list itself will be marked, and that's fixed here. */
{
word size; /* current object size */
ptr_t q; /* pointer to current object */
unsigned kind;

for (kind = 0; kind < GC_n_kinds; kind++) {
word size; /* current object size */

for (size = 1; size <= MAXOBJGRANULES; size++) {
void **fl = GC_obj_kinds[kind].ok_freelist[size];

if (fl != NULL)
GC_clear_fl_marks(fl);
q = (ptr_t)GC_obj_kinds[kind].ok_freelist[size];
if (q != NULL)
GC_clear_fl_marks(q);
}
}
}
Expand Down
4 changes: 3 additions & 1 deletion include/private/gc_priv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1920,11 +1920,13 @@ struct GC_traced_stack_sect_s {
/* offset and size (in bytes). */
# define MARK_BIT_OFFSET(sz) 1
/* Spacing between useful mark bits. */
# define IF_PER_OBJ(x) x
# define FINAL_MARK_BIT(sz) ((sz) > MAXOBJBYTES? 1 : HBLK_OBJS(sz))
/* Position of final, always set, mark bit. */
#else
# 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) \
((sz) > MAXOBJBYTES ? MARK_BITS_PER_HBLK \
: BYTES_TO_GRANULES((sz) * HBLK_OBJS(sz)))
Expand Down Expand Up @@ -2166,7 +2168,7 @@ GC_INNER void GC_clear_hdr_marks(hdr * hhdr);
/* Clear the mark bits in a header */
GC_INNER void GC_set_hdr_marks(hdr * hhdr);
/* Set the mark bits in a header */
GC_INNER void GC_set_fl_marks(void **fl);
GC_INNER void GC_set_fl_marks(ptr_t p);
/* Set all mark bits associated with */
/* a free list. */
#if defined(GC_ASSERTIONS) && defined(THREAD_LOCAL_ALLOC)
Expand Down
23 changes: 10 additions & 13 deletions thread_local_alloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,25 +266,22 @@ GC_API GC_ATTR_MALLOC void * GC_CALL GC_gcj_malloc(size_t lb,
/* we take care of an individual thread freelist structure. */
GC_INNER void GC_mark_thread_local_fls_for(GC_tlfs p)
{
int j;
ptr_t q;
int k, j;

for (j = 0; j < GC_TINY_FREELISTS; ++j) {
int k;

for (k = 0; k < THREAD_FREELISTS_KINDS; ++k) {
void **fl = (void **)AO_load((volatile AO_t *)&p->_freelists[k][j]);
/* Load the pointer atomically as it might be updated */
/* concurrently by GC_FAST_MALLOC_GRANS. */

if ((word)fl > HBLKSIZE)
GC_set_fl_marks(fl);
/* Load the pointer atomically as it might be updated */
/* concurrently by GC_FAST_MALLOC_GRANS. */
q = (ptr_t)AO_load((volatile AO_t *)&p->_freelists[k][j]);
if ((word)q > HBLKSIZE)
GC_set_fl_marks(q);
}
# ifdef GC_GCJ_SUPPORT
if (EXPECT(j > 0, TRUE)) {
void **fl = (void **)AO_load((volatile AO_t *)&p->gcj_freelists[j]);

if ((word)fl > HBLKSIZE)
GC_set_fl_marks(fl);
q = (ptr_t)AO_load((volatile AO_t *)&p->gcj_freelists[j]);
if ((word)q > HBLKSIZE)
GC_set_fl_marks(q);
}
# endif
}
Expand Down

0 comments on commit 0e3cf6d

Please sign in to comment.