Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
77a42b7
Smarter approach suggested by SingleAccretion
EgorBo Nov 1, 2022
2b2b2ec
Address Jan's feedback, Jakob noticed invalid contract in AllocateSta…
EgorBo Nov 1, 2022
b524f0d
Update src/coreclr/vm/methodtable.cpp
EgorBo Nov 2, 2022
a96a664
Address feedback
EgorBo Nov 2, 2022
7ebf214
Clean up
EgorBo Nov 2, 2022
ec21c92
give up if GetBase() returns nullptr
EgorBo Nov 2, 2022
63e6387
does this help
EgorBo Nov 2, 2022
ca4a77e
disable for foh forced 8byte alignment 32bit targets
EgorBo Nov 2, 2022
16a2438
Update methodtable.cpp
EgorBo Nov 2, 2022
d38e42b
Update src/coreclr/vm/jitinterface.cpp
EgorBo Nov 2, 2022
9868525
Update src/coreclr/vm/jitinterface.cpp
EgorBo Nov 2, 2022
4b7ca2b
Update jitinterface.cpp
EgorBo Nov 2, 2022
8c45daa
try fix
EgorBo Nov 2, 2022
68a130b
Update jitinterface.cpp
EgorBo Nov 2, 2022
20127aa
Merge branch 'main' of github.com:dotnet/runtime into boxed-statics-foh
EgorBo Nov 3, 2022
94ae8f1
Revert to getFieldInfo
EgorBo Nov 4, 2022
1739a55
Use fieldLookup
EgorBo Nov 5, 2022
78448f1
Run tests on CI (WIP), works locally
EgorBo Nov 8, 2022
faa5e51
Delete getFieldAddress
EgorBo Nov 8, 2022
90b3e1b
Fix regression around invariant ref-type statics
EgorBo Nov 8, 2022
6dc5a18
Remove getFieldAddress
EgorBo Nov 8, 2022
8d9f172
Merge branch 'main' of github.com:dotnet/runtime into boxed-statics-foh
EgorBo Nov 8, 2022
bff3b1f
Address feedback
EgorBo Nov 8, 2022
a35f7d1
Merge branch 'main' of github.com:dotnet/runtime into boxed-statics-foh
EgorBo Nov 9, 2022
cfdb18a
Implement JIT/EE level cache for fields' addresses
EgorBo Nov 9, 2022
f6f827d
Implement JIT/EE level cache for fields' addresses
EgorBo Nov 9, 2022
5b3d4fe
Merge branch 'main' of github.com:dotnet/runtime into boxed-statics-foh
EgorBo Nov 9, 2022
3b5c44f
Fix CQ regression around EqualityComparer.Default
EgorBo Nov 9, 2022
c5d6b55
Address Jan's feedback
EgorBo Nov 9, 2022
e25cfa3
Update methodtable.cpp
EgorBo Nov 9, 2022
890ab36
Apply suggestions from code review
EgorBo Nov 9, 2022
c100079
Address feedback
EgorBo Nov 9, 2022
89a99f0
Address SingleAccretion's feedback
EgorBo Nov 9, 2022
29ff0de
Fix FixedAddressValueType test - it didn't expect frozen statics
EgorBo Nov 10, 2022
ff5b6e7
Merge branch 'main' of github.com:dotnet/runtime into boxed-statics-foh
EgorBo Nov 10, 2022
71ff574
Update FixedAddressValueType.cs
EgorBo Nov 10, 2022
d8a7d46
Merge branch 'boxed-statics-foh' of github.com:EgorBo/runtime-1 into …
EgorBo Nov 11, 2022
c6bdcd7
Merge branch 'main' of github.com:dotnet/runtime into boxed-statics-foh
EgorBo Nov 12, 2022
c92a6c3
Resolve conflicts
EgorBo Nov 12, 2022
43c5724
Merge branch 'main' of github.com:dotnet/runtime into boxed-statics-foh
EgorBo Nov 13, 2022
3db4522
Fix "is removable field" check
EgorBo Nov 13, 2022
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
Prev Previous commit
Next Next commit
Run tests on CI (WIP), works locally
  • Loading branch information
EgorBo committed Nov 8, 2022
commit 78448f13023bf00c85a5b68ce9ee94ba554a8bb6
3 changes: 1 addition & 2 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3197,8 +3197,7 @@ GenTree* Compiler::optVNConstantPropOnTree(BasicBlock* block, GenTree* tree)

