Skip to content

Commit

Permalink
XArch: Trim the code block to match the actual code length (#61523)
Browse files Browse the repository at this point in the history
* Trim the hot code size to the actual code length

* Remove allocatedHotCodeSize field

* Remove verbose logging

* Perform trimming only for xarch

* Include more comment about armarch

* Fix the condition for arm64
  • Loading branch information
kunalspathak authored Nov 16, 2021
1 parent 56acd2e commit 4d82463
Showing 1 changed file with 18 additions and 0 deletions.
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,24 @@ private void CompileMethodInternal(IMethodNode methodCodeNodeNeedingCode, Method
#endif
}

if (codeSize < _code.Length)
{
if (_compilation.TypeSystemContext.Target.Architecture != TargetArchitecture.ARM64)
{
// For xarch/arm32, the generated code is sometimes smaller than the memory allocated.
// In that case, trim the codeBlock to the actual value.
//
// For arm64, the allocation request of `hotCodeSize` also includes the roData size
// while the `codeSize` returned just contains the size of the native code. As such,
// there is guarantee that for armarch, (codeSize == _code.Length) is always true.
//
// 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.
Debug.Assert(codeSize != 0);
Array.Resize(ref _code, (int)codeSize);
}
}
PublishCode();
PublishROData();
}
Expand Down

0 comments on commit 4d82463

Please sign in to comment.