Skip to content

Commit

Permalink
Revert "Revert frozen RuntimeType objects and write barriers for froz…
Browse files Browse the repository at this point in the history
…en 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]>
  • Loading branch information
3 people authored Oct 6, 2022
1 parent df26a63 commit 23bdaa3
Show file tree
Hide file tree
Showing 47 changed files with 864 additions and 423 deletions.
5 changes: 5 additions & 0 deletions src/coreclr/inc/CrstTypes.def
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ Crst FCall
End

Crst FrozenObjectHeap
Unordered
End

Crst MethodTableExposedObject
Unordered
End

Crst RetThunkCache
Expand Down
5 changes: 0 additions & 5 deletions src/coreclr/inc/clrconfigvalues.h
Original file line number Diff line number Diff line change
Expand Up @@ -399,11 +399,6 @@ CONFIG_DWORD_INFO(INTERNAL_LoaderHeapCallTracing, W("LoaderHeapCallTracing"), 0,
RETAIL_CONFIG_DWORD_INFO(INTERNAL_CodeHeapReserveForJumpStubs, W("CodeHeapReserveForJumpStubs"), 1, "Percentage of code heap to reserve for jump stubs")
RETAIL_CONFIG_DWORD_INFO(INTERNAL_BreakOnOutOfMemoryWithinRange, W("BreakOnOutOfMemoryWithinRange"), 0, "Break before out of memory within range exception is thrown")

///
/// Frozen segments (aka Frozen Object Heap)
///
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.")

///
/// Log
///
Expand Down
28 changes: 28 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2265,6 +2265,30 @@ class ICorStaticInfo
int bufferSize /* IN */
) = 0;


//------------------------------------------------------------------------------
// printObjectDescription: Prints a (possibly truncated) textual UTF8 representation of the given
// object to a preallocated buffer. It's intended to be used only for debug/diagnostic
// purposes such as JitDisasm. The buffer is null-terminated (even if truncated).
//
// Arguments:
// handle - Direct object handle
// buffer - Pointer to buffer
// bufferSize - Buffer size
// pRequiredBufferSize - Full length of the textual UTF8 representation, can be used to call this
// API again with a bigger buffer to get the full string if the first buffer
// from that first attempt was not big enough.
//
// Return Value:
// Bytes written to the given buffer, the range is [0..bufferSize)
//
virtual size_t printObjectDescription (
void* handle, /* IN */
char* buffer, /* OUT */
size_t bufferSize, /* IN */
size_t* pRequiredBufferSize = nullptr /* OUT */
) = 0;

/**********************************************************************************/
//
// ICorClassInfo
Expand Down Expand Up @@ -2475,6 +2499,10 @@ class ICorStaticInfo
CORINFO_CLASS_HANDLE cls
) = 0;

virtual void* getRuntimeTypePointer(
CORINFO_CLASS_HANDLE cls
) = 0;

