Skip to content

Commit

Permalink
Revert VSD stubs changes
Browse files Browse the repository at this point in the history
Extensive benchmarking has shown that the new model for VSD stubs is
causing steady state performance degradation for code using a lot of
virtual calls. It wasn't showing up in the plaintext benchmark I have
used as the driver of the change.
This change looses part of the startup perf improvements, but I am
planning to add back the Lookup stubs in a follow up change. Those
should not be perf critical and they are likely the ones where the
startup improvements are gained from.
  • Loading branch information
janvorli committed Mar 17, 2022
1 parent 118b427 commit 346af35
Show file tree
Hide file tree
Showing 22 changed files with 2,831 additions and 1,460 deletions.
33 changes: 0 additions & 33 deletions src/coreclr/vm/amd64/asmconstants.h
Original file line number Diff line number Diff line change
Expand Up @@ -590,39 +590,6 @@ ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForMethod == offsetof(CallCoun
#define CallCountingStubData__TargetForThresholdReached 0x10
ASMCONSTANTS_C_ASSERT(CallCountingStubData__TargetForThresholdReached == offsetof(CallCountingStubData, TargetForThresholdReached))

#define LookupStubData__DispatchToken 0x00
ASMCONSTANTS_C_ASSERT(LookupStubData__DispatchToken == offsetof(LookupStubData, DispatchToken))

#define LookupStubData__ResolveWorkerTarget 0x08
ASMCONSTANTS_C_ASSERT(LookupStubData__ResolveWorkerTarget == offsetof(LookupStubData, ResolveWorkerTarget))

#define DispatchStubData__ExpectedMT 0x00
ASMCONSTANTS_C_ASSERT(DispatchStubData__ExpectedMT == offsetof(DispatchStubData, ExpectedMT))

#define DispatchStubData__ImplTarget 0x08
ASMCONSTANTS_C_ASSERT(DispatchStubData__ImplTarget == offsetof(DispatchStubData, ImplTarget))

#define DispatchStubData__FailTarget 0x10
ASMCONSTANTS_C_ASSERT(DispatchStubData__FailTarget == offsetof(DispatchStubData, FailTarget))

#define ResolveStubData__HashedToken 0x08
ASMCONSTANTS_C_ASSERT(ResolveStubData__HashedToken == offsetof(ResolveStubData, HashedToken))

#define ResolveStubData__CacheAddress 0x00
ASMCONSTANTS_C_ASSERT(ResolveStubData__CacheAddress == offsetof(ResolveStubData, CacheAddress))

#define ResolveStubData__Token 0x10
ASMCONSTANTS_C_ASSERT(ResolveStubData__Token == offsetof(ResolveStubData, Token))

#define ResolveStubData__Counter 0x0c
ASMCONSTANTS_C_ASSERT(ResolveStubData__Counter == offsetof(ResolveStubData, Counter))

#define ResolveStubData__ResolveWorkerTarget 0x18
ASMCONSTANTS_C_ASSERT(ResolveStubData__ResolveWorkerTarget == offsetof(ResolveStubData, ResolveWorkerTarget))

#define CALL_STUB_CACHE_MASK_ASM 0xfff
ASMCONSTANTS_C_ASSERT(CALL_STUB_CACHE_MASK_ASM == CALL_STUB_CACHE_MASK)

#undef ASMCONSTANTS_RUNTIME_ASSERT
#undef ASMCONSTANTS_C_ASSERT
#ifndef UNIX_AMD64_ABI
Expand Down
47 changes: 0 additions & 47 deletions src/coreclr/vm/amd64/thunktemplates.S
Original file line number Diff line number Diff line change
Expand Up @@ -29,50 +29,3 @@ LEAF_ENTRY CallCountingStubCode, _TEXT
LOCAL_LABEL(CountReachedZero):
jmp QWORD PTR [rip + DATA_SLOT(CallCountingStub, TargetForThresholdReached)]
LEAF_END_MARKED CallCountingStubCode, _TEXT

LEAF_ENTRY LookupStubCode, _TEXT
push QWORD PTR [rip + DATA_SLOT(LookupStub, DispatchToken)]
jmp QWORD PTR [rip + DATA_SLOT(LookupStub, ResolveWorkerTarget)]
LEAF_END_MARKED LookupStubCode, _TEXT

LEAF_ENTRY DispatchStubCode, _TEXT
mov rax,QWORD PTR [rip + DATA_SLOT(DispatchStub, ExpectedMT)]
PATCH_LABEL DispatchStubCode_ThisDeref
cmp QWORD PTR [rdi],rax;
jne LOCAL_LABEL(Fail)
jmp QWORD PTR [rip + DATA_SLOT(DispatchStub, ImplTarget)]
LOCAL_LABEL(Fail):
jmp QWORD PTR [rip + DATA_SLOT(DispatchStub, FailTarget)]
LEAF_END_MARKED DispatchStubCode, _TEXT

LEAF_ENTRY ResolveStubCode, _TEXT
PATCH_LABEL ResolveStubCode_ResolveEntry
LOCAL_LABEL(Resolve):
push rdx
mov r10,QWORD PTR [rip + DATA_SLOT(ResolveStub, CacheAddress)]
PATCH_LABEL ResolveStubCode_ThisDeref
mov rax,QWORD PTR [rdi]
mov rdx,rax
shr rax,12
add rax,rdx
xor eax,DWORD PTR [rip + DATA_SLOT(ResolveStub, HashedToken)]
and eax, CALL_STUB_CACHE_MASK_ASM * 8
mov rax,QWORD PTR [r10+rax*1]
mov r10,QWORD PTR [rip + DATA_SLOT(ResolveStub, Token)]
cmp rdx,QWORD PTR [rax]
jne LOCAL_LABEL(Miss)
cmp r10,QWORD PTR [rax+8]
jne LOCAL_LABEL(Miss)
pop rdx
jmp QWORD PTR [rax+0x10]
PATCH_LABEL ResolveStubCode_FailEntry
add DWORD PTR [rip + DATA_SLOT(ResolveStub, Counter)], -1
jge LOCAL_LABEL(Resolve)
or r11, 1 // SDF_ResolveBackPatch
PATCH_LABEL ResolveStubCode_SlowEntry
push rdx
mov r10,QWORD PTR [rip + DATA_SLOT(ResolveStub, Token)]
LOCAL_LABEL(Miss):
push rax
jmp QWORD PTR [rip + DATA_SLOT(ResolveStub, ResolveWorkerTarget)]
LEAF_END_MARKED ResolveStubCode, _TEXT
46 changes: 0 additions & 46 deletions src/coreclr/vm/amd64/thunktemplates.asm
Original file line number Diff line number Diff line change
Expand Up @@ -31,50 +31,4 @@ LEAF_ENTRY CallCountingStubCode, _TEXT
jmp QWORD PTR [DATA_SLOT(CallCountingStub, TargetForThresholdReached)]
LEAF_END_MARKED CallCountingStubCode, _TEXT

LEAF_ENTRY LookupStubCode, _TEXT
push QWORD PTR [DATA_SLOT(LookupStub, DispatchToken)]
jmp QWORD PTR [DATA_SLOT(LookupStub, ResolveWorkerTarget)]
LEAF_END_MARKED LookupStubCode, _TEXT

LEAF_ENTRY DispatchStubCode, _TEXT
mov rax,QWORD PTR [DATA_SLOT(DispatchStub, ExpectedMT)]
PATCH_LABEL DispatchStubCode_ThisDeref
cmp QWORD PTR [rcx],rax;
jne Fail
jmp QWORD PTR [DATA_SLOT(DispatchStub, ImplTarget)]
Fail:
jmp QWORD PTR [DATA_SLOT(DispatchStub, FailTarget)]
LEAF_END_MARKED DispatchStubCode, _TEXT

LEAF_ENTRY ResolveStubCode, _TEXT
PATCH_LABEL ResolveStubCode_ResolveEntry
push rdx
mov r10,QWORD PTR [DATA_SLOT(ResolveStub, CacheAddress)]
PATCH_LABEL ResolveStubCode_ThisDeref
mov rax,QWORD PTR [rcx]
mov rdx,rax
shr rax,12
add rax,rdx
xor eax,DWORD PTR [DATA_SLOT(ResolveStub, HashedToken)]
and eax, CALL_STUB_CACHE_MASK_ASM * 8
mov rax,QWORD PTR [r10+rax*1]
mov r10,QWORD PTR [DATA_SLOT(ResolveStub, Token)]
cmp rdx,QWORD PTR [rax]
jne Miss
cmp r10,QWORD PTR [rax+8]
jne Miss
pop rdx
jmp QWORD PTR [rax+10h]
PATCH_LABEL ResolveStubCode_FailEntry
add DWORD PTR [DATA_SLOT(ResolveStub, Counter)], -1
jge ResolveStubCode
or r11, 1; SDF_ResolveBackPatch
PATCH_LABEL ResolveStubCode_SlowEntry
push rdx
mov r10,QWORD PTR [DATA_SLOT(ResolveStub, Token)]
Miss:
push rax
jmp QWORD PTR [DATA_SLOT(ResolveStub, ResolveWorkerTarget)]
LEAF_END_MARKED ResolveStubCode, _TEXT

end
Loading

0 comments on commit 346af35

Please sign in to comment.