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

Make MemberInfoCache`1<System.__Canon>.AddMethod prejittable #90441

Closed
wants to merge 1 commit into from

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Aug 12, 2023

Contributes to #85791

When we run empty app, the following method shows up in JitDisasmSummary:

   6: JIT compiled System.RuntimeType+RuntimeTypeCache+MemberInfoCache`1[System.__Canon]:AddMethod(System.RuntimeType,long,int) [Instrumented Tier0, IL size=354, code size=1672]

I've debugged why it's not prejitted and, basically, it fails with an exception due to an optimization in jit:
image

So when JIT tries to be smart and optimizes IND(obj) to just an embedded class handle, it fails here.

It happens on RuntimeTypeMethod[] type - I guess the reason is because arrays are not final on R2R?

cc @jkotas @MichalStrehovsky

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Aug 12, 2023
@ghost ghost assigned EgorBo Aug 12, 2023
@ghost
Copy link

ghost commented Aug 12, 2023

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

Issue Details

When we run empty app, the following method shows up in JitDisasmSummary:

   6: JIT compiled System.RuntimeType+RuntimeTypeCache+MemberInfoCache`1[System.__Canon]:AddMethod(System.RuntimeType,long,int) [Instrumented Tier0, IL size=354, code size=1672]

I've debugged why it's not prejitted, basically, it fails with an exception due to an optimization in jit:
image

So when JIT tries to be smart and optimizes IND(obj) to just an embedded class handle, it fails here.

It happens on RuntimeTypeMethod[] type - I guess the reason is because arrays are not final on R2R?

cc @jkotas @MichalStrehovsky

Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

if ((info.compCompHnd->getClassAttribs(handle) & CORINFO_FLG_SHAREDINST) == 0)
uint32_t attrs = info.compCompHnd->getClassAttribs(handle);

// Filter out all shared generic instantiations and non-exact arrays
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the difference between isExact that we have checked above and impIsClassExact that we are repeating here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isExact means that JIT knows the exact type of the tree (e.g. it sees that it's created via new). impIsClassExact is supposed to mean that a class is sealed (or "effectively sealed")

@jkotas
Copy link
Member

jkotas commented Aug 12, 2023

It happens on RuntimeTypeMethod[] type - I guess the reason is because arrays are not final on R2R?

Looks like a crossgen2 bug to me. I do not see any reason why it should be disallowed to embed RuntimeTypeHandle[] handle in R2R code.

@jkotas
Copy link
Member

jkotas commented Aug 12, 2023

cc @dotnet/crossgen-contrib

@mangod9
Copy link
Member

mangod9 commented Aug 12, 2023

hmm, not sure either. @trylek, might have some context. Assume if crossgen would support it this change wouldnt be required, or would we want to take this as well?

@EgorBo
Copy link
Member Author

EgorBo commented Aug 12, 2023

Repro: just run whatever we do for Clr.NativeCoreLib with

--singlemethodtypename System.RuntimeType+RuntimeTypeCache+MemberInfoCache`1[System.__Canon] --singlemethodname AddMethod --verbose

(double `` for powershell)

@EgorBo
Copy link
Member Author

EgorBo commented Aug 12, 2023

Assume if crossgen would support it this change wouldnt be required, or would we want to take this as well?

Yes, it should not be required, all "non-embeddable" handles are expected to be filter out by getClassAttribs(handle) & CORINFO_FLG_SHAREDINST

trylek added a commit to trylek/runtime that referenced this pull request Aug 13, 2023
As Egor Bogatov discovered in

dotnet#90441

Crossgen2 is unable to compile a method taking RuntimeTypeMethod[]
parameter because Crossgen2 decides that the array doesn't version
with the module being compiled (System.Private.CoreLib in this
case). This change modifies the relevant logic so that, for
parameterized types, we decide on versioning based on the
parameter type.

Thanks

Tomas
@EgorBo
Copy link
Member Author

EgorBo commented Aug 13, 2023

Closing in favour of #90501

@EgorBo EgorBo closed this Aug 13, 2023
trylek added a commit that referenced this pull request Aug 14, 2023
As Egor Bogatov discovered in

#90441

Crossgen2 is unable to compile a method taking RuntimeTypeMethod[]
parameter because Crossgen2 decides that the array doesn't version
with the module being compiled (System.Private.CoreLib in this
case). This change modifies the relevant logic so that, for
parameterized types, we decide on versioning based on the
parameter type.

Thanks

Tomas
@ghost ghost locked as resolved and limited conversation to collaborators Sep 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants