Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit b9f5ae8

Browse files
author
Fadi Hanna
authored
Generic dictionary minor performance improvement and simplification for R2R (#5690)
A set of refactoring changes to slighly improve the performance of generic dictionary access on R2R images, and simplifying the codebase: 1) Removing dependency on CEEInfo::ComputeRuntimeLookupForSharedGenericTokenStatic (and deleting the API). 2) Stop parsing the generic type/method signatures when generating the R2R dictionary lookup assembly stub. 3) Avoid re-encoding the generic type/method signatures in a new in-memory blob using a SigBuilder (signatures used directly from the R2R image) 4) Moved the parsing/loading of type/method signatures to Dictionary::PopulateEntry() 5) Dictionary index and slot number are now encoded in the generated assembly stub instead of the signature (stub takes a pointer to a data blob, which contains the signature, the dictionary index and slot, and the module pointer)
1 parent fb79613 commit b9f5ae8

15 files changed

+873
-534
lines changed

src/inc/corinfo.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -614,10 +614,10 @@ enum CorInfoHelpFunc
614614
CORINFO_HELP_MEMSET, // Init block of memory
615615
CORINFO_HELP_MEMCPY, // Copy block of memory
616616

617-
CORINFO_HELP_RUNTIMEHANDLE_METHOD, // determine a type/field/method handle at run-time
618-
CORINFO_HELP_RUNTIMEHANDLE_METHOD_LOG,// determine a type/field/method handle at run-time, with IBC logging
619-
CORINFO_HELP_RUNTIMEHANDLE_CLASS, // determine a type/field/method handle at run-time
620-
CORINFO_HELP_RUNTIMEHANDLE_CLASS_LOG,// determine a type/field/method handle at run-time, with IBC logging
617+
CORINFO_HELP_RUNTIMEHANDLE_METHOD, // determine a type/field/method handle at run-time
618+
CORINFO_HELP_RUNTIMEHANDLE_METHOD_LOG, // determine a type/field/method handle at run-time, with IBC logging
619+
CORINFO_HELP_RUNTIMEHANDLE_CLASS, // determine a type/field/method handle at run-time
620+
CORINFO_HELP_RUNTIMEHANDLE_CLASS_LOG, // determine a type/field/method handle at run-time, with IBC logging
621621

622622
// These helpers are required for MDIL backward compatibility only. They are not used by current JITed code.
623623
CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPEHANDLE_OBSOLETE, // Convert from a TypeHandle (native structure pointer) to RuntimeTypeHandle at run-time

src/vm/amd64/cgenamd64.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include "fcall.h"
2121
#include "array.h"
2222
#include "virtualcallstub.h"
23+
#include "jitinterface.h"
2324

2425
#ifdef FEATURE_COMINTEROP
2526
#include "clrtocomcall.h"
@@ -1140,19 +1141,28 @@ PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADD
11401141
END_DYNAMIC_HELPER_EMIT();
11411142
}
11421143