virtual bool getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN * pResolvedToken,
CORINFO_LOOKUP_KIND * pGenericLookupKind,
Expand Down
109 changes: 56 additions & 53 deletions src/coreclr/inc/crsttypes_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,58 +81,59 @@ enum CrstType
CrstLoaderHeap = 63,
CrstManagedObjectWrapperMap = 64,
CrstMethodDescBackpatchInfoTracker = 65,
CrstModule = 66,
CrstModuleFixup = 67,
CrstModuleLookupTable = 68,
CrstMulticoreJitHash = 69,
CrstMulticoreJitManager = 70,
CrstNativeImageEagerFixups = 71,
CrstNativeImageLoad = 72,
CrstNls = 73,
CrstNotifyGdb = 74,
CrstObjectList = 75,
CrstPEImage = 76,
CrstPendingTypeLoadEntry = 77,
CrstPgoData = 78,
CrstPinnedByrefValidation = 79,
CrstPinnedHeapHandleTable = 80,
CrstProfilerGCRefDataFreeList = 81,
CrstProfilingAPIStatus = 82,
CrstRCWCache = 83,
CrstRCWCleanupList = 84,
CrstReadyToRunEntryPointToMethodDescMap = 85,
CrstReflection = 86,
CrstReJITGlobalRequest = 87,
CrstRetThunkCache = 88,
CrstSavedExceptionInfo = 89,
CrstSaveModuleProfileData = 90,
CrstSecurityStackwalkCache = 91,
CrstSigConvert = 92,
CrstSingleUseLock = 93,
CrstSpecialStatics = 94,
CrstStackSampler = 95,
CrstStressLog = 96,
CrstStubCache = 97,
CrstStubDispatchCache = 98,
CrstStubUnwindInfoHeapSegments = 99,
CrstSyncBlockCache = 100,
CrstSyncHashLock = 101,
CrstSystemBaseDomain = 102,
CrstSystemDomain = 103,
CrstSystemDomainDelayedUnloadList = 104,
CrstThreadIdDispenser = 105,
CrstThreadStore = 106,
CrstTieredCompilation = 107,
CrstTypeEquivalenceMap = 108,
CrstTypeIDMap = 109,
CrstUMEntryThunkCache = 110,
CrstUMEntryThunkFreeListLock = 111,
CrstUniqueStack = 112,
CrstUnresolvedClassLock = 113,
CrstUnwindInfoTableLock = 114,
CrstVSDIndirectionCellLock = 115,
CrstWrapperTemplate = 116,
kNumberOfCrstTypes = 117
CrstMethodTableExposedObject = 66,
CrstModule = 67,
CrstModuleFixup = 68,
CrstModuleLookupTable = 69,
CrstMulticoreJitHash = 70,
CrstMulticoreJitManager = 71,
CrstNativeImageEagerFixups = 72,
CrstNativeImageLoad = 73,
CrstNls = 74,
CrstNotifyGdb = 75,
CrstObjectList = 76,
CrstPEImage = 77,
CrstPendingTypeLoadEntry = 78,
CrstPgoData = 79,
CrstPinnedByrefValidation = 80,
CrstPinnedHeapHandleTable = 81,
CrstProfilerGCRefDataFreeList = 82,
CrstProfilingAPIStatus = 83,
CrstRCWCache = 84,
CrstRCWCleanupList = 85,
CrstReadyToRunEntryPointToMethodDescMap = 86,
CrstReflection = 87,
CrstReJITGlobalRequest = 88,
CrstRetThunkCache = 89,
CrstSavedExceptionInfo = 90,
CrstSaveModuleProfileData = 91,
CrstSecurityStackwalkCache = 92,
CrstSigConvert = 93,
CrstSingleUseLock = 94,
CrstSpecialStatics = 95,
CrstStackSampler = 96,
CrstStressLog = 97,
CrstStubCache = 98,
CrstStubDispatchCache = 99,
CrstStubUnwindInfoHeapSegments = 100,
CrstSyncBlockCache = 101,
CrstSyncHashLock = 102,
CrstSystemBaseDomain = 103,
CrstSystemDomain = 104,
CrstSystemDomainDelayedUnloadList = 105,
CrstThreadIdDispenser = 106,
CrstThreadStore = 107,
CrstTieredCompilation = 108,
CrstTypeEquivalenceMap = 109,
CrstTypeIDMap = 110,
CrstUMEntryThunkCache = 111,
CrstUMEntryThunkFreeListLock = 112,
CrstUniqueStack = 113,
CrstUnresolvedClassLock = 114,
CrstUnwindInfoTableLock = 115,
CrstVSDIndirectionCellLock = 116,
CrstWrapperTemplate = 117,
kNumberOfCrstTypes = 118
};

