From d586b0c9520afd30d101522b1e09708bdd31fcc6 Mon Sep 17 00:00:00 2001 From: Gabriel Baraldi Date: Wed, 29 Mar 2023 18:09:22 -0300 Subject: [PATCH] Add bit to the GC tag --- src/gc.c | 2 +- src/julia.h | 1 + src/julia_internal.h | 1 + src/staticdata.c | 7 +++++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/gc.c b/src/gc.c index 9d5d49fa4fc53..195ee2d98ab4f 100644 --- a/src/gc.c +++ b/src/gc.c @@ -2390,7 +2390,7 @@ FORCE_INLINE void gc_mark_outrefs(jl_ptls_t ptls, jl_gc_markqueue_t *mq, void *_ int update_meta = __likely(!meta_updated && !gc_verifying); int foreign_alloc = 0; // directly point at eyt_obj_in_img to encourage inlining - if (update_meta && eyt_obj_in_img(new_obj)) { + if (update_meta && o->bits.in_image) { foreign_alloc = 1; update_meta = 0; } diff --git a/src/julia.h b/src/julia.h index 2186ee346418d..64b7fc452a4da 100644 --- a/src/julia.h +++ b/src/julia.h @@ -91,6 +91,7 @@ typedef struct _jl_value_t jl_value_t; struct _jl_taggedvalue_bits { uintptr_t gc:2; + uintptr_t in_image:1; }; JL_EXTENSION struct _jl_taggedvalue_t { diff --git a/src/julia_internal.h b/src/julia_internal.h index 2e1aef50d9a55..73f8b9467fcf4 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -301,6 +301,7 @@ static inline void memmove_refs(void **dstp, void *const *srcp, size_t n) JL_NOT #define GC_MARKED 1 // reachable and young #define GC_OLD 2 // if it is reachable it will be marked as old #define GC_OLD_MARKED (GC_OLD | GC_MARKED) // reachable and old +#define GC_IN_IMAGE 4 // useful constants extern jl_methtable_t *jl_type_type_mt JL_GLOBALLY_ROOTED; diff --git a/src/staticdata.c b/src/staticdata.c index ddc27f83cc0ee..d6c92ac93a851 100644 --- a/src/staticdata.c +++ b/src/staticdata.c @@ -1758,6 +1758,7 @@ void gc_sweep_sysimg(void) last_pos = pos; jl_taggedvalue_t *o = (jl_taggedvalue_t *)(base + pos); o->bits.gc = GC_OLD; + assert(o->bits.in_image == 1); } } } @@ -2811,7 +2812,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl *base = image_base; s.s = &sysimg; - jl_read_reloclist(&s, s.link_ids_gctags, GC_OLD); // gctags + jl_read_reloclist(&s, s.link_ids_gctags, GC_OLD | GC_IN_IMAGE); // gctags size_t sizeof_tags = ios_pos(&relocs); (void)sizeof_tags; jl_read_reloclist(&s, s.link_ids_relocs, 0); // general relocs @@ -2922,7 +2923,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl arraylist_push(&cleanup_list, (void*)obj); } if (tag) - *pfld = (uintptr_t)newobj | GC_OLD; + *pfld = (uintptr_t)newobj | GC_OLD | GC_IN_IMAGE; else *pfld = (uintptr_t)newobj; assert(!(image_base < (char*)newobj && (char*)newobj <= image_base + sizeof_sysimg + sizeof(uintptr_t))); @@ -2965,6 +2966,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl memset(o, 0xba, sizeof(jl_value_t*) + sizeof(jl_datatype_t)); else memset(o, 0xba, sizeof(jl_value_t*) + 0); // singleton + o->bits.in_image = 1; } arraylist_grow(&cleanup_list, -cleanup_list.len); // finally cache all our new types now @@ -3032,6 +3034,7 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl jl_value_t *t = jl_typeof(item); if (t == (jl_value_t*)jl_method_instance_type) memset(o, 0xba, sizeof(jl_value_t*) * 3); // only specTypes and sparams fields stored + o->bits.in_image = 1; } arraylist_free(&cleanup_list); for (size_t i = 0; i < s.fixup_objs.len; i++) {