Skip to content

Commit

Permalink
try to fix bug in writebarrier_before_copy
Browse files Browse the repository at this point in the history
when we are marking, we must not inspect the state of the
GCFLAG_TRACK_YOUNG_PTRS of the source array in writebarrier_before_copy.
the reason for that is that the write barrier is not only responsible
for identifying the old objects that point to young objects. it is
crucially also responsible for identifying the old black objects that
were modified at all since the last collection, to make sure that they
can be turned gray in the next minor collection and get traced again as
part of the incremental marking
  • Loading branch information
cfbolz committed Mar 21, 2024
1 parent 1e26d9b commit 78bbeb9
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions rpython/memory/gc/incminimark.py
Expand Up @@ -1634,8 +1634,11 @@ def writebarrier_before_copy(self, source_addr, dest_addr,
#
self.manually_copy_card_bits(source_addr, dest_addr, length)
return True
#
if source_hdr.tid & GCFLAG_TRACK_YOUNG_PTRS == 0:
# NB: if we are marking, we must not inspect the state of the
# GCFLAG_TRACK_YOUNG_PTRS of source_addr here, because in the marking
# phase we rely on the write barrier to also turn black objects back
# into gray ones. see also the end of collect_cardrefs_to_nursery
if source_hdr.tid & GCFLAG_TRACK_YOUNG_PTRS == 0 or self.gc_state == STATE_MARKING:
# there might be in source a pointer to a young object
self.old_objects_pointing_to_young.append(dest_addr)
dest_hdr.tid &= ~GCFLAG_TRACK_YOUNG_PTRS
Expand Down

0 comments on commit 78bbeb9

Please sign in to comment.