#endif // __CRST_TYPES_INCLUDED
Expand Down Expand Up @@ -180,7 +181,7 @@ int g_rgCrstLevelMap[] =
0, // CrstExecuteManRangeLock
0, // CrstExternalObjectContextCache
4, // CrstFCall
0, // CrstFrozenObjectHeap
-1, // CrstFrozenObjectHeap
7, // CrstFuncPtrStubs
10, // CrstFusionAppCtx
10, // CrstGCCover
Expand Down Expand Up @@ -209,6 +210,7 @@ int g_rgCrstLevelMap[] =
3, // CrstLoaderHeap
3, // CrstManagedObjectWrapperMap
10, // CrstMethodDescBackpatchInfoTracker
-1, // CrstMethodTableExposedObject
5, // CrstModule
16, // CrstModuleFixup
4, // CrstModuleLookupTable
Expand Down Expand Up @@ -331,6 +333,7 @@ LPCSTR g_rgCrstNameMap[] =
"CrstLoaderHeap",
"CrstManagedObjectWrapperMap",
"CrstMethodDescBackpatchInfoTracker",
"CrstMethodTableExposedObject",
"CrstModule",
"CrstModuleFixup",
"CrstModuleLookupTable",
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ int getStringLiteral(
char16_t* buffer,
int bufferSize) override;

size_t printObjectDescription(
void* handle,
char* buffer,
size_t bufferSize,
size_t* pRequiredBufferSize) override;

CorInfoType asCorInfoType(
CORINFO_CLASS_HANDLE cls) override;

