Skip to content

Commit b8f554d

Browse files
CodeVersionManager updates (dotnet#102298)
* Code Versioning - move native code versioning state Remove the dictionary from the CodeVersionManager and instead store the data directly on the MethodDesc. * Remove dictionary for IL version states. Remove the dictionary from the CodeVersionManager and instead store the data in the Module.
1 parent 4a99b64 commit b8f554d

File tree

13 files changed

+214
-166
lines changed

13 files changed

+214
-166
lines changed

src/coreclr/debug/ee/debugger.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12313,13 +12313,14 @@ HRESULT Debugger::DeoptimizeMethodHelper(Module* pModule, mdMethodDef methodDef)
1231312313
ILCodeVersion ilCodeVersion;
1231412314
CodeVersionManager *pCodeVersionManager = pModule->GetCodeVersionManager();
1231512315

12316+
LOG((LF_TIEREDCOMPILATION, LL_INFO100, "Debugger::DeoptimizeMethodHelper Module=%p Method=0x%08x\n",
12317+
pModule, methodDef));
12318+
1231612319
{
1231712320
CodeVersionManager::LockHolder codeVersioningLockHolder;
1231812321
if (FAILED(hr = pCodeVersionManager->AddILCodeVersion(pModule, methodDef, &ilCodeVersion, TRUE)))
1231912322
{
12320-
LOG((LF_TIEREDCOMPILATION, LL_INFO100, "TieredCompilationManager::DeOptimizeMethodHelper Module=0x%x Method=0x%x, AddILCodeVersion returned hr 0x%x\n",
12321-
pModule, methodDef,
12322-
hr));
12323+
LOG((LF_TIEREDCOMPILATION, LL_INFO100, "Debugger::DeoptimizeMethodHelper AddILCodeVersion returned hr 0x%x\n", hr));
1232312324
return hr;
1232412325
}
1232512326

@@ -12335,8 +12336,7 @@ HRESULT Debugger::DeoptimizeMethodHelper(Module* pModule, mdMethodDef methodDef)
1233512336
{
1233612337
if (FAILED(hr = pCodeVersionManager->SetActiveILCodeVersions(&ilCodeVersion, 1, NULL)))
1233712338
{
12338-
LOG((LF_TIEREDCOMPILATION, LL_INFO100, "TieredCompilationManager::DeOptimizeMethodHelper Module=0x%x Method=0x%x, SetActiveILCodeVersions returned hr 0x%x\n",
12339-
pModule, methodDef,
12339+
LOG((LF_TIEREDCOMPILATION, LL_INFO100, "Debugger::DeoptimizeMethodHelper SetActiveILCodeVersions returned hr 0x%x\n",
1234012340
hr));
1234112341
return hr;
1234212342
}
@@ -12358,7 +12358,7 @@ HRESULT Debugger::DeoptimizeMethod(Module* pModule, mdMethodDef methodDef)
1235812358
HRESULT hr = DeoptimizeMethodHelper(pModule, methodDef);
1235912359
if (FAILED(hr))
1236012360
{
12361-
LOG((LF_TIEREDCOMPILATION, LL_INFO100, "TieredCompilationManager::DeOptimizeMethod Module=0x%x Method=0x%x,, initial ReJIT returned hr 0x%x, aborting\n",
12361+
LOG((LF_TIEREDCOMPILATION, LL_INFO100, "Debugger::DeoptimizeMethod Module=%p Method=0x%08x, initial ReJIT returned hr 0x%x, aborting\n",
1236212362
pModule, methodDef, hr));
1236312363
return hr;
1236412364
}

src/coreclr/inc/dacvars.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,7 @@ DEFINE_DACVAR(BOOL, dac__g_isNewExceptionHandlingEnabled, ::g_isNewExceptionHand
123123
DEFINE_DACVAR(PTR_SString, SString__s_Empty, SString::s_Empty)
124124

125125
DEFINE_DACVAR(INT32, ArrayBase__s_arrayBoundsZero, ArrayBase::s_arrayBoundsZero)
126+
DEFINE_DACVAR(BOOL, CodeVersionManager__s_HasNonDefaultILVersions, CodeVersionManager::s_HasNonDefaultILVersions)
126127

127128
DEFINE_DACVAR(PTR_JITNotification, dac__g_pNotificationTable, ::g_pNotificationTable)
128129
DEFINE_DACVAR(ULONG32, dac__g_dacNotificationFlags, ::g_dacNotificationFlags)

src/coreclr/vm/amd64/asmconstants.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ ASMCONSTANTS_C_ASSERT(SIZEOF__ComPrestubMethodFrame
9898
ASMCONSTANTS_C_ASSERT(SIZEOF__ComMethodFrame
9999
== sizeof(ComMethodFrame));
100100

101-
#define OFFSETOF__ComPlusCallMethodDesc__m_pComPlusCallInfo DBG_FRE(0x30, 0x08)
102-
ASMCONSTANTS_C_ASSERT(OFFSETOF__ComPlusCallMethodDesc__m_pComPlusCallInfo
103-
== offsetof(ComPlusCallMethodDesc, m_pComPlusCallInfo));
104-
105-
#define OFFSETOF__ComPlusCallInfo__m_pILStub 0x0
106-
ASMCONSTANTS_C_ASSERT(OFFSETOF__ComPlusCallInfo__m_pILStub
107-
== offsetof(ComPlusCallInfo, m_pILStub));
108-
109101
#endif // FEATURE_COMINTEROP
110102

111103
#define OFFSETOF__Thread__m_fPreemptiveGCDisabled 0x04

src/coreclr/vm/ceeload.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,6 +1807,7 @@ void Module::AllocateMaps()
18071807
m_TypeRefToMethodTableMap.dwCount = TYPEREF_MAP_INITIAL_SIZE;
18081808
m_MemberRefMap.dwCount = MEMBERREF_MAP_INITIAL_SIZE;
18091809
m_MethodDefToDescMap.dwCount = MEMBERDEF_MAP_INITIAL_SIZE;
1810+
m_ILCodeVersioningStateMap.dwCount = MEMBERDEF_MAP_INITIAL_SIZE;
18101811
m_FieldDefToDescMap.dwCount = MEMBERDEF_MAP_INITIAL_SIZE;
18111812
m_GenericParamToDescMap.dwCount = GENERICPARAM_MAP_INITIAL_SIZE;
18121813
m_ManifestModuleReferencesMap.dwCount = ASSEMBLYREFERENCES_MAP_INITIAL_SIZE;
@@ -1827,6 +1828,9 @@ void Module::AllocateMaps()
18271828
// Get # MethodDefs
18281829
m_MethodDefToDescMap.dwCount = pImport->GetCountWithTokenKind(mdtMethodDef)+1;
18291830

1831+
// IL code versions are relatively rare so keep small.
1832+
m_ILCodeVersioningStateMap.dwCount = 1;
1833+
18301834
// Get # FieldDefs
18311835
m_FieldDefToDescMap.dwCount = pImport->GetCountWithTokenKind(mdtFieldDef)+1;
18321836

@@ -1843,6 +1847,7 @@ void Module::AllocateMaps()
18431847
nTotal += m_TypeRefToMethodTableMap.dwCount;
18441848
nTotal += m_MemberRefMap.dwCount;
18451849
nTotal += m_MethodDefToDescMap.dwCount;
1850+
nTotal += m_ILCodeVersioningStateMap.dwCount;
18461851
nTotal += m_FieldDefToDescMap.dwCount;
18471852
nTotal += m_GenericParamToDescMap.dwCount;
18481853
nTotal += m_ManifestModuleReferencesMap.dwCount;
@@ -1869,9 +1874,13 @@ void Module::AllocateMaps()
18691874
m_MethodDefToDescMap.supportedFlags = METHOD_DEF_MAP_ALL_FLAGS;
18701875
m_MethodDefToDescMap.pTable = &m_MemberRefMap.pTable[m_MemberRefMap.dwCount];
18711876

1877+
m_ILCodeVersioningStateMap.pNext = NULL;
1878+
m_ILCodeVersioningStateMap.supportedFlags = METHOD_DEF_MAP_ALL_FLAGS;
1879+
m_ILCodeVersioningStateMap.pTable = &m_MethodDefToDescMap.pTable[m_MethodDefToDescMap.dwCount];
1880+
18721881
m_FieldDefToDescMap.pNext = NULL;
18731882
m_FieldDefToDescMap.supportedFlags = FIELD_DEF_MAP_ALL_FLAGS;
1874-
m_FieldDefToDescMap.pTable = &m_MethodDefToDescMap.pTable[m_MethodDefToDescMap.dwCount];
1883+
m_FieldDefToDescMap.pTable = &m_ILCodeVersioningStateMap.pTable[m_ILCodeVersioningStateMap.dwCount];
18751884

18761885
m_GenericParamToDescMap.pNext = NULL;
18771886
m_GenericParamToDescMap.supportedFlags = GENERIC_PARAM_MAP_ALL_FLAGS;
@@ -4807,7 +4816,7 @@ VASigCookie *Module::GetVASigCookieWorker(Module* pDefiningModule, Module* pLoad
48074816
INJECT_FAULT(COMPlusThrowOM());
48084817
}
48094818
CONTRACT_END;
4810-
4819+
48114820
VASigCookieBlock *pBlock;
48124821
VASigCookie *pCookie;
48134822

@@ -4855,7 +4864,7 @@ VASigCookie *Module::GetVASigCookieWorker(Module* pDefiningModule, Module* pLoad
48554864
}
48564865
}
48574866
}
4858-
4867+
48594868
if (!pCookie)
48604869
{
48614870
// If not, time to make a new one.
@@ -4911,7 +4920,7 @@ VASigCookie *Module::GetVASigCookieWorker(Module* pDefiningModule, Module* pLoad
49114920
pCookie->pLoaderModule = pLoaderModule;
49124921

49134922
AllocMemTracker amt;
4914-
4923+
49154924
if (classInstCount != 0)
49164925
{
49174926
TypeHandle* pClassInst = (TypeHandle*)(void*)amt.Track(pLoaderAllocator->GetHighFrequencyHeap()->AllocMem(S_SIZE_T(classInstCount) * S_SIZE_T(sizeof(TypeHandle))));
@@ -4931,7 +4940,7 @@ VASigCookie *Module::GetVASigCookieWorker(Module* pDefiningModule, Module* pLoad
49314940
}
49324941
pCookie->methodInst = Instantiation(pMethodInst, methodInstCount);
49334942
}
4934-
4943+
49354944
amt.SuppressRelease();
49364945

49374946
// Finally, now that it's safe for asynchronous readers to see it,

src/coreclr/vm/ceeload.h

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
#endif
4242

4343
#include "ilinstrumentation.h"
44+
#include "codeversion.h"
4445

4546
class Stub;
4647
class MethodDesc;
@@ -63,7 +64,6 @@ class SString;
6364
class Pending;
6465
class MethodTable;
6566
class DynamicMethodTable;
66-
class CodeVersionManager;
6767
class TieredCompilationManager;
6868
class JITInlineTrackingMap;
6969

@@ -581,8 +581,7 @@ class ModuleBase
581581

582582
};
583583

584-
// A code:Module represents a DLL or EXE file loaded from the disk. It could either be a IL module or a
585-
// Native code (NGEN module). A module live in a code:Assembly
584+
// A code:Module represents a DLL or EXE file loaded from the disk. A module live in a code:Assembly
586585
//
587586
// Some important fields are
588587
// * code:Module.m_pPEAssembly - this points at a code:PEAssembly that understands the layout of a PE assembly. The most
@@ -727,6 +726,10 @@ class Module : public ModuleBase
727726
// For generic methods, IsGenericTypeDefinition() is true i.e. instantiation at formals
728727
LookupMap<PTR_MethodDesc> m_MethodDefToDescMap;
729728

729+
// Linear mapping from MethodDef token to ILCodeVersioningState *
730+
// This is used for Code Versioning logic
731+
LookupMap<PTR_ILCodeVersioningState> m_ILCodeVersioningStateMap;
732+
730733
// Linear mapping from FieldDef token to FieldDesc*
731734
LookupMap<PTR_FieldDesc> m_FieldDefToDescMap;
732735

@@ -1215,7 +1218,7 @@ class Module : public ModuleBase
12151218
}
12161219
#endif // !DACCESS_COMPILE
12171220

1218-
MethodDesc *LookupMethodDef(mdMethodDef token);
1221+
PTR_MethodDesc LookupMethodDef(mdMethodDef token);
12191222

12201223
#ifndef DACCESS_COMPILE
12211224
void EnsureMethodDefCanBeStored(mdMethodDef token)
@@ -1233,6 +1236,25 @@ class Module : public ModuleBase
12331236
}
12341237
#endif // !DACCESS_COMPILE
12351238

1239+
PTR_ILCodeVersioningState LookupILCodeVersioningState(mdMethodDef token);
1240+
1241+
#ifndef DACCESS_COMPILE
1242+
void EnsureILCodeVersioningStateCanBeStored(mdMethodDef token)
1243+
{
1244+
WRAPPER_NO_CONTRACT; // THROWS/GC_NOTRIGGER/INJECT_FAULT()/MODE_ANY
1245+
_ASSERTE(CodeVersionManager::IsLockOwnedByCurrentThread());
1246+
m_ILCodeVersioningStateMap.EnsureElementCanBeStored(this, RidFromToken(token));
1247+
}
1248+
1249+
void EnsuredStoreILCodeVersioningState(mdMethodDef token, PTR_ILCodeVersioningState value)
1250+
{
1251+
WRAPPER_NO_CONTRACT; // NOTHROW/GC_NOTRIGGER/FORBID_FAULT/MODE_ANY
1252+
_ASSERTE(CodeVersionManager::IsLockOwnedByCurrentThread());
1253+
_ASSERTE(TypeFromToken(token) == mdtMethodDef);
1254+
m_ILCodeVersioningStateMap.SetElement(RidFromToken(token), value);
1255+
}
1256+
#endif // !DACCESS_COMPILE
1257+
12361258
#ifndef DACCESS_COMPILE
12371259
FieldDesc *LookupFieldDef(mdFieldDef token)
12381260
{

src/coreclr/vm/ceeload.inl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ inline PTR_Assembly Module::GetAssembly() const
259259
return m_pAssembly;
260260
}
261261

262-
inline MethodDesc *Module::LookupMethodDef(mdMethodDef token)
262+
inline PTR_MethodDesc Module::LookupMethodDef(mdMethodDef token)
263263
{
264264
CONTRACTL
265265
{
@@ -274,6 +274,22 @@ inline MethodDesc *Module::LookupMethodDef(mdMethodDef token)
274274
return m_MethodDefToDescMap.GetElement(RidFromToken(token));
275275
}
276276

277+
inline PTR_ILCodeVersioningState Module::LookupILCodeVersioningState(mdMethodDef token)
278+
{
279+
CONTRACTL
280+
{
281+
NOTHROW;
282+
GC_NOTRIGGER;
283+
MODE_ANY;
284+
SUPPORTS_DAC;
285+
}
286+
CONTRACTL_END
287+
288+
_ASSERTE(CodeVersionManager::IsLockOwnedByCurrentThread());
289+
_ASSERTE(TypeFromToken(token) == mdtMethodDef);
290+
return m_ILCodeVersioningStateMap.GetElement(RidFromToken(token));
291+
}
292+
277293
inline MethodDesc *Module::LookupMemberRefAsMethod(mdMemberRef token)
278294
{
279295
LIMITED_METHOD_DAC_CONTRACT;

0 commit comments

Comments
 (0)