Remove st_lookup when updating object ID

This commit is contained in:
Peter Zhu 2024-03-26 13:59:21 -04:00
parent 4566843b3e
commit c50b6425b4

10
gc.c
View File

@ -9560,20 +9560,22 @@ gc_move(rb_objspace_t *objspace, VALUE scan, VALUE free, size_t src_slot_size, s
} }
if (FL_TEST((VALUE)src, FL_SEEN_OBJ_ID)) { if (FL_TEST((VALUE)src, FL_SEEN_OBJ_ID)) {
st_data_t srcid = (st_data_t)src, id;
/* If the source object's object_id has been seen, we need to update /* If the source object's object_id has been seen, we need to update
* the object to object id mapping. */ * the object to object id mapping. */
if (st_lookup(objspace->obj_to_id_tbl, srcid, &id)) { st_data_t srcid = (st_data_t)src, id;
gc_report(4, objspace, "Moving object with seen id: %p -> %p\n", (void *)src, (void *)dest); gc_report(4, objspace, "Moving object with seen id: %p -> %p\n", (void *)src, (void *)dest);
/* Resizing the st table could cause a malloc */ /* Resizing the st table could cause a malloc */
DURING_GC_COULD_MALLOC_REGION_START(); DURING_GC_COULD_MALLOC_REGION_START();
{ {
st_delete(objspace->obj_to_id_tbl, &srcid, 0); if (!st_delete(objspace->obj_to_id_tbl, &srcid, &id)) {
rb_bug("gc_move: object ID seen, but not in mapping table: %s", obj_info((VALUE)src));
}
st_insert(objspace->obj_to_id_tbl, (st_data_t)dest, id); st_insert(objspace->obj_to_id_tbl, (st_data_t)dest, id);
} }
DURING_GC_COULD_MALLOC_REGION_END(); DURING_GC_COULD_MALLOC_REGION_END();
} }
}
else { else {
GC_ASSERT(!st_lookup(objspace->obj_to_id_tbl, (st_data_t)src, NULL)); GC_ASSERT(!st_lookup(objspace->obj_to_id_tbl, (st_data_t)src, NULL));
} }