Skip to content
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

Allocate boxed static structs on Frozen Object Heap #77737

Merged
merged 41 commits into from
Nov 13, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
17 changes: 16 additions & 1 deletion src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1514,7 +1514,22 @@ void CEEInfo::getFieldInfo (CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_FIELD_ACCESSOR intrinsicAccessor;

if (pField->GetFieldType() == ELEMENT_TYPE_VALUETYPE)
fieldFlags |= CORINFO_FLG_FIELD_STATIC_IN_HEAP;
{
bool frozenBoxedStatic = false;
if (pFieldMT->ContainsPointersOrCollectible())
EgorBo marked this conversation as resolved.
Show resolved Hide resolved
{
Object** handle = (Object**)pField->GetStaticAddressHandle(pField->GetBase());
if (*handle == nullptr && GCHeapUtilities::GetGCHeap()->IsInFrozenSegment(*handle))
{
frozenBoxedStatic = true;
}
}

if (!frozenBoxedStatic)
{
fieldFlags |= CORINFO_FLG_FIELD_STATIC_IN_HEAP;
}
}

EgorBo marked this conversation as resolved.
Show resolved Hide resolved
if (pFieldMT->IsSharedByGenericInstantiations())
{
Expand Down
26 changes: 22 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 @@ -3498,8 +3499,11 @@ void MethodTable::AllocateRegularStaticBoxes()
TypeHandle th = pField->GetFieldTypeHandleThrowing();
MethodTable* pFieldMT = th.GetMethodTable();

bool neverCollected = !pFieldMT->ContainsPointersOrCollectible() &&
!pField->GetApproxEnclosingMethodTable()->Collectible();

EgorBo marked this conversation as resolved.
Show resolved Hide resolved
LOG((LF_CLASSLOADER, LL_INFO10000, "\tInstantiating static of type %s\n", pFieldMT->GetDebugClassName()));
OBJECTREF obj = AllocateStaticBox(pFieldMT, HasFixedAddressVTStatics());
OBJECTREF obj = AllocateStaticBox(pFieldMT, HasFixedAddressVTStatics(), NULL, neverCollected);

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

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

Expand All @@ -3526,7 +3530,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 (neverCollected)
{
// In case if we don't plan to collect this handle we may try to allocate it on FOH
_ASSERT(!pFieldMT->ContainsPointersOrCollectible());
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 neverCollected = false);

void CheckRestore();

Expand Down