Skip to content

Commit 10107d3

Browse files
authored
fixing an assert (#106752)
we are hitting this assert in gc_thread_function assert ((n_heaps <= heap_number) || !gc_t_join.joined()); during the init stage. this is because the main thread (that does the GC init) is calling change_heap_count which acts like h0's thread while h0's thread can be anywhere before waiting on ee_suspend_event. so we could be in this situation - 1) main thread calls GCHeap::Init and creates h0's GC thread 2) main thread calls gc_heap::change_heap_count and this will change n_heaps to 1, and after there's another join, when the main thread and all other heaps' GC threads have joined, it changes gc_t_join.joined_p to true 3) h0's thread runs and sees that n_heaps is 1, and gc_t_join.joined_p is true which triggers the assert. so this only happens during the init stage on h0's thread.
1 parent 2af0051 commit 10107d3

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

src/coreclr/gc/gc.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6999,8 +6999,21 @@ void gc_heap::gc_thread_function ()
69996999

70007000
while (1)
70017001
{
7002-
// inactive GC threads may observe gc_t_join.joined() being true here
7003-
assert ((n_heaps <= heap_number) || !gc_t_join.joined());
7002+
#ifdef DYNAMIC_HEAP_COUNT
7003+
if (gc_heap::dynamic_adaptation_mode == dynamic_adaptation_to_application_sizes)
7004+
{
7005+
// Inactive GC threads may observe gc_t_join.joined() being true here.
7006+
// Before the 1st GC happens, h0's GC thread can also observe gc_t_join.joined() being true because it's
7007+
// also inactive as the main thread (that inits the GC) will act as h0 (to call change_heap_count).
7008+
assert (((heap_number == 0) && (VolatileLoadWithoutBarrier (&settings.gc_index) == 0)) ||
7009+
(n_heaps <= heap_number) ||
7010+
!gc_t_join.joined());
7011+
}
7012+
else
7013+
#endif //DYNAMIC_HEAP_COUNT
7014+
{
7015+
assert (!gc_t_join.joined());
7016+
}
70047017

70057018
if (heap_number == 0)
70067019
{

0 commit comments

Comments
 (0)