Skip to content

Commit

Permalink
1 outref opt
Browse files Browse the repository at this point in the history
  • Loading branch information
Diogo Netto committed Jul 3, 2022
1 parent 9806c23 commit 6f42f17
Show file tree
Hide file tree
Showing 3 changed files with 378 additions and 324 deletions.
170 changes: 85 additions & 85 deletions src/gc-debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -198,93 +198,93 @@ static void restore(void)

static void gc_verify_track(jl_ptls_t ptls)
{
jl_gc_mark_cache_t *gc_cache = &ptls->gc_cache;
do {
jl_gc_mark_sp_t sp;
gc_mark_sp_init(gc_cache, &sp);
arraylist_push(&lostval_parents_done, lostval);
jl_safe_printf("Now looking for %p =======\n", lostval);
clear_mark(GC_CLEAN);
gc_mark_queue_all_roots(ptls, &sp);
gc_mark_queue_finlist(gc_cache, &sp, &to_finalize, 0);
for (int i = 0;i < jl_n_threads;i++) {
jl_ptls_t ptls2 = jl_all_tls_states[i];
gc_mark_queue_finlist(gc_cache, &sp, &ptls2->finalizers, 0);
}
gc_mark_queue_finlist(gc_cache, &sp, &finalizer_list_marked, 0);
gc_mark_loop(ptls, sp);
if (lostval_parents.len == 0) {
jl_safe_printf("Could not find the missing link. We missed a toplevel root. This is odd.\n");
break;
}
jl_value_t *lostval_parent = NULL;
for(int i = 0; i < lostval_parents.len; i++) {
lostval_parent = (jl_value_t*)lostval_parents.items[i];
int clean_len = bits_save[GC_CLEAN].len;
for(int j = 0; j < clean_len + bits_save[GC_OLD].len; j++) {
void *p = bits_save[j >= clean_len ? GC_OLD : GC_CLEAN].items[j >= clean_len ? j - clean_len : j];
if (jl_valueof(p) == lostval_parent) {
lostval = lostval_parent;
lostval_parent = NULL;
break;
}
}
if (lostval_parent != NULL) break;
}
if (lostval_parent == NULL) { // all parents of lostval were also scheduled for deletion
lostval = (jl_value_t*)arraylist_pop(&lostval_parents);
}
else {
jl_safe_printf("Missing write barrier found !\n");
jl_safe_printf("%p was written a reference to %p that was not recorded\n", lostval_parent, lostval);
jl_safe_printf("(details above)\n");
lostval = NULL;
}
restore();
} while(lostval != NULL);
// jl_gc_mark_cache_t *gc_cache = &ptls->gc_cache;
// do {
// jl_gc_mark_sp_t sp;
// gc_mark_sp_init(gc_cache, &sp);
// arraylist_push(&lostval_parents_done, lostval);
// jl_safe_printf("Now looking for %p =======\n", lostval);
// clear_mark(GC_CLEAN);
// gc_mark_queue_all_roots(ptls, &sp);
// gc_mark_queue_finlist(gc_cache, &sp, &to_finalize, 0);
// for (int i = 0;i < jl_n_threads;i++) {
// jl_ptls_t ptls2 = jl_all_tls_states[i];
// gc_mark_queue_finlist(gc_cache, &sp, &ptls2->finalizers, 0);
// }
// gc_mark_queue_finlist(gc_cache, &sp, &finalizer_list_marked, 0);
// gc_mark_loop(ptls, sp);
// if (lostval_parents.len == 0) {
// jl_safe_printf("Could not find the missing link. We missed a toplevel root. This is odd.\n");
// break;
// }
// jl_value_t *lostval_parent = NULL;
// for(int i = 0; i < lostval_parents.len; i++) {
// lostval_parent = (jl_value_t*)lostval_parents.items[i];
// int clean_len = bits_save[GC_CLEAN].len;
// for(int j = 0; j < clean_len + bits_save[GC_OLD].len; j++) {
// void *p = bits_save[j >= clean_len ? GC_OLD : GC_CLEAN].items[j >= clean_len ? j - clean_len : j];
// if (jl_valueof(p) == lostval_parent) {
// lostval = lostval_parent;
// lostval_parent = NULL;
// break;
// }
// }
// if (lostval_parent != NULL) break;
// }
// if (lostval_parent == NULL) { // all parents of lostval were also scheduled for deletion
// lostval = (jl_value_t*)arraylist_pop(&lostval_parents);
// }
// else {
// jl_safe_printf("Missing write barrier found !\n");
// jl_safe_printf("%p was written a reference to %p that was not recorded\n", lostval_parent, lostval);
// jl_safe_printf("(details above)\n");
// lostval = NULL;
// }
// restore();
// } while(lostval != NULL);
}

