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

Make JIT<->EE printing methods consistent and support nested classes when printing class names #76505

Merged
merged 53 commits into from
Nov 20, 2022
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
53 commits
Select commit Hold shift + click to select a range
5c25688
Clean up JIT<->EE "get class name" methods
jakobbotsch Oct 2, 2022
a176df0
Further cleanups/fixes
jakobbotsch Oct 2, 2022
3bfb46f
Run jit-format
jakobbotsch Oct 2, 2022
e8fa31d
Revert TypeString removal
jakobbotsch Oct 2, 2022
42501aa
Use getTypeForPrimitiveNumericClass instead
jakobbotsch Oct 2, 2022
70d4370
Nit
jakobbotsch Oct 2, 2022
e7d0aa9
Fix unsupported test
jakobbotsch Oct 2, 2022
fcb4cc3
Address feedback
jakobbotsch Oct 3, 2022
0449899
Remove leftover file
jakobbotsch Oct 3, 2022
04def1f
Fix test failure
jakobbotsch Oct 3, 2022
70866d0
Optimize
jakobbotsch Oct 4, 2022
9b29a16
Remove StringPrinter::Grow
jakobbotsch Oct 4, 2022
9bc6620
Fix contract, fix compiler error on x64
jakobbotsch Oct 4, 2022
ffaf9a4
Fix escaping
jakobbotsch Oct 4, 2022
0f37c4e
Fix GCC build
jakobbotsch Oct 4, 2022
77e799a
Clarify comment
jakobbotsch Oct 4, 2022
0b58859
Avoid unnecessary eeGetMethodName call
jakobbotsch Oct 4, 2022
b987608
Nit
jakobbotsch Oct 4, 2022
17388ed
Remove StringPrinter::Printf in favor of Append
jakobbotsch Oct 4, 2022
08a63d9
Run jit-format
jakobbotsch Oct 4, 2022
c59ec3f
Merge branch 'main' of github.com:dotnet/runtime into print-nested-cl…
jakobbotsch Oct 8, 2022
37f5cfa
Fix build
jakobbotsch Oct 8, 2022
539162c
appendClassName -> printClassName
jakobbotsch Oct 8, 2022
f385851
Merge branch 'main' of github.com:dotnet/runtime into print-nested-cl…
jakobbotsch Nov 13, 2022
f1d6112
Fix build after merge
jakobbotsch Nov 13, 2022
2a76d18
Remove escaping type names complication
jakobbotsch Nov 13, 2022
b8a0573
Nit
jakobbotsch Oct 8, 2022
e753c23
Factor PrintFromUtf16
jakobbotsch Oct 8, 2022
f61fc18
Remove unnecessary function
jakobbotsch Oct 8, 2022
e16357b
Fix missing write
jakobbotsch Oct 8, 2022
62c2622
Work on switching getMethodName and getFieldName to print
jakobbotsch Oct 8, 2022
f5447b3
More work
jakobbotsch Oct 10, 2022
d9643e1
Fix bad merge
jakobbotsch Nov 13, 2022
8a2368e
Fix bad merge
jakobbotsch Nov 13, 2022
d0c4b9f
Update for consistency, builds again
jakobbotsch Nov 13, 2022
fea3eec
Run jit-format
jakobbotsch Nov 13, 2022
8b9d371
SPMI related fixes
jakobbotsch Nov 13, 2022
0ca9cde
Unnecessary diff
jakobbotsch Nov 13, 2022
5e53677
Run jit-format
jakobbotsch Nov 13, 2022
a5b7986
Avoid unnecessary diff 2
jakobbotsch Nov 13, 2022
2f93dcb
Minor clean up for isEnum
jakobbotsch Nov 13, 2022
f8bac91
Avoid another diff
jakobbotsch Nov 13, 2022
2f215cb
Remove a couple more hackishX in favor of <unknown X>
jakobbotsch Nov 13, 2022
79ed341
More consistent buffer size
jakobbotsch Nov 13, 2022
d88c235
GC_NOTRIGGER
jakobbotsch Nov 13, 2022
486a4fc
Remove getHelperName
jakobbotsch Nov 13, 2022
b45f7dd
Few fixes
jakobbotsch Nov 13, 2022
6676673
Merge branch 'main' of github.com:dotnet/runtime into print-nested-cl…
jakobbotsch Nov 14, 2022
a8d8be1
Handle a few more cases in JitTypeNameFormatter
jakobbotsch Nov 14, 2022
2b7e2ae
Update src/coreclr/vm/jitinterface.cpp
jakobbotsch Nov 14, 2022
8c7a16c
Address feedback, remove outdated comment I forgot to remove in previ…
jakobbotsch Nov 16, 2022
65c06f7
Address some more feedback
jakobbotsch Nov 16, 2022
9aa933c
Small fix
jakobbotsch Nov 16, 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
19 changes: 4 additions & 15 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2277,11 +2277,6 @@ class ICorStaticInfo
CORINFO_CLASS_HANDLE cls
) = 0;

