Skip to content

Commit 3e293bc

Browse files
authored
[JIT] Do not force creation of a new IG if the current IG has no instructions (dotnet#89876)
* Added 78891 test * Fix name * Fix test * Feedback * 78891 test is process isolated to use the environment variables. When enabling GC in the emitter, if the current IG has no instructions, do not force a new IG. * Remove extend flag * Quick cleanup * Quick cleanup * Update Runtime_78891.csproj * Feedback * Fix test * Fix test * Reset flags * Fix test * Fixing test again... * Only set the NOGCINTERRUPT flag accordingly
1 parent e2c4b10 commit 3e293bc

File tree

3 files changed

+92
-1
lines changed

3 files changed

+92
-1
lines changed

src/coreclr/jit/emit.cpp

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1654,7 +1654,22 @@ void* emitter::emitAllocAnyInstr(size_t sz, emitAttr opsz)
16541654
if ((emitCurIGfreeNext + fullSize >= emitCurIGfreeEndp) || emitForceNewIG ||
16551655
(emitCurIGinsCnt >= (EMIT_MAX_IG_INS_COUNT - 1)))
16561656
{
1657-
emitNxtIG(true);
1657+
// If the current IG has instructions, then we need to create a new one.
1658+
if (emitCurIGnonEmpty())
1659+
{
1660+
emitNxtIG(true);
1661+
}
1662+
else
1663+
{
1664+
if (emitNoGCIG)
1665+
{
1666+
emitCurIG->igFlags |= IGF_NOGCINTERRUPT;
1667+
}
1668+
else
1669+
{
1670+
emitCurIG->igFlags &= ~IGF_NOGCINTERRUPT;
1671+
}
1672+
}
16581673
}
16591674

16601675
/* Grab the space for the instruction */
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using System;
5+
using System.Runtime.CompilerServices;
6+
using Xunit;
7+
8+
// This test is to ensure that an assertion does not occur in the JIT.
9+
public class Runtime_78891
10+
{
11+
class C0
12+
{
13+
public long F1;
14+
}
15+
16+
struct S5
17+
{
18+
public bool F1;
19+
public int F2;
20+
public C0 F4;
21+
public short F5;
22+
public ulong F6;
23+
public uint F7;
24+
}
25+
26+
static S5 s_48;
27+
28+
[MethodImpl(MethodImplOptions.NoInlining)]
29+
static void Consume(short x)
30+
{
31+
32+
}
33+
34+
static void M59(S5 arg0, S5 arg1)
35+
{
36+
try
37+
{
38+
arg0 = arg1;
39+
arg0 = arg1;
40+
short var3 = arg1.F5;
41+
Consume(var3);
42+
}
43+
finally
44+
{
45+
if (s_48.F4.F1 > arg0.F7)
46+
{
47+
arg0.F1 |= false;
48+
}
49+
}
50+
}
51+
52+
[Fact]
53+
public static void TestEntryPoint()
54+
{
55+
var vr2 = new S5();
56+
var vr3 = new S5();
57+
Assert.Throws<NullReferenceException>(() => M59(vr2, vr3));
58+
}
59+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<!-- Needed for CLRTestEnvironmentVariable -->
4+
<RequiresProcessIsolation>true</RequiresProcessIsolation>
5+
<Optimize>True</Optimize>
6+
</PropertyGroup>
7+
<ItemGroup>
8+
<Compile Include="$(MSBuildProjectName).cs" />
9+
</ItemGroup>
10+
<ItemGroup>
11+
<CLRTestEnvironmentVariable Include="DOTNET_JitDoVNBasedDeadStoreRemoval" Value="0" />
12+
<CLRTestEnvironmentVariable Include="DOTNET_JitEnableEarlyLivenessRange" Value="0" />
13+
<CLRTestEnvironmentVariable Include="DOTNET_JitEnablePhysicalPromotion" Value="0" />
14+
<CLRTestEnvironmentVariable Include="DOTNET_EnableAVX2" Value="0" />
15+
<CLRTestEnvironmentVariable Include="DOTNET_TieredCompilation" Value="0" />
16+
</ItemGroup>
17+
</Project>

0 commit comments

Comments
 (0)