Skip to content

Log Method of every CI that was GCed #244

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: v1.10.2+RAI
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 0 additions & 32 deletions src/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand All @@ -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);
}

Expand Down
15 changes: 15 additions & 0 deletions src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 0 additions & 4 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down