// for completeness
virtual const char* getClassName (
CORINFO_CLASS_HANDLE cls
) = 0;

// Return class name as in metadata, or nullptr if there is none.
// Suitable for non-debugging use.
virtual const char* getClassNameFromMetadata (
Expand All @@ -2297,13 +2292,11 @@ class ICorStaticInfo
) = 0;

// Append a (possibly truncated) textual representation of the type `cls` to a preallocated buffer.
// Includes enclosing classes and namespaces.
//
// Arguments:
// ppBuf - Pointer to buffer pointer. See below for details.
// pnBufLen - Pointer to buffer length. Must not be nullptr. See below for details.
// fNamespace - If true, include the namespace/enclosing classes.
// fFullInst - If true (regardless of fNamespace and fAssembly), include namespace and assembly for any type parameters.
// fAssembly - If true, suffix with a comma and the full assembly qualification.
//
// Returns the length of the representation, as a count of characters (but not including a terminating null character).
// Note that this will always be the actual number of characters required by the representation, even if the string
Expand All @@ -2324,13 +2317,9 @@ class ICorStaticInfo
// character that was added to the end of the name.
//
virtual int appendClassName(
_Outptr_opt_result_buffer_(*pnBufLen) char16_t** ppBuf, /* IN OUT */
int* pnBufLen, /* IN OUT */
CORINFO_CLASS_HANDLE cls,
bool fNamespace,
bool fFullInst,
bool fAssembly
) = 0;
_Outptr_opt_result_buffer_(*pnBufLen) char** ppBuf, /* IN OUT */
int* pnBufLen, /* IN OUT */
CORINFO_CLASS_HANDLE cls) = 0;

// Quick check whether the type is a value class. Returns the same value as getClassAttribs(cls) & CORINFO_FLG_VALUECLASS, except faster.
virtual bool isValueClass(CORINFO_CLASS_HANDLE cls) = 0;
Expand Down
10 changes: 2 additions & 8 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,6 @@ int getStringLiteral(
CorInfoType asCorInfoType(
CORINFO_CLASS_HANDLE cls) override;

const char* getClassName(
CORINFO_CLASS_HANDLE cls) override;

const char* getClassNameFromMetadata(
CORINFO_CLASS_HANDLE cls,
const char** namespaceName) override;
Expand All @@ -190,12 +187,9 @@ CORINFO_CLASS_HANDLE getTypeInstantiationArgument(
unsigned index) override;

int appendClassName(
char16_t** ppBuf,
char** ppBuf,
int* pnBufLen,
CORINFO_CLASS_HANDLE cls,
bool fNamespace,
bool fFullInst,
bool fAssembly) override;
CORINFO_CLASS_HANDLE cls) override;

bool isValueClass(
CORINFO_CLASS_HANDLE cls) override;
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 = { /* 1e794e80-ec63-4d7a-b11f-fcda6e7fe4f4 */
0x1e794e80,
0xec63,
0x4d7a,
{0xb1, 0x1f, 0xfc, 0xda, 0x6e, 0x7f, 0xe4, 0xf4}
};

//////////////////////////////////////////////////////////////////////////////////////////////////////////
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ DEF_CLR_API(isValidToken)
DEF_CLR_API(isValidStringRef)
DEF_CLR_API(getStringLiteral)
DEF_CLR_API(asCorInfoType)
DEF_CLR_API(getClassName)
DEF_CLR_API(getClassNameFromMetadata)
DEF_CLR_API(getTypeInstantiationArgument)
DEF_CLR_API(appendClassName)
Expand Down
18 changes: 3 additions & 15 deletions src/coreclr/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -383,15 +383,6 @@ CorInfoType WrapICorJitInfo::asCorInfoType(
return temp;
}

const char* WrapICorJitInfo::getClassName(
CORINFO_CLASS_HANDLE cls)
{
API_ENTER(getClassName);
const char* temp = wrapHnd->getClassName(cls);
API_LEAVE(getClassName);
return temp;
}

const char* WrapICorJitInfo::getClassNameFromMetadata(
CORINFO_CLASS_HANDLE cls,
const char** namespaceName)
Expand All @@ -413,15 +404,12 @@ CORINFO_CLASS_HANDLE WrapICorJitInfo::getTypeInstantiationArgument(
}

int WrapICorJitInfo::appendClassName(
char16_t** ppBuf,
char** ppBuf,
int* pnBufLen,
CORINFO_CLASS_HANDLE cls,
bool fNamespace,
bool fFullInst,
bool fAssembly)
CORINFO_CLASS_HANDLE cls)
{
API_ENTER(appendClassName);
int temp = wrapHnd->appendClassName(ppBuf, pnBufLen, cls, fNamespace, fFullInst, fAssembly);
int temp = wrapHnd->appendClassName(ppBuf, pnBufLen, cls);
API_LEAVE(appendClassName);
return temp;
}
Expand Down
28 changes: 17 additions & 11 deletions src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -7538,19 +7538,12 @@ class Compiler
var_types eeGetFieldType(CORINFO_FIELD_HANDLE fldHnd, CORINFO_CLASS_HANDLE* pStructHnd = nullptr);

void eePrintJitType(class StringPrinter* printer, var_types jitType);
void eePrintType(class StringPrinter* printer,
CORINFO_CLASS_HANDLE clsHnd,
bool includeNamespaces,
bool includeInstantiation);
void eePrintTypeOrJitAlias(class StringPrinter* printer,
CORINFO_CLASS_HANDLE clsHnd,
bool includeNamespaces,
bool includeInstantiation);
void eePrintType(class StringPrinter* printer, CORINFO_CLASS_HANDLE clsHnd, bool includeInstantiation);
void eePrintTypeOrJitAlias(class StringPrinter* printer, CORINFO_CLASS_HANDLE clsHnd, bool includeInstantiation);
void eePrintMethod(class StringPrinter* printer,
CORINFO_CLASS_HANDLE clsHnd,
CORINFO_METHOD_HANDLE methodHnd,
CORINFO_SIG_INFO* sig,
bool includeNamespaces,
bool includeClassInstantiation,
bool includeMethodInstantiation,
bool includeSignature,
Expand Down Expand Up @@ -7802,7 +7795,7 @@ class Compiler
#if defined(DEBUG)
const WCHAR* eeGetCPString(size_t stringHandle);
unsigned eeTryGetClassSize(CORINFO_CLASS_HANDLE clsHnd);
const char16_t* eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd);
const char* eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd);
#endif

const char* eeGetClassName(CORINFO_CLASS_HANDLE clsHnd);
Expand Down Expand Up @@ -8492,13 +8485,18 @@ XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
return CORINFO_TYPE_UNDEF;
}

bool isNumericsNamespace(const char* ns)
{
return strcmp(ns, "System.Numerics") == 0;
}

bool isSIMDClass(CORINFO_CLASS_HANDLE clsHnd)
{
if (isIntrinsicType(clsHnd))
{
const char* namespaceName = nullptr;
(void)getClassNameFromMetadata(clsHnd, &namespaceName);
return strcmp(namespaceName, "System.Numerics") == 0;
return isNumericsNamespace(namespaceName);
}
return false;
}
Expand Down Expand Up @@ -11288,6 +11286,8 @@ class StringPrinter
size_t m_bufferMax;
size_t m_bufferIndex = 0;

void Grow(size_t newSize);

public:
StringPrinter(CompAllocator alloc, char* buffer = nullptr, size_t bufferMax = 0)
: m_alloc(alloc), m_buffer(buffer), m_bufferMax(bufferMax)
Expand Down Expand Up @@ -11318,6 +11318,12 @@ class StringPrinter
m_buffer[m_bufferIndex] = '\0';
}

// Allocate a chunk of 'size' bytes at the current location to be printed.
// Will increment the index by the size specified. Assumes the user will
// copy 'size' characters directly into the buffer returned.
// returned[size] will be null terminated.
char* AllocToPrint(size_t size);

void Printf(const char* format, ...);
};

Expand Down
41 changes: 17 additions & 24 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1417,7 +1417,7 @@ struct FilterSuperPMIExceptionsParam_ee_il
CORINFO_CLASS_HANDLE clazz;
const char** classNamePtr;
const char* fieldOrMethodOrClassNamePtr;
char16_t* classNameWidePtr;
char* className;
unsigned classSize;
EXCEPTION_POINTERS exceptionPointers;
};
Expand Down Expand Up @@ -1515,7 +1515,7 @@ const char* Compiler::eeGetFieldName(CORINFO_FIELD_HANDLE field, const char** cl
const char* Compiler::eeGetClassName(CORINFO_CLASS_HANDLE clsHnd)
{
StringPrinter printer(getAllocator(CMK_DebugOnly));
if (!eeRunFunctorWithSPMIErrorTrap([&]() { eePrintType(&printer, clsHnd, true, true); }))
if (!eeRunFunctorWithSPMIErrorTrap([&]() { eePrintType(&printer, clsHnd, true); }))
{
printer.Truncate(0);
printer.Printf("hackishClassName");
Expand Down Expand Up @@ -1560,7 +1560,7 @@ unsigned Compiler::eeTryGetClassSize(CORINFO_CLASS_HANDLE clsHnd)

//------------------------------------------------------------------------
// eeGetShortClassName: wraps appendClassName to provide functionality
// similar to getClassName(), but returns a class name that is shortened,
// similar to eeGetClassName(), but returns a class name that is shortened,
// not using full assembly info.
//
// Arguments:
Expand All @@ -1569,9 +1569,8 @@ unsigned Compiler::eeTryGetClassSize(CORINFO_CLASS_HANDLE clsHnd)
// Return value:
// string class name. Note: unlike eeGetClassName/getClassName, this string is
// allocated from the JIT heap, so care should possibly be taken to avoid leaking it.
// It returns a char16_t string, since that's what appendClassName returns.
//
const char16_t* Compiler::eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd)
const char* Compiler::eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd)
{
FilterSuperPMIExceptionsParam_ee_il param;

Expand All @@ -1581,38 +1580,32 @@ const char16_t* Compiler::eeGetShortClassName(CORINFO_CLASS_HANDLE clsHnd)

bool success = eeRunWithSPMIErrorTrap<FilterSuperPMIExceptionsParam_ee_il>(
[](FilterSuperPMIExceptionsParam_ee_il* pParam) {
int len = 0;
constexpr bool fNamespace = true;
constexpr bool fFullInst = false;
constexpr bool fAssembly = false;

int len = 0;
// Warning: crossgen2 doesn't fully implement the `appendClassName` API.
jkotas marked this conversation as resolved.
Show resolved Hide resolved
// We need to pass size zero, get back the actual buffer size required, allocate that space,
// and call the API again to get the full string.
int cchStrLen = pParam->pJitInfo->compCompHnd->appendClassName(nullptr, &len, pParam->clazz, fNamespace,
fFullInst, fAssembly);
int cchStrLen = pParam->pJitInfo->compCompHnd->appendClassName(nullptr, &len, pParam->clazz);

size_t cchBufLen = (size_t)cchStrLen + /* null terminator */ 1;
pParam->classNameWidePtr = pParam->pThis->getAllocator(CMK_DebugOnly).allocate<char16_t>(cchBufLen);
char16_t* pbuf = pParam->classNameWidePtr;
len = (int)cchBufLen;
size_t cchBufLen = (size_t)cchStrLen + /* null terminator */ 1;
pParam->className = pParam->pThis->getAllocator(CMK_DebugOnly).allocate<char>(cchBufLen);
char* pbuf = pParam->className;
len = (int)cchBufLen;

int cchResultStrLen = pParam->pJitInfo->compCompHnd->appendClassName(&pbuf, &len, pParam->clazz, fNamespace,
fFullInst, fAssembly);
int cchResultStrLen = pParam->pJitInfo->compCompHnd->appendClassName(&pbuf, &len, pParam->clazz);
noway_assert(cchStrLen == cchResultStrLen);
noway_assert(pParam->classNameWidePtr[cchResultStrLen] == 0);
noway_assert(pParam->className[cchResultStrLen] == 0);
},
&param);

if (!success)
{
const char16_t substituteClassName[] = u"hackishClassName";
size_t cchLen = ArrLen(substituteClassName);
param.classNameWidePtr = getAllocator(CMK_DebugOnly).allocate<char16_t>(cchLen);
memcpy(param.classNameWidePtr, substituteClassName, cchLen * sizeof(char16_t));
const char substituteClassName[] = "hackishClassName";
size_t cchLen = ArrLen(substituteClassName);
param.className = getAllocator(CMK_DebugOnly).allocate<char>(cchLen);
memcpy(param.className, substituteClassName, cchLen * sizeof(char));
}

return param.classNameWidePtr;
return param.className;
}

const WCHAR* Compiler::eeGetCPString(size_t strHandle)
Expand Down
Loading