Skip to content

Commit a1c8b66

Browse files
Maoni0Maoni0
andauthored
fix IndexOutOfRangeException in ProcessGlobalHistory (#2185)
Co-authored-by: Maoni0 <[email protected]>
1 parent 1dea52b commit a1c8b66

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/TraceEvent/Computers/TraceManagedProcess.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4825,11 +4825,17 @@ internal static void ProcessGlobalHistory(TraceLoadedDotNetRuntime proc, GCGloba
48254825
if (data.Times != null)
48264826
{
48274827
_event.TimingInfo = new Nullable<int>[(int)TraceGC.TimingType.Sweep + 1];
4828+
4829+
// These are fired by all GCs and the only fields fired by BGCs.
48284830
_event.TimingInfo[(int)TraceGC.TimingType.MarkRoot] = data.Times[1];
48294831
_event.TimingInfo[(int)TraceGC.TimingType.MarkShortWeak] = data.Times[2];
48304832
_event.TimingInfo[(int)TraceGC.TimingType.MarkScanFinalization] = data.Times[3];
48314833
_event.TimingInfo[(int)TraceGC.TimingType.MarkLongWeak] = data.Times[4];
4832-
if (_event.Type != GCType.BackgroundGC)
4834+
4835+
// Instead of checking for the type we check the length of the data because we could be in
4836+
// a situation where the beginning of a BGC is not in the trace and GetLastGC might not
4837+
// get the actual BGC when it should.
4838+
if (data.Times.Length > 5)
48334839
{
48344840
_event.TimingInfo[(int)TraceGC.TimingType.Plan] = data.Times[5];
48354841
if ((_event.GlobalHeapHistory.GlobalMechanisms & GCGlobalMechanisms.Compaction) != 0)

0 commit comments

Comments
 (0)