From c82656dac05c5802b6a10dce4227246f280bf055 Mon Sep 17 00:00:00 2001 From: Diogo Netto <61364108+d-netto@users.noreply.github.com> Date: Fri, 21 Jul 2023 21:55:32 -0300 Subject: [PATCH] gc: faster invalid object lookup in conservative GC (#50599) Optimizes invalid object lookup in conservative GC by just looking at the page metadata and GC bits. --- src/gc.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/gc.c b/src/gc.c index ec6d6b42cc71e..54d1bf53dbf75 100644 --- a/src/gc.c +++ b/src/gc.c @@ -4070,18 +4070,11 @@ JL_DLLEXPORT jl_value_t *jl_gc_internal_obj_base_ptr(void *p) // before the freelist pointer was either live during the last // sweep or has been allocated since. if (gc_page_data(cell) == gc_page_data(pool->freelist) - && (char *)cell < (char *)pool->freelist) { + && (char *)cell < (char *)pool->freelist) goto valid_object; - } - else { - jl_taggedvalue_t *v = pool->freelist; - while (v != NULL) { - if (v == cell) { - return NULL; - } - v = v->next; - } - } + // already skipped marked or old objects above, so here + // the age bits are 0, thus the object is on the freelist + return NULL; // Not a freelist entry, therefore a valid object. valid_object: // We have to treat objects with type `jl_buff_tag` differently,