Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 1656af6

Browse files
author
Sergey Andreenko
authored
Fix GC tests. (#17594) (#17613)
* Fix dlbigleak * cleanup dlstack * Fix doublinknoleak * Fix doublinkstay * Fix dlcollect * Fix doublinkgen * Fix dlbigleakthd
1 parent 8e7aa00 commit 1656af6

File tree

7 files changed

+102
-42
lines changed

7 files changed

+102
-42
lines changed

tests/src/GC/Scenarios/DoublinkList/dlbigleak.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
namespace DoubLink {
1414
using System;
15+
using System.Runtime.CompilerServices;
1516

1617
public class DLBigLeak
1718
{
@@ -65,13 +66,7 @@ public static int Main(System.String [] Args)
6566

6667
public bool runTest(int iRep, int iObj)
6768
{
68-
Mv_Doub = new DoubLink[iRep];
69-
for(int i=0; i<10; i++)
70-
{
71-
SetLink(iRep, iObj);
72-
MakeLeak(iRep);
73-
GC.Collect();
74-
}
69+
CreateDLinkListsWithLeak(iRep, iObj, 10);
7570

7671
GC.Collect();
7772
GC.WaitForPendingFinalizers();
@@ -85,6 +80,21 @@ public bool runTest(int iRep, int iObj)
8580
}
8681

8782

83+
[MethodImpl(MethodImplOptions.NoInlining)]
84+
// Do not inline the method that creates GC objects, because it could
85+
// extend their live intervals until the end of the parent method.
86+
public void CreateDLinkListsWithLeak(int iRep, int iObj, int iters)
87+
{
88+
Mv_Doub = new DoubLink[iRep];
89+
for (int i = 0; i < iters; i++)
90+
{
91+
SetLink(iRep, iObj);
92+
MakeLeak(iRep);
93+
GC.Collect();
94+
}
95+
}
96+
97+
8898
public void SetLink(int iRep, int iObj)
8999
{
90100

tests/src/GC/Scenarios/DoublinkList/dlbigleakthd.cs

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace DoubLink {
1313
using System.Threading;
1414
using System;
1515
using System.IO;
16+
using System.Runtime.CompilerServices;
1617

1718
public class DLBigLeakThd
1819
{
@@ -84,6 +85,23 @@ public static int Main(System.String [] Args)
8485

8586

8687
public bool runTest(int iRep, int iObj, int iThd)
88+
{
89+
CreateDLinkListsWithLeak(iRep, iObj, iThd, 20);
90+
91+
GC.Collect();
92+
GC.WaitForPendingFinalizers();
93+
GC.Collect();
94+
95+
int goal = iRep*15*iThd*iObj+20*iRep*iObj;
96+
Console.WriteLine("{0}/{1} DLinkNodes finalized", DLinkNode.FinalCount, goal);
97+
return (DLinkNode.FinalCount==goal);
98+
}
99+
100+
101+
[MethodImpl(MethodImplOptions.NoInlining)]
102+
// Do not inline the method that creates GC objects, because it could
103+
// extend their live intervals until the end of the parent method.
104+
public void CreateDLinkListsWithLeak(int iRep, int iObj, int iThd, int iters)
87105
{
88106
this.iRep = iRep;
89107
this.iObj = iObj;
@@ -94,7 +112,7 @@ public bool runTest(int iRep, int iObj, int iThd)
94112
Mv_Thread[i] = new Thread(new ThreadStart(this.ThreadStart));
95113
Mv_Thread[i].Start( );
96114
}
97-
for(int i=0; i<20; i++)
115+
for (int i = 0; i < iters; i++)
98116
{
99117
SetLink(iRep, iObj);
100118
MakeLeak(iRep);
@@ -103,15 +121,7 @@ public bool runTest(int iRep, int iObj, int iThd)
103121
{
104122
Mv_Thread[i].Join();
105123
}
106-
107124
Mv_Doub = null;
108-
GC.Collect();
109-
GC.WaitForPendingFinalizers();
110-
GC.Collect();
111-
112-
int goal = iRep*15*iThd*iObj+20*iRep*iObj;
113-
Console.WriteLine("{0}/{1} DLinkNodes finalized", DLinkNode.FinalCount, goal);
114-
return (DLinkNode.FinalCount==goal);
115125
}
116126

117127

tests/src/GC/Scenarios/DoublinkList/dlcollect.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -93,15 +93,9 @@ public bool DrainFinalizerQueue(int iRep, int iObj)
9393

9494
public bool runTest(int iRep, int iObj)
9595
{
96+
CreateDLinkListsWithLeak(iRep, iObj, 10);
9697

97-
Mv_Collect = new List<DoubLink>(iRep);
9898
bool success = false;
99-
for(int i=0; i <10; i++)
100-
{
101-
SetLink(iRep, iObj);
102-
Mv_Collect.RemoveRange(0, Mv_Collect.Count);
103-
GC.Collect();
104-
}
10599

106100
if (DrainFinalizerQueue(iRep, iObj))
107101
{
@@ -113,6 +107,21 @@ public bool runTest(int iRep, int iObj)
113107
}
114108

115109

110+
[MethodImpl(MethodImplOptions.NoInlining)]
111+
// Do not inline the method that creates GC objects, because it could
112+
// extend their live intervals until the end of the parent method.
113+
public void CreateDLinkListsWithLeak(int iRep, int iObj, int iters)
114+
{
115+
Mv_Collect = new List<DoubLink>(iRep);
116+
for(int i = 0; i < iters; i++)
117+
{
118+
SetLink(iRep, iObj);
119+
Mv_Collect.RemoveRange(0, Mv_Collect.Count);
120+
GC.Collect();
121+
}
122+
}
123+
124+
116125
public void SetLink(int iRep, int iObj)
117126
{
118127
Mv_Doub = new DoubLink[iRep];

tests/src/GC/Scenarios/DoublinkList/dlstack.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ public bool DrainFinalizerQueue(int iRep, int iObj)
9494

9595
public bool runTest(int iRep, int iObj)
9696
{
97-
CreateDLinkListsWithLeak(iRep, iObj);
97+
CreateDLinkListsWithLeak(iRep, iObj, 10);
9898

9999
bool success = false;
100100
if (DrainFinalizerQueue(iRep, iObj))
@@ -111,9 +111,9 @@ public bool runTest(int iRep, int iObj)
111111
[MethodImpl(MethodImplOptions.NoInlining)]
112112
// Do not inline the method that creates GC objects, because it could
113113
// extend their live intervals until the end of the parent method.
114-
public void CreateDLinkListsWithLeak(int iRep, int iObj)
114+
public void CreateDLinkListsWithLeak(int iRep, int iObj, int iters)
115115
{
116-
for(int i=0; i <10; i++)
116+
for(int i = 0; i < iters; i++)
117117
{
118118
SetLink(iRep, iObj);
119119
MakeLeak(iRep);

tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ public bool DrainFinalizerQueue(int iRep, int iObj)
9191

9292
public bool runTest(int iRep, int iObj)
9393
{
94-
SetLink(iRep, iObj);
95-
Mv_Doub = null;
94+
CreateDLinkListsWithLeak(iRep, iObj);
95+
9696
bool success = false;
9797

9898
if (DrainFinalizerQueue(iRep, iObj))
@@ -107,6 +107,18 @@ public bool runTest(int iRep, int iObj)
107107
}
108108

109109

110+
111+
112+
[MethodImpl(MethodImplOptions.NoInlining)]
113+
// Do not inline the method that creates GC objects, because it could
114+
// extend their live intervals until the end of the parent method.
115+
public void CreateDLinkListsWithLeak(int iRep, int iObj)
116+
{
117+
SetLink(iRep, iObj);
118+
Mv_Doub = null;
119+
}
120+
121+
110122
public void SetLink(int iRep, int iObj)
111123
{
112124
for(int i=0; i<iRep; i++)

tests/src/GC/Scenarios/DoublinkList/doublinknoleak.cs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace DoubLink {
1212
using System;
1313
using System.Collections.Generic;
14+
using System.Runtime.CompilerServices;
1415

1516
public class DoubLinkNoLeak
1617
{
@@ -62,13 +63,7 @@ public static int Main(System.String [] Args)
6263

6364
public bool runTest(int iRep, int iObj)
6465
{
65-
for(int i=0; i<10; i++)
66-
{
67-
SetLink(iRep, iObj);
68-
}
69-
70-
Mv_Doub = null;
71-
Mv_Save = null;
66+
CreateDLinkListsWithLeak(iRep, iObj, 10);
7267

7368
GC.Collect();
7469
GC.WaitForPendingFinalizers();
@@ -80,6 +75,21 @@ public bool runTest(int iRep, int iObj)
8075
}
8176

8277

78+
[MethodImpl(MethodImplOptions.NoInlining)]
79+
// Do not inline the method that creates GC objects, because it could
80+
// extend their live intervals until the end of the parent method.
81+
public void CreateDLinkListsWithLeak(int iRep, int iObj, int iters)
82+
{
83+
for(int i = 0; i < iters; i++)
84+
{
85+
SetLink(iRep, iObj);
86+
}
87+
88+
Mv_Doub = null;
89+
Mv_Save = null;
90+
}
91+
92+
8393
public void SetLink(int iRep, int iObj)
8494
{
8595
Mv_Doub = new DoubLink[iRep];

tests/src/GC/Scenarios/DoublinkList/doublinkstay.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
namespace DoubLink {
1515
using System;
16+
using System.Runtime.CompilerServices;
1617

1718
public class DoubLinkStay
1819
{
@@ -63,13 +64,7 @@ public static int Main(System.String [] Args)
6364

6465
public bool runTest(int iRep, int iObj)
6566
{
66-
Mv_Doub = new DoubLink[iRep];
67-
for(int i=0; i<20; i++)
68-
{
69-
SetLink(iRep, iObj);
70-
MakeLeak(iRep);
71-
}
72-
67+
CreateDLinkListsWithLeak(iRep, iObj, 20);
7368

7469
GC.Collect();
7570
GC.WaitForPendingFinalizers();
@@ -83,6 +78,20 @@ public bool runTest(int iRep, int iObj)
8378

8479
}
8580

81+
82+
[MethodImpl(MethodImplOptions.NoInlining)]
83+
// Do not inline the method that creates GC objects, because it could
84+
// extend their live intervals until the end of the parent method.
85+
public void CreateDLinkListsWithLeak(int iRep, int iObj, int iters)
86+
{
87+
Mv_Doub = new DoubLink[iRep];
88+
for(int i = 0; i < iters; i++)
89+
{
90+
SetLink(iRep, iObj);
91+
MakeLeak(iRep);
92+
}
93+
}
94+
8695
public void SetLink(int iRep, int iObj)
8796
{
8897

0 commit comments

Comments
 (0)