-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Implement getStaticFieldCurrentClass for NAOT #96982
Changes from all commits
9c571e6
1c3a0a9
4b255f5
75ab3e4
efb46d8
fe94fa5
87f2383
d342042
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2395,5 +2395,36 @@ private bool notifyMethodInfoUsage(CORINFO_METHOD_STRUCT_* ftn) | |
{ | ||
return true; | ||
} | ||
|
||
private CORINFO_CLASS_STRUCT_* getStaticFieldCurrentClass(CORINFO_FIELD_STRUCT_* field, byte* pIsSpeculative) | ||
{ | ||
Debug.Assert(pIsSpeculative == null); // To be deleted | ||
|
||
FieldDesc fieldDesc = HandleToObject(field); | ||
|
||
if (fieldDesc.IsStatic && !fieldDesc.IsThreadStatic && fieldDesc.OwningType is MetadataType owningType && | ||
!owningType.IsCanonicalSubtype(CanonicalFormKind.Any)) | ||
{ | ||
// Generally, this API is only used for reference types to provide better information | ||
// to the JIT for possible devirtualizations. Value types are typically handled | ||
// separately and folded to constants via getStaticFieldContent. However, some | ||
// fields aren't foldable (e.g. ExternSymbolMappedField), so let's tell the JIT | ||
// it can rely on them being invariant too. | ||
if (fieldDesc.HasRva) | ||
{ | ||
// Read-only RVA fields need no "is class initialized" check. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. How do you know that the RVA field is read-only? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Can it be not so? I thought RVA can be mutable only for C++/CLI. Here we check that the field is final. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We have several of these compiler generated RVA fields. Some of them are read-only, some of them are mutable.
Where do we check that? |
||
Debug.Assert(fieldDesc.FieldType.IsValueType); | ||
return ObjectToHandle(fieldDesc.FieldType); | ||
} | ||
|
||
PreinitializationManager preinitManager = _compilation.NodeFactory.PreinitializationManager; | ||
if (!fieldDesc.FieldType.IsValueType && preinitManager.IsPreinitialized(owningType) && | ||
preinitManager.GetPreinitializationInfo(owningType).GetFieldValue(fieldDesc) != null) | ||
{ | ||
return ObjectToHandle(fieldDesc.FieldType); | ||
} | ||
} | ||
return null; | ||
} | ||
} | ||
} |
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'm a bit confused about the expected semantics of this API.
Like Jan said - we don't check the initonly part - neither for the RVA nor for non-RVA statics. Should this always return null for
!initonly
?We also return the type of the field, not the type of the value stored in the field (in the reference type case).