Skip to content

Commit

Permalink
Add bit to the GC tag
Browse files Browse the repository at this point in the history
  • Loading branch information
gbaraldi committed Mar 29, 2023
1 parent 8f78a94 commit d586b0c
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
1 change: 1 addition & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 5 additions & 2 deletions src/staticdata.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)));
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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++) {
Expand Down

0 comments on commit d586b0c

Please sign in to comment.