diff options
author | Shiming Ge (Pactera Technologies) <v-shige@microsoft.com> | 2017-08-09 02:36:11 -0700 |
---|---|---|
committer | Shiming Ge (Pactera Technologies) <v-shige@microsoft.com> | 2017-08-09 02:36:11 -0700 |
commit | 1d91eb4b2baa15009f378908de464627079560fa (patch) | |
tree | 97dc706bafeeb8a766a731e1b38561979e85558e /tests/src/GC/Performance | |
parent | bb1c4a48f9c6d49d5c75628394b7c822f96c57be (diff) | |
download | coreclr-1d91eb4b2baa15009f378908de464627079560fa.tar.gz coreclr-1d91eb4b2baa15009f378908de464627079560fa.tar.bz2 coreclr-1d91eb4b2baa15009f378908de464627079560fa.zip |
add perf test case GCLarge
Diffstat (limited to 'tests/src/GC/Performance')
-rw-r--r-- | tests/src/GC/Performance/Tests/GCLarge.cs | 203 | ||||
-rw-r--r-- | tests/src/GC/Performance/Tests/GCLarge.csproj | 35 |
2 files changed, 238 insertions, 0 deletions
diff --git a/tests/src/GC/Performance/Tests/GCLarge.cs b/tests/src/GC/Performance/Tests/GCLarge.cs new file mode 100644 index 0000000000..453cb0742a --- /dev/null +++ b/tests/src/GC/Performance/Tests/GCLarge.cs @@ -0,0 +1,203 @@ +using System; + +internal class List +{ + const int LOOP = 847; + public SmallGC dat; + public List next; + + public static void Main(string[] p_args) + { + long iterations = 200; + + //Large Object Collection + CreateLargeObjects(); + GC.Collect(); + GC.WaitForPendingFinalizers(); + + for(long i = 0; i < iterations; i++) + { + CreateLargeObjects(); + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + + + //Large Object Collection (half array) + CreateLargeObjectsHalf(); + GC.Collect(); + GC.WaitForPendingFinalizers(); + + for(long i = 0; i < iterations; i++) + { + CreateLargeObjectsHalf(); + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + + //Promote from Gen1 to Gen2 + SmallGC [] sgc; + sgc = new SmallGC [LOOP]; + for (int j = 0; j < LOOP; j++) + sgc[j] = new SmallGC(0); + + GC.Collect(); + + for (int j = 0; j < LOOP; j++) + sgc[j] = null; + + GC.Collect(); + GC.WaitForPendingFinalizers(); + + for(long i = 0; i < iterations; i++) + { + // allocate into gen 0 + sgc = new SmallGC [LOOP]; + for (int j = 0; j < LOOP; j++) + sgc[j] = new SmallGC(0); + + // promote to gen 1 + while (GC.GetGeneration(sgc[LOOP-1])<1) + { + GC.Collect(); + } + + while (GC.GetGeneration(sgc[LOOP-1])<2) + { + // promote to gen 2 + GC.Collect(); + } + + for (int j = 0; j < LOOP; j++) + sgc[j] = null; + + GC.Collect(); + GC.WaitForPendingFinalizers(); + } + + //Promote from Gen1 to Gen2 (Gen1 ptr updates) + List node = PopulateList(LOOP); + GC.Collect(); + GC.WaitForPendingFinalizers(); + + if(List.ValidateList(node, LOOP) == 0) + Console.WriteLine("Pointers after promotion are not valid"); + + for(long i = 0; i < iterations; i++) + { + // allocate into gen 0 + node = PopulateList(LOOP); + + // promote to gen 1 + while (GC.GetGeneration(node)<1) + { + GC.Collect(); + } + + while (GC.GetGeneration(node)<2) + { + //promote to gen 2 + GC.Collect(); + GC.WaitForPendingFinalizers(); + + if(ValidateList(node, LOOP) == 0) + Console.WriteLine("Pointers after promotion are not valid"); + + } + } + } + + public static List PopulateList(int len) + { + if (len == 0) return null; + List Node = new List(); + Node.dat = new SmallGC(1); + Node.dat.AttachSmallObjects(); + Node.next = null; + for (int i = len -1; i > 0; i--) + { + List cur = new List(); + cur.dat = new SmallGC(1); + cur.dat.AttachSmallObjects(); + cur.next = Node; + Node = cur; + } + return Node; + } + public static int ValidateList(List First, int len) + { + List tmp1 = First; + int i = 0; + LargeGC tmp2; + while(tmp1 != null) + { + //Check the list have correct small object pointers after collection + if(tmp1.dat == null) break; + tmp2 = tmp1.dat.m_pLarge; + //check the large object has non zero small object pointers + if (tmp2.m_pSmall == null) break; + //check the large object has correct small object pointers + if(tmp2.m_pSmall != tmp1.dat) break; + tmp1 = tmp1.next; + i++; + } + if (i == len) + return 1; + else + return 0; + } + + + public static void CreateLargeObjects() + { + LargeGC [] lgc; + lgc = new LargeGC[LOOP]; + for (int i=0; i < LOOP ; i++) + lgc[i] = new LargeGC(); + } + + public static void CreateLargeObjectsHalf() + { + LargeGC [] lgc; + lgc = new LargeGC[LOOP]; + + for(int i = 0; i < LOOP; i++) + lgc[i] = new LargeGC(); + + for(int i = 0; i < LOOP; i+=2) + lgc[i] = null; + } +} + +internal class LargeGC +{ + public double [] d; + public SmallGC m_pSmall; + + public LargeGC() + { + d = new double [10625]; //85 KB + m_pSmall = null; + } + + public virtual void AttachSmallObjects(SmallGC small) + { + m_pSmall = small; + } +} + +internal class SmallGC +{ + public LargeGC m_pLarge; + public SmallGC(int HasLargeObj) + { + if (HasLargeObj == 1) + m_pLarge = new LargeGC(); + else + m_pLarge = null; + } + public virtual void AttachSmallObjects() + { + m_pLarge.AttachSmallObjects(this); + } +} diff --git a/tests/src/GC/Performance/Tests/GCLarge.csproj b/tests/src/GC/Performance/Tests/GCLarge.csproj new file mode 100644 index 0000000000..27c46cb4ba --- /dev/null +++ b/tests/src/GC/Performance/Tests/GCLarge.csproj @@ -0,0 +1,35 @@ +<?xml version="1.0" encoding="utf-8"?> +<Project ToolsVersion="12.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.props))\dir.props" /> + <PropertyGroup> + <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> + <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> + <SchemaVersion>2.0</SchemaVersion> + <ProjectGuid>{95DFC527-4DC1-495E-97D7-E94EE1F7140D}</ProjectGuid> + <OutputType>Exe</OutputType> + <ProjectTypeGuids>{786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> + <SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\</SolutionDir> + <AllowUnsafeBlocks>true</AllowUnsafeBlocks> + <DefineConstants>$(DefineConstants);STATIC;PROJECTK_BUILD</DefineConstants> + <CLRTestKind>BuildOnly</CLRTestKind> + </PropertyGroup> + <!-- Default configurations to help VS understand the configurations --> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "> + </PropertyGroup> + <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> + </PropertyGroup> + <ItemGroup> + <CodeAnalysisDependentAssemblyPaths Condition=" '$(VS100COMNTOOLS)' != '' " Include="$(VS100COMNTOOLS)..\IDE\PrivateAssemblies"> + <Visible>False</Visible> + </CodeAnalysisDependentAssemblyPaths> + </ItemGroup> + <ItemGroup> + <Compile Include="GCLarge.cs" /> + </ItemGroup> + <ItemGroup> + <Service Include="{82A7F48D-3B50-4B1E-B82E-3ADA8210C358}" /> + </ItemGroup> + <Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> + <PropertyGroup Condition=" '$(MsBuildProjectDirOverride)' != '' "> + </PropertyGroup> +</Project>
\ No newline at end of file |