Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorBo committed Oct 5, 2022
1 parent aadadc6 commit ecc25ea
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 58 deletions.
16 changes: 14 additions & 2 deletions src/coreclr/inc/corinfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -2265,8 +2265,20 @@ class ICorStaticInfo
int bufferSize /* IN */
) = 0;

// Calls ToString() for given pinned/frozen object handle
virtual int objectToString (

//------------------------------------------------------------------------------
// appendFrozenObjectTextualRepresentation: Append a (possibly truncated) textual UTF8 representation of the given frozen/pinned
// object to a preallocated buffer. It's intended to use only for debug/diagnostic purposes such as JitDisasm
//
// Arguments:
// handle - Direct handle for a pinned/frozen object
// buffer - Pointer to buffer
// bufferSize - Pointer to buffer length. Must not be nullptr
//
// Return Value:
// bytes written to the buffer, the data is not null-terminated so caller is responsible for that.
//
virtual int appendFrozenObjectTextualRepresentation (
void* handle, /* IN */
char* buffer, /* OUT */
int bufferSize /* IN */
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/inc/icorjitinfoimpl_generated.h
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ int getStringLiteral(
char16_t* buffer,
int bufferSize) override;

int objectToString(
int appendFrozenObjectTextualRepresentation(
void* handle,
char* buffer,
int bufferSize) override;
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/jit/ICorJitInfo_API_names.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ DEF_CLR_API(getTokenTypeAsHandle)
DEF_CLR_API(isValidToken)
DEF_CLR_API(isValidStringRef)
DEF_CLR_API(getStringLiteral)
DEF_CLR_API(objectToString)
DEF_CLR_API(appendFrozenObjectTextualRepresentation)
DEF_CLR_API(asCorInfoType)
DEF_CLR_API(getClassName)
DEF_CLR_API(getClassNameFromMetadata)
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/jit/ICorJitInfo_API_wrapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,14 +374,14 @@ int WrapICorJitInfo::getStringLiteral(
return temp;
}

int WrapICorJitInfo::objectToString(
int WrapICorJitInfo::appendFrozenObjectTextualRepresentation(
void* handle,
char* buffer,
int bufferSize)
{
API_ENTER(objectToString);
int temp = wrapHnd->objectToString(handle, buffer, bufferSize);
API_LEAVE(objectToString);
API_ENTER(appendFrozenObjectTextualRepresentation);
int temp = wrapHnd->appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize);
API_LEAVE(appendFrozenObjectTextualRepresentation);
return temp;
}

Expand Down
12 changes: 6 additions & 6 deletions src/coreclr/jit/ee_il_dll.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1619,13 +1619,13 @@ void Compiler::eePrintFrozenObjectDescription(const char* prefix, size_t handle)
{
const int maxStrSize = 64;
char str[maxStrSize];
int realLength = this->info.compCompHnd->objectToString((void*)handle, str, maxStrSize);
if (realLength == -1)
int bytesWritten = this->info.compCompHnd->appendFrozenObjectTextualRepresentation((void*)handle, str, maxStrSize);
if (bytesWritten == -1)
{
printf("%s 'unknown frozen object'", prefix);
return;
}
else if (realLength >= maxStrSize)
else if (bytesWritten >= maxStrSize)
{
// string is too long, trim it and null-terminate
str[maxStrSize - 4] = '.';
Expand All @@ -1635,11 +1635,11 @@ void Compiler::eePrintFrozenObjectDescription(const char* prefix, size_t handle)
}
else
{
// objectToString doesn't null-terminate buffer
str[realLength] = 0;
// appendFrozenObjectTextualRepresentation doesn't null-terminate buffer
str[bytesWritten] = 0;
}

for (int i = 0; i < min(maxStrSize, realLength); i++)
for (int i = 0; i < min(maxStrSize, bytesWritten); i++)
{
// Replace \n and \r symbols with whitespaces
if (str[i] == '\n' || str[i] == '\r')
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/tools/Common/JitInterface/CorInfoBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -554,12 +554,12 @@ private static int _getStringLiteral(IntPtr thisHandle, IntPtr* ppException, COR
}

[UnmanagedCallersOnly]
private static int _objectToString(IntPtr thisHandle, IntPtr* ppException, void* handle, byte* buffer, int bufferSize)
private static int _appendFrozenObjectTextualRepresentation(IntPtr thisHandle, IntPtr* ppException, void* handle, byte* buffer, int bufferSize)
{
var _this = GetThis(thisHandle);
try
{
return _this.objectToString(handle, buffer, bufferSize);
return _this.appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize);
}
catch (Exception ex)
{
Expand Down Expand Up @@ -2664,7 +2664,7 @@ private static IntPtr GetUnmanagedCallbacks()
callbacks[34] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_MODULE_STRUCT_*, uint, byte>)&_isValidToken;
callbacks[35] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_MODULE_STRUCT_*, uint, byte>)&_isValidStringRef;
callbacks[36] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_MODULE_STRUCT_*, uint, char*, int, int>)&_getStringLiteral;
callbacks[37] = (delegate* unmanaged<IntPtr, IntPtr*, void*, byte*, int, int>)&_objectToString;
callbacks[37] = (delegate* unmanaged<IntPtr, IntPtr*, void*, byte*, int, int>)&_appendFrozenObjectTextualRepresentation;
callbacks[38] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_CLASS_STRUCT_*, CorInfoType>)&_asCorInfoType;
callbacks[39] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_CLASS_STRUCT_*, byte*>)&_getClassName;
callbacks[40] = (delegate* unmanaged<IntPtr, IntPtr*, CORINFO_CLASS_STRUCT_*, byte**, byte*>)&_getClassNameFromMetadata;
Expand Down
6 changes: 2 additions & 4 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1831,16 +1831,14 @@ private int getStringLiteral(CORINFO_MODULE_STRUCT_* module, uint metaTOK, char*
return str.Length;
}

#pragma warning disable CA1822 // Mark members as static
private int objectToString(void* handle, byte* buffer, int bufferSize)
#pragma warning restore CA1822 // Mark members as static
private int appendFrozenObjectTextualRepresentation(void* handle, byte* buffer, int bufferSize)
{
Debug.Assert(bufferSize > 0 && handle != null && buffer != null);

// NOTE: this function is used for pinned/frozen handles
// it doesn't need to null-terminate the string

ReadOnlySpan<char> objStr = HandleToObject(handle).ToString();
ReadOnlySpan<char> objStr = HandleToObject((IntPtr)handle).ToString();
var bufferSpan = new Span<byte>(buffer, bufferSize);
Utf8.FromUtf16(objStr, bufferSpan, out _, out int written);
return written;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ FUNCTIONS
bool isValidToken(CORINFO_MODULE_HANDLE module, unsigned metaTOK)
bool isValidStringRef(CORINFO_MODULE_HANDLE module, unsigned metaTOK)
int getStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, char16_t* buffer, int bufferSize)
int objectToString(void* handle, char* buffer, int bufferSize)
int appendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize)
CorInfoType asCorInfoType(CORINFO_CLASS_HANDLE cls)
const char* getClassName(CORINFO_CLASS_HANDLE cls)
const char* getClassNameFromMetadata(CORINFO_CLASS_HANDLE cls, const char **namespaceName)
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/tools/aot/jitinterface/jitinterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ struct JitInterfaceCallbacks
bool (* isValidToken)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_MODULE_HANDLE module, unsigned metaTOK);
bool (* isValidStringRef)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_MODULE_HANDLE module, unsigned metaTOK);
int (* getStringLiteral)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_MODULE_HANDLE module, unsigned metaTOK, char16_t* buffer, int bufferSize);
int (* objectToString)(void * thisHandle, CorInfoExceptionClass** ppException, void* handle, char* buffer, int bufferSize);
int (* appendFrozenObjectTextualRepresentation)(void * thisHandle, CorInfoExceptionClass** ppException, void* handle, char* buffer, int bufferSize);
CorInfoType (* asCorInfoType)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls);
const char* (* getClassName)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls);
const char* (* getClassNameFromMetadata)(void * thisHandle, CorInfoExceptionClass** ppException, CORINFO_CLASS_HANDLE cls, const char** namespaceName);
Expand Down Expand Up @@ -565,13 +565,13 @@ class JitInterfaceWrapper : public ICorJitInfo
return temp;
}

