summaryrefslogtreecommitdiff
path: root/src/vm/i386
diff options
context:
space:
mode:
authorJan Kotas <jkotas@microsoft.com>2018-05-04 10:40:28 -0700
committerGitHub <noreply@github.com>2018-05-04 10:40:28 -0700
commit37e643696f860094ca3182c87f1375540b9d704e (patch)
tree5a840c7743873ca6c46e64a89487989a95880887 /src/vm/i386
parentfac17ce1413c2d270eb52e958faf5e869bcd33a2 (diff)
downloadcoreclr-37e643696f860094ca3182c87f1375540b9d704e.tar.gz
coreclr-37e643696f860094ca3182c87f1375540b9d704e.tar.bz2
coreclr-37e643696f860094ca3182c87f1375540b9d704e.zip
Fix System.String over-allocation (#17876)
BaseSize for System.String was not set correctly. It caused unnecessary extra 8 bytes to be allocated at the end of strings that had `Length % 4 < 2` on 64-bit platforms. This change makes affected strings proportionally cheaper. For example, `new string('a', 1)` in a long-running loop is 7% faster.
Diffstat (limited to 'src/vm/i386')
-rw-r--r--src/vm/i386/jitinterfacex86.cpp9
1 files changed, 4 insertions, 5 deletions
diff --git a/src/vm/i386/jitinterfacex86.cpp b/src/vm/i386/jitinterfacex86.cpp
index 642c417598..4eccd35a76 100644
--- a/src/vm/i386/jitinterfacex86.cpp
+++ b/src/vm/i386/jitinterfacex86.cpp
@@ -1063,14 +1063,13 @@ void *JIT_TrialAlloc::GenAllocString(Flags flags)
// jae noLock - seems tempting to jump to noAlloc, but we haven't taken the lock yet
sl.X86EmitCondJump(noLock, X86CondCode::kJAE);
- // mov edx, [ecx]MethodTable.m_BaseSize
- sl.X86EmitIndexRegLoad(kEDX, kECX, offsetof(MethodTable,m_BaseSize));
-
// Calculate the final size to allocate.
// We need to calculate baseSize + cnt*2, then round that up by adding 3 and anding ~3.
- // lea eax, [edx+eax*2+5]
- sl.X86EmitOp(0x8d, kEAX, kEDX, (DATA_ALIGNMENT-1), kEAX, 2);
+ // lea eax, [basesize+(alignment-1)+eax*2]
+ sl.Emit16(0x048d);
+ sl.Emit8(0x45);
+ sl.Emit32(StringObject::GetBaseSize() + (DATA_ALIGNMENT-1));
// and eax, ~3
sl.Emit16(0xe083);