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

XArch: Trim the code block to match the actual code length #61523

Merged
merged 6 commits into from
Nov 16, 2021
Merged
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
18 changes: 18 additions & 0 deletions src/coreclr/tools/Common/JitInterface/CorInfoImpl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,21 @@ private void CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, Method
#endif
}

if (codeSize != allocatedHotCodeSize)
{
// If the generated code is smaller than allocatedHotCodeSize, then trim the codeBlock.
//
// Currently, hot/cold splitting is not done and hence `codeSize` just includes the size of
// hotCode. Once hot/cold splitting is done, need to trim respective `_code` or `_coldCode`
// accordingly.
if (_compilation.Logger.IsVerbose)
{
Log.WriteLine($"Trimming codeSize from {_code.Length} to {codeSize}, Savings: {allocatedHotCodeSize - codeSize}, Method: {_methodCodeNode.Method.Name}");
}
Debug.Assert(codeSize != 0);
Debug.Assert(allocatedHotCodeSize > codeSize);
Array.Resize(ref _code, (int)codeSize);
mangod9 marked this conversation as resolved.
Show resolved Hide resolved
}
PublishCode();
PublishROData();
}
Expand Down Expand Up @@ -3242,6 +3257,8 @@ private bool getTailCallHelpers(ref CORINFO_RESOLVED_TOKEN callToken, CORINFO_SI
private byte[] _gcInfo;
private CORINFO_EH_CLAUSE[] _ehClauses;

private long allocatedHotCodeSize = 0;

private void allocMem(ref AllocMemArgs args)
{
args.hotCodeBlock = (void*)GetPin(_code = new byte[args.hotCodeSize]);
Expand All @@ -3252,6 +3269,7 @@ private void allocMem(ref AllocMemArgs args)
args.coldCodeBlock = (void*)GetPin(_coldCode = new byte[args.coldCodeSize]);
args.coldCodeBlockRW = args.coldCodeBlock;
}
allocatedHotCodeSize = args.hotCodeSize;
kunalspathak marked this conversation as resolved.
Show resolved Hide resolved

_codeAlignment = -1;
if ((args.flag & CorJitAllocMemFlag.CORJIT_ALLOCMEM_FLG_32BYTE_ALIGN) != 0)
Expand Down