This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stack trace population to get proper source/line info for tier 1 …
…methods (#16302) Fixes https://github.com/dotnet/coreclr/issues/16224
- Loading branch information
Showing
10 changed files
with
150 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
tests/src/baseservices/exceptions/stacktrace/Tier1StackTrace.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
// See the LICENSE file in the project root for more information. | ||
|
||
using System; | ||
using System.Diagnostics; | ||
using System.Runtime.CompilerServices; | ||
using System.Threading; | ||
|
||
internal static class Program | ||
{ | ||
private static int Main() | ||
{ | ||
const int Pass = 100, Fail = 1; | ||
|
||
string tier0StackTrace = Capture(true); | ||
PromoteToTier1(() => Capture(false)); | ||
string tier1StackTrace = Capture(true); | ||
return tier0StackTrace == tier1StackTrace ? Pass : Fail; | ||
} | ||
|
||
private static void PromoteToTier1(Action action) | ||
{ | ||
// Call the method once to register a call for call counting | ||
action(); | ||
|
||
// Allow time for call counting to begin | ||
Thread.Sleep(500); | ||
|
||
// Call the method enough times to trigger tier 1 promotion | ||
for (int i = 0; i < 100; i++) | ||
{ | ||
action(); | ||
} | ||
|
||
// Allow time for the method to be jitted at tier 1 | ||
Thread.Sleep(500); | ||
} | ||
|
||
[MethodImpl(MethodImplOptions.NoInlining)] | ||
private static string Capture(bool doWork) | ||
{ | ||
if (!doWork) | ||
{ | ||
return null; | ||
} | ||
|
||
string stackTrace = new StackTrace(true).ToString().Trim(); | ||
|
||
// Remove the last line of the stack trace, which would correspond with Main() | ||
int lastNewLineIndex = stackTrace.LastIndexOf('\n'); | ||
if (lastNewLineIndex == -1) | ||
{ | ||
return null; | ||
} | ||
return stackTrace.Substring(0, lastNewLineIndex).Trim(); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
tests/src/baseservices/exceptions/stacktrace/Tier1StackTrace.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?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> | ||
<ProjectGuid>{8758BFAC-7D36-4244-8A36-4C464C0AFA6D}</ProjectGuid> | ||
<OutputType>Exe</OutputType> | ||
<LangVersion>latest</LangVersion> | ||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> | ||
<Optimize>true</Optimize> | ||
<CLRTestPriority>1</CLRTestPriority> | ||
</PropertyGroup> | ||
<!-- Default configurations to help VS understand the configurations --> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> | ||
</PropertyGroup> | ||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="Tier1StackTrace.cs" /> | ||
</ItemGroup> | ||
<PropertyGroup> | ||
<CLRTestBatchPreCommands><![CDATA[ | ||
$(CLRTestBatchPreCommands) | ||
set COMPlus_EXPERIMENTAL_TieredCompilation=1 | ||
]]></CLRTestBatchPreCommands> | ||
<BashCLRTestPreCommands><![CDATA[ | ||
$(BashCLRTestPreCommands) | ||
export COMPlus_EXPERIMENTAL_TieredCompilation=1 | ||
]]></BashCLRTestPreCommands> | ||
</PropertyGroup> | ||
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), dir.targets))\dir.targets" /> | ||
</Project> |