Skip to content

Commit

Permalink
enable GC sooner when loading precompiled modules
Browse files Browse the repository at this point in the history
part of #20671
  • Loading branch information
JeffBezanson committed Mar 27, 2017
1 parent f65b8ab commit b76c7c7
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 2 deletions.
35 changes: 33 additions & 2 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2123,6 +2123,18 @@ static void jl_insert_methods(linkedlist_t *list)
}
}

static void linkedlist_to_array(jl_array_t *a, linkedlist_t *list)
{
while (list) {
size_t i;
for (i = 0; i < list->count; i++) {
jl_array_ptr_1d_push(a, (jl_value_t*)list->def[i].meth);
jl_array_ptr_1d_push(a, (jl_value_t*)list->def[i].simpletype);
}
list = list->next;
}
}

static void jl_insert_backedges(linkedlist_t *list)
{
while (list) {
Expand Down Expand Up @@ -3047,6 +3059,20 @@ static int trace_method(jl_typemap_entry_t *entry, void *closure)
return 1;
}

void jl_gc_mark_deserializer_state(jl_ptls_t ptls)
{
size_t i;
for (i=0; i < flagref_list.len; ) {
jl_value_t **loc = (jl_value_t**)flagref_list.items[i];
if (loc)
jl_gc_push_root(ptls, *loc);
i += 2;
}
for (i=0; i < backref_list.len; i++) {
jl_gc_push_root(ptls, (jl_value_t*)backref_list.items[i]);
}
}

static jl_value_t *_jl_restore_incremental(ios_t *f)
{
if (ios_eof(f) || !jl_read_verify_header(f)) {
Expand Down Expand Up @@ -3100,14 +3126,19 @@ static jl_value_t *_jl_restore_incremental(ios_t *f)
// now all of the interconnects will be created
jl_recache_types(); // make all of the types identities correct
init_order = jl_finalize_deserializer(&s, tracee_list); // done with f and s (needs to be after recache types)

jl_array_t *extmeths = jl_alloc_vec_any(0); // make array of references for GC
linkedlist_to_array(extmeths, &external_methods);

JL_GC_PUSH3(&init_order, &restored, &extmeths);
jl_gc_enable(en);

jl_insert_methods(&external_methods); // hook up methods of external generic functions (needs to be after recache types)
jl_recache_other(); // make all of the other objects identities correct (needs to be after insert methods)
jl_insert_backedges(&external_methods); // restore external backedges (needs to be after recache other)
free_linkedlist(external_methods.next);
serializer_worklist = NULL;

JL_GC_PUSH2(&init_order, &restored);
jl_gc_enable(en);
arraylist_free(&flagref_list);
arraylist_free(&backref_list);
ios_close(f);
Expand Down
8 changes: 8 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1321,6 +1321,11 @@ NOINLINE static int gc_mark_module(jl_ptls_t ptls, jl_module_t *m,
return refyoung;
}

void jl_gc_push_root(jl_ptls_t ptls, jl_value_t *v)
{
gc_push_root(ptls, v, 0);
}

// Handle the case where the stack is only partially copied.
STATIC_INLINE uintptr_t gc_get_stack_addr(void *_addr, uintptr_t offset,
uintptr_t lb, uintptr_t ub)
Expand Down Expand Up @@ -1674,6 +1679,9 @@ static void mark_roots(jl_ptls_t ptls)
// constants
gc_push_root(ptls, jl_typetype_type, 0);
gc_push_root(ptls, jl_emptytuple_type, 0);

// deserializer state during module reload
jl_gc_mark_deserializer_state(ptls);
}

// find unmarked objects that need to be finalized from the finalizer list "list".
Expand Down
1 change: 1 addition & 0 deletions src/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ void gc_mark_object_list(jl_ptls_t ptls, arraylist_t *list, size_t start);
void visit_mark_stack(jl_ptls_t ptls);
void gc_debug_init(void);
void jl_mark_box_caches(jl_ptls_t ptls);
void jl_gc_mark_deserializer_state(jl_ptls_t ptls);

// GC pages

Expand Down
1 change: 1 addition & 0 deletions src/julia_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ jl_tupletype_t *jl_argtype_with_function(jl_function_t *f, jl_tupletype_t *types
JL_DLLEXPORT jl_value_t *jl_apply_2va(jl_value_t *f, jl_value_t **args, uint32_t nargs);

void jl_gc_setmark(jl_ptls_t ptls, jl_value_t *v);
void jl_gc_push_root(jl_ptls_t ptls, jl_value_t *v);
void jl_gc_sync_total_bytes(void);
void jl_gc_track_malloced_array(jl_ptls_t ptls, jl_array_t *a);
void jl_gc_count_allocd(size_t sz);
Expand Down

0 comments on commit b76c7c7

Please sign in to comment.