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

dotnet hang in JIT #55323

Closed
mfilippov opened this issue Jul 8, 2021 · 4 comments · Fixed by #55372
Closed

dotnet hang in JIT #55323

mfilippov opened this issue Jul 8, 2021 · 4 comments · Fixed by #55372
Assignees
Milestone

Comments

@mfilippov
Copy link
Contributor

Description

dotnet.exe hang in JIT in ctor call with stack:

  3.05%   HostTextControl..ctor  •  34,929 ms  •  JetBrains.RdBackend.Common.Features.TextControls.HostTextControl..ctor(IDocument, IShellLocks, IActionManager, ChangeManager, DocumentChangeManager, RiderTextControlActionExecuter, Int32)
    3.05%   coreclr.dll  •  34,929 ms
      3.05%   PreStubWorker  •  34,929 ms  •  coreclr.dll!PreStubWorker
        3.05%   MethodDesc::DoPrestub  •  34,929 ms  •  coreclr.dll!MethodDesc::DoPrestub
          3.05%   CodeVersionManager::PublishVersionableCodeIfNecessary  •  34,929 ms  •  coreclr.dll!CodeVersionManager::PublishVersionableCodeIfNecessary
            3.05%   MethodDesc::JitCompileCode  •  34,929 ms  •  coreclr.dll!MethodDesc::JitCompileCode
              3.05%   MethodDesc::JitCompileCodeLockedEventWrapper  •  34,929 ms  •  coreclr.dll!MethodDesc::JitCompileCodeLockedEventWrapper
                3.05%   MethodDesc::JitCompileCodeLocked  •  34,929 ms  •  coreclr.dll!MethodDesc::JitCompileCodeLocked
                  3.05%   UnsafeJitFunction  •  34,929 ms  •  coreclr.dll!UnsafeJitFunction
                    3.05%   CILJit::compileMethod  •  34,929 ms  •  clrjit.dll!CILJit::compileMethod
                      3.05%   jitNativeCode  •  34,929 ms  •  clrjit.dll!jitNativeCode
                        3.05%   Compiler::compCompile  •  34,929 ms  •  clrjit.dll!Compiler::compCompile
                          3.05%   Compiler::compCompileHelper  •  34,929 ms  •  clrjit.dll!Compiler::compCompileHelper
                            3.05%   Compiler::compCompile  •  34,929 ms  •  clrjit.dll!Compiler::compCompile
                              3.05%   Compiler::fgImport  •  34,929 ms  •  clrjit.dll!Compiler::fgImport
                                3.05%   Compiler::impImport  •  34,929 ms  •  clrjit.dll!Compiler::impImport
                                  3.05%   Compiler::impImportBlock  •  34,929 ms  •  clrjit.dll!Compiler::impImportBlock
                                    3.05%   Compiler::impImportBlockCode  •  34,929 ms  •  clrjit.dll!Compiler::impImportBlockCode
                                      3.05%   CEEInfo::resolveToken  •  34,929 ms  •  coreclr.dll!CEEInfo::resolveToken
                                        3.05%   MemberLoader::GetDescFromMemberRef  •  34,929 ms  •  coreclr.dll!MemberLoader::GetDescFromMemberRef
                                          3.05%   SigPointer::GetTypeHandleThrowing  •  34,929 ms  •  coreclr.dll!SigPointer::GetTypeHandleThrowing
                                            3.05%   ClassLoader::LoadGenericInstantiationThrowing  •  34,929 ms  •  coreclr.dll!ClassLoader::LoadGenericInstantiationThrowing
                                              3.05%   ClassLoader::LoadTypeDefThrowing  •  34,929 ms  •  coreclr.dll!ClassLoader::LoadTypeDefThrowing
                                                3.05%   ClassLoader::LoadTypeHandleForTypeKey  •  34,929 ms  •  coreclr.dll!ClassLoader::LoadTypeHandleForTypeKey
                                                  3.05%   MethodTable::DoFullyLoad  •  34,929 ms  •  coreclr.dll!MethodTable::DoFullyLoad
                                                    3.05%   MethodTable::DoFullyLoad  •  34,929 ms  •  coreclr.dll!MethodTable::DoFullyLoad
                                                      3.05%   TypeHandle::DoFullyLoad  •  34,929 ms  •  coreclr.dll!TypeHandle::DoFullyLoad
                                                        3.05%   MethodTable::DoFullyLoad  •  34,929 ms  •  coreclr.dll!MethodTable::DoFullyLoad
                                                          3.05%   MethodTable::DoFullyLoad  •  34,929 ms  •  coreclr.dll!MethodTable::DoFullyLoad
                                                            3.05%   TypeHandle::DoFullyLoad  •  34,929 ms  •  coreclr.dll!TypeHandle::DoFullyLoad
                                                              3.05%   MethodTable::DoFullyLoad  •  34,929 ms  •  coreclr.dll!MethodTable::DoFullyLoad
                                                                3.05%   ClassLoader::EnsureLoaded  •  34,929 ms  •  coreclr.dll!ClassLoader::EnsureLoaded
                                                                  3.05%   ClassLoader::LoadTypeHandleForTypeKey  •  34,929 ms  •  coreclr.dll!ClassLoader::LoadTypeHandleForTypeKey
                                                                    3.05%   ClassLoader::LoadTypeHandleForTypeKey_Body  •  34,929 ms  •  coreclr.dll!ClassLoader::LoadTypeHandleForTypeKey_Body
                                                                      3.05%   MethodTableBuilder::LoadExactInterfaceMap  •  34,929 ms  •  coreclr.dll!MethodTableBuilder::LoadExactInterfaceMap
                                                                      ► 1.02%   MDInternalRW::EnumInit  •  11,693 ms  •  coreclr.dll!MDInternalRW::EnumInit
                                                                      ► 0.66%   ClassLoader::LoadTypeDefOrRefOrSpecThrowing  •  7,578 ms  •  coreclr.dll!ClassLoader::LoadTypeDefOrRefOrSpecThrowing
                                                                      ► 0.24%   InstantiationIsAllTypeVariables  •  2,710 ms  •  coreclr.dll!InstantiationIsAllTypeVariables
                                                                      ► 0.16%   ClassLoader::LoadTypeDefThrowing  •  1,828 ms  •  coreclr.dll!ClassLoader::LoadTypeDefThrowing
                                                                      ► 0.12%   MDInternalRW::GetTypeSpecFromToken  •  1,381 ms  •  coreclr.dll!MDInternalRW::GetTypeSpecFromToken
                                                                      ► 0.10%   MethodTable::GetInstantiation  •  1,170 ms  •  coreclr.dll!MethodTable::GetInstantiation
                                                                      ► 0.10%   MethodTable::InterfaceMapIterator::GetInterface  •  1,105 ms  •  coreclr.dll!MethodTable::InterfaceMapIterator::GetInterface
                                                                      ► 0.05%   MDInternalRW::GetTypeOfInterfaceImpl  •  629 ms  •  coreclr.dll!MDInternalRW::GetTypeOfInterfaceImpl
                                                                      ► 0.05%   MethodTable::GetCl  •  524 ms  •  coreclr.dll!MethodTable::GetCl
                                                                      ► 0.04%   ntdll.dll  •  430 ms
                                                                      ► 0.04%   MethodTable::GetModule  •  428 ms  •  coreclr.dll!MethodTable::GetModule
                                                                      ► 0.03%   [Unknown]  •  294 ms
                                                                      ► 0.02%   MethodTable::InterfaceMapIterator::GetInterfaceApprox  •  218 ms  •  coreclr.dll!MethodTable::InterfaceMapIterator::GetInterfaceApprox
                                                                      ► 0.02%   Module::IsSystem  •  179 ms  •  coreclr.dll!Module::IsSystem
                                                                      ► 0.01%   MethodTable::ContainsGenericVariables  •  170 ms  •  coreclr.dll!MethodTable::ContainsGenericVariables
                                                                      ► <0.01%   coreclr.dll  •  73 ms
                                                                      ► <0.01%   MethodTable::IsSpecialMarkerTypeForGenericCasting  •  53 ms  •  coreclr.dll!MethodTable::IsSpecialMarkerTypeForGenericCasting
                                                                        <0.01%   [Waiting for CPU]  •  6.2 ms