1143-
PCODE DynamicHelpers::CreateDictionaryLookupHelper(LoaderAllocator * pAllocator, CORINFO_RUNTIME_LOOKUP * pLookup)
1144+
PCODE DynamicHelpers::CreateDictionaryLookupHelper(LoaderAllocator * pAllocator, CORINFO_RUNTIME_LOOKUP * pLookup, DWORD dictionaryIndexAndSlot, Module * pModule)
11441145
{
11451146
STANDARD_VM_CONTRACT;
11461147

1148+
PCODE helperAddress = (pLookup->helper == CORINFO_HELP_RUNTIMEHANDLE_METHOD ?
1149+
GetEEFuncEntryPoint(JIT_GenericHandleMethodWithSlotAndModule) :
1150+
GetEEFuncEntryPoint(JIT_GenericHandleClassWithSlotAndModule));
1151+
1152+
GenericHandleArgs * pArgs = (GenericHandleArgs *)(void *)pAllocator->GetDynamicHelpersHeap()->AllocAlignedMem(sizeof(GenericHandleArgs), DYNAMIC_HELPER_ALIGNMENT);
1153+
pArgs->dictionaryIndexAndSlot = dictionaryIndexAndSlot;
1154+
pArgs->signature = pLookup->signature;
1155+
pArgs->module = (CORINFO_MODULE_HANDLE)pModule;
1156+
11471157
// It's available only via the run-time helper function
11481158
if (pLookup->indirections == CORINFO_USEHELPER)
11491159
{
11501160
BEGIN_DYNAMIC_HELPER_EMIT(15);
11511161

11521162
// rcx/rdi contains the generic context parameter
1153-
// mov rdx/rsi,pLookup->signature
1154-
// jmp pLookup->helper
1155-
EmitHelperWithArg(p, pAllocator, (TADDR)pLookup->signature, CEEJitInfo::getHelperFtnStatic(pLookup->helper));
1163+
// mov rdx/rsi,pArgs
1164+
// jmp helperAddress
1165+
EmitHelperWithArg(p, pAllocator, (TADDR)pArgs, helperAddress);
11561166

11571167
END_DYNAMIC_HELPER_EMIT();
11581168
}
@@ -1248,9 +1258,9 @@ PCODE DynamicHelpers::CreateDictionaryLookupHelper(LoaderAllocator * pAllocator,
12481258
*(UINT32*)p = 0x00c18948; p += 3; // mov rcx,rax
12491259
#endif
12501260

1251-
// mov rdx,pLookup->signature
1252-
// jmp pLookup->helper
1253-
EmitHelperWithArg(p, pAllocator, (TADDR)pLookup->signature, CEEJitInfo::getHelperFtnStatic(pLookup->helper));
1261+
// mov rdx,pArgs
1262+
// jmp helperAddress
1263+
EmitHelperWithArg(p, pAllocator, (TADDR)pArgs, helperAddress);
12541264
}
12551265
}
12561266

src/vm/arm64/stubs.cpp

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include "tls.h"
1414
#include "asmconstants.h"
1515
#include "virtualcallstub.h"
16+
#include "jitinterface.h"
1617

1718
#ifndef DACCESS_COMPILE
1819
//-----------------------------------------------------------------------
@@ -2004,20 +2005,29 @@ PCODE DynamicHelpers::CreateHelperWithTwoArgs(LoaderAllocator * pAllocator, TADD
20042005
END_DYNAMIC_HELPER_EMIT();
20052006
}
20062007