Expand Down Expand Up @@ -280,6 +286,9 @@ CorInfoHelpFunc getBoxHelper(
CorInfoHelpFunc getUnBoxHelper(
CORINFO_CLASS_HANDLE cls) override;

void* getRuntimeTypePointer(
CORINFO_CLASS_HANDLE cls) override;

bool getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
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 @@ -43,11 +43,11 @@ typedef const GUID *LPCGUID;
#define GUID_DEFINED
#endif // !GUID_DEFINED

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

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ DEF_CLR_API(getTokenTypeAsHandle)
DEF_CLR_API(isValidToken)
DEF_CLR_API(isValidStringRef)
DEF_CLR_API(getStringLiteral)
DEF_CLR_API(printObjectDescription)
DEF_CLR_API(asCorInfoType)
DEF_CLR_API(getClassName)
DEF_CLR_API(getClassNameFromMetadata)
Expand Down Expand Up @@ -70,6 +71,7 @@ DEF_CLR_API(getSharedCCtorHelper)
DEF_CLR_API(getTypeForBox)
DEF_CLR_API(getBoxHelper)
DEF_CLR_API(getUnBoxHelper)
DEF_CLR_API(getRuntimeTypePointer)
DEF_CLR_API(getReadyToRunHelper)
DEF_CLR_API(getReadyToRunDelegateCtorHelper)
DEF_CLR_API(getHelperName)
Expand Down
21 changes: 21 additions & 0 deletions src/coreclr/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,18 @@ int WrapICorJitInfo::getStringLiteral(
return temp;
}

size_t WrapICorJitInfo::printObjectDescription(
void* handle,
char* buffer,
size_t bufferSize,
size_t* pRequiredBufferSize)
{
API_ENTER(printObjectDescription);
size_t temp = wrapHnd->printObjectDescription(handle, buffer, bufferSize, pRequiredBufferSize);
API_LEAVE(printObjectDescription);
return temp;
}

CorInfoType WrapICorJitInfo::asCorInfoType(
CORINFO_CLASS_HANDLE cls)
{
Expand Down Expand Up @@ -652,6 +664,15 @@ CorInfoHelpFunc WrapICorJitInfo::getUnBoxHelper(
return temp;
}

void* WrapICorJitInfo::getRuntimeTypePointer(
CORINFO_CLASS_HANDLE cls)
{
API_ENTER(getRuntimeTypePointer);
void* temp = wrapHnd->getRuntimeTypePointer(cls);
API_LEAVE(getRuntimeTypePointer);
return temp;
}

bool WrapICorJitInfo::getReadyToRunHelper(
CORINFO_RESOLVED_TOKEN* pResolvedToken,
CORINFO_LOOKUP_KIND* pGenericLookupKind,
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/jit/assertionprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2134,7 +2134,7 @@ void Compiler::optDebugCheckAssertion(AssertionDsc* assertion)
break;
case O1K_LCLVAR:
assert((lvaGetDesc(assertion->op1.lcl.lclNum)->lvType != TYP_REF) ||
(assertion->op2.u1.iconVal == 0) || doesMethodHaveFrozenString());
(assertion->op2.u1.iconVal == 0) || doesMethodHaveFrozenObjects());
break;
case O1K_VALUE_NUMBER:
assert((vnStore->TypeOfVN(assertion->op1.vn) != TYP_REF) || (assertion->op2.u1.iconVal == 0));
Expand Down Expand Up @@ -3408,7 +3408,7 @@ GenTree* Compiler::optConstantAssertionProp(AssertionDsc* curAssertion,

// Make sure we don't retype const gc handles to TYP_I_IMPL
// Although, it's possible for e.g. GTF_ICON_STATIC_HDL
if (!newTree->IsIntegralConst(0) && newTree->IsIconHandle(GTF_ICON_STR_HDL))
if (!newTree->IsIntegralConst(0) && newTree->IsIconHandle(GTF_ICON_OBJ_HDL))
{
if (tree->TypeIs(TYP_BYREF))
{
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9415,6 +9415,11 @@ void cTreeFlags(Compiler* comp, GenTree* tree)
chars += printf("[ICON_STR_HDL]");
break;

case GTF_ICON_OBJ_HDL:

chars += printf("[ICON_OBJ_HDL]");
break;

case GTF_ICON_CONST_PTR:

chars += printf("[ICON_CONST_PTR]");
Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -6802,7 +6802,7 @@ class Compiler
#define OMF_HAS_EXPRUNTIMELOOKUP 0x00000080 // Method contains a runtime lookup to an expandable dictionary.
#define OMF_HAS_PATCHPOINT 0x00000100 // Method contains patchpoints
#define OMF_NEEDS_GCPOLLS 0x00000200 // Method needs GC polls
#define OMF_HAS_FROZEN_STRING 0x00000400 // Method has a frozen string (REF constant int), currently only on NativeAOT.
#define OMF_HAS_FROZEN_OBJECTS 0x00000400 // Method has frozen objects (REF constant int)
#define OMF_HAS_PARTIAL_COMPILATION_PATCHPOINT 0x00000800 // Method contains partial compilation patchpoints
#define OMF_HAS_TAILCALL_SUCCESSOR 0x00001000 // Method has potential tail call in a non BBJ_RETURN block
#define OMF_HAS_MDNEWARRAY 0x00002000 // Method contains 'new' of an MD array
Expand All @@ -6827,14 +6827,14 @@ class Compiler

void addFatPointerCandidate(GenTreeCall* call);

bool doesMethodHaveFrozenString() const
bool doesMethodHaveFrozenObjects() const
{
return (optMethodFlags & OMF_HAS_FROZEN_STRING) != 0;
return (optMethodFlags & OMF_HAS_FROZEN_OBJECTS) != 0;
}

void setMethodHasFrozenString()
void setMethodHasFrozenObjects()
{
optMethodFlags |= OMF_HAS_FROZEN_STRING;
optMethodFlags |= OMF_HAS_FROZEN_OBJECTS;
}

bool doesMethodHaveGuardedDevirtualization() const
Expand Down Expand Up @@ -7799,7 +7799,7 @@ class Compiler
const char* eeGetFieldName(CORINFO_FIELD_HANDLE fieldHnd, const char** classNamePtr = nullptr);

#if defined(DEBUG)
const WCHAR* eeGetCPString(size_t stringHandle);
void eePrintObjectDescriptionDescription(const char* prefix, size_t handle);
unsigned eeTryGetClassSize(CORINFO_CLASS_HANDLE clsHnd);
const char16_t* eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd);
#endif
Expand Down
Loading

0 comments on commit 23bdaa3

Please sign in to comment.