Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JIT: fix OSR handling for pinned locals #67680

Merged
merged 1 commit into from
Apr 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,14 @@ void Compiler::lvaInitTypeRef()
{
JITDUMP("Setting lvPinned for V%02u\n", varNum);
varDsc->lvPinned = 1;

if (opts.IsOSR())
{
// OSR method may not see any references to the pinned local,
// but must still report it in GC info.
//
varDsc->lvImplicitlyReferenced = 1;
}
}
else
{
Expand Down
37 changes: 37 additions & 0 deletions src/tests/JIT/opt/OSR/pinnedlocal.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using System;

// Run under COMPlus_GCStress=3

class PinnedLocal
{
static int F(char c)
{
return (int) c;
}

public static unsafe int Main()
{
string ss = "goodbye, world\n";
string s = "hello, world\n";
int r = 0;
fixed(char* p = s)
{
for (int i = 0; i < 100_000; i++)
{
r += F(p[i % s.Length]);

if ((i % 10_000) == 0)
{
GC.Collect(2);
ss = new String('a', 100);
}
}

Console.WriteLine($"r is {r}");
return r - 9000061 + 100;
}
}
}
21 changes: 21 additions & 0 deletions src/tests/JIT/opt/OSR/pinnedlocal.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<DebugType />
<Optimize>True</Optimize>
<AllowUnsafeBlocks>True</AllowUnsafeBlocks>
</PropertyGroup>
<ItemGroup>
<Compile Include="$(MSBuildProjectName).cs" />
</ItemGroup>
<PropertyGroup>
<CLRTestBatchPreCommands><![CDATA[
$(CLRTestBatchPreCommands)
set COMPlus_GCStress=3
]]></CLRTestBatchPreCommands>
<BashCLRTestPreCommands><![CDATA[
$(BashCLRTestPreCommands)
export COMPlus_GCStress=3
]]></BashCLRTestPreCommands>
</PropertyGroup>
</Project>