virtual int objectToString(
virtual int appendFrozenObjectTextualRepresentation(
void* handle,
char* buffer,
int bufferSize)
{
CorInfoExceptionClass* pException = nullptr;
int temp = _callbacks->objectToString(_thisHandle, &pException, handle, buffer, bufferSize);
int temp = _callbacks->appendFrozenObjectTextualRepresentation(_thisHandle, &pException, handle, buffer, bufferSize);
if (pException != nullptr) throw pException;
return temp;
}
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/tools/superpmi/superpmi-shared/lwmlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ LWM(IsIntrinsicType, DWORDLONG, DWORD)
LWM(IsSDArray, DWORDLONG, DWORD)
LWM(IsValidStringRef, DLD, DWORD)
LWM(GetStringLiteral, DLDD, DD)
LWM(ObjectToString, DLD, DD)
LWM(AppendFrozenObjectTextualRepresentation, DLD, DD)
LWM(IsValidToken, DLD, DWORD)
LWM(IsValueClass, DWORDLONG, DWORD)
LWM(MergeClasses, DLDL, DWORDLONG)
Expand Down
30 changes: 15 additions & 15 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4898,10 +4898,10 @@ int MethodContext::repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned me
}
}

void MethodContext::recObjectToString(void* handle, char* buffer, int bufferSize, int length)
void MethodContext::recAppendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize, int length)
{
if (ObjectToString == nullptr)
ObjectToString = new LightWeightMap<DLD, DD>();
if (AppendFrozenObjectTextualRepresentation == nullptr)
AppendFrozenObjectTextualRepresentation = new LightWeightMap<DLD, DD>();

DLD key;
ZeroMemory(&key, sizeof(key)); // Zero key including any struct padding
Expand All @@ -4912,24 +4912,24 @@ void MethodContext::recObjectToString(void* handle, char* buffer, int bufferSize
if (buffer != nullptr && length != -1)
{
int bufferRealSize = min(length, bufferSize);
strBuf = (DWORD)ObjectToString->AddBuffer((unsigned char*)buffer, (unsigned int)bufferRealSize);
strBuf = (DWORD)AppendFrozenObjectTextualRepresentation->AddBuffer((unsigned char*)buffer, (unsigned int)bufferRealSize);
}

DD value;
value.A = (DWORD)length;
value.B = (DWORD)strBuf;

ObjectToString->Add(key, value);
DEBUG_REC(dmpObjectToString(key, value));
AppendFrozenObjectTextualRepresentation->Add(key, value);
DEBUG_REC(dmpAppendFrozenObjectTextualRepresentation(key, value));
}
void MethodContext::dmpObjectToString(DLD key, DD value)
void MethodContext::dmpAppendFrozenObjectTextualRepresentation(DLD key, DD value)
{
printf("ObjectToString key hnd-%016llX bufSize-%u, len-%u", key.A, key.B, value.A);
ObjectToString->Unlock();
printf("AppendFrozenObjectTextualRepresentation key hnd-%016llX bufSize-%u, len-%u", key.A, key.B, value.A);
AppendFrozenObjectTextualRepresentation->Unlock();
}
int MethodContext::repObjectToString(void* handle, char* buffer, int bufferSize)
int MethodContext::repAppendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize)
{
if (ObjectToString == nullptr)
if (AppendFrozenObjectTextualRepresentation == nullptr)
{
return -1;
}
Expand All @@ -4939,19 +4939,19 @@ int MethodContext::repObjectToString(void* handle, char* buffer, int bufferSize)
key.A = CastHandle(handle);
key.B = (DWORD)bufferSize;

int itemIndex = ObjectToString->GetIndex(key);
int itemIndex = AppendFrozenObjectTextualRepresentation->GetIndex(key);
if (itemIndex < 0)
{
return -1;
}
else
{
DD value = ObjectToString->Get(key);
DEBUG_REP(dmpObjectToString(key, value));
DD value = AppendFrozenObjectTextualRepresentation->Get(key);
DEBUG_REP(dmpAppendFrozenObjectTextualRepresentation(key, value));
int srcBufferLength = (int)value.A;
if (buffer != nullptr && srcBufferLength > 0)
{
char* srcBuffer = (char*)ObjectToString->GetBuffer(value.B);
char* srcBuffer = (char*)AppendFrozenObjectTextualRepresentation->GetBuffer(value.B);
Assert(srcBuffer != nullptr);
memcpy(buffer, srcBuffer, min(srcBufferLength, bufferSize));
}
Expand Down
8 changes: 4 additions & 4 deletions src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -622,9 +622,9 @@ class MethodContext
void dmpGetStringLiteral(DLDD key, DD value);
int repGetStringLiteral(CORINFO_MODULE_HANDLE module, unsigned metaTOK, char16_t* buffer, int bufferSize);

void recObjectToString(void* handle, char* buffer, int bufferSize, int length);
void dmpObjectToString(DLD key, DD value);
int repObjectToString(void* handle, char* buffer, int bufferSize);
void recAppendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize, int length);
void dmpAppendFrozenObjectTextualRepresentation(DLD key, DD value);
int repAppendFrozenObjectTextualRepresentation(void* handle, char* buffer, int bufferSize);

void recGetHelperName(CorInfoHelpFunc funcNum, const char* result);
void dmpGetHelperName(DWORD key, DWORD value);
Expand Down Expand Up @@ -1139,7 +1139,7 @@ enum mcPackets
Packet_GetLoongArch64PassStructInRegisterFlags = 194,
Packet_GetExactClasses = 195,
Packet_GetRuntimeTypePointer = 196,
Packet_ObjectToString = 197,
Packet_AppendFrozenObjectTextualRepresentation = 197,
};