2007-
PCODE DynamicHelpers::CreateDictionaryLookupHelper(LoaderAllocator * pAllocator, CORINFO_RUNTIME_LOOKUP * pLookup)
2008+
PCODE DynamicHelpers::CreateDictionaryLookupHelper(LoaderAllocator * pAllocator, CORINFO_RUNTIME_LOOKUP * pLookup, DWORD dictionaryIndexAndSlot, Module * pModule)
20082009
{
20092010
STANDARD_VM_CONTRACT;
20102011

2012+
PCODE helperAddress = (pLookup->helper == CORINFO_HELP_RUNTIMEHANDLE_METHOD ?
2013+
GetEEFuncEntryPoint(JIT_GenericHandleMethodWithSlotAndModule) :
2014+
GetEEFuncEntryPoint(JIT_GenericHandleClassWithSlotAndModule));
2015+
2016+
GenericHandleArgs * pArgs = (GenericHandleArgs *)(void *)pAllocator->GetDynamicHelpersHeap()->AllocAlignedMem(sizeof(GenericHandleArgs), DYNAMIC_HELPER_ALIGNMENT);
2017+
pArgs->dictionaryIndexAndSlot = dictionaryIndexAndSlot;
2018+
pArgs->signature = pLookup->signature;
2019+
pArgs->module = (CORINFO_MODULE_HANDLE)pModule;
2020+
20112021
// It's available only via the run-time helper function
20122022
if (pLookup->indirections == CORINFO_USEHELPER)
20132023
{
20142024
BEGIN_DYNAMIC_HELPER_EMIT(32);
20152025

20162026
// X0 already contains generic context parameter
20172027
// reuse EmitHelperWithArg for below two operations
2018-
// X1 <- pLookup->signature
2019-
// branch to pLookup->helper
2020-
EmitHelperWithArg(p, pAllocator, (TADDR)pLookup->signature, CEEJitInfo::getHelperFtnStatic(pLookup->helper));
2028+
// X1 <- pArgs
2029+
// branch to helperAddress
2030+
EmitHelperWithArg(p, pAllocator, (TADDR)pArgs, helperAddress);
20212031

20222032
END_DYNAMIC_HELPER_EMIT();
20232033
}
@@ -2104,9 +2114,9 @@ PCODE DynamicHelpers::CreateDictionaryLookupHelper(LoaderAllocator * pAllocator,
21042114
*(DWORD*)p = 0x91000120;
21052115
p += 4;
21062116
// reuse EmitHelperWithArg for below two operations
2107-
// X1 <- pLookup->signature
2108-
// branch to pLookup->helper
2109-
EmitHelperWithArg(p, pAllocator, (TADDR)pLookup->signature, CEEJitInfo::getHelperFtnStatic(pLookup->helper));
2117+
// X1 <- pArgs
2118+
// branch to helperAddress
2119+
EmitHelperWithArg(p, pAllocator, (TADDR)pArgs, helperAddress);
21102120
}
21112121

21122122
// datalabel:

src/vm/codeman.cpp

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4534,6 +4534,40 @@ PTR_Module ExecutionManager::FindZapModule(TADDR currentData)
45344534
return dac_cast<PTR_Module>(pRS->pHeapListOrZapModule);
45354535
}
45364536

4537+
/* static */
4538+
PTR_Module ExecutionManager::FindReadyToRunModule(TADDR currentData)
4539+
{
4540+
CONTRACTL
4541+
{
4542+
NOTHROW;
4543+
GC_NOTRIGGER;
4544+
SO_TOLERANT;
4545+
MODE_ANY;
4546+
STATIC_CONTRACT_HOST_CALLS;
4547+
SUPPORTS_DAC;
4548+
}
4549+
CONTRACTL_END;
4550+
4551+
#ifdef FEATURE_READYTORUN
4552+
ReaderLockHolder rlh;
4553+
4554+
RangeSection * pRS = GetRangeSection(currentData);
4555+
if (pRS == NULL)
4556+
return NULL;
4557+
4558+
if (pRS->flags & RangeSection::RANGE_SECTION_CODEHEAP)
4559+
return NULL;
4560+
4561+
if (pRS->flags & RangeSection::RANGE_SECTION_READYTORUN)
4562+
return dac_cast<PTR_Module>(pRS->pHeapListOrZapModule);;
4563+
4564+
return NULL;
4565+
#else
4566+
return NULL;
4567+
#endif
4568+
}
4569+
4570+
45374571
/* static */
45384572
PTR_Module ExecutionManager::FindModuleForGCRefMap(TADDR currentData)
45394573
{

src/vm/codeman.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1298,6 +1298,7 @@ class ExecutionManager
12981298
}
12991299

13001300
static PTR_Module FindZapModule(TADDR currentData);
1301+
static PTR_Module FindReadyToRunModule(TADDR currentData);
13011302

13021303
// FindZapModule flavor to be used during GC to find GCRefMap
13031304
static PTR_Module FindModuleForGCRefMap(TADDR currentData);

src/vm/crossgencompile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ void CRemotingServices::DestroyThunk(MethodDesc* pMD)
305305
}
306306
#endif
307307

308-
CORINFO_GENERIC_HANDLE JIT_GenericHandleWorker(MethodDesc * pMD, MethodTable * pMT, LPVOID signature)
308+
CORINFO_GENERIC_HANDLE JIT_GenericHandleWorker(MethodDesc * pMD, MethodTable * pMT, LPVOID signature, DWORD dictionaryIndexAndSlot, Module* pModule)
309309
{
310310
UNREACHABLE();
311311
}

0 commit comments

Comments
 (0)