Skip to content

Using Covariant returns for RuntimeType crashes during crossgen #45356

Closed

Description

@benaadams

This PR #45355 crashes in crossgen

Using WinDebug it crashed on this line

DWORD numVirtuals = pParentClass->GetNumVirtuals();

Due to g_pArrayClass being a null ptr

// this is the base for every array type
MethodTable *pParentClass = g_pArrayClass;

/cc @janvorli

Activity

  1. added
    untriaged
    on Nov 30, 2020
  2. self-assigned this
    on Nov 30, 2020
  3. janvorli commented on Nov 30, 2020

    @janvorli
    Member

    @benaadams it seems that the fix here is simple. With the change below, I was able to successfully build runtime:

    diff --git a/src/coreclr/src/vm/appdomain.cpp b/src/coreclr/src/vm/appdomain.cpp
    index f703b4214ce..87cc347fe10 100644
    --- a/src/coreclr/src/vm/appdomain.cpp
    +++ b/src/coreclr/src/vm/appdomain.cpp
    @@ -1448,13 +1448,13 @@ void SystemDomain::LoadBaseSystemClasses()
         g_pEnumClass = CoreLibBinder::GetClass(CLASS__ENUM);
         _ASSERTE(!g_pEnumClass->IsValueType());
    
    +    // Load Array class
    +    g_pArrayClass = CoreLibBinder::GetClass(CLASS__ARRAY);
    +
         // Load System.RuntimeType
         g_pRuntimeTypeClass = CoreLibBinder::GetClass(CLASS__CLASS);
         _ASSERTE(g_pRuntimeTypeClass->IsFullyLoaded());
    
    -    // Load Array class
    -    g_pArrayClass = CoreLibBinder::GetClass(CLASS__ARRAY);
    -
         // Calling a method on IList<T> for an array requires redirection to a method on
         // the SZArrayHelper class. Retrieving such methods means calling
         // GetActualImplementationForArrayGenericIListMethod, which calls FetchMethod for
  4. janvorli commented on Nov 30, 2020

    @janvorli
    Member

    I am running coreclr tests with your change and this fix to verify everything is fine.

  5. benaadams commented on Nov 30, 2020

    @benaadams
    MemberAuthor

    Is a suggestion some of the types might get linked out #45355 (comment); which would be a different reason if the tests fail :)

  6. janvorli commented on Nov 30, 2020

    @janvorli
    Member

    So unfortunately the fix doesn't work at runtime. Attempt to run anything crashes. I need to figure out why.

  7. benaadams commented on Nov 30, 2020

    @benaadams
    MemberAuthor

    Might be ILLink step removing too many things?

  8. janvorli commented on Nov 30, 2020

    @janvorli
    Member

    It didn't seem so. It looked like a problem with the swapped order of those two class loads, but it was a checked build and so some details were obscured by the compiler optimizations. I am building a debug build now to be able to debug with comfort.

  9. benaadams commented on Nov 30, 2020

    @benaadams
    MemberAuthor

    Jit diff now works with your fix #45356 (comment) 🙂

    Which I was trying to use to evaluate if covariant returns made much difference, and indeed it looks to allow devirtualization:

    image

  10. added and removed
    untriaged
    on Nov 30, 2020
  11. added this to the 5.0.x milestone on Nov 30, 2020
  12. janvorli commented on Nov 30, 2020

    @janvorli
    Member

    @benaadams I have a fix, it required just a bit more involved reordering of stuff in the SystemDomain::LoadBaseSystemClasses. With that, all the pri1 coreclr tests pass with your change.
    I'll create a PR soon.

  13. benaadams commented on Nov 30, 2020

    @benaadams
    MemberAuthor

    Thank you 😁

  14. janvorli commented on Sep 7, 2021

    @janvorli
    Member

    The crossgen is dead now, replaced by crossgen2 completely, closing the issue.

  15. ghost locked as resolved and limited conversation to collaborators on Oct 7, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions