diff options
author | Jan Kotas <jkotas@microsoft.com> | 2018-05-04 10:40:28 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-05-04 10:40:28 -0700 |
commit | 37e643696f860094ca3182c87f1375540b9d704e (patch) | |
tree | 5a840c7743873ca6c46e64a89487989a95880887 /src/vm/amd64 | |
parent | fac17ce1413c2d270eb52e958faf5e869bcd33a2 (diff) | |
download | coreclr-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/amd64')
-rw-r--r-- | src/vm/amd64/JitHelpers_InlineGetThread.asm | 4 | ||||
-rw-r--r-- | src/vm/amd64/JitHelpers_Slow.asm | 4 | ||||
-rw-r--r-- | src/vm/amd64/asmconstants.h | 3 |
3 files changed, 5 insertions, 6 deletions
diff --git a/src/vm/amd64/JitHelpers_InlineGetThread.asm b/src/vm/amd64/JitHelpers_InlineGetThread.asm index d9f58cc30f..8ebffeb38e 100644 --- a/src/vm/amd64/JitHelpers_InlineGetThread.asm +++ b/src/vm/amd64/JitHelpers_InlineGetThread.asm @@ -134,12 +134,10 @@ LEAF_ENTRY AllocateStringFastMP_InlineGetThread, _TEXT cmp ecx, (ASM_LARGE_OBJECT_SIZE - 256)/2 jae OversizedString - mov edx, [r9 + OFFSET__MethodTable__m_BaseSize] - ; Calculate the final size to allocate. ; We need to calculate baseSize + cnt*2, then round that up by adding 7 and anding ~7. - lea edx, [edx + ecx*2 + 7] + lea edx, [STRING_BASE_SIZE + ecx*2 + 7] and edx, -8 INLINE_GETTHREAD r11 diff --git a/src/vm/amd64/JitHelpers_Slow.asm b/src/vm/amd64/JitHelpers_Slow.asm index 0e26ae6dfd..cd3aa14a92 100644 --- a/src/vm/amd64/JitHelpers_Slow.asm +++ b/src/vm/amd64/JitHelpers_Slow.asm @@ -276,12 +276,10 @@ LEAF_ENTRY AllocateStringFastUP, _TEXT cmp ecx, (ASM_LARGE_OBJECT_SIZE - 256)/2 jae FramedAllocateString - mov r8d, [r11 + OFFSET__MethodTable__m_BaseSize] - ; Calculate the final size to allocate. ; We need to calculate baseSize + cnt*2, then round that up by adding 7 and anding ~7. - lea r8d, [r8d + ecx*2 + 7] + lea r8d, [STRING_BASE_SIZE + ecx*2 + 7] and r8d, -8 inc [g_global_alloc_lock] diff --git a/src/vm/amd64/asmconstants.h b/src/vm/amd64/asmconstants.h index f526e22f2b..cadc10ac56 100644 --- a/src/vm/amd64/asmconstants.h +++ b/src/vm/amd64/asmconstants.h @@ -545,6 +545,9 @@ ASMCONSTANTS_C_ASSERT(ASM_LARGE_OBJECT_SIZE == LARGE_OBJECT_SIZE); ASMCONSTANTS_C_ASSERT(OFFSETOF__ArrayBase__m_NumComponents == offsetof(ArrayBase, m_NumComponents)); +#define STRING_BASE_SIZE 0x16 +ASMCONSTANTS_RUNTIME_ASSERT(STRING_BASE_SIZE == StringObject::GetBaseSize()); + #define OFFSETOF__StringObject__m_StringLength 0x8 ASMCONSTANTS_C_ASSERT(OFFSETOF__StringObject__m_StringLength == offsetof(StringObject, m_StringLength)); |