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

Access violation (0xC0000005, AccessViolationException) when JITting a method #10826

Closed
januszn opened this issue Apr 8, 2017 · 6 comments

Comments

@januszn
Copy link

commented Apr 8, 2017

OS is Windows 10 Creators Update 64-bit.
Visual Studio 2017 Update 1 is installed - I've only used tools bundled with it to create the repro code.
Command line tool reports the following information:

Version  : 1.1.0
Build    : 928f77c4bc3f49d892459992fb6e1d5542cb5e86

To reproduce the issue using .NET Core, create a console application with the code below and run its release configuration. This is as specific as I was able to make it - making the property auto-implemented or reducing the depth of the nested loops hides the problem.

using System;
using System.Collections.Generic;

namespace AccessViolationRepro
{
    class Program
    {
        static void Main(string[] args)
        {
            ClassWithLogic.MethodWithLogic(null);
        }
    }

    public class ClassWithLogic
    {
        public static void MethodWithLogic(IEnumerable<OuterDataClass> outerCollection)
        {
            bool flagMisusedInPlaceOfPreprocessorSymbol = false;
            if (flagMisusedInPlaceOfPreprocessorSymbol)
            {
                foreach (var outerDataInstance in outerCollection)
                {
                    foreach (var innerDataInstance in outerDataInstance.innerCollection)
                    {
                        GC.KeepAlive(innerDataInstance.PropertyWithLogicInGetter);
                    }
                }
            }

            if (flagMisusedInPlaceOfPreprocessorSymbol)
            {
            }
        }
    }

    public class OuterDataClass
    {
        public IEnumerable<InnerDataClass> innerCollection;
    }

    public class InnerDataClass
    {
        private double? backingField;

        public double PropertyWithLogicInGetter
        {
            get
            {
                return backingField.HasValue ? backingField.Value : -1.0;
            }
            set
            {
                backingField = value;
            }
        }
    }
}

Stack trace for desktop .NET 4.7 is as follows:

>	clrjit.dll!ValueNumStore::GetVNFunc(unsigned int,struct VNFuncApp *)	Unknown
 	clrjit.dll!Compiler::optCreateAssertion(struct GenTree *,struct GenTree *,enum Compiler::optAssertionKind,struct Compiler::AssertionDsc *)	Unknown
 	clrjit.dll!Compiler::optAssertionPropMain(void)	Unknown
 	clrjit.dll!Compiler::compCompile(void * *,unsigned long *,class JitFlags *)	Unknown
 	clrjit.dll!Compiler::compCompileHelper(struct CORINFO_MODULE_STRUCT_ *,class ICorJitInfo *,struct CORINFO_METHOD_INFO *,void * *,unsigned long *,class JitFlags *,enum CorInfoInstantiationVerification)	Unknown
 	clrjit.dll!Compiler::compCompile(struct CORINFO_METHOD_STRUCT_ *,struct CORINFO_MODULE_STRUCT_ *,class ICorJitInfo *,struct CORINFO_METHOD_INFO *,void * *,unsigned long *,class JitFlags *)	Unknown
 	clrjit.dll!jitNativeCode(struct CORINFO_METHOD_STRUCT_ *,struct CORINFO_MODULE_STRUCT_ *,class ICorJitInfo *,struct CORINFO_METHOD_INFO *,void * *,unsigned long *,class JitFlags *,void *)	Unknown
 	clrjit.dll!CILJit::compileMethod(class ICorJitInfo *,struct CORINFO_METHOD_INFO *,unsigned int,unsigned char * *,unsigned long *)	Unknown
 	[Managed to Native Transition]	
 	AccessViolationRepro.exe!AccessViolationRepro.Program.Main(string[] args) Line 11	C#
 	[Native to Managed Transition]	
 	mscoreei.dll!_CorExeMain�()	Unknown
 	mscoree.dll!_CorExeMain_Exported�()	Unknown
 	kernel32.dll!BaseThreadInitThunk�()	Unknown
 	ntdll.dll!RtlUserThreadStart�()	Unknown

