Skip to content

Commit 810171d

Browse files
committed
Revert "Revert "Allocate RuntimeType objects on Frozen Object Heap (dotnet#76235)"
This reverts commit 91706f1.
1 parent 8fd74f3 commit 810171d

Some content is hidden

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

44 files changed

+748
-366
lines changed

src/coreclr/inc/clrconfigvalues.h

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

407-
///
408-
/// Frozen segments (aka Frozen Object Heap)
409-
///
410-
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.")
411-
412407
///
413408
/// Log
414409
///

src/coreclr/inc/corinfo.h

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

2268+
// Calls ToString() for given pinned/frozen object handle
2269+
virtual int objectToString (
2270+
void* handle, /* IN */
2271+
char* buffer, /* OUT */
2272+
int bufferSize /* IN */
2273+
) = 0;
2274+
22682275
/**********************************************************************************/
22692276
//
22702277
// ICorClassInfo
@@ -2475,6 +2482,10 @@ class ICorStaticInfo
24752482
CORINFO_CLASS_HANDLE cls
24762483
) = 0;
24772484

2485+
virtual void* getRuntimeTypePointer(
2486+
CORINFO_CLASS_HANDLE cls
2487+
) = 0;
2488+
24782489
virtual bool getReadyToRunHelper(
24792490
CORINFO_RESOLVED_TOKEN * pResolvedToken,
24802491
CORINFO_LOOKUP_KIND * pGenericLookupKind,

src/coreclr/inc/icorjitinfoimpl_generated.h

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

178+
int objectToString(
179+
void* handle,
180+
char* buffer,
181+
int bufferSize) override;
182+
178183
CorInfoType asCorInfoType(
179184
CORINFO_CLASS_HANDLE cls) override;
180185

@@ -280,6 +285,9 @@ CorInfoHelpFunc getBoxHelper(
280285
CorInfoHelpFunc getUnBoxHelper(
281286
CORINFO_CLASS_HANDLE cls) override;
282287

288+
void* getRuntimeTypePointer(
289+
CORINFO_CLASS_HANDLE cls) override;
290+
283291
bool getReadyToRunHelper(
284292
CORINFO_RESOLVED_TOKEN* pResolvedToken,
285293
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 = { /* 11b4ea58-c400-4c3d-995e-4e2f0676f6e8 */
47+
0x11b4ea58,
48+
0xc400,
49+
0x4c3d,
50+
{0x99, 0x5e, 0x4e, 0x2f, 0x6, 0x76, 0xf6, 0xe8}
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(objectToString)
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: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,17 @@ int WrapICorJitInfo::getStringLiteral(
374374
return temp;
375375
}
376376

377+
int WrapICorJitInfo::objectToString(
378+
void* handle,
379+
char* buffer,
380+
int bufferSize)
381+
{
382+
API_ENTER(objectToString);
383+
int temp = wrapHnd->objectToString(handle, buffer, bufferSize);
384+
API_LEAVE(objectToString);
385+
return temp;
386+
}
387+
377388
CorInfoType WrapICorJitInfo::asCorInfoType(
378389
CORINFO_CLASS_HANDLE cls)
379390
{
@@ -652,6 +663,15 @@ CorInfoHelpFunc WrapICorJitInfo::getUnBoxHelper(
652663
return temp;
653664
}
654665

666+
void* WrapICorJitInfo::getRuntimeTypePointer(
667+
CORINFO_CLASS_HANDLE cls)
668+
{
669+
API_ENTER(getRuntimeTypePointer);
670+
void* temp = wrapHnd->getRuntimeTypePointer(cls);
671+
API_LEAVE(getRuntimeTypePointer);
672+
return temp;
673+
}
674+
655675
bool WrapICorJitInfo::getReadyToRunHelper(
656676
CORINFO_RESOLVED_TOKEN* pResolvedToken,
657677
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]");

src/coreclr/jit/compiler.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6804,7 +6804,7 @@ class Compiler
68046804
#define OMF_HAS_EXPRUNTIMELOOKUP 0x00000080 // Method contains a runtime lookup to an expandable dictionary.
68056805
#define OMF_HAS_PATCHPOINT 0x00000100 // Method contains patchpoints
68066806
#define OMF_NEEDS_GCPOLLS 0x00000200 // Method needs GC polls
6807-
#define OMF_HAS_FROZEN_STRING 0x00000400 // Method has a frozen string (REF constant int), currently only on NativeAOT.
6807+
#define OMF_HAS_FROZEN_OBJECTS 0x00000400 // Method has frozen objects (REF constant int)
68086808
#define OMF_HAS_PARTIAL_COMPILATION_PATCHPOINT 0x00000800 // Method contains partial compilation patchpoints
68096809
#define OMF_HAS_TAILCALL_SUCCESSOR 0x00001000 // Method has potential tail call in a non BBJ_RETURN block
68106810
#define OMF_HAS_MDNEWARRAY 0x00002000 // Method contains 'new' of an MD array
@@ -6829,14 +6829,14 @@ class Compiler
68296829

68306830
void addFatPointerCandidate(GenTreeCall* call);
68316831

6832-
bool doesMethodHaveFrozenString() const
6832+
bool doesMethodHaveFrozenObjects() const
68336833
{
6834-
return (optMethodFlags & OMF_HAS_FROZEN_STRING) != 0;
6834+
return (optMethodFlags & OMF_HAS_FROZEN_OBJECTS) != 0;
68356835
}
68366836

6837-
void setMethodHasFrozenString()
6837+
void setMethodHasFrozenObjects()
68386838
{
6839-
optMethodFlags |= OMF_HAS_FROZEN_STRING;
6839+
optMethodFlags |= OMF_HAS_FROZEN_OBJECTS;
68406840
}
68416841

68426842
bool doesMethodHaveGuardedDevirtualization() const
@@ -7801,7 +7801,7 @@ class Compiler
78017801
const char* eeGetFieldName(CORINFO_FIELD_HANDLE fieldHnd, const char** classNamePtr = nullptr);
78027802

78037803
#if defined(DEBUG)
7804-
const WCHAR* eeGetCPString(size_t stringHandle);
7804+
void eePrintFrozenObjectDescription(const char* prefix, size_t handle);
78057805
unsigned eeTryGetClassSize(CORINFO_CLASS_HANDLE clsHnd);
78067806
const char16_t* eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd);
78077807
#endif

src/coreclr/jit/ee_il_dll.cpp

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,45 +1615,40 @@ const char16_t* Compiler::eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd)
16151615
return param.classNameWidePtr;
16161616
}
16171617

1618-
const WCHAR* Compiler::eeGetCPString(size_t strHandle)
1618+
void Compiler::eePrintFrozenObjectDescription(const char* prefix, size_t handle)
16191619
{
1620-
#ifdef HOST_UNIX
1621-
return nullptr;
1622-
#else
1623-
char buff[512 + sizeof(CORINFO_String)];
1624-
1625-
// make this bulletproof, so it works even if we are wrong.
1626-
if (ReadProcessMemory(GetCurrentProcess(), (void*)strHandle, buff, 4, nullptr) == 0)
1620+
const int maxStrSize = 64;
1621+
char str[maxStrSize];
1622+
int realLength = this->info.compCompHnd->objectToString((void*)handle, str, maxStrSize);
1623+
if (realLength == -1)
16271624
{
1628-
return (nullptr);
1625+
printf("%s 'unknown frozen object'", prefix);
1626+
return;
16291627
}
1630-
1631-
CORINFO_String* asString = nullptr;
1632-
if (impGetStringClass() == *((CORINFO_CLASS_HANDLE*)strHandle))
1628+
else if (realLength >= maxStrSize)
16331629
{
1634-
// strHandle is a frozen string
1635-
// We assume strHandle is never an "interior" pointer in a frozen string
1636-
// (jit is not expected to perform such foldings)
1637-
asString = (CORINFO_String*)strHandle;
1630+
// string is too long, trim it and null-terminate
1631+
str[maxStrSize - 4] = '.';
1632+
str[maxStrSize - 3] = '.';
1633+
str[maxStrSize - 2] = '.';
1634+
str[maxStrSize - 1] = 0;
16381635
}
16391636
else
16401637
{
1641-
// strHandle is a pinned handle to a string object
1642-
asString = *((CORINFO_String**)strHandle);
1643-
}
1644-
1645-
if (ReadProcessMemory(GetCurrentProcess(), asString, buff, sizeof(buff), nullptr) == 0)
1646-
{
1647-
return (nullptr);
1638+
// objectToString doesn't null-terminate buffer
1639+
str[realLength] = 0;
16481640
}
16491641

1650-
if (asString->stringLen >= 255 || asString->chars[asString->stringLen] != 0)
1642+
for (int i = 0; i < min(maxStrSize, realLength); i++)
16511643
{
1652-
return nullptr;
1644+
// Replace \n and \r symbols with whitespaces
1645+
if (str[i] == '\n' || str[i] == '\r')
1646+
{
1647+
str[i] = ' ';
1648+
}
16531649
}
16541650

1655-
return (WCHAR*)(asString->chars);
1656-
#endif // HOST_UNIX
1651+
printf("%s '%s'\n", prefix, str);
16571652
}
16581653
#else // DEBUG
16591654
void jitprintf(const char* fmt, ...)

0 commit comments

Comments
 (0)