diff --git a/src/coreclr/vm/jitinterface.cpp b/src/coreclr/vm/jitinterface.cpp index 9471239e25a87..c68284c4ca521 100644 --- a/src/coreclr/vm/jitinterface.cpp +++ b/src/coreclr/vm/jitinterface.cpp @@ -140,7 +140,14 @@ FCIMPLEND FCIMPL1(INT64, GetCompiledMethodCount, CLR_BOOL currentThread) { FCALL_CONTRACT; - + // WIP-DEBUG-ONLY change: Windows is causing problems in the CI, but can't + // be replicated locally. Using this for some logging there to try to figure + // it out. + printf("\nENTERING GETCOMPILEDMETHODCOUNT:"); + printf("%d\n", currentThread ? 1 : 0); + printf("%ld\n", (long) t_cMethodsJittedForThread); + printf("%ld\n", (long) AtomicLoad64WithoutTearing(&g_cMethodsJitted)); + printf(":EXITING GETCOMPILEDMETHODCOUNT\n"); return currentThread ? t_cMethodsJittedForThread : AtomicLoad64WithoutTearing(&g_cMethodsJitted); } FCIMPLEND diff --git a/src/tests/Directory.Build.targets b/src/tests/Directory.Build.targets index 7402a015c3598..11c86348e22c2 100644 --- a/src/tests/Directory.Build.targets +++ b/src/tests/Directory.Build.targets @@ -153,6 +153,7 @@ - + true diff --git a/src/tests/readytorun/JittedMethodsCountingTest/JittedMethodsCountingTest.cs b/src/tests/readytorun/JittedMethodsCountingTest/JittedMethodsCountingTest.cs new file mode 100644 index 0000000000000..a7516b024f87d --- /dev/null +++ b/src/tests/readytorun/JittedMethodsCountingTest/JittedMethodsCountingTest.cs @@ -0,0 +1,60 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using System; +using Xunit; + +using InteropServices = System.Runtime.InteropServices; +using JitInfo = System.Runtime.JitInfo; + +public class JittedMethodsCountingTest +{ + private const int MAX_JITTED_METHODS_ACCEPTED = 70; + + [Fact] + public static int TestEntryPoint() + { + // If DOTNET_ReadyToRun is disabled, then this test ought to be skipped. + if (!IsReadyToRunEnvSet()) + { + Console.WriteLine("\nThis test is only supported in ReadyToRun scenarios." + + " Skipping...\n"); + return 100; + } + + if (IsRunCrossgen2Set() && IsRunningOnARM64()) + { + Console.WriteLine("\nThis test is currently unsupported on ARM64 when" + + " RunCrossGen2 is enabled. Skipping...\n"); + return 100; + } + + Console.WriteLine("\nHello World from Jitted Methods Counting Test!"); + + long jits = JitInfo.GetCompiledMethodCount(false); + Console.WriteLine("Number of Jitted Methods in App: {0}\n", jits); + + return (jits >= 0 && jits <= MAX_JITTED_METHODS_ACCEPTED) ? 100 : 101; + } + + private static bool IsReadyToRunEnvSet() + { + string? dotnetR2R = Environment.GetEnvironmentVariable("DOTNET_ReadyToRun"); + return (string.IsNullOrEmpty(dotnetR2R) || dotnetR2R == "1"); + } + + private static bool IsRunCrossgen2Set() + { + string? runCrossgen2 = Environment.GetEnvironmentVariable("RunCrossGen2"); + return (runCrossgen2 == "1"); + } + + private static bool IsRunningOnARM64() + { + InteropServices.Architecture thisMachineArch = InteropServices + .RuntimeInformation + .OSArchitecture; + + return (thisMachineArch == InteropServices.Architecture.Arm64); + } +} diff --git a/src/tests/readytorun/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj b/src/tests/readytorun/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj new file mode 100644 index 0000000000000..af743de313506 --- /dev/null +++ b/src/tests/readytorun/JittedMethodsCountingTest/JittedMethodsCountingTest.csproj @@ -0,0 +1,13 @@ + + + + pdbonly + true + true + + + + + + +