Skip to content

Commit fc2a203

Browse files
committed
Log MI of every CI that was GCed
1 parent 37cdbd8 commit fc2a203

File tree

4 files changed

+16
-38
lines changed

4 files changed

+16
-38
lines changed

src/array.c

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -457,43 +457,13 @@ JL_DLLEXPORT jl_array_t *jl_pchar_to_array(const char *str, size_t len)
457457
return a;
458458
}
459459

460-
uv_mutex_t array_to_string_print_lock;
461-
462-
void jl_set_in_flight_bit_for_array_to_string(jl_array_t *a)
463-
{
464-
uintptr_t msk = (1 << ARRAY_TO_STRING_IN_FLIGHT_BIT_OFFSET);
465-
uintptr_t header = jl_atomic_fetch_or((_Atomic(uintptr_t) *)jl_astaggedvalue(a), msk);
466-
if (header & msk) {
467-
uv_mutex_lock(&array_to_string_print_lock);
468-
// Race detected... Someone already set the in-flight bit.
469-
jl_safe_printf("Race detected... Someone already set the in-flight bit.\n");
470-
jlbacktracet(jl_current_task);
471-
uv_mutex_unlock(&array_to_string_print_lock);
472-
}
473-
}
474-
475-
void jl_reset_in_flight_bit_for_array_to_string(jl_array_t *a)
476-
{
477-
uintptr_t msk = (1 << ARRAY_TO_STRING_IN_FLIGHT_BIT_OFFSET);
478-
uintptr_t header = jl_atomic_fetch_and((_Atomic(uintptr_t) *)jl_astaggedvalue(a), ~msk);
479-
if (!(header & msk)) {
480-
uv_mutex_lock(&array_to_string_print_lock);
481-
// Race detected... Someone reset the in-flight bit before we could.
482-
jl_safe_printf("Race detected... Someone reset the in-flight bit before we could.\n");
483-
jlbacktracet(jl_current_task);
484-
uv_mutex_unlock(&array_to_string_print_lock);
485-
}
486-
}
487-
488460
JL_DLLEXPORT jl_value_t *jl_array_to_string(jl_array_t *a)
489461
{
490-
jl_set_in_flight_bit_for_array_to_string(a);
491462
size_t len = jl_array_len(a);
492463
if (len == 0) {
493464
// this may seem like purely an optimization (which it also is), but it
494465
// also ensures that calling `String(a)` doesn't corrupt a previous
495466
// string also created the same way, where `a = StringVector(_)`.
496-
jl_reset_in_flight_bit_for_array_to_string(a);
497467
return jl_an_empty_string;
498468
}
499469
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)
506476
a->nrows = 0;
507477
a->length = 0;
508478
a->maxsize = 0;
509-
jl_reset_in_flight_bit_for_array_to_string(a);
510479
return o;
511480
}
512481
}
513482
a->nrows = 0;
514483
a->length = 0;
515-
jl_reset_in_flight_bit_for_array_to_string(a);
516484
return jl_pchar_to_string((const char*)jl_array_data(a), len);
517485
}
518486

src/gc.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1472,6 +1472,20 @@ static void gc_sweep_page(gc_page_profiler_serializer_t *s, jl_gc_pool_t *p, jl_
14721472
int bits = v->bits.gc;
14731473
// if an object is past `lim_newpages` then we can guarantee it's garbage
14741474
if (!gc_marked(bits) || (char*)v >= lim_newpages) {
1475+
if (jl_is_method_instance(jl_valueof(v)) || jl_is_method(jl_valueof(v))) {
1476+
if (!v->bits.obj_whose_gc_was_delayed) {
1477+
v->bits.obj_whose_gc_was_delayed = 1;
1478+
goto next_obj;
1479+
}
1480+
}
1481+
if (jl_is_code_instance(jl_valueof(v))) {
1482+
jl_code_instance_t *ci = (jl_code_instance_t*)jl_valueof(v);
1483+
// Print the CI's method
1484+
jl_method_instance_t *mi = ci->def;
1485+
jl_method_t *m = mi->def.method;
1486+
jl_(m);
1487+
jl_safe_printf("=====\n");
1488+
}
14751489
*pfl = v;
14761490
pfl = &v->next;
14771491
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_
14851499
has_marked |= gc_marked(bits);
14861500
freedall = 0;
14871501
}
1502+
next_obj:
14881503
v = (jl_taggedvalue_t*)((char*)v + osize);
14891504
}
14901505
assert(!freedall);

src/init.c

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -864,8 +864,6 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
864864

865865
void jl_init_heartbeat(void);
866866

867-
extern uv_mutex_t array_to_string_print_lock;
868-
869867
static NOINLINE void _finish_julia_init(JL_IMAGE_SEARCH rel, jl_ptls_t ptls, jl_task_t *ct)
870868
{
871869
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_
913911
jl_start_gc_threads();
914912
uv_barrier_wait(&thread_init_done);
915913

916-
uv_mutex_init(&array_to_string_print_lock);
917-
918914
jl_init_heartbeat();
919915

920916
jl_gc_enable(1);

src/julia.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ struct _jl_taggedvalue_bits {
9898
// Bit to indicate whether a call to `jl_array_to_string` is in-flight
9999
// Mostly used to implement a poor-man's dynamic race detector.
100100
// See usage in `jl_array_to_string`.
101-
#define ARRAY_TO_STRING_IN_FLIGHT_BIT_OFFSET (3)
102-
uintptr_t array_to_string_in_flight:1;
101+
uintptr_t obj_whose_gc_was_delayed:1;
103102
#ifdef _P64
104103
uintptr_t tag:60;
105104
#else

0 commit comments

Comments
 (0)