diff --git a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp index 74040dc5aa3be..c49182402648c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.cpp @@ -65,12 +65,18 @@ bool CompileResult::IsEmpty() return isEmpty; } -// Allocate memory associated with this CompileResult. Keep track of it in a list so we can free it all later. -void* CompileResult::allocateMemory(size_t sizeInBytes) +MemoryTracker* CompileResult::getOrCreateMemoryTracker() { if (memoryTracker == nullptr) memoryTracker = new MemoryTracker(); - return memoryTracker->allocate(sizeInBytes); + + return memoryTracker; +} + +// Allocate memory associated with this CompileResult. Keep track of it in a list so we can free it all later. +void* CompileResult::allocateMemory(size_t sizeInBytes) +{ + return getOrCreateMemoryTracker()->allocate(sizeInBytes); } void CompileResult::recAssert(const char* assertText) @@ -1259,7 +1265,7 @@ bool CompileResult::fndRecordCallSiteSigInfo(ULONG instrOffset, CORINFO_SIG_INFO if (value.callSig.callConv == (DWORD)-1) return false; - *pCallSig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.callSig, RecordCallSiteWithSignature, CrSigInstHandleMap); + *pCallSig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.callSig, RecordCallSiteWithSignature, CrSigInstHandleMap, getOrCreateMemoryTracker()); return true; } diff --git a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.h b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.h index 72415f1d38f59..5326be7d8dd16 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/compileresult.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/compileresult.h @@ -229,6 +229,7 @@ class CompileResult // not persisted to disk. public: LightWeightMap* CallTargetTypes; + MemoryTracker* getOrCreateMemoryTracker(); private: MemoryTracker* memoryTracker; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp index 53bb5a2f00c42..e818afbac539c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.cpp @@ -696,8 +696,8 @@ void MethodContext::repCompileMethod(CORINFO_METHOD_INFO* info, unsigned* flags, info->options = (CorInfoOptions)value.info.options; info->regionKind = (CorInfoRegionKind)value.info.regionKind; - info->args = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.args, CompileMethod, SigInstHandleMap); - info->locals = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.locals, CompileMethod, SigInstHandleMap); + info->args = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.args, CompileMethod, SigInstHandleMap, cr->getOrCreateMemoryTracker()); + info->locals = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.locals, CompileMethod, SigInstHandleMap, cr->getOrCreateMemoryTracker()); *flags = (unsigned)value.flags; *os = (CORINFO_OS)value.os; @@ -1572,7 +1572,7 @@ void MethodContext::repGetCallInfo(CORINFO_RESOLVED_TOKEN* pResolvedToken, pResult->methodFlags |= CORINFO_FLG_DONT_INLINE; pResult->classFlags = (unsigned)value.classFlags; - pResult->sig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.sig, GetCallInfo, SigInstHandleMap); + pResult->sig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.sig, GetCallInfo, SigInstHandleMap, cr->getOrCreateMemoryTracker()); pResult->accessAllowed = (CorInfoIsAccessAllowedResult)value.accessAllowed; pResult->callsiteCalloutHelper.helperNum = (CorInfoHelpFunc)value.callsiteCalloutHelper.helperNum; pResult->callsiteCalloutHelper.numArgs = (unsigned)value.callsiteCalloutHelper.numArgs; @@ -2905,7 +2905,7 @@ void MethodContext::repGetMethodSig(CORINFO_METHOD_HANDLE ftn, CORINFO_SIG_INFO* DEBUG_REP(dmpGetMethodSig(key, value)); - *sig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value, GetMethodSig, SigInstHandleMap); + *sig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value, GetMethodSig, SigInstHandleMap, cr->getOrCreateMemoryTracker()); } void MethodContext::recGetArgClass(CORINFO_SIG_INFO* sig, @@ -3060,8 +3060,8 @@ bool MethodContext::repGetMethodInfo(CORINFO_METHOD_HANDLE ftn, CORINFO_METHOD_I info->options = (CorInfoOptions)value.info.options; info->regionKind = (CorInfoRegionKind)value.info.regionKind; - info->args = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.args, GetMethodInfo, SigInstHandleMap); - info->locals = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.locals, GetMethodInfo, SigInstHandleMap); + info->args = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.args, GetMethodInfo, SigInstHandleMap, cr->getOrCreateMemoryTracker()); + info->locals = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value.info.locals, GetMethodInfo, SigInstHandleMap, cr->getOrCreateMemoryTracker()); } bool result = value.result; *exceptionCode = (DWORD)value.exceptionCode; @@ -4320,7 +4320,7 @@ void MethodContext::repFindSig(CORINFO_MODULE_HANDLE moduleHandle, DEBUG_REP(dmpFindSig(key, value)); - *sig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value, FindSig, SigInstHandleMap); + *sig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value, FindSig, SigInstHandleMap, cr->getOrCreateMemoryTracker()); } void MethodContext::recGetEEInfo(CORINFO_EE_INFO* pEEInfoOut) @@ -5388,7 +5388,7 @@ void MethodContext::repFindCallSiteSig(CORINFO_MODULE_HANDLE module, DEBUG_REP(dmpFindCallSiteSig(key, value)); - *sig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value, FindCallSiteSig, SigInstHandleMap); + *sig = SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(value, FindCallSiteSig, SigInstHandleMap, cr->getOrCreateMemoryTracker()); } void MethodContext::recGetMethodSync(CORINFO_METHOD_HANDLE ftn, void** ppIndirection, void* result) diff --git a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h index 679fa2e0355e1..669455c729939 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/methodcontext.h @@ -920,7 +920,6 @@ class MethodContext } CompileResult* cr; - CompileResult* originalCR; int index; bool ignoreStoredConfig; diff --git a/src/coreclr/tools/superpmi/superpmi-shared/spmirecordhelper.h b/src/coreclr/tools/superpmi/superpmi-shared/spmirecordhelper.h index 1214894b231ab..dbf074996c98c 100644 --- a/src/coreclr/tools/superpmi/superpmi-shared/spmirecordhelper.h +++ b/src/coreclr/tools/superpmi/superpmi-shared/spmirecordhelper.h @@ -77,19 +77,22 @@ class SpmiRecordsHelper DWORD handleInstCount, DWORD handleInstIndex, const DenseLightWeightMap* handleMap, + MemoryTracker* memoryTracker, /* OUT */ unsigned* handleInstCountOut, /* OUT */ CORINFO_CLASS_HANDLE** handleInstArrayOut); static void DeserializeCORINFO_SIG_INST( CORINFO_SIG_INFO& sigInfoOut, const Agnostic_CORINFO_SIG_INFO& sigInfo, - const DenseLightWeightMap* handleMap); + const DenseLightWeightMap* handleMap, + MemoryTracker* memoryTracker); template static CORINFO_SIG_INFO Restore_CORINFO_SIG_INFO( const Agnostic_CORINFO_SIG_INFO& sigInfo, LightWeightMap* buffers, - const DenseLightWeightMap* handleMap); + const DenseLightWeightMap* handleMap, + MemoryTracker* memoryTracker); static Agnostic_CORINFO_LOOKUP_KIND CreateAgnostic_CORINFO_LOOKUP_KIND( const CORINFO_LOOKUP_KIND* pGenericLookupKind); @@ -381,6 +384,7 @@ inline void SpmiRecordsHelper::DeserializeCORINFO_SIG_INST_HandleArray( DWORD handleInstCount, DWORD handleInstIndex, const DenseLightWeightMap* handleMap, + MemoryTracker* memoryTracker, /* OUT */ unsigned* handleInstCountOut, /* OUT */ CORINFO_CLASS_HANDLE** handleInstArrayOut) { @@ -388,7 +392,7 @@ inline void SpmiRecordsHelper::DeserializeCORINFO_SIG_INST_HandleArray( if (handleInstCount > 0) { - handleInstArray = new CORINFO_CLASS_HANDLE[handleInstCount]; // memory leak? + handleInstArray = (CORINFO_CLASS_HANDLE*)memoryTracker->allocate(handleInstCount * sizeof(CORINFO_CLASS_HANDLE)); for (unsigned int i = 0; i < handleInstCount; i++) { DWORD key = handleInstIndex + i; @@ -405,16 +409,17 @@ inline void SpmiRecordsHelper::DeserializeCORINFO_SIG_INST_HandleArray( } inline void SpmiRecordsHelper::DeserializeCORINFO_SIG_INST( - CORINFO_SIG_INFO& sigInfoOut, const Agnostic_CORINFO_SIG_INFO& sigInfo, const DenseLightWeightMap* handleMap) + CORINFO_SIG_INFO& sigInfoOut, const Agnostic_CORINFO_SIG_INFO& sigInfo, const DenseLightWeightMap* handleMap, MemoryTracker* memoryTracker) { - DeserializeCORINFO_SIG_INST_HandleArray(sigInfo.sigInst_classInstCount, sigInfo.sigInst_classInst_Index, handleMap, &sigInfoOut.sigInst.classInstCount, &sigInfoOut.sigInst.classInst); - DeserializeCORINFO_SIG_INST_HandleArray(sigInfo.sigInst_methInstCount, sigInfo.sigInst_methInst_Index, handleMap, &sigInfoOut.sigInst.methInstCount, &sigInfoOut.sigInst.methInst); + DeserializeCORINFO_SIG_INST_HandleArray(sigInfo.sigInst_classInstCount, sigInfo.sigInst_classInst_Index, handleMap, memoryTracker, &sigInfoOut.sigInst.classInstCount, &sigInfoOut.sigInst.classInst); + DeserializeCORINFO_SIG_INST_HandleArray(sigInfo.sigInst_methInstCount, sigInfo.sigInst_methInst_Index, handleMap, memoryTracker, &sigInfoOut.sigInst.methInstCount, &sigInfoOut.sigInst.methInst); } template inline CORINFO_SIG_INFO SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(const Agnostic_CORINFO_SIG_INFO& sigInfo, LightWeightMap* buffers, - const DenseLightWeightMap* handleMap) + const DenseLightWeightMap* handleMap, + MemoryTracker* memoryTracker) { CORINFO_SIG_INFO sig; sig.callConv = (CorInfoCallConv)sigInfo.callConv; @@ -430,7 +435,7 @@ inline CORINFO_SIG_INFO SpmiRecordsHelper::Restore_CORINFO_SIG_INFO(const Agnost sig.scope = (CORINFO_MODULE_HANDLE)sigInfo.scope; sig.token = (mdToken)sigInfo.token; - DeserializeCORINFO_SIG_INST(sig, sigInfo, handleMap); + DeserializeCORINFO_SIG_INST(sig, sigInfo, handleMap, memoryTracker); return sig; } diff --git a/src/coreclr/tools/superpmi/superpmi/superpmi.cpp b/src/coreclr/tools/superpmi/superpmi/superpmi.cpp index 1286a06ef03b3..012c433977282 100644 --- a/src/coreclr/tools/superpmi/superpmi/superpmi.cpp +++ b/src/coreclr/tools/superpmi/superpmi/superpmi.cpp @@ -417,9 +417,6 @@ int __cdecl main(int argc, char* argv[]) continue; } - // Save the stored CompileResult - mc->originalCR = mc->cr; - // Compile this method context as many times as we have been asked to (default is once). for (int iter = 0; iter < o.repeatCount; iter++) { @@ -446,10 +443,6 @@ int __cdecl main(int argc, char* argv[]) } } - // Create a new CompileResult for this compilation (the CompileResult from the stored file is - // in originalCR if necessary). - mc->cr = new CompileResult(); - // For asm diffs, we need to store away the CompileResult generated by the first JIT when compiling // with the 2nd JIT. CompileResult* crl = nullptr; @@ -776,6 +769,11 @@ int __cdecl main(int argc, char* argv[]) } delete crl; + + if (iter + 1 < o.repeatCount) + { + mc->Reset(); + } } delete mc;