From e2637731b980a6d73c5bb244720f4a5931001727 Mon Sep 17 00:00:00 2001 From: Lubomir Litchev Date: Sun, 10 Apr 2016 13:46:01 -0700 Subject: Add a test for Issue 4147. This checkin adds a test for Issue 4147. --- .../Regression/JitBlue/GitHub_4115/GitHub_4115.cs | 146 +++++++++++++++++++++ .../JitBlue/GitHub_4115/GitHub_4115.csproj | 50 +++++++ .../JIT/Regression/JitBlue/GitHub_4115/app.config | 27 ++++ .../Regression/JitBlue/GitHub_4115/project.json | 36 +++++ 4 files changed, 259 insertions(+) create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_4115/GitHub_4115.cs create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_4115/GitHub_4115.csproj create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_4115/app.config create mode 100644 tests/src/JIT/Regression/JitBlue/GitHub_4115/project.json diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_4115/GitHub_4115.cs b/tests/src/JIT/Regression/JitBlue/GitHub_4115/GitHub_4115.cs new file mode 100644 index 0000000000..bfe14cc037 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_4115/GitHub_4115.cs @@ -0,0 +1,146 @@ +// 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. + +// This test could fail in GCStress=0xC case, if the object movement happens at the right place and time. +// If the GC guarantees object movement at every collection, the case will fail in that GC stress mode always. +using System; +using System.Runtime.CompilerServices; +using System.Runtime.InteropServices; +using System.Threading; +using System.Threading.Tasks; + +namespace Issue_4115 +{ + public class MyClass + { + private GCHandle _pinHandle; + private IntPtr _dataArrayPtr; + public ArraySegment Data; + public MyClass() + { + } + + public object Obj { get; private set; } + public byte[] Array => Data.Array; + public int Start { get; set; } + public int End { get; set; } + public MyClass Next { get; set; } + } + + public struct MyIterator + { + private static readonly int _vectorSpan = 100; + + private MyClass _class; + + private int _index; + + public bool IsDefault + { + get + { + return this._class == null; + } + } + + public bool IsEnd + { + get + { + if (this._class == null) { + return true; + } + if (this._index < this._class.End) { + return false; + } + for (MyClass next = this._class.Next; next != null; next = next.Next) { + if (next.Start < next.End) { + return false; + } + } + return true; + } + } + + public MyClass Class + { + get + { + return this._class; + } + } + + public int Index + { + get + { + return this._index; + } + } + + public MyIterator(MyClass clazz) + { + this._class = clazz; + MyClass expr_0E = this._class; + this._index = ((expr_0E != null) ? expr_0E.Start : 0); + } + + public MyIterator(MyClass clazz, int index) + { + this._class = clazz; + this._index = index; + } + } + + public class MainClass + { + private readonly object _returnLock = new object(); + + private MyClass _head; + private MyClass _tail; + private MyIterator _lastStart; + + public MyIterator TestMethod() + { + lock (_returnLock) + { + if (_tail == null) + { + return default(MyIterator); + } + + // In this assignment there could be a GC hole: + // gcrReg -[rbx] + // byrReg +[rbx] + // add rbx, 32 + // mov r15, rbx <--- r15 is not tracked to have a byref pointer. + // If a GC happens between this instruction and the next one, we have an invalid pointer. + // gcrReg -[rdi] + // byrReg +[rdi] + // mov rdi, r15 + // New gcrReg live regs = 00000000 { } + + _lastStart = new MyIterator(_tail, _tail.End); + return _lastStart; + } + } + + static int Main(string[] args) + { + MainClass mainClass = new MainClass(); + mainClass._head = mainClass._tail = new MyClass(); + mainClass._head.End = 4; + if (mainClass.TestMethod().Class.End == 4) + { + Console.WriteLine("Passed"); + return 100; + } + else + { + Console.WriteLine("Failed"); + return 1; + } + } + } +} \ No newline at end of file diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_4115/GitHub_4115.csproj b/tests/src/JIT/Regression/JitBlue/GitHub_4115/GitHub_4115.csproj new file mode 100644 index 0000000000..23bd109fc0 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_4115/GitHub_4115.csproj @@ -0,0 +1,50 @@ + + + + + Debug + AnyCPU + $(MSBuildProjectName) + 2.0 + {95DFC527-4DC1-495E-97D7-E94EE1F7140D} + Exe + Properties + 512 + {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + $(ProgramFiles)\Common Files\microsoft shared\VSTT\11.0\UITestExtensionPackages + ..\..\ + + 7a9bfb7d + + + + + + + + + False + + + + + True + + + + + + + + + + + + + project.json + project.lock.json + + + + + diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_4115/app.config b/tests/src/JIT/Regression/JitBlue/GitHub_4115/app.config new file mode 100644 index 0000000000..62803f5972 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_4115/app.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/JIT/Regression/JitBlue/GitHub_4115/project.json b/tests/src/JIT/Regression/JitBlue/GitHub_4115/project.json new file mode 100644 index 0000000000..f084fdaed9 --- /dev/null +++ b/tests/src/JIT/Regression/JitBlue/GitHub_4115/project.json @@ -0,0 +1,36 @@ +{ + "dependencies": { + "Microsoft.NETCore.Platforms": "1.0.1-rc2-23816", + "System.Collections": "4.0.10", + "System.Collections.NonGeneric": "4.0.1-rc2-23816", + "System.Collections.Specialized": "4.0.1-rc2-23816", + "System.ComponentModel": "4.0.1-rc2-23816", + "System.Console": "4.0.0-rc2-23816", + "System.Diagnostics.Process": "4.1.0-rc2-23816", + "System.Globalization": "4.0.10", + "System.Globalization.Calendars": "4.0.0", + "System.IO": "4.0.10", + "System.IO.FileSystem": "4.0.0", + "System.IO.FileSystem.Primitives": "4.0.0", + "System.Linq": "4.0.1-rc2-23816", + "System.Linq.Queryable": "4.0.1-rc2-23816", + "System.Reflection": "4.1.0-rc2-23816", + "System.Reflection.Primitives": "4.0.0", + "System.Runtime": "4.1.0-rc2-23816", + "System.Runtime.Extensions": "4.0.10", + "System.Runtime.Handles": "4.0.0", + "System.Runtime.InteropServices": "4.1.0-rc2-23816", + "System.Runtime.Loader": "4.0.0-rc2-23816", + "System.Text.Encoding": "4.0.10", + "System.Threading": "4.0.10", + "System.Threading.Thread": "4.0.0-rc2-23816", + "System.Threading.ThreadPool": "4.0.10-rc2-23816", + "System.Xml.ReaderWriter": "4.0.11-rc2-23816", + "System.Xml.XDocument": "4.0.11-rc2-23816", + "System.Xml.XmlDocument": "4.0.1-rc2-23816", + "System.Xml.XmlSerializer": "4.0.11-rc2-23816" + }, + "frameworks": { + "dnxcore50": {} + } +} \ No newline at end of file -- cgit v1.2.3