Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2883,10 +2883,17 @@ private CorInfoHelpFunc getUnBoxHelper(CORINFO_CLASS_STRUCT_* cls)

private CorInfoInitClassResult initClass(CORINFO_FIELD_STRUCT_* field, CORINFO_METHOD_STRUCT_* method, CORINFO_CONTEXT_STRUCT* context)
{
FieldDesc fd = field == null ? null : HandleToObject(field);
return initClass(
field == null ? null : HandleToObject(field),
method == null ? null : HandleToObject(method),
context);
}

private CorInfoInitClassResult initClass(FieldDesc fd, MethodDesc method, CORINFO_CONTEXT_STRUCT* context)
{
Debug.Assert(fd == null || fd.IsStatic);

MethodDesc md = method == null ? MethodBeingCompiled : HandleToObject(method);
MethodDesc md = method ?? MethodBeingCompiled;
TypeDesc type = fd != null ? fd.OwningType : typeFromContext(context);

#if !READYTORUN
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2126,6 +2126,8 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET

if (field.IsStatic)
{
CorInfoInitClassResult initResult = initClass(field, null, pResolvedToken.tokenContext);

fieldFlags |= CORINFO_FIELD_FLAGS.CORINFO_FLG_FIELD_STATIC;
Comment thread
MichalStrehovsky marked this conversation as resolved.

if (field.HasRva)
Expand All @@ -2140,7 +2142,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET
pResult->fieldLookup.accessType = node.RepresentsIndirectionCell ? InfoAccessType.IAT_PVALUE : InfoAccessType.IAT_VALUE;

// We are not going through a helper. The constructor has to be triggered explicitly.
if (_compilation.HasLazyStaticConstructor(field.OwningType))
if (initResult != CorInfoInitClassResult.CORINFO_INITCLASS_NOT_REQUIRED)
{
fieldFlags |= CORINFO_FIELD_FLAGS.CORINFO_FLG_FIELD_INITCLASS;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

CORINFO_FLG_FIELD_INITCLASS means "initClass has to be called before accessing the field". We should not need to optimize it by calling initClass proactively before the flag is set. The JIT is going to call initClass when CORINFO_FLG_FIELD_INITCLASS is set.

}
Expand Down Expand Up @@ -2213,7 +2215,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET
if (ti.IsInlined)
{
fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_TLS_MANAGED;
if (_compilation.HasLazyStaticConstructor(field.OwningType))
if (initResult != CorInfoInitClassResult.CORINFO_INITCLASS_NOT_REQUIRED)
{
fieldFlags |= CORINFO_FIELD_FLAGS.CORINFO_FLG_FIELD_INITCLASS;
}
Expand All @@ -2224,7 +2226,7 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET
pResult->helper = CorInfoHelpFunc.CORINFO_HELP_READYTORUN_THREADSTATIC_BASE;
helperId = ReadyToRunHelperId.GetThreadStaticBase;
}
else if (!_compilation.HasLazyStaticConstructor(field.OwningType))
else if (initResult == CorInfoInitClassResult.CORINFO_INITCLASS_NOT_REQUIRED)
{
fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_RELOCATABLE;
ISymbolNode baseAddr;
Expand Down
Loading