Skip to content

Commit 23bdaa3

Browse files
EgorBojkotasjakobbotsch
authored
Revert "Revert frozen RuntimeType objects and write barriers for frozen objects" (#76649)
This PR reverts #76235 with a few manual modifications: The main issue why the initial PRs (#75573 and #76135) were reverted has just been resolved via #76251: GC could collect some associated (with frozen objects) objects as unreachable, e.g. it could collect a SyncBlock, WeakReferences and Dependent handles associated with frozen objects which could (e.g. for a short period of time) be indeed unreachable but return back to life after. Co-authored-by: Jan Kotas <[email protected]> Co-authored-by: Jakob Botsch Nielsen <[email protected]>
1 parent df26a63 commit 23bdaa3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+864
-423
lines changed

src/coreclr/inc/CrstTypes.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,11 @@ Crst FCall
214214
End
215215

216216
Crst FrozenObjectHeap
217+
Unordered
218+
End
219+
220+
Crst MethodTableExposedObject
221+
Unordered
217222
End
218223

219224
Crst RetThunkCache

src/coreclr/inc/clrconfigvalues.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,6 @@ CONFIG_DWORD_INFO(INTERNAL_LoaderHeapCallTracing, W("LoaderHeapCallTracing"), 0,
399399
RETAIL_CONFIG_DWORD_INFO(INTERNAL_CodeHeapReserveForJumpStubs, W("CodeHeapReserveForJumpStubs"), 1, "Percentage of code heap to reserve for jump stubs")
400400
RETAIL_CONFIG_DWORD_INFO(INTERNAL_BreakOnOutOfMemoryWithinRange, W("BreakOnOutOfMemoryWithinRange"), 0, "Break before out of memory within range exception is thrown")
401401

402-
///
403-
/// Frozen segments (aka Frozen Object Heap)
404-
///
405-
RETAIL_CONFIG_DWORD_INFO(INTERNAL_UseFrozenObjectHeap, W("UseFrozenObjectHeap"), 1, "Use frozen object heap for certain types of objects (e.g. string literals) as an optimization.")
406-
407402
///
408403
/// Log
409404
///

src/coreclr/inc/corinfo.h

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,6 +2265,30 @@ class ICorStaticInfo
22652265
int bufferSize /* IN */
22662266
) = 0;
22672267

2268+
2269+
//------------------------------------------------------------------------------
2270+
// printObjectDescription: Prints a (possibly truncated) textual UTF8 representation of the given
2271+
// object to a preallocated buffer. It's intended to be used only for debug/diagnostic
2272+
// purposes such as JitDisasm. The buffer is null-terminated (even if truncated).
2273+
//
2274+
// Arguments:
2275+
// handle - Direct object handle
2276+
// buffer - Pointer to buffer
2277+
// bufferSize - Buffer size
2278+
// pRequiredBufferSize - Full length of the textual UTF8 representation, can be used to call this
2279+
// API again with a bigger buffer to get the full string if the first buffer
2280+
// from that first attempt was not big enough.
2281+
//
2282+
// Return Value:
2283+
// Bytes written to the given buffer, the range is [0..bufferSize)
2284+
//
2285+
virtual size_t printObjectDescription (
2286+
void* handle, /* IN */
2287+
char* buffer, /* OUT */
2288+
size_t bufferSize, /* IN */
2289+
size_t* pRequiredBufferSize = nullptr /* OUT */
2290+
) = 0;
2291+
22682292
/**********************************************************************************/
22692293
//
22702294
// ICorClassInfo
@@ -2475,6 +2499,10 @@ class ICorStaticInfo
24752499
CORINFO_CLASS_HANDLE cls
24762500
) = 0;
24772501

