diff --git a/src/coreclr/vm/amd64/asmconstants.h b/src/coreclr/vm/amd64/asmconstants.h index f51f3b00836b76..3e2c50cd61131a 100644 --- a/src/coreclr/vm/amd64/asmconstants.h +++ b/src/coreclr/vm/amd64/asmconstants.h @@ -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 diff --git a/src/coreclr/vm/codeversion.cpp b/src/coreclr/vm/codeversion.cpp index ea95e274419cef..96ce1ea28d2375 100644 --- a/src/coreclr/vm/codeversion.cpp +++ b/src/coreclr/vm/codeversion.cpp @@ -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; @@ -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 @@ -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; diff --git a/src/coreclr/vm/codeversion.h b/src/coreclr/vm/codeversion.h index a6fabc38c99a08..391137a142d1a3 100644 --- a/src/coreclr/vm/codeversion.h +++ b/src/coreclr/vm/codeversion.h @@ -475,36 +475,6 @@ class MethodDescVersioningState PTR_NativeCodeVersionNode m_pFirstVersionNode; }; -class MethodDescVersioningStateHashTraits : public NoRemoveSHashTraits> -{ -public: - typedef typename DefaultSHashTraits::element_t element_t; - typedef typename DefaultSHashTraits::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(k); - } - - static element_t Null() { LIMITED_METHOD_CONTRACT; return dac_cast(nullptr); } - static bool IsNull(const element_t &e) { LIMITED_METHOD_CONTRACT; return e == NULL; } -}; - -typedef SHash MethodDescVersioningStateHash; - class ILCodeVersioningState { public: @@ -572,7 +542,7 @@ class CodeVersionManager friend class ILCodeVersion; public: - CodeVersionManager(); + CodeVersionManager() = default; DWORD GetNonDefaultILVersionCount(); ILCodeVersionCollection GetILCodeVersions(PTR_MethodDesc pMethod); @@ -648,9 +618,6 @@ class CodeVersionManager //Module,MethodDef -> ILCodeVersioningState ILCodeVersioningStateHash m_ilCodeVersioningStateMap; - //closed MethodDesc -> MethodDescVersioningState - MethodDescVersioningStateHash m_methodDescVersioningStateMap; - private: static CrstStatic s_lock; diff --git a/src/coreclr/vm/i386/asmconstants.h b/src/coreclr/vm/i386/asmconstants.h index 475a0f857ebd98..c1a577caa0f864 100644 --- a/src/coreclr/vm/i386/asmconstants.h +++ b/src/coreclr/vm/i386/asmconstants.h @@ -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 diff --git a/src/coreclr/vm/method.cpp b/src/coreclr/vm/method.cpp index bbbed6bd33a486..c882f9c2c8e945 100644 --- a/src/coreclr/vm/method.cpp +++ b/src/coreclr/vm/method.cpp @@ -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() @@ -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) diff --git a/src/coreclr/vm/method.hpp b/src/coreclr/vm/method.hpp index ad662fa9607495..49ffbb0a1e155e 100644 --- a/src/coreclr/vm/method.hpp +++ b/src/coreclr/vm/method.hpp @@ -35,7 +35,6 @@ class Dictionary; class GCCoverageInfo; class DynamicMethodDesc; class ReJitManager; -class CodeVersionManager; class PrepareCodeConfig; typedef DPTR(FCallMethodDesc) PTR_FCallMethodDesc; @@ -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: @@ -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 @@ -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 @@ -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 { @@ -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 @@ -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; diff --git a/src/coreclr/vm/methodtablebuilder.cpp b/src/coreclr/vm/methodtablebuilder.cpp index db015d227538e2..b60be41230f571 100644 --- a/src/coreclr/vm/methodtablebuilder.cpp +++ b/src/coreclr/vm/methodtablebuilder.cpp @@ -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)); @@ -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); @@ -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();