Skip to content

Commit

Permalink
Avoid duplicated ranges
Browse files Browse the repository at this point in the history
  • Loading branch information
cshung committed Aug 26, 2021
1 parent 17d8007 commit 9aaba6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
4 changes: 0 additions & 4 deletions src/coreclr/gc/gc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44805,13 +44805,9 @@ GCHeap::GarbageCollectGeneration (unsigned int gen, gc_reason reason)
gc_heap::proceed_with_gc_p = gc_heap::should_proceed_with_gc();
gc_heap::disable_preemptive (cooperative_mode);
if (gc_heap::proceed_with_gc_p)
{
pGenGCHeap->settings.init_mechanisms();
}
else
{
gc_heap::update_collection_counts_for_no_gc();
}

#endif //!MULTIPLE_HEAPS
}
Expand Down
17 changes: 17 additions & 0 deletions src/coreclr/vm/proftoeeinterfaceimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,23 @@ void GenerationTable::AddRecord(int generation, BYTE* rangeStart, BYTE* rangeEnd
PRECONDITION(CheckPointer(rangeEnd));
PRECONDITION(CheckPointer(rangeEndReserved));
} CONTRACT_END;

CrstHolder holder(&mutex);

// Because the segment/region are added to the heap before they are reported to the profiler,
// it is possible that the region is added to the heap, a racing GenerationTable refresh happened,
// that refresh would contain the new region, and then it get reported again here.
// This check will make sure we never add duplicated record to the table.
for (ULONG i = 0; i < count; i++)
{
if (genDescTable[i].rangeStart == rangeStart)
{
_ASSERTE (genDescTable[i].generation == generation);
_ASSERTE (genDescTable[i].rangeEnd == rangeEnd);
_ASSERTE (genDescTable[i].rangeEndReserved == rangeEndReserved);
RETURN;
}
}
AddRecordNoLock(generation, rangeStart, rangeEnd, rangeEndReserved);
RETURN;
}
Expand Down Expand Up @@ -875,6 +891,7 @@ void GenerationTable::Refresh()
// the ranges by calling GenWalkFunc for each one
CrstHolder holder(&mutex);
IGCHeap *hp = GCHeapUtilities::GetGCHeap();
this->count = 0;
hp->DiagDescrGenerations(GenWalkFunc, this);
}

Expand Down

0 comments on commit 9aaba6d

Please sign in to comment.