void gc_verify(jl_ptls_t ptls)
{
jl_gc_mark_cache_t *gc_cache = &ptls->gc_cache;
jl_gc_mark_sp_t sp;
gc_mark_sp_init(gc_cache, &sp);
lostval = NULL;
lostval_parents.len = 0;
lostval_parents_done.len = 0;
clear_mark(GC_CLEAN);
gc_verifying = 1;
gc_mark_queue_all_roots(ptls, &sp);
gc_mark_queue_finlist(gc_cache, &sp, &to_finalize, 0);
for (int i = 0;i < jl_n_threads;i++) {
jl_ptls_t ptls2 = jl_all_tls_states[i];
gc_mark_queue_finlist(gc_cache, &sp, &ptls2->finalizers, 0);
}
gc_mark_queue_finlist(gc_cache, &sp, &finalizer_list_marked, 0);
gc_mark_loop(ptls, sp);
int clean_len = bits_save[GC_CLEAN].len;
for(int i = 0; i < clean_len + bits_save[GC_OLD].len; i++) {
jl_taggedvalue_t *v = (jl_taggedvalue_t*)bits_save[i >= clean_len ? GC_OLD : GC_CLEAN].items[i >= clean_len ? i - clean_len : i];
if (gc_marked(v->bits.gc)) {
jl_safe_printf("Error. Early free of %p type :", v);
jl_(jl_typeof(jl_valueof(v)));
jl_safe_printf("val : ");
jl_(jl_valueof(v));
jl_safe_printf("Let's try to backtrack the missing write barrier :\n");
lostval = jl_valueof(v);
break;
}
}
if (lostval == NULL) {
gc_verifying = 0;
restore(); // we did not miss anything
return;
}
restore();
gc_verify_track(ptls);
jl_gc_debug_print_status();
jl_gc_debug_critical_error();
abort();
// jl_gc_mark_cache_t *gc_cache = &ptls->gc_cache;
// jl_gc_mark_sp_t sp;
// gc_mark_sp_init(gc_cache, &sp);
// lostval = NULL;
// lostval_parents.len = 0;
// lostval_parents_done.len = 0;
// clear_mark(GC_CLEAN);
// gc_verifying = 1;
// gc_mark_queue_all_roots(ptls, &sp);
// gc_mark_queue_finlist(gc_cache, &sp, &to_finalize, 0);
// for (int i = 0;i < jl_n_threads;i++) {
// jl_ptls_t ptls2 = jl_all_tls_states[i];
// gc_mark_queue_finlist(gc_cache, &sp, &ptls2->finalizers, 0);
// }
// gc_mark_queue_finlist(gc_cache, &sp, &finalizer_list_marked, 0);
// gc_mark_loop(ptls, sp);
// int clean_len = bits_save[GC_CLEAN].len;
// for(int i = 0; i < clean_len + bits_save[GC_OLD].len; i++) {
// jl_taggedvalue_t *v = (jl_taggedvalue_t*)bits_save[i >= clean_len ? GC_OLD : GC_CLEAN].items[i >= clean_len ? i - clean_len : i];
// if (gc_marked(v->bits.gc)) {
// jl_safe_printf("Error. Early free of %p type :", v);
// jl_(jl_typeof(jl_valueof(v)));
// jl_safe_printf("val : ");
// jl_(jl_valueof(v));
// jl_safe_printf("Let's try to backtrack the missing write barrier :\n");
// lostval = jl_valueof(v);
// break;
// }
// }
// if (lostval == NULL) {
// gc_verifying = 0;
// restore(); // we did not miss anything
// return;
// }
// restore();
// gc_verify_track(ptls);
// jl_gc_debug_print_status();
// jl_gc_debug_critical_error();
// abort();
}
#endif

Expand Down Expand Up @@ -1285,8 +1285,8 @@ NOINLINE void gc_mark_loop_unwind(jl_ptls_t ptls, jl_gc_markqueue_t *mq, int off
jl_value_t **end = mq->current + offset;
for (; start < end; start++) {
jl_value_t *obj = *start;
jl_taggedvalue_t *o = jl_astaggedvalue(o);
jl_safe_printf("Queued object: %p :: (header: %zu) (bits: %zu)\n", obj, (uintptr_t)o->header,
jl_taggedvalue_t *o = jl_astaggedvalue(obj);
jl_safe_printf("Queued object: %p :: (header: %zu) (bits: %zu)\n", obj, (uintptr_t)o->header,
((uintptr_t)o->header & 3));
jl_((void*)(jl_datatype_t *)(o->header & ~(uintptr_t)0xf));
}
Expand Down
Loading

0 comments on commit 6f42f17

Please sign in to comment.