Skip to content

MethodTable::IsClassInited returns false for <PrivateImplementationDetails> class #104247

Closed

Description

@EgorBo

See #104054 for discussion.

public class Program
{
    static void Main()
    {
        Test();
    }

    static ReadOnlySpan<int> RvaData => [1, 2, 3, 4];

    [MethodImpl(MethodImplOptions.NoInlining)]
    static int Test() => RvaData[2];
}

This code (TieredCompilation=0) used to fold RvaData[2] into 3, it's no longer happening because getStaticFieldContent gives up on <PrivateImplementationDetails> being non-initialized statically (despite the fact it has no cctor)

Previously, it used to return true and everything was correctly folded, it's no longer the case after #99183

Activity

  1. ghost added
    needs-area-label
    on Jul 1, 2024
  2. added
    untriaged
    on Jul 1, 2024
  3. added and removed
    needs-area-label
    on Jul 1, 2024
  4. dotnet-policy-service commented on Jul 1, 2024

    @dotnet-policy-service
    Contributor

    Tagging subscribers to this area: @mangod9
    See info in area-owners.md if you want to be subscribed.

  5. jkotas commented on Jul 1, 2024

    @jkotas
    Member

    I think the problem is more in the JIT/EE interface.

    Before the change, CORINFO_FLG_FIELD_INITCLASS means initialization is required.

    After the change, CORINFO_FLG_FIELD_INITCLASS means initialization may be required, call initClass to be sure.

    We either need to fix JIT/EE interface to have the old behavior; or we need fix the JIT to account for the new behavior.

    Alternatively, we can get rid of CORINFO_FLG_FIELD_INITCLASS and require JIT to always call initClass to figure out whether the initialization is required.

  6. EgorBo commented on Jul 1, 2024

    @EgorBo
    MemberAuthor

    and require JIT to always call initClass to figure out whether the initialization is required.

    so who (and when) is going to call initClass in case of CreateSpan(ldtoken) ?

  7. jkotas commented on Jul 1, 2024

    @jkotas
    Member

    Why does initClass need to be called for CreateSpan(ldtoken) in the first place? The unexpanded implementation of CreateSpan(ldtoken) does not trigger static constructors, so I do not see why we need to call initClass in the intrinsic expansion of CreateSpan(ldtoken).

  8. EgorBo commented on Jul 1, 2024

    @EgorBo
    MemberAuthor

    Why does initClass need to be called for CreateSpan(ldtoken) in the first place? The unexpanded implementation of CreateSpan(ldtoken) does not trigger static constructors, so I do not see why we need to call initClass in the intrinsic expansion of CreateSpan(ldtoken).

    um.. so it means nobody calls initClass for <PrivateImplementationDetails> (since the only way it's referenced is via CreateSpan(ldtoken)) and then getStaticFieldContent always refuses to fold anything since IsClassInited will return false. I feel like I am missing something 😐 how is JIT-EE fixup going to help here?

  9. jkotas commented on Jul 1, 2024

    @jkotas
    Member

    getStaticFieldContent always refuses to fold anything since IsClassInited will return false.

    getStaticFieldContent may want to call AttemptToPreinit() before calling IsClassInitialized.

  10. davidwrighton commented on Jul 1, 2024

    @davidwrighton
    Member

    I think we would prefer to make a new function... I'm calling it IsClassInitedOrPreinited which will will do the IsClassInited check + the AttemptToPreinit + a final IsClassInited. It looks like there may be several places in the JIT interface which should be calling it and just using the more complete function is a more reliable fix. I'm taking a look at making that change, which seems fairly simple.

  11. added 2 commits that reference this issue on Jul 1, 2024
    c9ca21e
    015b7ed
  12. removed
    untriaged
    on Jul 3, 2024
  13. locked and limited conversation to collaborators on Aug 3, 2024
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

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions