diff --git a/src/array.c b/src/array.c index bb8fcb03c4c93..9fd24f937fdbd 100644 --- a/src/array.c +++ b/src/array.c @@ -457,43 +457,13 @@ JL_DLLEXPORT jl_array_t *jl_pchar_to_array(const char *str, size_t len) return a; } -uv_mutex_t array_to_string_print_lock; - -void jl_set_in_flight_bit_for_array_to_string(jl_array_t *a) -{ - uintptr_t msk = (1 << ARRAY_TO_STRING_IN_FLIGHT_BIT_OFFSET); - uintptr_t header = jl_atomic_fetch_or((_Atomic(uintptr_t) *)jl_astaggedvalue(a), msk); - if (header & msk) { - uv_mutex_lock(&array_to_string_print_lock); - // Race detected... Someone already set the in-flight bit. - jl_safe_printf("Race detected... Someone already set the in-flight bit.\n"); - jlbacktracet(jl_current_task); - uv_mutex_unlock(&array_to_string_print_lock); - } -} - -void jl_reset_in_flight_bit_for_array_to_string(jl_array_t *a) -{ - uintptr_t msk = (1 << ARRAY_TO_STRING_IN_FLIGHT_BIT_OFFSET); - uintptr_t header = jl_atomic_fetch_and((_Atomic(uintptr_t) *)jl_astaggedvalue(a), ~msk); - if (!(header & msk)) { - uv_mutex_lock(&array_to_string_print_lock); - // Race detected... Someone reset the in-flight bit before we could. - jl_safe_printf("Race detected... Someone reset the in-flight bit before we could.\n"); - jlbacktracet(jl_current_task); - uv_mutex_unlock(&array_to_string_print_lock); - } -} - JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a) { - jl_set_in_flight_bit_for_array_to_string(a); size_t len = jl_array_len(a); if (len == 0) { // this may seem like purely an optimization (which it also is), but it // also ensures that calling `String(a)` doesn't corrupt a previous // string also created the same way, where `a = StringVector(_)`. - jl_reset_in_flight_bit_for_array_to_string(a); return jl_an_empty_string; } if (a->flags.how == 3 && a->offset == 0 && a->elsize == 1 && @@ -506,13 +476,11 @@ JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a) a->nrows = 0; a->length = 0; a->maxsize = 0; - jl_reset_in_flight_bit_for_array_to_string(a); return o; } } a->nrows = 0; a->length = 0; - jl_reset_in_flight_bit_for_array_to_string(a); return jl_pchar_to_string((const char*)jl_array_data(a), len); } diff --git a/src/gc.c b/src/gc.c index 98ed32cd4a54a..4e78cf79e0e3b 100644 --- a/src/gc.c +++ b/src/gc.c @@ -1472,6 +1472,20 @@ static void gc_sweep_page(gc_page_profiler_serializer_t *s, jl_gc_pool_t *p, jl_ int bits = v->bits.gc; // if an object is past `lim_newpages` then we can guarantee it's garbage if (!gc_marked(bits) || (char*)v >= lim_newpages) { + if (jl_is_method_instance(jl_valueof(v)) || jl_is_method(jl_valueof(v))) { + if (!v->bits.obj_whose_gc_was_delayed) { + v->bits.obj_whose_gc_was_delayed = 1; + goto next_obj; + } + } + if (jl_is_code_instance(jl_valueof(v))) { + jl_code_instance_t *ci = (jl_code_instance_t*)jl_valueof(v); + // Print the CI's method + jl_method_instance_t *mi = ci->def; + jl_method_t *m = mi->def.method; + jl_(m); + jl_safe_printf("=====\n"); + } *pfl = v; pfl = &v->next; pfl_begin = (pfl_begin != NULL) ? pfl_begin : pfl; @@ -1485,6 +1499,7 @@ static void gc_sweep_page(gc_page_profiler_serializer_t *s, jl_gc_pool_t *p, jl_ has_marked |= gc_marked(bits); freedall = 0; } + next_obj: v = (jl_taggedvalue_t*)((char*)v + osize); } assert(!freedall); diff --git a/src/init.c b/src/init.c index dae5afb375916..e58fc68d34b4d 100644 --- a/src/init.c +++ b/src/init.c @@ -864,8 +864,6 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel) void jl_init_heartbeat(void); -extern uv_mutex_t array_to_string_print_lock; - static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_task_t *ct) { JL_TIMING(JULIA_INIT, JULIA_INIT); @@ -913,8 +911,6 @@ static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_ jl_start_gc_threads(); uv_barrier_wait(&thread_init_done); - uv_mutex_init(&array_to_string_print_lock); - jl_init_heartbeat(); jl_gc_enable(1); diff --git a/src/julia.h b/src/julia.h index dbe4fe4deb7bf..93633d53899a2 100644 --- a/src/julia.h +++ b/src/julia.h @@ -98,8 +98,7 @@ struct _jl_taggedvalue_bits { // Bit to indicate whether a call to `jl_array_to_string` is in-flight // Mostly used to implement a poor-man's dynamic race detector. // See usage in `jl_array_to_string`. -#define ARRAY_TO_STRING_IN_FLIGHT_BIT_OFFSET (3) - uintptr_t array_to_string_in_flight:1; + uintptr_t obj_whose_gc_was_delayed:1; #ifdef _P64 uintptr_t tag:60; #else