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
3 changes: 3 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2836,6 +2836,9 @@ class ICorStaticInfo
// Returns true iff "fldHnd" represents a static field.
virtual bool isFieldStatic(CORINFO_FIELD_HANDLE fldHnd) = 0;

// Returns true iff pinning of the field's address can be elided because runtime guarantees stability.
virtual bool canOmitPinning(CORINFO_FIELD_HANDLE fldHnd) = 0;

// Returns Length of an Array or of a String object, otherwise -1.
// objHnd must not be null.
virtual int getArrayOrStringLength(CORINFO_OBJECT_HANDLE objHnd) = 0;
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,9 @@ void getThreadLocalStaticInfo_NativeAOT(
bool isFieldStatic(
CORINFO_FIELD_HANDLE fldHnd) override;

bool canOmitPinning(
CORINFO_FIELD_HANDLE fldHnd) override;

int getArrayOrStringLength(
CORINFO_OBJECT_HANDLE objHnd) override;

Expand Down
10 changes: 5 additions & 5 deletions src/coreclr/inc/jiteeversionguid.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@

#include <minipal/guid.h>

constexpr GUID JITEEVersionIdentifier = { /* 3d2bdd20-eced-4a07-b9fb-227ce7f55fcd */
0x3d2bdd20,
0xeced,
0x4a07,
{0xb9, 0xfb, 0x22, 0x7c, 0xe7, 0xf5, 0x5f, 0xcd}
constexpr GUID JITEEVersionIdentifier = { /* 4bf1fd8c-bcc6-43e6-8151-0bb3b231b421 */
0x4bf1fd8c,
0xbcc6,
0x43e6,
{0x81, 0x51, 0x0b, 0xb3, 0xb2, 0x31, 0xb4, 0x21}
};

#endif // JIT_EE_VERSIONING_GUID_H
1 change: 1 addition & 0 deletions src/coreclr/jit/ICorJitInfo_names_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ DEF_CLR_API(getThreadLocalFieldInfo)
DEF_CLR_API(getThreadLocalStaticBlocksInfo)
DEF_CLR_API(getThreadLocalStaticInfo_NativeAOT)
DEF_CLR_API(isFieldStatic)
DEF_CLR_API(canOmitPinning)
DEF_CLR_API(getArrayOrStringLength)
DEF_CLR_API(getBoundaries)
DEF_CLR_API(setBoundaries)
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1005,6 +1005,15 @@ bool WrapICorJitInfo::isFieldStatic(
return temp;
}

bool WrapICorJitInfo::canOmitPinning(
CORINFO_FIELD_HANDLE fldHnd)
{
API_ENTER(canOmitPinning);
bool temp = wrapHnd->canOmitPinning(fldHnd);
API_LEAVE(canOmitPinning);
return temp;
}

int WrapICorJitInfo::getArrayOrStringLength(
CORINFO_OBJECT_HANDLE objHnd)
{
Expand Down
31 changes: 31 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6987,6 +6987,37 @@ GenTree* GenTree::gtGetParent(GenTree*** pUse)
return user;
}

bool GenTree::IsNotGcDef(Compiler* comp) const
{
GenTree* tree = const_cast<GenTree*>(this);

target_ssize_t offset = 0;
FieldSeq* fldSeq = nullptr;
comp->gtPeelOffsets(&tree, &offset, &fldSeq);
if (comp->fgIsBigOffset(offset))
{
return false;
}

if (tree->IsIntegralConst(0) || tree->OperIs(GT_LCL_ADDR) || tree->IsIconHandle(GTF_ICON_OBJ_HDL))
{
return true;
}

if (tree->IsCnsIntOrI())
{
fldSeq = comp->m_fieldSeqStore->Append(fldSeq, tree->AsIntCon()->gtFieldSeq);
}

if ((fldSeq != nullptr) && fldSeq->IsStaticField() &&
comp->info.compCompHnd->canOmitPinning(fldSeq->GetFieldHandle()))
{
return true;
}

return false;
}
Copy link
Member Author

Choose a reason for hiding this comment

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

This function was moved from gentree.h and canOmitPinning is added.
Also I added gtPeelOffsets check


//------------------------------------------------------------------------------
// OperRequiresAsgFlag : Check whether the operation requires GTF_ASG flag regardless
// of the children's flags.
Expand Down
16 changes: 1 addition & 15 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -1105,21 +1105,7 @@ struct GenTree
return true;
}

bool IsNotGcDef() const
{
if (IsIntegralConst(0) || OperIs(GT_LCL_ADDR))
{
return true;
}

// Any NonGC object or NonGC object + any offset.
if (IsIconHandle(GTF_ICON_OBJ_HDL) || (OperIs(GT_ADD) && gtGetOp1()->IsIconHandle(GTF_ICON_OBJ_HDL)))
{
return true;
}

return false;
}
bool IsNotGcDef(Compiler* comp) const;

// LIR flags
// These helper methods, along with the flag values they manipulate, are defined in lir.h
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/lclvars.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3504,7 +3504,7 @@ void Compiler::lvaMarkLclRefs(GenTree* tree, BasicBlock* block, Statement* stmt,
{
GenTree* value = tree->AsLclVar()->Data();

if (varDsc->lvPinned && varDsc->lvAllDefsAreNoGc && !value->IsNotGcDef())
if (varDsc->lvPinned && varDsc->lvAllDefsAreNoGc && !value->IsNotGcDef(this))
{
varDsc->lvAllDefsAreNoGc = false;
}
Expand Down
10 changes: 10 additions & 0 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3188,6 +3188,16 @@ private bool isFieldStatic(CORINFO_FIELD_STRUCT_* fldHnd)
return HandleToObject(fldHnd).IsStatic;
}

private bool canOmitPinning(CORINFO_FIELD_STRUCT_* fldHnd)
{
FieldDesc field = HandleToObject(fldHnd);
if (!field.IsStatic || field.IsThreadStatic || field.OwningType.IsCanonicalSubtype(CanonicalFormKind.Any))
{
return false;
}
return true;
}

private void getBoundaries(CORINFO_METHOD_STRUCT_* ftn, ref uint cILOffsets, ref uint* pILOffsets, BoundaryTypes* implicitBoundaries)
{
// TODO: Debugging
Expand Down
Loading
Loading