forked from dotnet/runtime
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
JIT: fix invocation of unboxed entry when method returns struct
If a value class method returns a struct, and its unboxed entry point requires a type context argument, make sure to pass the context argument properly. Also, fetch the type context (method table) from the box, rather than creating it from the class handle we have on hand; this tends to produce smaller code as we're often fetching the method table for other reasons anyways. Closes dotnet#52975.
- Loading branch information
1 parent
aad916c
commit b2e3f96
Showing
3 changed files
with
123 additions
and
13 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
63 changes: 63 additions & 0 deletions
63
src/tests/JIT/opt/Devirtualization/structreturningstruct.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,63 @@ | ||
// 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 System.Collections; | ||
using System.Collections.Generic; | ||
using System.Threading; | ||
|
||
// Runtime issue 52975. | ||
// | ||
// If we devirtualize an interface call on a struct, ** and ** | ||
// update the call site to invoke the unboxed entry, ** and ** | ||
// the method returns a struct via hidden buffer pointer, ** and ** | ||
// the unboxed method requires a type context arg, | ||
// | ||
// we need to be careful to pass the type context argument | ||
// in the right spot in the arglist. | ||
// | ||
// The test below is set up to devirtualize under PGO. | ||
// | ||
// COMPlus_TieredPGO=1 | ||
// COMPlus_TC_QuickJitForLoopsO=1 | ||
// | ||
class X | ||
{ | ||
static int F(IDictionary i) | ||
{ | ||
int r = 0; | ||
IDictionaryEnumerator e = i.GetEnumerator(); | ||
while (e.MoveNext()) | ||
{ | ||
// This is the critical call. | ||
// | ||
DictionaryEntry entry = e.Entry; | ||
r++; | ||
} | ||
return r; | ||
} | ||
|
||
public static int Main() | ||
{ | ||
Dictionary<string, string> s = new Dictionary<string, string>(); | ||
s["hello"] = "world"; | ||
int r = 0; | ||
|
||
for (int i = 0; i < 50; i++) | ||
{ | ||
r += F(s); | ||
Thread.Sleep(15); | ||
} | ||
|
||
int iter = 100; | ||
|
||
for (int i = 0; i < iter; i++) | ||
{ | ||
r += F(s); | ||
} | ||
|
||
int result = 2 * (r - iter); | ||
Console.WriteLine($"Result={result}"); | ||
return result; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
src/tests/JIT/opt/Devirtualization/structreturningstruct.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,27 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<DebugType>PdbOnly</DebugType> | ||
<Optimize>True</Optimize> | ||
</PropertyGroup> | ||
<PropertyGroup> | ||
<!-- This test requires tiered compilation and PGO --> | ||
<CLRTestBatchPreCommands><![CDATA[ | ||
$(CLRTestBatchPreCommands) | ||
set DOTNET_TieredCompilation=1 | ||
set DOTNET_TieredPGO=1 | ||
set DOTNET_TC_QuickJitForLoops=1 | ||
]]></CLRTestBatchPreCommands> | ||
<BashCLRTestPreCommands><![CDATA[ | ||
$(BashCLRTestPreCommands) | ||
export DOTNET_TieredCompilation=1 | ||
export DOTNET_TieredPGO=1 | ||
export DOTNET_TC_QuickJitForLoops=1 | ||
]]></BashCLRTestPreCommands> | ||
</PropertyGroup> | ||
<ItemGroup> | ||
<Compile Include="structreturningstruct.cs" /> | ||
</ItemGroup> | ||
</Project> |