Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Do not save overall record length for methods
This change reduces mcj profile size
  • Loading branch information
gbalykov committed May 5, 2021
commit cd2820fa9d3a4763d21ce0e47debe358b8c22f70
10 changes: 2 additions & 8 deletions src/coreclr/vm/multicorejit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -435,13 +435,7 @@ HRESULT MulticoreJitRecorder::WriteOutput(IStream * pStream)
}

memcpy(pSignature, pBlob, dwLength);

if (!m_JitInfoArray[i].PackSignatureForMethod(pSignature, dwLength))
{
_ASSERTE(m_JitInfoArray[i].GetRawMethodData2() == 0);
_ASSERTE(m_JitInfoArray[i].GetRawMethodSignature() == nullptr);
delete[] pSignature;
}
m_JitInfoArray[i].PackSignatureForMethod(pSignature, dwLength);
}

{
Expand Down Expand Up @@ -502,7 +496,7 @@ HRESULT MulticoreJitRecorder::WriteOutput(IStream * pStream)
{
// Method record
DWORD data1 = m_JitInfoArray[i].GetRawMethodData1();
DWORD data2 = m_JitInfoArray[i].GetRawMethodData2();
unsigned short data2 = m_JitInfoArray[i].GetRawMethodData2();
BYTE * pSignature = m_JitInfoArray[i].GetRawMethodSignature();

if (pSignature == nullptr)
Expand Down
33 changes: 12 additions & 21 deletions src/coreclr/vm/multicorejitimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ const unsigned MAX_MODULE_LEVELS = 0x100; // maximum allowed number of

const unsigned MAX_METHODS = 0x4000; // Maximum allowed number of methods (2^14 values) (in principle this is also limited by "unsigned short" counters)

const unsigned SIGNATURE_LENGTH_OFFSET = 16; // offset of signature length
const unsigned SIGNATURE_LENGTH_MASK = 0xffff; // mask to get signature from packed data (2^16-1 max signature length)

const int HEADER_W_COUNTER = 14; // Extra 16-bit counters in header for statistics: 28
Expand Down Expand Up @@ -76,7 +75,7 @@ inline unsigned Pack8_24(unsigned up, unsigned low)
// <HeaderRecord>::= <recordType=MULTICOREJIT_HEADER_RECORD_ID> <3byte_recordSize> <version> <timeStamp> <moduleCount> <methodCount> <DependencyCount> <unsigned short counter>*14 <unsigned counter>*3
// <ModuleRecord>::= <recordType=MULTICOREJIT_MODULE_RECORD_ID> <3byte_recordSize> <ModuleVersion> <JitMethodCount> <loadLevel> <lenModuleName> char*lenModuleName <padding>
// <ModuleDependency>::= <recordType=MULTICOREJIT_MODULEDEPENDENCY_RECORD_ID> <loadLevel_1byte> <moduleIndex_2bytes>
// <Method> ::= <recordType=MULTICOREJIT_METHOD_RECORD_ID> <methodFlags_1byte> <moduleIndex_2byte> <recordSize_2byte> <sigSize_2byte> <signature> <optional padding>
// <Method> ::= <recordType=MULTICOREJIT_METHOD_RECORD_ID> <methodFlags_1byte> <moduleIndex_2byte> <sigSize_2byte> <signature> <optional padding>
//
//
// Actual profile has two representations: internal and the one, that is stored in file.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment was very useful, thanks for including it : )

Expand Down Expand Up @@ -115,7 +114,7 @@ inline unsigned Pack8_24(unsigned up, unsigned low)
// 2. Methods.
// For methods, binary signature is computed and RecorderInfo contents are changed.
// a) RecorderInfo::data1 doesn't change.
// b) RecorderInfo::data2 stores binary sizes, bits 0-15 store signature length, bits 16-31 store overall record length.
// b) RecorderInfo::data2 stores signature length.
// c) RecorderInfo::ptr is replaced with pointer to method's binary signature.
//
// File write order: RecorderInfo::data1, RecorderInfo::data2, signature, extra alignment (this is optional). All of these represent JitInfRecord.
Expand Down Expand Up @@ -349,9 +348,9 @@ struct RecorderModuleInfo

struct RecorderInfo
{
unsigned data1;
unsigned data2;
BYTE * ptr;
unsigned data1;
unsigned short data2;
BYTE * ptr;

RecorderInfo()
{
Expand Down Expand Up @@ -435,7 +434,7 @@ struct RecorderInfo
return data1;
}

unsigned GetRawMethodData2()
unsigned short GetRawMethodData2()
{
LIMITED_METHOD_CONTRACT;

Expand All @@ -458,7 +457,7 @@ struct RecorderInfo
_ASSERTE(IsMethodInfo());
_ASSERTE(IsFullyInitialized());

return data2 & SIGNATURE_LENGTH_MASK;
return data2;
}

unsigned GetMethodRecordPaddingSize()
Expand All @@ -468,8 +467,9 @@ struct RecorderInfo
_ASSERTE(IsMethodInfo());
_ASSERTE(IsFullyInitialized());

unsigned recSize = data2 >> SIGNATURE_LENGTH_OFFSET;
unsigned paddingSize = recSize - GetMethodSignatureSize() - 2 * sizeof(DWORD);
unsigned unalignedrecSize = GetMethodSignatureSize() + sizeof(DWORD) + sizeof(unsigned short);
unsigned recSize = AlignUp(unalignedrecSize, sizeof(DWORD));
unsigned paddingSize = recSize - unalignedrecSize;
_ASSERTE(paddingSize < sizeof(unsigned));

return paddingSize;
Expand All @@ -489,7 +489,7 @@ struct RecorderInfo
return ret;
}

bool PackSignatureForMethod(BYTE *pSignature, unsigned signatureLength)
void PackSignatureForMethod(BYTE *pSignature, unsigned signatureLength)
{
LIMITED_METHOD_CONTRACT;

Expand All @@ -500,19 +500,10 @@ struct RecorderInfo
_ASSERTE(pSignature != nullptr);
_ASSERTE(signatureLength > 0);

DWORD dataSize = signatureLength + sizeof(DWORD) * 2;
dataSize = AlignUp(dataSize, sizeof(DWORD));
if (dataSize >= SIGNATURE_LENGTH_MASK + 1)
{
return false;
}

data2 = (dataSize << SIGNATURE_LENGTH_OFFSET) | (signatureLength & SIGNATURE_LENGTH_MASK);
data2 = signatureLength & SIGNATURE_LENGTH_MASK;
ptr = pSignature;

_ASSERTE(IsFullyInitialized());

return true;
}

void PackMethod(unsigned moduleIndex, MethodDesc * pMethod, bool application)
Expand Down
22 changes: 14 additions & 8 deletions src/coreclr/vm/multicorejitplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1096,7 +1096,7 @@ HRESULT MulticoreJitProfilePlayer::PlayProfile()
while ((SUCCEEDED(hr)) && (nSize > sizeof(unsigned)))
{
unsigned data1 = * (const unsigned *) pBuffer;
unsigned data2 = 0;
unsigned short data2 = 0;
unsigned rcdTyp = data1 >> RECORD_TYPE_OFFSET;
unsigned rcdLen = 0;

Expand All @@ -1110,8 +1110,11 @@ HRESULT MulticoreJitProfilePlayer::PlayProfile()
}
else if (rcdTyp == MULTICOREJIT_METHOD_RECORD_ID)
{
data2 = * (((const unsigned *) pBuffer) + 1);
rcdLen = data2 >> SIGNATURE_LENGTH_OFFSET;
data2 = * (const unsigned short *) (((const unsigned *) pBuffer) + 1);
unsigned signatureLength = data2;
DWORD dataSize = signatureLength + sizeof(DWORD) + sizeof(unsigned short);
dataSize = AlignUp(dataSize, sizeof(DWORD));
rcdLen = dataSize;
}
else
{
Expand Down Expand Up @@ -1160,8 +1163,11 @@ HRESULT MulticoreJitProfilePlayer::PlayProfile()

do
{
unsigned curdata2 = * (((const unsigned *) pCurBuf) + 1);
unsigned currcdLen = curdata2 >> SIGNATURE_LENGTH_OFFSET;
unsigned short curdata2 = * (const unsigned short *) (((const unsigned *) pCurBuf) + 1);
unsigned cursignatureLength = curdata2;
DWORD dataSize = cursignatureLength + sizeof(DWORD) + sizeof(unsigned short);
dataSize = AlignUp(dataSize, sizeof(DWORD));
unsigned currcdLen = dataSize;

if (currcdLen > curSize)
{
Expand Down Expand Up @@ -1204,10 +1210,10 @@ HRESULT MulticoreJitProfilePlayer::PlayProfile()
unsigned curmoduleIndex = curdata1 & MODULE_MASK;
unsigned curflags = curdata1 & METHOD_FLAGS_MASK;

unsigned curdata2 = * (((const unsigned *) pCurBuf) + 1);
unsigned cursignatureLength = curdata2 & SIGNATURE_LENGTH_MASK;
unsigned short curdata2 = * (const unsigned short *) (((const unsigned *) pCurBuf) + 1);
unsigned cursignatureLength = curdata2;

hr = HandleMethodInfoRecord(curmoduleIndex, (BYTE *) (pCurBuf + sizeof(unsigned) * 2), cursignatureLength);
hr = HandleMethodInfoRecord(curmoduleIndex, (BYTE *) (pCurBuf + sizeof(unsigned) + sizeof(unsigned short)), cursignatureLength);

if (SUCCEEDED(hr) && ShouldAbort(false))
{
Expand Down