Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
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
4 changes: 4 additions & 0 deletions src/coreclr/vm/frozenobjectheap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ Object* FrozenObjectHeapManager::TryAllocateObject(PTR_MethodTable type, size_t
_ASSERT(type != nullptr);
_ASSERT(FOH_COMMIT_SIZE >= MIN_OBJECT_SIZE);

#ifdef FEATURE_64BIT_ALIGNMENT
_ASSERT(!type->RequiresAlign8());
#endif

// NOTE: objectSize is expected be the full size including header
_ASSERT(objectSize >= MIN_OBJECT_SIZE);

Expand Down
60 changes: 57 additions & 3 deletions src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1453,6 +1453,41 @@ static CorInfoHelpFunc getInstanceFieldHelper(FieldDesc * pField, CORINFO_ACCESS
return (CorInfoHelpFunc)helper;
}

static OBJECTREF getFrozenBoxedStatic(FieldDesc* field)
{
CONTRACTL {
THROWS;
GC_TRIGGERS;
MODE_COOPERATIVE;
} CONTRACTL_END;

// These fields never hold frozen boxed statics
if (!field->IsStatic() || !field->IsByValue() || field->IsSpecialStatic())
{
return NULL;
}

TypeHandle typeHandle = field->GetFieldTypeHandleThrowing();
MethodTable* pFieldMT = typeHandle.GetMethodTable();
if (typeHandle.IsCanonicalSubtype() || pFieldMT->IsSharedByGenericInstantiations() || pFieldMT->ContainsPointers())
{
return NULL;
}

PTR_BYTE basePtr = field->GetBase();
if (basePtr == nullptr)
{
return NULL;
}

Object** handle = (Object**)field->GetStaticAddressHandle(basePtr);
if (handle != nullptr && GCHeapUtilities::GetGCHeap()->IsInFrozenSegment(*handle))
{
return ObjectToOBJECTREF(*handle);
}
return NULL;
}

/*********************************************************************/
void CEEInfo::getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_METHOD_HANDLE callerHandle,
Expand Down Expand Up @@ -1514,7 +1549,13 @@ void CEEInfo::getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_FIELD_ACCESSOR intrinsicAccessor;

if (pField->GetFieldType() == ELEMENT_TYPE_VALUETYPE)
fieldFlags |= CORINFO_FLG_FIELD_STATIC_IN_HEAP;
{
GCX_COOP();
if (getFrozenBoxedStatic(pField) == NULL)
{
fieldFlags |= CORINFO_FLG_FIELD_STATIC_IN_HEAP;
}
}

if (pFieldMT->IsSharedByGenericInstantiations())
{
Expand Down Expand Up @@ -11950,10 +11991,23 @@ void* CEEJitInfo::getFieldAddress(CORINFO_FIELD_HANDLE fieldHnd,

GCX_COOP();

base = (void *) field->GetBase();
// Check if the field holds a frozen boxed static, return its content in that case
result = OBJECTREFToObject(getFrozenBoxedStatic(field));
if (result != NULL)
{
// Skip pMT
result = (uint8_t*)result + sizeof(void*);
}
else
{
base = (void*)field->GetBase();
}
}

result = field->GetStaticAddressHandle(base);
if (result == NULL)
{
result = field->GetStaticAddressHandle(base);
}

EE_TO_JIT_TRANSITION();

Expand Down
34 changes: 30 additions & 4 deletions src/coreclr/vm/methodtable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
#include "array.h"
#include "castcache.h"
#include "dynamicinterfacecastable.h"
#include "frozenobjectheap.h"

#ifdef FEATURE_INTERPRETER
#include "interpreter.h"
Expand Down Expand Up @@ -3499,7 +3500,18 @@ void MethodTable::AllocateRegularStaticBoxes()
MethodTable* pFieldMT = th.GetMethodTable();

LOG((LF_CLASSLOADER, LL_INFO10000, "\tInstantiating static of type %s\n", pFieldMT->GetDebugClassName()));
OBJECTREF obj = AllocateStaticBox(pFieldMT, HasFixedAddressVTStatics());

bool canBeFrozen = !pFieldMT->ContainsPointers() && !Collectible();

#ifdef FEATURE_64BIT_ALIGNMENT
if (pFieldMT->RequiresAlign8())
{
// 64bit alignment is not yet supported in FOH for 32bit targets
canBeFrozen = false;
}
#endif

OBJECTREF obj = AllocateStaticBox(pFieldMT, HasFixedAddressVTStatics(), NULL, canBeFrozen);

SetObjectReference( (OBJECTREF*)(pStaticBase + pField->GetOffset()), obj);
}
Expand All @@ -3511,13 +3523,13 @@ void MethodTable::AllocateRegularStaticBoxes()
}

//==========================================================================================
OBJECTREF MethodTable::AllocateStaticBox(MethodTable* pFieldMT, BOOL fPinned, OBJECTHANDLE* pHandle)
OBJECTREF MethodTable::AllocateStaticBox(MethodTable* pFieldMT, BOOL fPinned, OBJECTHANDLE* pHandle, bool canBeFrozen)
{
CONTRACTL
{
THROWS;
GC_TRIGGERS;
MODE_ANY;
MODE_COOPERATIVE;
CONTRACTL_END;
}

Expand All @@ -3526,7 +3538,21 @@ OBJECTREF MethodTable::AllocateStaticBox(MethodTable* pFieldMT, BOOL fPinned, OB
// Activate any dependent modules if necessary
pFieldMT->EnsureInstanceActive();

OBJECTREF obj = AllocateObject(pFieldMT);
OBJECTREF obj = NULL;
if (canBeFrozen)
{
// In case if we don't plan to collect this handle we may try to allocate it on FOH
_ASSERT(!pFieldMT->ContainsPointers());
FrozenObjectHeapManager* foh = SystemDomain::GetFrozenObjectHeapManager();
obj = ObjectToOBJECTREF(foh->TryAllocateObject(pFieldMT, pFieldMT->GetBaseSize()));
// obj can be null in case if struct is huge (>64kb)
if (obj != NULL)
{
return obj;
}
}

obj = AllocateObject(pFieldMT);

// Pin the object if necessary
if (fPinned)
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/methodtable.h
Original file line number Diff line number Diff line change
Expand Up @@ -831,7 +831,7 @@ class MethodTable
// instantiations of the superclass or interfaces e.g. System.Int32 : IComparable<System.Int32>

void AllocateRegularStaticBoxes();
static OBJECTREF AllocateStaticBox(MethodTable* pFieldMT, BOOL fPinned, OBJECTHANDLE* pHandle = 0);
static OBJECTREF AllocateStaticBox(MethodTable* pFieldMT, BOOL fPinned, OBJECTHANDLE* pHandle = 0, bool canBeFrozen = false);

void CheckRestore();

Expand Down