-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Improve getStaticFieldContent for classes without cctors #104054
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Yes, it looks like a regression from @davidwrighton's change. Are there other callers of IsClassInited that will hit the same problem? |
1b5e88b
to
b2dff30
Compare
Hard to say, it seems like the problematic case is |
b2dff30
to
3673427
Compare
@jkotas actually, the problem is on the JIT side since the same snippet works when I use It seems that when we expand
|
@@ -2815,6 +2815,10 @@ GenTree* Compiler::impCreateSpanIntrinsic(CORINFO_SIG_INFO* sig) | |||
|
|||
CORINFO_CLASS_HANDLE fieldOwnerHnd = info.compCompHnd->getFieldClass(fieldToken); | |||
|
|||
// We're expanding RuntimeHelpers.CreateSpan<int>((RuntimeFieldHandle)0x...), thus, we need to | |||
// statically initialize the class containing that RuntimeFieldHandle |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not following why we need to do this. The comment should explain why we need to do this.
This comment suggests that the non-expanded version of RuntimeHelpers.CreateSpan performs equivalent operation, but I do not see an equivalent operation in non-expanded version of RuntimeHelpers.CreateSpan. I am not sure whether this is the right fix.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Case 1: ReadOnlySpan<byte>
RVA: sharplab
here JIT triggers class initialization for <PrivateImplementationDetails>
when it imports get_Data()
method and sees ldsflda
for which it calls getFieldInfo
and triggers class init in jit time here
Nothing like that happens for CreateSpan
case - there is no ld[s]fld opcode anywhere, only ldtoken field
This comment suggests that the non-expanded version of RuntimeHelpers.CreateSpan performs equivalent operation,
Then I guess it should do the same somehow?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe David's PR indeed broke this behavior, but it seems that if we put some real cctor to <PrivateImplementationDetails>
- nobody will call it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I guess it should do the same somehow?
RuntimeHelpers.CreateSpan
and RuntimeHelpers.InitializeArray
APIs never triggered static constructors. They are special APIs. Nothing says that they have to trigger static constructor. I do not see a problem with it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then I guess it should do the same somehow?
RuntimeHelpers.CreateSpan
andRuntimeHelpers.InitializeArray
APIs never triggered static constructors. They are special APIs. Nothing says that they have to trigger static constructor. I do not see a problem with it.
Ok, I will leave this problem to @davidwrighton then since I presume we came to conclusion that MethodTable::IsClassInited
should return true for such classes
When a class has no static constructor (cctor), its
pEnclosingMT->IsClassInited()
returns false. It shouldn't stop us from folding RVA fields. Example:Codegen of
Test()
in Main (Tier1 or FullOpts):New codegen of
Test()
:PS: I have an impression that
pEnclosingMT->IsClassInited()
used to return true in such cases 🤔 Or maybe entrypoint holders always used to have cctors? cc @jkotasPerhaps it's some change from DavidWr's statics PR?
The same snippet works well on NAOT.