Configuration

Windows 10 x64
dotnet-runtime-6.0.0-preview.7.21357.14-win-x64

Regression?

yes, preview5 works fine

Other information

I verified issue on main (7b0cdaf) it still there.
I can't create a small repro but I have 100% repro in our tests.

@dotnet-issue-labeler
Copy link

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

@dotnet-issue-labeler dotnet-issue-labeler bot added the untriaged New issue has not been triaged by the area owner label Jul 8, 2021
@jkotas
Copy link
Member

jkotas commented Jul 8, 2021

cc @davidwrighton Related to #54941

@davidwrighton
Copy link
Member

Minimal repro

using System;
using System.Collections.Generic;
using System.Collections;

namespace CuriouslyRecurringPatternThroughInterface
{
    interface IGeneric<T_IGeneric>
    {
    }
    interface ICuriouslyRecurring<T_ICuriouslyRecurring> : IGeneric<CuriouslyRecurringThroughInterface<T_ICuriouslyRecurring>>
    {
    }
    class CuriouslyRecurringThroughInterface<T_CuriouslyRecurringThroughInterface> : ICuriouslyRecurring<T_CuriouslyRecurringThroughInterface>
    {
    }

    class Program
    {
        static object _o;
        static int Main(string[] args)
        {
            // Test that the a generic using a variant of the curiously recurring pattern involving an interface can be loaded.
            _o = typeof(CuriouslyRecurringThroughInterface<int>);
            return 100;
        }
    }
}

