Skip to content

Instantly share code, notes, and snippets.

@ReubenBond
Created September 19, 2018 02:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ReubenBond/b5bdf98423d5279a8e9ae63a5e6e8f0a to your computer and use it in GitHub Desktop.
Save ReubenBond/b5bdf98423d5279a8e9ae63a5e6e8f0a to your computer and use it in GitHub Desktop.
CoreCLR TieredCompilation JIT bug
> .\repro.cmd
C:\tmp\TieredJit\TierJit\TierJit>set COMPlus_TieredCompilation=0
C:\tmp\TieredJit\TierJit\TierJit>dotnet run -c Release
Correct value: True
C:\tmp\TieredJit\TierJit\TierJit>set COMPlus_TieredCompilation=1
C:\tmp\TieredJit\TierJit\TierJit>dotnet run -c Release
Correct value: False
using System;
namespace TierJit
{
class Program
{
static void Main(string[] args)
{
var array = new byte[] {0x00, 0x01};
var reader = new BinaryTokenStreamReader(array);
var val = reader.ReadByte();
// Prints true if tiered jit is disabled
// and false if tiered jit is enabled.
Console.WriteLine("Correct value: " + (val == 0x01));
}
}
public class BinaryTokenStreamReader
{
private readonly byte[] currentBuffer;
public BinaryTokenStreamReader(byte[] input)
{
this.currentBuffer = input;
}
byte[] CheckLength(out int offset)
{
// In the original code, this logic is more complicated.
// It's simplified here to demonstrate the bug.
offset = 1;
return currentBuffer;
}
public byte ReadByte()
{
int offset;
var buff = CheckLength(out offset);
return buff[offset];
}
}
}
set COMPlus_TieredCompilation=0
dotnet run -c Release
set COMPlus_TieredCompilation=1
dotnet run -c Release
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment