From ae975d418cb909b44ea9ba7fe4728442935e27c5 Mon Sep 17 00:00:00 2001 From: Sean Gillespie Date: Wed, 26 Apr 2017 14:50:19 -0700 Subject: [PATCH] Fix and re-enable some GC finalizer tests (#11216) * Fix and re-enable some GC finalizer tests * Make the Usage test a little more robust --- tests/issues.targets | 6 --- tests/src/GC/API/GCHandleCollector/Usage.cs | 13 ++++-- tests/src/GC/Scenarios/DoublinkList/dlcollect.cs | 37 +++++++++++++--- tests/src/GC/Scenarios/DoublinkList/dlstack.cs | 49 ++++++++++++++-------- tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs | 39 +++++++++++++---- tests/testsFailingOutsideWindows.txt | 1 - 6 files changed, 104 insertions(+), 41 deletions(-) diff --git a/tests/issues.targets b/tests/issues.targets index 0592888..0d2fb68 100644 --- a/tests/issues.targets +++ b/tests/issues.targets @@ -1,9 +1,6 @@ - - 6574 - 3392 @@ -43,9 +40,6 @@ 3392 - - 6553 - 4851 diff --git a/tests/src/GC/API/GCHandleCollector/Usage.cs b/tests/src/GC/API/GCHandleCollector/Usage.cs index b78271b..f346966 100644 --- a/tests/src/GC/API/GCHandleCollector/Usage.cs +++ b/tests/src/GC/API/GCHandleCollector/Usage.cs @@ -146,9 +146,16 @@ public class Usage // ensure threshold is increasing if (!CheckPercentageIncrease(handleCount, prevHandleCount)) { - // see github#4093 for the rationale for fail-fast in this test. - Environment.FailFast(string.Empty); - return false; + Console.WriteLine("Percentage not increasing, performing Collect/WFPF/Collect cycle"); + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + + if (handleCount == HandleCollectorTest.Count) + { + Console.WriteLine("No handles finalized in Collect/WFPF/Collect cycle"); + return false; + } } prevHandleCount = handleCount; } diff --git a/tests/src/GC/Scenarios/DoublinkList/dlcollect.cs b/tests/src/GC/Scenarios/DoublinkList/dlcollect.cs index a17e95a..f7aa10d 100644 --- a/tests/src/GC/Scenarios/DoublinkList/dlcollect.cs +++ b/tests/src/GC/Scenarios/DoublinkList/dlcollect.cs @@ -11,6 +11,7 @@ namespace DoubLink { using System; using System.Collections.Generic; + using System.Runtime.CompilerServices; public class DLCollect { @@ -63,11 +64,38 @@ namespace DoubLink { } + [MethodImpl(MethodImplOptions.NoInlining)] + public bool DrainFinalizerQueue(int iRep, int iObj) + { + int lastValue = DLinkNode.FinalCount; + while (true) + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + + if (DLinkNode.FinalCount == iRep * iObj * 10) + { + return true; + } + + if (DLinkNode.FinalCount != lastValue) + { + Console.WriteLine(" Performing Collect/Wait/Collect cycle again"); + lastValue = DLinkNode.FinalCount; + continue; + } + + Console.WriteLine(" Finalized number stable at " + lastValue); + return false; + } + } public bool runTest(int iRep, int iObj) { Mv_Collect = new List(iRep); + bool success = false; for(int i=0; i <10; i++) { SetLink(iRep, iObj); @@ -75,16 +103,13 @@ namespace DoubLink { GC.Collect(); } - GC.WaitForPendingFinalizers(); - - if (DLinkNode.FinalCount != iRep * iObj * 10) + if (DrainFinalizerQueue(iRep, iObj)) { - // see github#4093 for the rationale for fail-fast in this test. - Environment.FailFast(string.Empty); + success = true; } Console.WriteLine("{0} DLinkNodes finalized", DLinkNode.FinalCount); - return (DLinkNode.FinalCount==iRep*iObj*10); + return success; } diff --git a/tests/src/GC/Scenarios/DoublinkList/dlstack.cs b/tests/src/GC/Scenarios/DoublinkList/dlstack.cs index 5e207be..8fa63bf 100644 --- a/tests/src/GC/Scenarios/DoublinkList/dlstack.cs +++ b/tests/src/GC/Scenarios/DoublinkList/dlstack.cs @@ -13,6 +13,7 @@ namespace DoubLink { using System; + using System.Runtime.CompilerServices; public class DLStack { @@ -63,36 +64,50 @@ namespace DoubLink { } + [MethodImpl(MethodImplOptions.NoInlining)] + public bool DrainFinalizerQueue(int iRep, int iObj) + { + int lastValue = DLinkNode.FinalCount; + while (true) + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + + if (DLinkNode.FinalCount == iRep * iObj * 10) + { + return true; + } + + if (DLinkNode.FinalCount != lastValue) + { + Console.WriteLine(" Performing Collect/Wait/Collect cycle again"); + lastValue = DLinkNode.FinalCount; + continue; + } + + Console.WriteLine(" Finalized number stable at " + lastValue); + return false; + } + } + public bool runTest(int iRep, int iObj) { - + bool success = false; for(int i=0; i <10; i++) { SetLink(iRep, iObj); MakeLeak(iRep); } - long lastTotalMemory = long.MaxValue; - long curTotalMemory = GC.GetTotalMemory(false); - - while (lastTotalMemory != curTotalMemory) - { - GC.Collect(); - GC.WaitForPendingFinalizers(); - - lastTotalMemory = curTotalMemory; - curTotalMemory = GC.GetTotalMemory(false); - } - - if (DLinkNode.FinalCount != iRep * iObj * 10) + if (DrainFinalizerQueue(iRep, iObj)) { - // see github#4093 for the rationale for fail-fast in this test. - Environment.FailFast(string.Empty); + success = true; } Console.WriteLine("{0} DLinkNodes finalized", DLinkNode.FinalCount); - return (DLinkNode.FinalCount==iRep*iObj*10); + return success; } diff --git a/tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs b/tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs index 76436ea..0f1016c 100644 --- a/tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs +++ b/tests/src/GC/Scenarios/DoublinkList/doublinkgen.cs @@ -11,6 +11,7 @@ namespace DoubLink { using System; + using System.Runtime.CompilerServices; public class DoubLinkGen { @@ -61,25 +62,47 @@ namespace DoubLink { return 1; } + [MethodImpl(MethodImplOptions.NoInlining)] + public bool DrainFinalizerQueue(int iRep, int iObj) + { + int lastValue = DLinkNode.FinalCount; + while (true) + { + GC.Collect(); + GC.WaitForPendingFinalizers(); + GC.Collect(); + + if (DLinkNode.FinalCount == iRep * iObj) + { + return true; + } + + if (DLinkNode.FinalCount != lastValue) + { + Console.WriteLine(" Performing Collect/Wait/Collect cycle again"); + lastValue = DLinkNode.FinalCount; + continue; + } + + Console.WriteLine(" Finalized number stable at " + lastValue); + return false; + } + } public bool runTest(int iRep, int iObj) { SetLink(iRep, iObj); Mv_Doub = null; + bool success = false; - GC.Collect(); - GC.WaitForPendingFinalizers(); - GC.Collect(); - - if (DLinkNode.FinalCount != iRep * iObj) + if (DrainFinalizerQueue(iRep, iObj)) { - // see github#4093 for the rationale for fail-fast in this test. - Environment.FailFast(string.Empty); + success = true; } Console.Write(DLinkNode.FinalCount); Console.WriteLine(" DLinkNodes finalized"); - return (DLinkNode.FinalCount==iRep*iObj); + return success; } diff --git a/tests/testsFailingOutsideWindows.txt b/tests/testsFailingOutsideWindows.txt index 5829a8f..f286b21 100644 --- a/tests/testsFailingOutsideWindows.txt +++ b/tests/testsFailingOutsideWindows.txt @@ -70,7 +70,6 @@ GC/Features/BackgroundGC/foregroundgc/foregroundgc.sh GC/Features/LOHFragmentation/lohfragmentation/lohfragmentation.sh GC/Features/SustainedLowLatency/scenario/scenario.sh GC/Regressions/dev10bugs/536168/536168/536168.sh -GC/Scenarios/DoublinkList/doublinkgen/doublinkgen.sh Loader/classloader/TypeGeneratorTests/TypeGeneratorTest612/Generated612/Generated612.sh Loader/classloader/TypeGeneratorTests/TypeGeneratorTest613/Generated613/Generated613.sh Loader/classloader/TypeGeneratorTests/TypeGeneratorTest614/Generated614/Generated614.sh -- 2.7.4