Meaningful stack trace for .NET Core is trickier to get without actually building CoreCLR for yourself (no mixed mode debugging support, no official builds with symbols), this is what I'm getting:

>	KernelBase.dll!RaiseException�()	Unknown
 	coreclr.dll!__CxxCallCatchBlock�()	Unknown
 	ntdll.dll!RcConsolidateFrames�()	Unknown
 	coreclr.dll!MethodDesc::MakeJitWorker(class COR_ILMETHOD_DECODER *,unsigned long,unsigned long)	Unknown
 	coreclr.dll!MethodDesc::DoPrestub(class MethodTable *)	Unknown
 	coreclr.dll!PreStubWorker�()	Unknown
 	coreclr.dll!ThePreStub�()	Unknown
 	00007fff46fb048b()	Unknown
 	coreclr.dll!CallDescrWorkerInternal�()	Unknown
 	coreclr.dll!MethodDescCallSite::CallTargetWorker(unsigned __int64 const *,unsigned __int64 *,int)	Unknown
 	coreclr.dll!RunMain(class MethodDesc *,short,int *,class PtrArray * *)	Unknown
 	coreclr.dll!Assembly::ExecuteMainMethod(class PtrArray * *,int)	Unknown
 	coreclr.dll!CorHost2::ExecuteAssembly(unsigned long,unsigned short const *,int,unsigned short const * *,unsigned long *)	Unknown
 	coreclr.dll!coreclr_execute_assembly�()	Unknown
 	hostpolicy.dll!00007fffbb8eeeb4()	Unknown
 	hostpolicy.dll!00007fffbb8ef482()	Unknown
 	hostfxr.dll!00007fffc19a8b8e()	Unknown
 	hostfxr.dll!00007fffc19acdaf()	Unknown
 	hostfxr.dll!00007fffc19ac4e2()	Unknown
 	hostfxr.dll!00007fffc19aafdf()	Unknown
 	dotnet.exe!00007ff7556295a2()	Unknown
 	dotnet.exe!00007ff75562cc44()	Unknown
 	kernel32.dll!BaseThreadInitThunk�()	Unknown
 	ntdll.dll!RtlUserThreadStart�()	Unknown
@mikedn

This comment has been minimized.

Copy link
Contributor

commented Apr 9, 2017

Looks like another case of #7958, neither .NET 4.7 nor .NET Core 1.1.0 have that fix.

@jkotas jkotas added the area-CodeGen label Apr 10, 2017
@RussKeldorph RussKeldorph added the bug label Apr 11, 2017
@RussKeldorph RussKeldorph added this to the 2.0.0 milestone Apr 11, 2017
@pgavlin

This comment has been minimized.

Copy link
Contributor

commented Apr 26, 2017

I have confirmed that this was indeed another case of #7958.

@RussKeldorph do you think we should backport that fix?

@RussKeldorph

This comment has been minimized.

Copy link
Member

commented Apr 26, 2017

@januszn Thanks for reporting this! We have confirmed that this will be fixed in .NET Core 2.0 and a future update to the .NET Framework. If you don't have an acceptable workaround and need an update to .NET Core 1.x you can respond on this thread and I'll see what we can do. If you need an update to one or more releases of the .NET Framework, I believe you can now submit feedback from within Visual Studio itself that shows up here, or there's also Connect.

@rickbrew

This comment has been minimized.

Copy link

commented Jul 16, 2017

@januszn

This comment has been minimized.

Copy link
Author

commented Jul 18, 2017

@rickbrew It's already been released, see here:
https://blogs.msdn.microsoft.com/dotnet/2017/05/26/net-framework-may-2017-cumulative-quality-update-for-windows-10/
After installing it, I'm no longer seeing the bug occur in the original application that prompted me to research it.

@rickbrew

This comment has been minimized.

Copy link

commented Jul 21, 2017

Okay, that's troubling then. There may be another bug that we're bumping into :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
6 participants
You can’t perform that action at this time.