void SetDebugDumpVariables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -453,14 +453,14 @@ int interceptor_ICJI::getStringLiteral(CORINFO_MODULE_HANDLE module, /* IN *
return temp;
}

int interceptor_ICJI::objectToString(void* handle, /* IN */
int interceptor_ICJI::appendFrozenObjectTextualRepresentation(void* handle, /* IN */
char* buffer, /* OUT */
int bufferSize /* IN */
)
{
mc->cr->AddCall("objectToString");
int temp = original_ICorJitInfo->objectToString(handle, buffer, bufferSize);
mc->recObjectToString(handle, buffer, bufferSize, temp);
mc->cr->AddCall("appendFrozenObjectTextualRepresentation");
int temp = original_ICorJitInfo->appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize);
mc->recAppendFrozenObjectTextualRepresentation(handle, buffer, bufferSize, temp);
return temp;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -314,13 +314,13 @@ int interceptor_ICJI::getStringLiteral(
return original_ICorJitInfo->getStringLiteral(module, metaTOK, buffer, bufferSize);
}

int interceptor_ICJI::objectToString(
int interceptor_ICJI::appendFrozenObjectTextualRepresentation(
void* handle,
char* buffer,
int bufferSize)
{
mcs->AddCall("objectToString");
return original_ICorJitInfo->objectToString(handle, buffer, bufferSize);
mcs->AddCall("appendFrozenObjectTextualRepresentation");
return original_ICorJitInfo->appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize);
}

CorInfoType interceptor_ICJI::asCorInfoType(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,12 +277,12 @@ int interceptor_ICJI::getStringLiteral(
return original_ICorJitInfo->getStringLiteral(module, metaTOK, buffer, bufferSize);
}

int interceptor_ICJI::objectToString(
int interceptor_ICJI::appendFrozenObjectTextualRepresentation(
void* handle,
char* buffer,
int bufferSize)
{
return original_ICorJitInfo->objectToString(handle, buffer, bufferSize);
return original_ICorJitInfo->appendFrozenObjectTextualRepresentation(handle, buffer, bufferSize);
}

CorInfoType interceptor_ICJI::asCorInfoType(
Expand Down
6 changes: 3 additions & 3 deletions src/coreclr/tools/superpmi/superpmi/icorjitinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,13 @@ int MyICJI::getStringLiteral(CORINFO_MODULE_HANDLE module, /* IN */
return jitInstance->mc->repGetStringLiteral(module, metaTOK, buffer, bufferSize);
}

int MyICJI::objectToString(void* handle, /* IN */
int MyICJI::appendFrozenObjectTextualRepresentation(void* handle, /* IN */
char* buffer, /* OUT */
int bufferSize /* IN */
)
{
jitInstance->mc->cr->AddCall("objectToString");
return jitInstance->mc->repObjectToString(handle, buffer, bufferSize);
jitInstance->mc->cr->AddCall("appendFrozenObjectTextualRepresentation");
return jitInstance->mc->repAppendFrozenObjectTextualRepresentation(handle, buffer, bufferSize);
}

/**********************************************************************************/
Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/jitinterface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -715,7 +715,7 @@ int CEEInfo::getStringLiteral (
return result;
}

int CEEInfo::objectToString (
int CEEInfo::appendFrozenObjectTextualRepresentation (
void* handle,
char* buffer,
int bufferSize)
Expand Down

0 comments on commit ecc25ea

Please sign in to comment.