Skip to content

Commit

Permalink
fixing an assert in GetGCMemoryInfo when there hasn't been any GC of …
Browse files Browse the repository at this point in the history
…that kind yet (dotnet#87848)

when there hasn't been any GC of that kind yet, we cannot validate the info as it's all 0's.
  • Loading branch information
Maoni0 committed Jun 21, 2023
1 parent 74196a0 commit 9963dd1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
29 changes: 16 additions & 13 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50271,22 +50271,25 @@ void GCHeap::GetMemoryInfo(uint64_t* highMemLoadThresholdBytes,
}

#ifdef _DEBUG
if ((gc_kind)kind == gc_kind_ephemeral)
{
assert (last_gc_info->condemned_generation < max_generation);
}
else if ((gc_kind)kind == gc_kind_full_blocking)
if (VolatileLoadWithoutBarrier (&last_gc_info->index) != 0)
{
assert (last_gc_info->condemned_generation == max_generation);
assert (last_gc_info->concurrent == false);
}
if ((gc_kind)kind == gc_kind_ephemeral)
{
assert (last_gc_info->condemned_generation < max_generation);
}
else if ((gc_kind)kind == gc_kind_full_blocking)
{
assert (last_gc_info->condemned_generation == max_generation);
assert (last_gc_info->concurrent == false);
}
#ifdef BACKGROUND_GC
else if ((gc_kind)kind == gc_kind_background)
{
assert (last_gc_info->condemned_generation == max_generation);
assert (last_gc_info->concurrent == true);
}
else if ((gc_kind)kind == gc_kind_background)
{
assert (last_gc_info->condemned_generation == max_generation);
assert (last_gc_info->concurrent == true);
}
#endif //BACKGROUND_GC
}
#endif //_DEBUG
}

Expand Down
4 changes: 4 additions & 0 deletions src/tests/GC/API/GC/GetGCMemoryInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ public static int Main()
// We will keep executing the test in case of a failure to see if we have multiple failures.
bool isTestSucceeded = true;

// Before any GCs happen, this should not assert
GCMemoryInfo memoryInfoNoGC = GC.GetGCMemoryInfo(GCKind.Background);
Console.WriteLine("BGC index is {0}", memoryInfoNoGC.Index);

try
{
GCMemoryInfo memoryInfoInvalid = GC.GetGCMemoryInfo((GCKind)(-1));
Expand Down

0 comments on commit 9963dd1

Please sign in to comment.