2502+
virtual void* getRuntimeTypePointer(
2503+
CORINFO_CLASS_HANDLE cls
2504+
) = 0;
2505+
24782506
virtual bool getReadyToRunHelper(
24792507
CORINFO_RESOLVED_TOKEN * pResolvedToken,
24802508
CORINFO_LOOKUP_KIND * pGenericLookupKind,

src/coreclr/inc/crsttypes_generated.h

Lines changed: 56 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -81,58 +81,59 @@ enum CrstType
8181
CrstLoaderHeap = 63,
8282
CrstManagedObjectWrapperMap = 64,
8383
CrstMethodDescBackpatchInfoTracker = 65,
84-
CrstModule = 66,
85-
CrstModuleFixup = 67,
86-
CrstModuleLookupTable = 68,
87-
CrstMulticoreJitHash = 69,
88-
CrstMulticoreJitManager = 70,
89-
CrstNativeImageEagerFixups = 71,
90-
CrstNativeImageLoad = 72,
91-
CrstNls = 73,
92-
CrstNotifyGdb = 74,
93-
CrstObjectList = 75,
94-
CrstPEImage = 76,
95-
CrstPendingTypeLoadEntry = 77,
96-
CrstPgoData = 78,
97-
CrstPinnedByrefValidation = 79,
98-
CrstPinnedHeapHandleTable = 80,
99-
CrstProfilerGCRefDataFreeList = 81,
100-
CrstProfilingAPIStatus = 82,
101-
CrstRCWCache = 83,
102-
CrstRCWCleanupList = 84,
103-
CrstReadyToRunEntryPointToMethodDescMap = 85,
104-
CrstReflection = 86,
105-
CrstReJITGlobalRequest = 87,
106-
CrstRetThunkCache = 88,
107-
CrstSavedExceptionInfo = 89,
108-
CrstSaveModuleProfileData = 90,
109-
CrstSecurityStackwalkCache = 91,
110-
CrstSigConvert = 92,
111-
CrstSingleUseLock = 93,
112-
CrstSpecialStatics = 94,
113-
CrstStackSampler = 95,
114-
CrstStressLog = 96,
115-
CrstStubCache = 97,
116-
CrstStubDispatchCache = 98,
117-
CrstStubUnwindInfoHeapSegments = 99,
118-
CrstSyncBlockCache = 100,
119-
CrstSyncHashLock = 101,
120-
CrstSystemBaseDomain = 102,
121-
CrstSystemDomain = 103,
122-
CrstSystemDomainDelayedUnloadList = 104,
123-
CrstThreadIdDispenser = 105,
124-
CrstThreadStore = 106,
125-
CrstTieredCompilation = 107,
126-
CrstTypeEquivalenceMap = 108,
127-
CrstTypeIDMap = 109,
128-
CrstUMEntryThunkCache = 110,
129-
CrstUMEntryThunkFreeListLock = 111,
130-
CrstUniqueStack = 112,
131-
CrstUnresolvedClassLock = 113,
132-
CrstUnwindInfoTableLock = 114,
133-
CrstVSDIndirectionCellLock = 115,
134-
CrstWrapperTemplate = 116,
135-
kNumberOfCrstTypes = 117
84+
CrstMethodTableExposedObject = 66,
85+
CrstModule = 67,
86+
CrstModuleFixup = 68,
87+
CrstModuleLookupTable = 69,
88+
CrstMulticoreJitHash = 70,
89+
CrstMulticoreJitManager = 71,
90+
CrstNativeImageEagerFixups = 72,
91+
CrstNativeImageLoad = 73,
92+
CrstNls = 74,
93+
CrstNotifyGdb = 75,
94+
CrstObjectList = 76,
95+
CrstPEImage = 77,
96+
CrstPendingTypeLoadEntry = 78,
97+
CrstPgoData = 79,
98+
CrstPinnedByrefValidation = 80,
99+
CrstPinnedHeapHandleTable = 81,
100+
CrstProfilerGCRefDataFreeList = 82,
101+
CrstProfilingAPIStatus = 83,
102+
CrstRCWCache = 84,
103+
CrstRCWCleanupList = 85,
104+
CrstReadyToRunEntryPointToMethodDescMap = 86,
105+
CrstReflection = 87,
106+
CrstReJITGlobalRequest = 88,
107+
CrstRetThunkCache = 89,
108+
CrstSavedExceptionInfo = 90,
109+
CrstSaveModuleProfileData = 91,
110+
CrstSecurityStackwalkCache = 92,
111+
CrstSigConvert = 93,
112+
CrstSingleUseLock = 94,
113+
CrstSpecialStatics = 95,
114+
CrstStackSampler = 96,
115+
CrstStressLog = 97,
116+
CrstStubCache = 98,
117+
CrstStubDispatchCache = 99,
118+
CrstStubUnwindInfoHeapSegments = 100,
119+
CrstSyncBlockCache = 101,
120+
CrstSyncHashLock = 102,
121+
CrstSystemBaseDomain = 103,
122+
CrstSystemDomain = 104,
123+
CrstSystemDomainDelayedUnloadList = 105,
124+
CrstThreadIdDispenser = 106,
125+
CrstThreadStore = 107,
126+
CrstTieredCompilation = 108,
127+
CrstTypeEquivalenceMap = 109,
128+
CrstTypeIDMap = 110,
129+
CrstUMEntryThunkCache = 111,
130+
CrstUMEntryThunkFreeListLock = 112,
131+
CrstUniqueStack = 113,
132+
CrstUnresolvedClassLock = 114,
133+
CrstUnwindInfoTableLock = 115,
134+
CrstVSDIndirectionCellLock = 116,
135+
CrstWrapperTemplate = 117,
136+
kNumberOfCrstTypes = 118
136137
};
137138

