Skip to content

Commit

Permalink
Mark to_finalize after marking the finalizer list
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyichao committed Jun 5, 2016
1 parent 37cc5e6 commit 9388a82
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
2 changes: 2 additions & 0 deletions src/gc-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ static void gc_verify_track(void)
jl_printf(JL_STDERR, "Now looking for %p =======\n", lostval);
clear_mark(GC_CLEAN);
pre_mark();
gc_mark_object_list(&to_finalize);
post_mark(&finalizer_list, 1);
post_mark(&finalizer_list_marked, 1);
if (lostval_parents.len == 0) {
Expand Down Expand Up @@ -212,6 +213,7 @@ void gc_verify(void)
clear_mark(GC_CLEAN);
gc_verifying = 1;
pre_mark();
gc_mark_object_list(&to_finalize);
post_mark(&finalizer_list, 1);
post_mark(&finalizer_list_marked, 1);
int clean_len = bits_save[GC_CLEAN].len;
Expand Down
28 changes: 10 additions & 18 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -358,14 +358,8 @@ static inline int gc_setmark_big(void *o, int mark_mode)
mark_mode = GC_MARKED;
if ((mark_mode == GC_MARKED) & (bits != GC_MARKED)) {
// Move hdr from big_objects list to big_objects_marked list
*hdr->prev = hdr->next;
if (hdr->next)
hdr->next->prev = hdr->prev;
hdr->next = big_objects_marked;
hdr->prev = &big_objects_marked;
if (big_objects_marked)
big_objects_marked->prev = &hdr->next;
big_objects_marked = hdr;
gc_big_object_unlink(hdr);
gc_big_object_link(hdr, &big_objects_marked);
}
if (!(bits & GC_MARKED)) {
if (mark_mode == GC_MARKED)
Expand Down Expand Up @@ -509,11 +503,7 @@ static NOINLINE void *alloc_big(size_t sz)
v->sz = allocsz;
v->flags = 0;
v->age = 0;
v->next = jl_thread_heap.big_objects;
v->prev = &jl_thread_heap.big_objects;
if (v->next)
v->next->prev = &v->next;
jl_thread_heap.big_objects = v;
gc_big_object_link(v, &jl_thread_heap.big_objects);
return (void*)&v->header;
}

Expand Down Expand Up @@ -1202,6 +1192,12 @@ NOINLINE static void gc_mark_task(jl_task_t *ta, int d)
gc_mark_task_stack(ta, d);
}

void gc_mark_object_list(arraylist_t *list)
{
for (size_t i = 0;i < list->len;i++) {
gc_push_root(list->items[i], 0);
}
}

// for chasing down unwanted references
/*
Expand Down Expand Up @@ -1434,11 +1430,6 @@ void pre_mark(void)
gc_push_root(jl_anytuple_type_type, 0);
gc_push_root(jl_ANY_flag, 0);

// objects currently being finalized
for(i=0; i < to_finalize.len; i++) {
gc_push_root(to_finalize.items[i], 0);
}

jl_mark_box_caches();
//gc_push_root(jl_unprotect_stack_func, 0);
gc_push_root(jl_typetype_type, 0);
Expand Down Expand Up @@ -1597,6 +1588,7 @@ static void _jl_gc_collect(int full, char *stack_hi)
post_mark(&finalizer_list, 0);
if (prev_sweep_full)
post_mark(&finalizer_list_marked, 0);
gc_mark_object_list(&to_finalize);
gc_settime_postmark_end();

int64_t live_sz_ub = live_bytes + actual_allocd;
Expand Down
18 changes: 18 additions & 0 deletions src/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,26 @@ STATIC_INLINE jl_gc_pagemeta_t *page_metadata(void *data)
return &r->meta[pg_idx];
}

STATIC_INLINE void gc_big_object_unlink(const bigval_t *hdr)
{
*hdr->prev = hdr->next;
if (hdr->next) {
hdr->next->prev = hdr->prev;
}
}

STATIC_INLINE void gc_big_object_link(bigval_t *hdr, bigval_t **list)
{
hdr->next = *list;
hdr->prev = list;
if (*list)
(*list)->prev = &hdr->next;
*list = hdr;
}

void pre_mark(void);
void post_mark(arraylist_t *list, int dryrun);
void gc_mark_object_list(arraylist_t *list);
void gc_debug_init(void);

#define jl_thread_heap (jl_get_ptls_states()->heap)
Expand Down

0 comments on commit 9388a82

Please sign in to comment.