This is caused by PR #54588. Fortunately #54941 is unrelated and there are no race conditions to deal with.

@davidwrighton davidwrighton added this to the 6.0.0 milestone Jul 8, 2021
@davidwrighton davidwrighton removed the untriaged New issue has not been triaged by the area owner label Jul 8, 2021
davidwrighton added a commit to davidwrighton/runtime that referenced this issue Jul 8, 2021
- While invalid via the ECMA spec, the runtime currently represents a type explicitly instantiated over its own generic type parameters via the open type MethodTable
- This is not strictly correct, as per the spec, these should be represented via an instantiated type, but changing that detail at this time is considered highly risky
- This conflicts with the perf optimization around partialy interface loading which uses the open type of an interface to represent a type instantiated in the curiously recurring fashion.
- The fix is to detect types instantiated over generic variables, and make them ineligible for the optimization, and to detect those cases where the optimization is ineligible, and revert back to the non-optimized behavior

Fixes dotnet#55323
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jul 8, 2021
@mfilippov
Copy link
Contributor Author

@davidwrighton I verified the fix from PR in our tests. Looks good, no hang anymore.

davidwrighton added a commit that referenced this issue Jul 13, 2021
* Open types can exist as entries in interface map
- While invalid via the ECMA spec, the runtime currently represents a type explicitly instantiated over its own generic type parameters via the open type MethodTable
- This is not strictly correct, as per the spec, these should be represented via an instantiated type, but changing that detail at this time is considered highly risky
- This conflicts with the perf optimization around partialy interface loading which uses the open type of an interface to represent a type instantiated in the curiously recurring fashion.
- The fix is to detect types instantiated over generic variables, and make them ineligible for the optimization, and to detect those cases where the optimization is ineligible, and revert back to the non-optimized behavior

Fixes #55323
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 13, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants