Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
6 changes: 6 additions & 0 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2290,6 +2290,12 @@ class ICorStaticInfo
int startIndex = 0 /* IN */
) = 0;

virtual bool tryGetNonRandomizedHashCode (
CORINFO_MODULE_HANDLE module, /* IN */
unsigned metaTOK, /* IN */
bool ignoreCase, /* IN */
int32_t* pHashCode /* OUT */
) = 0;

//------------------------------------------------------------------------------
// printObjectDescription: Prints a (possibly truncated) textual UTF8 representation of the given
Expand Down
6 changes: 6 additions & 0 deletions src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ int getStringLiteral(
int bufferSize,
int startIndex) override;

bool tryGetNonRandomizedHashCode(
CORINFO_MODULE_HANDLE module,
unsigned metaTOK,
bool ignoreCase,
int* pHashCode) override;

size_t printObjectDescription(
CORINFO_OBJECT_HANDLE handle,
char* buffer,
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 @@ -37,11 +37,11 @@

#include <minipal/guid.h>

constexpr GUID JITEEVersionIdentifier = { /* ce8cef5e-261f-469a-b599-9f3f3e8b2448 */
0xce8cef5e,
0x261f,
0x469a,
{0xb5, 0x99, 0x9f, 0x3f, 0x3e, 0x8b, 0x24, 0x48}
constexpr GUID JITEEVersionIdentifier = { /* 656cf7ee-3332-4a85-abac-ef24dc2980a6 */
0x656cf7ee,
0x3332,
0x4a85,
{0xab, 0xac, 0xef, 0x24, 0xdc, 0x29, 0x80, 0xa6}
};

#endif // JIT_EE_VERSIONING_GUID_H
1 change: 1 addition & 0 deletions src/coreclr/jit/ICorJitInfo_names_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ DEF_CLR_API(findSig)
DEF_CLR_API(findCallSiteSig)
DEF_CLR_API(getTokenTypeAsHandle)
DEF_CLR_API(getStringLiteral)
DEF_CLR_API(tryGetNonRandomizedHashCode)
DEF_CLR_API(printObjectDescription)
DEF_CLR_API(asCorInfoType)
DEF_CLR_API(getClassNameFromMetadata)
Expand Down
12 changes: 12 additions & 0 deletions src/coreclr/jit/ICorJitInfo_wrapper_generated.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,18 @@ int WrapICorJitInfo::getStringLiteral(
return temp;
}

bool WrapICorJitInfo::tryGetNonRandomizedHashCode(
CORINFO_MODULE_HANDLE module,
unsigned metaTOK,
bool ignoreCase,
int* pHashCode)
{
API_ENTER(tryGetNonRandomizedHashCode);
bool temp = wrapHnd->tryGetNonRandomizedHashCode(module, metaTOK, ignoreCase, pHashCode);
API_LEAVE(tryGetNonRandomizedHashCode);
return temp;
}

size_t WrapICorJitInfo::printObjectDescription(
CORINFO_OBJECT_HANDLE handle,
char* buffer,
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10622,7 +10622,7 @@ const char* Compiler::convertUtf16ToUtf8ForPrinting(const WCHAR* utf16String)
{
const char* utf8Str = "<utf8 conversion failure>";
int utf8Len = WideCharToMultiByte(CP_UTF8, 0, utf16String, -1, nullptr, 0, nullptr, nullptr);
if (utf8Len == 0)
if (utf8Len > 0)
{
char* allocated = new (this, CMK_DebugOnly) char[utf8Len];

Expand Down
1 change: 1 addition & 0 deletions src/coreclr/jit/fgprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2535,6 +2535,7 @@ PhaseStatus Compiler::fgPrepareToInstrumentMethod()
// These are marked as [Intrinsic] only to be handled (unrolled) for constant inputs.
// In other cases they have large managed implementations we want to profile.
case NI_System_String_Equals:
case NI_System_String_GetNonRandomizedHashCode:
case NI_System_SpanHelpers_Memmove:
case NI_System_MemoryExtensions_Equals:
case NI_System_MemoryExtensions_SequenceEqual:
Expand Down
30 changes: 28 additions & 2 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12233,8 +12233,34 @@ void Compiler::gtDispConst(GenTree* tree)
}

case GT_CNS_STR:
printf("<string constant>");
break;
{
GenTreeStrCon* cnsStr = tree->AsStrCon();
if (cnsStr->IsStringEmptyField())
{
// Special case: do not call getStringLiteral for the empty string field
printf("\"\"");
break;
}

const int MaxLiteralLen = 512;
char16_t str[MaxLiteralLen] = {};
int len = info.compCompHnd->getStringLiteral(cnsStr->gtScpHnd, cnsStr->gtSconCPX, str, sizeof(str));
if (len == 0)
{
printf("\"\"");
}
else if ((len < 0) || (len >= MaxLiteralLen))
{
printf("<unknown string literal>");
}
else
{
// Trim the string to 64 characters for printing
printf("\"%.64s%s\"", convertUtf16ToUtf8ForPrinting(reinterpret_cast<WCHAR*>(str)),
len > 64 ? "..." : "");
}
}
break;

#if defined(FEATURE_SIMD)
case GT_CNS_VEC:
Expand Down
12 changes: 7 additions & 5 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13855,14 +13855,16 @@ unsigned Compiler::impInlineFetchLocal(unsigned lclNum DEBUGARG(const char* reas
//
GenTree* Compiler::impInlineFetchArg(InlArgInfo& argInfo, const InlLclVarInfo& lclInfo)
{
GenTree* argNode = argInfo.arg->GetNode();
assert(!argNode->OperIs(GT_RET_EXPR));

// Cache the relevant arg and lcl info for this argument.
// We will modify argInfo but not lclVarInfo.
const bool argCanBeModified = argInfo.argHasLdargaOp || argInfo.argHasStargOp;
const var_types lclTyp = lclInfo.lclTypeInfo;
GenTree* op1 = nullptr;

GenTree* argNode = argInfo.arg->GetNode();
assert(!argNode->OperIs(GT_RET_EXPR));
// NOTE: Any attempt to modify CNS_STR is an Undefined Behavior, so we can ignore argHasLdargaOp for them
const bool argCanBeModified = ((argInfo.argHasLdargaOp && !argNode->OperIs(GT_CNS_STR)) || argInfo.argHasStargOp);
const var_types lclTyp = lclInfo.lclTypeInfo;
GenTree* op1 = nullptr;

// For TYP_REF args, if the argNode doesn't have any class information
// we will lose some type info if we directly substitute it.
Expand Down
31 changes: 31 additions & 0 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3612,6 +3612,29 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd,
break;
}

case NI_System_String_GetNonRandomizedHashCode:
case NI_System_String_GetNonRandomizedHashCodeOrdinalIgnoreCase:
{
assert(sig->numArgs == 0);
assert(sig->hasThis());
if (opts.OptimizationEnabled() && !compCurBB->isRunRarely() && impStackTop().val->OperIs(GT_CNS_STR))
{
GenTreeStrCon* strCon = impStackTop().val->AsStrCon();
if (!strCon->IsStringEmptyField())
{
bool ignoreCase = (ni == NI_System_String_GetNonRandomizedHashCodeOrdinalIgnoreCase);
int hashCode = 0;
if (info.compCompHnd->tryGetNonRandomizedHashCode(strCon->gtScpHnd, strCon->gtSconCPX,
ignoreCase, &hashCode))
{
impPopStack();
retNode = gtNewIconNode(hashCode, TYP_INT);
}
}
}
break;
}

case NI_System_String_get_Length:
{
GenTree* op1 = impPopStack().val;
Expand Down Expand Up @@ -10278,6 +10301,14 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method)
{
result = NI_System_String_Equals;
}
else if (strcmp(methodName, "GetNonRandomizedHashCode") == 0)
{
result = NI_System_String_GetNonRandomizedHashCode;
}
else if (strcmp(methodName, "GetNonRandomizedHashCodeOrdinalIgnoreCase") == 0)
{
result = NI_System_String_GetNonRandomizedHashCodeOrdinalIgnoreCase;
}
else if (strcmp(methodName, "get_Chars") == 0)
{
result = NI_System_String_get_Chars;
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/namedintrinsiclist.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ enum NamedIntrinsic : unsigned short
NI_System_Runtime_InteropService_MemoryMarshal_GetArrayDataReference,

NI_System_String_Equals,
NI_System_String_GetNonRandomizedHashCode,
NI_System_String_GetNonRandomizedHashCodeOrdinalIgnoreCase,
NI_System_String_get_Chars,
NI_System_String_get_Length,
NI_System_String_op_Implicit,
Expand Down
5 changes: 5 additions & 0 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,11 @@ private int getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, char*
return result;
}

private bool tryGetNonRandomizedHashCode(CORINFO_MODULE_STRUCT_* module, uint metaTOK, bool ignoreCase, ref int pHashCode)
{
return false;
}

private nuint printObjectDescription(CORINFO_OBJECT_STRUCT_* handle, byte* buffer, nuint bufferSize, nuint* pRequiredBufferSize)
{
Debug.Assert(handle != null);
Expand Down
Loading