138139
#endif // __CRST_TYPES_INCLUDED
@@ -180,7 +181,7 @@ int g_rgCrstLevelMap[] =
180181
0, // CrstExecuteManRangeLock
181182
0, // CrstExternalObjectContextCache
182183
4, // CrstFCall
183-
0, // CrstFrozenObjectHeap
184+
-1, // CrstFrozenObjectHeap
184185
7, // CrstFuncPtrStubs
185186
10, // CrstFusionAppCtx
186187
10, // CrstGCCover
@@ -209,6 +210,7 @@ int g_rgCrstLevelMap[] =
209210
3, // CrstLoaderHeap
210211
3, // CrstManagedObjectWrapperMap
211212
10, // CrstMethodDescBackpatchInfoTracker
213+
-1, // CrstMethodTableExposedObject
212214
5, // CrstModule
213215
16, // CrstModuleFixup
214216
4, // CrstModuleLookupTable
@@ -331,6 +333,7 @@ LPCSTR g_rgCrstNameMap[] =
331333
"CrstLoaderHeap",
332334
"CrstManagedObjectWrapperMap",
333335
"CrstMethodDescBackpatchInfoTracker",
336+
"CrstMethodTableExposedObject",
334337
"CrstModule",
335338
"CrstModuleFixup",
336339
"CrstModuleLookupTable",

src/coreclr/inc/icorjitinfoimpl_generated.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,12 @@ int getStringLiteral(
175175
char16_t* buffer,
176176
int bufferSize) override;
177177

178+
size_t printObjectDescription(
179+
void* handle,
180+
char* buffer,
181+
size_t bufferSize,
182+
size_t* pRequiredBufferSize) override;
183+
178184
CorInfoType asCorInfoType(
179185
CORINFO_CLASS_HANDLE cls) override;
180186

@@ -280,6 +286,9 @@ CorInfoHelpFunc getBoxHelper(
280286
CorInfoHelpFunc getUnBoxHelper(
281287
CORINFO_CLASS_HANDLE cls) override;
282288

289+
void* getRuntimeTypePointer(
290+
CORINFO_CLASS_HANDLE cls) override;
291+
283292
bool getReadyToRunHelper(
284293
CORINFO_RESOLVED_TOKEN* pResolvedToken,
285294
CORINFO_LOOKUP_KIND* pGenericLookupKind,

src/coreclr/inc/jiteeversionguid.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
4343
#define GUID_DEFINED
4444
#endif // !GUID_DEFINED
4545

46-
constexpr GUID JITEEVersionIdentifier = { /* eb8352bd-0a13-4b5b-badb-58f9ecc40c44 */
47-
0xeb8352bd,
48-
0x0a13,
49-
0x4b5b,
50-
{0xba, 0xdb, 0x58, 0xf9, 0xec, 0xc4, 0x0c, 0x44}
46+
constexpr GUID JITEEVersionIdentifier = { /* 3f5e4630-b29a-4aeb-bab7-07bdff43a156 */
47+
0x3f5e4630,
48+
0xb29a,
49+
0x4aeb,
50+
{0xba, 0xb7, 0x7, 0xbd, 0xff, 0x43, 0xa1, 0x56}
5151
};
5252

5353
//////////////////////////////////////////////////////////////////////////////////////////////////////////

src/coreclr/jit/ICorJitInfo_API_names.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ DEF_CLR_API(getTokenTypeAsHandle)
4141
DEF_CLR_API(isValidToken)
4242
DEF_CLR_API(isValidStringRef)
4343
DEF_CLR_API(getStringLiteral)
44+
DEF_CLR_API(printObjectDescription)
4445
DEF_CLR_API(asCorInfoType)
4546
DEF_CLR_API(getClassName)
4647
DEF_CLR_API(getClassNameFromMetadata)
@@ -70,6 +71,7 @@ DEF_CLR_API(getSharedCCtorHelper)
7071
DEF_CLR_API(getTypeForBox)
7172
DEF_CLR_API(getBoxHelper)
7273
DEF_CLR_API(getUnBoxHelper)
74+
DEF_CLR_API(getRuntimeTypePointer)
7375
DEF_CLR_API(getReadyToRunHelper)
7476
DEF_CLR_API(getReadyToRunDelegateCtorHelper)
7577
DEF_CLR_API(getHelperName)

src/coreclr/jit/ICorJitInfo_API_wrapper.hpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,18 @@ int WrapICorJitInfo::getStringLiteral(
374374
return temp;
375375
}
376376

377+
size_t WrapICorJitInfo::printObjectDescription(
378+
void* handle,
379+
char* buffer,
380+
size_t bufferSize,
381+
size_t* pRequiredBufferSize)
382+
{
383+
API_ENTER(printObjectDescription);
384+
size_t temp = wrapHnd->printObjectDescription(handle, buffer, bufferSize, pRequiredBufferSize);
385+
API_LEAVE(printObjectDescription);
386+
return temp;
387+
}
388+
377389
CorInfoType WrapICorJitInfo::asCorInfoType(
378390
CORINFO_CLASS_HANDLE cls)
379391
{
@@ -652,6 +664,15 @@ CorInfoHelpFunc WrapICorJitInfo::getUnBoxHelper(
652664
return temp;
653665
}
654666

667+
void* WrapICorJitInfo::getRuntimeTypePointer(
668+
CORINFO_CLASS_HANDLE cls)
669+
{
670+
API_ENTER(getRuntimeTypePointer);
671+
void* temp = wrapHnd->getRuntimeTypePointer(cls);
672+
API_LEAVE(getRuntimeTypePointer);
673+
return temp;
674+
}
675+
655676
bool WrapICorJitInfo::getReadyToRunHelper(
656677
CORINFO_RESOLVED_TOKEN* pResolvedToken,
657678
CORINFO_LOOKUP_KIND* pGenericLookupKind,

src/coreclr/jit/assertionprop.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,7 +2134,7 @@ void Compiler::optDebugCheckAssertion(AssertionDsc* assertion)
21342134
break;
21352135
case O1K_LCLVAR:
21362136
assert((lvaGetDesc(assertion->op1.lcl.lclNum)->lvType != TYP_REF) ||
2137-
(assertion->op2.u1.iconVal == 0) || doesMethodHaveFrozenString());
2137+
(assertion->op2.u1.iconVal == 0) || doesMethodHaveFrozenObjects());
21382138
break;
21392139
case O1K_VALUE_NUMBER:
21402140
assert((vnStore->TypeOfVN(assertion->op1.vn) != TYP_REF) || (assertion->op2.u1.iconVal == 0));
@@ -3408,7 +3408,7 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,
34083408

34093409
// Make sure we don't retype const gc handles to TYP_I_IMPL
34103410
// Although, it's possible for e.g. GTF_ICON_STATIC_HDL
3411-
if (!newTree->IsIntegralConst(0) && newTree->IsIconHandle(GTF_ICON_STR_HDL))
3411+
if (!newTree->IsIntegralConst(0) && newTree->IsIconHandle(GTF_ICON_OBJ_HDL))
34123412
{
34133413
if (tree->TypeIs(TYP_BYREF))
34143414
{

src/coreclr/jit/compiler.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9415,6 +9415,11 @@ void cTreeFlags(Compiler* comp, GenTree* tree)
94159415
chars += printf("[ICON_STR_HDL]");
94169416
break;
94179417

9418+
case GTF_ICON_OBJ_HDL:
9419+
9420+
chars += printf("[ICON_OBJ_HDL]");
9421+
break;
9422+
94189423
case GTF_ICON_CONST_PTR:
94199424

94209425
chars += printf("[ICON_CONST_PTR]");

0 commit comments

Comments
 (0)