Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Code Versioning - move native code versioning state #101652

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 0 additions & 8 deletions src/coreclr/vm/amd64/asmconstants.h
Expand Up @@ -98,14 +98,6 @@ ASMCONSTANTS_C_ASSERT(SIZEOF__ComPrestubMethodFrame
ASMCONSTANTS_C_ASSERT(SIZEOF__ComMethodFrame
== sizeof(ComMethodFrame));

#define OFFSETOF__ComPlusCallMethodDesc__m_pComPlusCallInfo DBG_FRE(0x30, 0x08)
ASMCONSTANTS_C_ASSERT(OFFSETOF__ComPlusCallMethodDesc__m_pComPlusCallInfo
== offsetof(ComPlusCallMethodDesc, m_pComPlusCallInfo));

#define OFFSETOF__ComPlusCallInfo__m_pILStub 0x0
ASMCONSTANTS_C_ASSERT(OFFSETOF__ComPlusCallInfo__m_pILStub
== offsetof(ComPlusCallInfo, m_pILStub));

#endif // FEATURE_COMINTEROP

#define OFFSETOF__Thread__m_fPreemptiveGCDisabled 0x04
Expand Down
35 changes: 15 additions & 20 deletions src/coreclr/vm/codeversion.cpp
Expand Up @@ -1306,9 +1306,6 @@ void ILCodeVersioningState::LinkILCodeVersionNode(ILCodeVersionNode* pILCodeVers
bool CodeVersionManager::s_initialNativeCodeVersionMayNotBeTheDefaultNativeCodeVersion = false;
#endif

CodeVersionManager::CodeVersionManager()
{}

PTR_ILCodeVersioningState CodeVersionManager::GetILCodeVersioningState(PTR_Module pModule, mdMethodDef methodDef) const
{
LIMITED_METHOD_DAC_CONTRACT;
Expand All @@ -1319,7 +1316,7 @@ PTR_ILCodeVersioningState CodeVersionManager::GetILCodeVersioningState(PTR_Modul
PTR_MethodDescVersioningState CodeVersionManager::GetMethodDescVersioningState(PTR_MethodDesc pClosedMethodDesc) const
{
LIMITED_METHOD_DAC_CONTRACT;
return m_methodDescVersioningStateMap.Lookup(pClosedMethodDesc);
return pClosedMethodDesc->GetMethodDescVersionState();
}

#ifndef DACCESS_COMPILE
Expand Down Expand Up @@ -1354,28 +1351,26 @@ HRESULT CodeVersionManager::GetOrCreateILCodeVersioningState(Module* pModule, md

HRESULT CodeVersionManager::GetOrCreateMethodDescVersioningState(MethodDesc* pMethod, MethodDescVersioningState** ppMethodVersioningState)
{
LIMITED_METHOD_CONTRACT;
HRESULT hr = S_OK;
MethodDescVersioningState* pMethodVersioningState = m_methodDescVersioningStateMap.Lookup(pMethod);
CONTRACTL
{
NOTHROW;
GC_NOTRIGGER;
PRECONDITION(pMethod != NULL);
PRECONDITION(ppMethodVersioningState != NULL);
}
CONTRACTL_END;

MethodDescVersioningState* pMethodVersioningState = pMethod->GetMethodDescVersionState();
if (pMethodVersioningState == NULL)
{
pMethodVersioningState = new (nothrow) MethodDescVersioningState(pMethod);
if (pMethodVersioningState == NULL)
{
return E_OUTOFMEMORY;
}
EX_TRY
{
// This throws when out of memory, but remains internally
// consistent (without adding the new element)
m_methodDescVersioningStateMap.Add(pMethodVersioningState);
}
EX_CATCH_HRESULT(hr);
if (FAILED(hr))
{

if (!pMethod->SetMethodDescVersionState(pMethodVersioningState))
delete pMethodVersioningState;
return hr;
}

pMethodVersioningState = pMethod->GetMethodDescVersionState();
}
*ppMethodVersioningState = pMethodVersioningState;
return S_OK;
Expand Down
35 changes: 1 addition & 34 deletions src/coreclr/vm/codeversion.h
Expand Up @@ -475,36 +475,6 @@ class MethodDescVersioningState
PTR_NativeCodeVersionNode m_pFirstVersionNode;
};

class MethodDescVersioningStateHashTraits : public NoRemoveSHashTraits<DefaultSHashTraits<PTR_MethodDescVersioningState>>
{
public:
typedef typename DefaultSHashTraits<PTR_MethodDescVersioningState>::element_t element_t;
typedef typename DefaultSHashTraits<PTR_MethodDescVersioningState>::count_t count_t;

typedef const PTR_MethodDesc key_t;

static key_t GetKey(element_t e)
{
LIMITED_METHOD_CONTRACT;
return e->GetMethodDesc();
}
static BOOL Equals(key_t k1, key_t k2)
{
LIMITED_METHOD_CONTRACT;
return k1 == k2;
}
static count_t Hash(key_t k)
{
LIMITED_METHOD_CONTRACT;
return (count_t)dac_cast<TADDR>(k);
}

static element_t Null() { LIMITED_METHOD_CONTRACT; return dac_cast<PTR_MethodDescVersioningState>(nullptr); }
static bool IsNull(const element_t &e) { LIMITED_METHOD_CONTRACT; return e == NULL; }
};

typedef SHash<MethodDescVersioningStateHashTraits> MethodDescVersioningStateHash;

class ILCodeVersioningState
{
public:
Expand Down Expand Up @@ -572,7 +542,7 @@ class CodeVersionManager
friend class ILCodeVersion;

public:
CodeVersionManager();
CodeVersionManager() = default;

DWORD GetNonDefaultILVersionCount();
ILCodeVersionCollection GetILCodeVersions(PTR_MethodDesc pMethod);
Expand Down Expand Up @@ -648,9 +618,6 @@ class CodeVersionManager
//Module,MethodDef -> ILCodeVersioningState
ILCodeVersioningStateHash m_ilCodeVersioningStateMap;

//closed MethodDesc -> MethodDescVersioningState
MethodDescVersioningStateHash m_methodDescVersioningStateMap;

private:
static CrstStatic s_lock;

Expand Down
2 changes: 1 addition & 1 deletion src/coreclr/vm/i386/asmconstants.h
Expand Up @@ -233,7 +233,7 @@ ASMCONSTANTS_C_ASSERT(OFFSETOF__FrameHandlerExRecord__m_pEntryFrame == offsetof(

#endif

#define ComPlusCallMethodDesc__m_pComPlusCallInfo DBG_FRE(0x1C, 0x8)
#define ComPlusCallMethodDesc__m_pComPlusCallInfo DBG_FRE(0x20, 0xC)
ASMCONSTANTS_C_ASSERT(ComPlusCallMethodDesc__m_pComPlusCallInfo == offsetof(ComPlusCallMethodDesc, m_pComPlusCallInfo))

#define ComPlusCallInfo__m_pRetThunk 0x10
Expand Down
29 changes: 29 additions & 0 deletions src/coreclr/vm/method.cpp
Expand Up @@ -209,8 +209,36 @@ LoaderAllocator * MethodDesc::GetDomainSpecificLoaderAllocator()

}

void MethodDesc::AllocateCodeData(LoaderHeap* pHeap, AllocMemTracker* pamTracker)
{
CONTRACTL
{
THROWS;
GC_NOTRIGGER;
PRECONDITION(pHeap != NULL);
PRECONDITION(pamTracker != NULL);
}
CONTRACTL_END;

m_codeData = (MethodDescCodeData*)pamTracker->Track(
pHeap->AllocMem(S_SIZE_T(sizeof(MethodDescCodeData))));
}

bool MethodDesc::SetMethodDescVersionState(PTR_MethodDescVersioningState state)
{
WRAPPER_NO_CONTRACT;
_ASSERTE(m_codeData != NULL);
return InterlockedCompareExchangeT(&m_codeData->MDState, state, NULL) == NULL;
}

#endif //!DACCESS_COMPILE

PTR_MethodDescVersioningState MethodDesc::GetMethodDescVersionState()
{
WRAPPER_NO_CONTRACT;
_ASSERTE(m_codeData != NULL);
return m_codeData->MDState;
}

//*******************************************************************************
LPCUTF8 MethodDesc::GetNameThrowing()
Expand Down Expand Up @@ -1719,6 +1747,7 @@ MethodDescChunk *MethodDescChunk::CreateChunk(LoaderHeap *pHeap, DWORD methodDes
{
pMD->SetChunkIndex(pChunk);
pMD->SetMethodDescIndex(i);
pMD->AllocateCodeData(pHeap, pamTracker);

pMD->SetClassification(classification);
if (fNonVtableSlot)
Expand Down
33 changes: 17 additions & 16 deletions src/coreclr/vm/method.hpp
Expand Up @@ -35,7 +35,6 @@ class Dictionary;
class GCCoverageInfo;
class DynamicMethodDesc;
class ReJitManager;
class CodeVersionManager;
class PrepareCodeConfig;

typedef DPTR(FCallMethodDesc) PTR_FCallMethodDesc;
Expand Down Expand Up @@ -159,6 +158,12 @@ enum MethodDescFlags
mdfIsIntrinsic = 0x8000 // Jit may expand method as an intrinsic
};

struct MethodDescCodeData
{
PTR_MethodDescVersioningState MDState;
};
using PTR_MethodDescCodeData = DPTR(MethodDescCodeData);

// The size of this structure needs to be a multiple of MethodDesc::ALIGNMENT
//
// @GENERICS:
Expand All @@ -177,18 +182,6 @@ enum MethodDescFlags
// It also knows how to get at its IL code (code:IMAGE_COR_ILMETHOD)
class MethodDesc
{
friend class EEClass;
friend class MethodTableBuilder;
friend class ArrayClass;
friend class NDirect;
friend class MethodDescChunk;
friend class InstantiatedMethodDesc;
friend class MethodImpl;
friend class CheckAsmOffsets;
friend class ClrDataAccess;

friend class MethodDescCallSite;

public:

#ifdef TARGET_64BIT
Expand Down Expand Up @@ -1624,6 +1617,7 @@ class MethodDesc

WORD m_wSlotNumber; // The slot number of this MethodDesc in the vtable array.
WORD m_wFlags; // See MethodDescFlags
PTR_MethodDescCodeData m_codeData;

public:
#ifdef DACCESS_COMPILE
Expand All @@ -1632,15 +1626,25 @@ class MethodDesc

BYTE GetMethodDescIndex()
{
LIMITED_METHOD_CONTRACT;
return m_methodIndex;
}

void SetMethodDescIndex(COUNT_T index)
{
LIMITED_METHOD_CONTRACT;
_ASSERTE(index <= 255);
m_methodIndex = (BYTE)index;
}

#ifndef DACCESS_COMPILE
void AllocateCodeData(LoaderHeap* pHeap, AllocMemTracker* pamTracker);

bool SetMethodDescVersionState(PTR_MethodDescVersioningState state);
#endif //!DACCESS_COMPILE

PTR_MethodDescVersioningState GetMethodDescVersionState();

public:
inline DWORD GetClassification() const
{
Expand Down Expand Up @@ -2108,7 +2112,6 @@ class MulticoreJitPrepareCodeConfig : public PrepareCodeConfig
class MethodDescChunk
{
friend class MethodDesc;
friend class CheckAsmOffsets;

enum {
enum_flag_TokenRangeMask = 0x0FFF, // This must equal METHOD_TOKEN_RANGE_MASK calculated higher in this file
Expand Down Expand Up @@ -2411,9 +2414,7 @@ typedef DPTR(DynamicResolver) PTR_DynamicResolver;
class DynamicMethodDesc : public StoredSigMethodDesc
{
friend class ILStubCache;
friend class ILStubState;
friend class DynamicMethodTable;
friend class MethodDesc;

protected:
PTR_CUTF8 m_pszMethodName;
Expand Down
5 changes: 4 additions & 1 deletion src/coreclr/vm/methodtablebuilder.cpp
Expand Up @@ -7039,8 +7039,9 @@ VOID MethodTableBuilder::AllocAndInitMethodDescChunk(COUNT_T startIndex, COUNT_T
PRECONDITION(sizeOfMethodDescs <= MethodDescChunk::MaxSizeOfMethodDescs);
} CONTRACTL_END;

PTR_LoaderHeap pHeap = GetLoaderAllocator()->GetHighFrequencyHeap();
void * pMem = GetMemTracker()->Track(
GetLoaderAllocator()->GetHighFrequencyHeap()->AllocMem(S_SIZE_T(sizeof(TADDR) + sizeof(MethodDescChunk) + sizeOfMethodDescs)));
pHeap->AllocMem(S_SIZE_T(sizeof(TADDR) + sizeof(MethodDescChunk) + sizeOfMethodDescs)));

// Skip pointer to temporary entrypoints
MethodDescChunk * pChunk = (MethodDescChunk *)((BYTE*)pMem + sizeof(TADDR));
Expand All @@ -7065,6 +7066,7 @@ VOID MethodTableBuilder::AllocAndInitMethodDescChunk(COUNT_T startIndex, COUNT_T

pMD->SetChunkIndex(pChunk);
pMD->SetMethodDescIndex(methodDescCount);
pMD->AllocateCodeData(pHeap, GetMemTracker());

InitNewMethodDesc(pMDMethod, pMD);

Expand Down Expand Up @@ -7109,6 +7111,7 @@ VOID MethodTableBuilder::AllocAndInitMethodDescChunk(COUNT_T startIndex, COUNT_T
// Reset the chunk index
pUnboxedMD->SetChunkIndex(pChunk);
pUnboxedMD->SetMethodDescIndex(methodDescCount);
pUnboxedMD->AllocateCodeData(pHeap, GetMemTracker());

if (bmtGenerics->GetNumGenericArgs() == 0) {
pUnboxedMD->SetHasNonVtableSlot();
Expand Down