Improve getStaticFieldContent for classes without cctors#104054
Improve getStaticFieldContent for classes without cctors#104054EgorBo wants to merge 1 commit intodotnet:mainfrom
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
|
| 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.
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.
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.
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.
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.
Then I guess it should do the same somehow?
RuntimeHelpers.CreateSpanandRuntimeHelpers.InitializeArrayAPIs 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.