case TYP_SIMD32:
{
simd32_t value = vnStore->ConstantValue<simd32_t>(vnCns);

simd32_t value = vnStore->ConstantValue<simd32_t>(vnCns);
GenTreeVecCon* vecCon = gtNewVconNode(tree->TypeGet());
vecCon->gtSimd32Val = value;

Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/emitxarch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12828,6 +12828,8 @@ BYTE* emitter::emitOutputCV(BYTE* dst, instrDesc* id, code_t code, CnsVal* addc)
}
else
{
// Should not be ever called here?

addr = (BYTE*)emitComp->info.compCompHnd->getFieldAddress(fldh, nullptr);
if (addr == nullptr)
{
Expand Down
31 changes: 11 additions & 20 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4387,8 +4387,8 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT
FieldSeq::FieldKind fieldKind =
isSharedStatic ? FieldSeq::FieldKind::SharedStatic : FieldSeq::FieldKind::SimpleStatic;

bool hasKnownDirectAddress = !opts.IsReadyToRun() && pFieldInfo->fieldLookup.addr != nullptr &&
pFieldInfo->fieldLookup.accessType == IAT_VALUE;
bool hasConstAddr = (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_ADDRESS) ||
(pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_RVA_ADDRESS);

FieldSeq* innerFldSeq;
FieldSeq* outerFldSeq;
Expand All @@ -4399,21 +4399,11 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT
}
else
{
bool hasConstAddr = (pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_ADDRESS) ||
(pFieldInfo->fieldAccessor == CORINFO_FIELD_STATIC_RVA_ADDRESS);

ssize_t offset;
if (hasConstAddr)
{
if (hasKnownDirectAddress)
{
offset = reinterpret_cast<ssize_t>(pFieldInfo->fieldLookup.addr);
}
else
{
offset = reinterpret_cast<ssize_t>(info.compCompHnd->getFieldAddress(pResolvedToken->hField));
}
assert(offset != 0);
assert(pFieldInfo->fieldLookup.accessType == IAT_VALUE);
offset = reinterpret_cast<ssize_t>(pFieldInfo->fieldLookup.addr);
}
else
{
Expand Down Expand Up @@ -4518,12 +4508,11 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT
{
// Do we need the address of a static field?
//
if (!hasKnownDirectAddress && (access & CORINFO_ACCESS_ADDRESS))
if (access & CORINFO_ACCESS_ADDRESS)
{
void** pFldAddr = nullptr;
void* fldAddr = info.compCompHnd->getFieldAddress(pResolvedToken->hField, (void**)&pFldAddr);
assert(pFieldInfo->fieldLookup.accessType == IAT_VALUE);
void* fldAddr = pFieldInfo->fieldLookup.addr;
// We should always be able to access this static's address directly.
assert(pFldAddr == nullptr);

// Create the address node.
GenTreeFlags handleKind = isBoxedStatic ? GTF_ICON_STATIC_BOX_PTR : GTF_ICON_STATIC_HDL;
Expand All @@ -4535,8 +4524,11 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT
op1->gtFlags |= GTF_ICON_INITCLASS;
}
}
else if (hasKnownDirectAddress)
else if (hasConstAddr && !isBoxedStatic)
{
assert(pFieldInfo->fieldLookup.addr != nullptr);
assert(!isSharedStatic);
assert(pFieldInfo->fieldLookup.accessType == IAT_VALUE);
assert(!isBoxedStatic);
op1 = gtNewIconHandleNode((size_t)pFieldInfo->fieldLookup.addr, GTF_ICON_STATIC_HDL, innerFldSeq);
INDEBUG(op1->AsIntCon()->gtTargetHandle = reinterpret_cast<size_t>(pResolvedToken->hField));
Expand Down Expand Up @@ -4577,7 +4569,6 @@ GenTree* Compiler::impImportStaticFieldAccess(CORINFO_RESOLVED_TOKEN* pResolvedT

if (isBoxedStatic)
{
assert(!hasKnownDirectAddress);
op1 = gtNewOperNode(GT_IND, TYP_REF, op1);
op1->gtFlags |= (GTF_IND_INVARIANT | GTF_IND_NONFAULTING | GTF_IND_NONNULL);

Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5297,6 +5297,8 @@ GenTree* Compiler::fgMorphField(GenTree* tree, MorphAddrContext* mac)
}
else
{
// TODO: delete the boxed-static part (move to importer)

// Normal static field reference
//
// If we can we access the static's address directly
Expand All @@ -5315,6 +5317,7 @@ GenTree* Compiler::fgMorphField(GenTree* tree, MorphAddrContext* mac)
bool isBoxedStatic = gtIsStaticFieldPtrToBoxedStruct(tree->TypeGet(), symHnd);
if (!isBoxedStatic)
{
assert(!"unreachable!");
// Only simple statics get importred as GT_FIELDs.
fieldSeq = GetFieldSeqStore()->Create(symHnd, reinterpret_cast<size_t>(fldAddr),
FieldSeq::FieldKind::SimpleStatic);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1499,6 +1499,10 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET
// TODO: Handle the case when the RVA is in the TLS range
fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_RVA_ADDRESS;

ISymbolNode node = _compilation.GetFieldRvaData(field);
pResult->fieldLookup.addr = (void*)ObjectToHandle(node);
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 (!IsClassPreInited(field.OwningType))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2061,6 +2061,10 @@ private void getFieldInfo(ref CORINFO_RESOLVED_TOKEN pResolvedToken, CORINFO_MET
// TODO: Handle the case when the RVA is in the TLS range
fieldAccessor = CORINFO_FIELD_ACCESSOR.CORINFO_FIELD_STATIC_RVA_ADDRESS;

ISymbolNode node = _compilation.GetFieldRvaData(field);
pResult->fieldLookup.addr = (void*)ObjectToHandle(node);
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))
{
Expand Down
46 changes: 29 additions & 17 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1535,16 +1535,17 @@ void CEEInfo::getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken,
// Provide helper to use if the JIT is not able to emit the TLS access
// as intrinsic
pResult->helper = CORINFO_HELP_GETSTATICFIELDADDR_TLS;

pResult->offset = module->GetFieldTlsOffset(pResult->offset);
}
else
{
fieldAccessor = CORINFO_FIELD_STATIC_RVA_ADDRESS;
pResult->fieldLookup.addr = pField->GetStaticAddressHandle(NULL);
pResult->fieldLookup.accessType = IAT_VALUE;
}

// We are not going through a helper. The constructor has to be triggered explicitly.
if (!pFieldMT->IsClassPreInited())
if (!pFieldMT->IsClassInited())
fieldFlags |= CORINFO_FLG_FIELD_INITCLASS;
}
else
Expand All @@ -1553,20 +1554,7 @@ void CEEInfo::getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_FIELD_ACCESSOR intrinsicAccessor;

if (pField->GetFieldType() == ELEMENT_TYPE_VALUETYPE)
{
GCX_COOP();
Object* frozenBoxedStatic = OBJECTREFToObject(getFrozenBoxedStatic(pField));
if (frozenBoxedStatic != nullptr)
{
// Skip pMT of the frozen object holding struct
pResult->fieldLookup.addr = (uint8_t*)frozenBoxedStatic + sizeof(void*);
pResult->fieldLookup.accessType = InfoAccessType::IAT_VALUE;
}
else
{
fieldFlags |= CORINFO_FLG_FIELD_STATIC_IN_HEAP;
}
}
fieldFlags |= CORINFO_FLG_FIELD_STATIC_IN_HEAP;

if (pFieldMT->IsSharedByGenericInstantiations())
{
Expand Down Expand Up @@ -1597,9 +1585,33 @@ void CEEInfo::getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken,
{
fieldAccessor = CORINFO_FIELD_STATIC_ADDRESS;

// Allocate space for the local class if necessary, but don't trigger
// class construction.
DomainLocalModule* pLocalModule = pFieldMT->GetDomainLocalModule();
pLocalModule->PopulateClass(pFieldMT);

// We are not going through a helper. The constructor has to be triggered explicitly.
if (!pFieldMT->IsClassPreInited())
if (!pFieldMT->IsClassInited())
fieldFlags |= CORINFO_FLG_FIELD_INITCLASS;

GCX_COOP();

pResult->fieldLookup.addr = pField->GetStaticAddressHandle((void*)pField->GetBase());
pResult->fieldLookup.accessType = IAT_VALUE;

if ((fieldFlags & (CORINFO_FLG_FIELD_STATIC_IN_HEAP | CORINFO_FLG_FIELD_INITCLASS)) == CORINFO_FLG_FIELD_STATIC_IN_HEAP)
{
Object* frozenObj = *(Object**)pResult->fieldLookup.addr;

// ContainsPointers here is unnecessary but it's cheaper than IsInFrozenSegment
// for structs containing gc handles
if (frozenObj != nullptr && !frozenObj->GetMethodTable()->ContainsPointers() &&
GCHeapUtilities::GetGCHeap()->IsInFrozenSegment(frozenObj))
{
pResult->fieldLookup.addr = frozenObj->GetData();
fieldFlags &= ~CORINFO_FLG_FIELD_STATIC_IN_HEAP;
}
}
}
}

Expand Down