From 9e9879b952d9565ba6efc775b3abf2f4630c7e1e Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 20 Apr 2022 11:51:32 -0400 Subject: [PATCH] gc-ext: only sweep unmarked objects (#45035) This prior conditional was a fixed constant branch, so this seems more like the intent. (cherry picked from commit ac51add4a610668835bb12db4913af1c2c16aaf8) --- src/gc.c | 13 +++++++------ test/gcext/gcext.c | 6 ++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/gc.c b/src/gc.c index df06d7e5a6e7f..a9f8f952795bc 100644 --- a/src/gc.c +++ b/src/gc.c @@ -548,20 +548,21 @@ JL_DLLEXPORT void jl_finalize_th(jl_ptls_t ptls, jl_value_t *o) arraylist_free(&copied_list); } +// explicitly scheduled objects for the sweepfunc callback static void gc_sweep_foreign_objs_in_list(arraylist_t *objs) { size_t p = 0; for (size_t i = 0; i < objs->len; i++) { - jl_value_t *v = (jl_value_t *)(objs->items[i]); - jl_datatype_t *t = (jl_datatype_t *)(jl_typeof(v)); + jl_value_t *v = (jl_value_t*)(objs->items[i]); + jl_datatype_t *t = (jl_datatype_t*)(jl_typeof(v)); const jl_datatype_layout_t *layout = t->layout; jl_fielddescdyn_t *desc = (jl_fielddescdyn_t*)jl_dt_layout_fields(layout); - if (!gc_ptr_tag(v, 1)) { + + int bits = jl_astaggedvalue(v)->bits.gc; + if (!gc_marked(bits)) desc->sweepfunc(v); - } - else { + else objs->items[p++] = v; - } } objs->len = p; } diff --git a/test/gcext/gcext.c b/test/gcext/gcext.c index 2b380c43feccb..b66f21bb660ee 100644 --- a/test/gcext/gcext.c +++ b/test/gcext/gcext.c @@ -561,8 +561,10 @@ void sweep_stack_data(jl_value_t *p) { obj_sweeps++; dynstack_t *stk = (dynstack_t *)p; - if (stk->size > stk->capacity) - jl_error("internal error during sweeping"); + if (stk->size > stk->capacity) { + assert(0 && "internal error during sweeping"); + abort(); + } } // Safely execute Julia code