diff options
Diffstat (limited to 'src/ToolBox/superpmi/superpmi/jitinstance.cpp')
-rw-r--r-- | src/ToolBox/superpmi/superpmi/jitinstance.cpp | 151 |
1 files changed, 73 insertions, 78 deletions
diff --git a/src/ToolBox/superpmi/superpmi/jitinstance.cpp b/src/ToolBox/superpmi/superpmi/jitinstance.cpp index 5003e91f96..e463f82139 100644 --- a/src/ToolBox/superpmi/superpmi/jitinstance.cpp +++ b/src/ToolBox/superpmi/superpmi/jitinstance.cpp @@ -12,9 +12,9 @@ #include "errorhandling.h" #include "spmiutil.h" -JitInstance *JitInstance::InitJit(char *nameOfJit, bool breakOnAssert, SimpleTimer *st1, MethodContext* firstContext) +JitInstance* JitInstance::InitJit(char* nameOfJit, bool breakOnAssert, SimpleTimer* st1, MethodContext* firstContext) { - JitInstance *jit = new JitInstance(); + JitInstance* jit = new JitInstance(); if (jit == nullptr) { LogError("Failed to allocate a JitInstance"); @@ -36,12 +36,15 @@ JitInstance *JitInstance::InitJit(char *nameOfJit, bool breakOnAssert, SimpleTim return jit; } -HRESULT JitInstance::StartUp(char * PathToJit, bool copyJit, bool parambreakOnDebugBreakorAV, MethodContext* firstContext) +HRESULT JitInstance::StartUp(char* PathToJit, + bool copyJit, + bool parambreakOnDebugBreakorAV, + MethodContext* firstContext) { - //startup jit + // startup jit DWORD dwRetVal = 0; - UINT uRetVal = 0; - BOOL bRetVal = FALSE; + UINT uRetVal = 0; + BOOL bRetVal = FALSE; breakOnDebugBreakorAV = parambreakOnDebugBreakorAV; @@ -49,16 +52,16 @@ HRESULT JitInstance::StartUp(char * PathToJit, bool copyJit, bool parambreakOnDe char lpTempPathBuffer[MAX_PATH]; char szTempFileName[MAX_PATH]; -//Get an allocator instance -//Note: we do this to keep cleanup somewhat simple... - ourHeap = ::HeapCreate(0,0,0); - if(ourHeap == nullptr) + // Get an allocator instance + //Note: we do this to keep cleanup somewhat simple... + ourHeap = ::HeapCreate(0, 0, 0); + if (ourHeap == nullptr) { LogError("Failed to get a new heap (0x%08x)", ::GetLastError()); return E_FAIL; } -//find the full jit path + // find the full jit path dwRetVal = ::GetFullPathNameA(PathToJit, MAX_PATH, pFullPathName, nullptr); if (dwRetVal == 0) { @@ -66,18 +69,18 @@ HRESULT JitInstance::StartUp(char * PathToJit, bool copyJit, bool parambreakOnDe return E_FAIL; } -//Store the full path to the jit - PathToOriginalJit = (char *)::HeapAlloc(ourHeap, 0, MAX_PATH); - if(PathToOriginalJit == nullptr) + // Store the full path to the jit + PathToOriginalJit = (char*)::HeapAlloc(ourHeap, 0, MAX_PATH); + if (PathToOriginalJit == nullptr) { LogError("1st HeapAlloc failed (0x%08x)", ::GetLastError()); return E_FAIL; } ::strcpy_s(PathToOriginalJit, MAX_PATH, pFullPathName); - if(copyJit) + if (copyJit) { - //Get a temp file location + // Get a temp file location dwRetVal = ::GetTempPathA(MAX_PATH, lpTempPathBuffer); if (dwRetVal == 0) { @@ -89,7 +92,7 @@ HRESULT JitInstance::StartUp(char * PathToJit, bool copyJit, bool parambreakOnDe LogError("GetTempPath returned a path that was larger than MAX_PATH"); return E_FAIL; } - //Get a temp filename + // Get a temp filename uRetVal = ::GetTempFileNameA(lpTempPathBuffer, "Jit", 0, szTempFileName); if (uRetVal == 0) { @@ -98,16 +101,16 @@ HRESULT JitInstance::StartUp(char * PathToJit, bool copyJit, bool parambreakOnDe } dwRetVal = (DWORD)::strlen(szTempFileName); - //Store the full path to the temp jit - PathToTempJit = (char *)::HeapAlloc(ourHeap, 0, MAX_PATH); - if(PathToTempJit == nullptr) + // Store the full path to the temp jit + PathToTempJit = (char*)::HeapAlloc(ourHeap, 0, MAX_PATH); + if (PathToTempJit == nullptr) { LogError("2nd HeapAlloc failed 0x%08x)", ::GetLastError()); return E_FAIL; } ::strcpy_s(PathToTempJit, MAX_PATH, szTempFileName); - //Copy Temp File + // Copy Temp File bRetVal = ::CopyFileA(PathToOriginalJit, PathToTempJit, FALSE); if (bRetVal == FALSE) { @@ -119,25 +122,25 @@ HRESULT JitInstance::StartUp(char * PathToJit, bool copyJit, bool parambreakOnDe PathToTempJit = PathToOriginalJit; #ifndef FEATURE_PAL // No file version APIs in the PAL - //Do a quick version check + // Do a quick version check DWORD dwHandle = 0; - DWORD fviSize = GetFileVersionInfoSizeA(PathToTempJit, &dwHandle); + DWORD fviSize = GetFileVersionInfoSizeA(PathToTempJit, &dwHandle); - if ((fviSize != 0)&&(dwHandle==0)) + if ((fviSize != 0) && (dwHandle == 0)) { - unsigned char *fviData = new unsigned char[fviSize]; + unsigned char* fviData = new unsigned char[fviSize]; if (GetFileVersionInfoA(PathToTempJit, dwHandle, fviSize, fviData)) { - UINT size = 0; - VS_FIXEDFILEINFO *verInfo = nullptr; + UINT size = 0; + VS_FIXEDFILEINFO* verInfo = nullptr; if (VerQueryValueA(fviData, "\\", (LPVOID*)&verInfo, &size)) { if (size) { if (verInfo->dwSignature == 0xfeef04bd) - LogDebug("'%s' is version %u.%u.%u.%u", PathToTempJit, - (verInfo->dwFileVersionMS)>>16, (verInfo->dwFileVersionMS)&0xFFFF, - (verInfo->dwFileVersionLS)>>16, (verInfo->dwFileVersionLS)&0xFFFF); + LogDebug("'%s' is version %u.%u.%u.%u", PathToTempJit, (verInfo->dwFileVersionMS) >> 16, + (verInfo->dwFileVersionMS) & 0xFFFF, (verInfo->dwFileVersionLS) >> 16, + (verInfo->dwFileVersionLS) & 0xFFFF); } } } @@ -145,43 +148,43 @@ HRESULT JitInstance::StartUp(char * PathToJit, bool copyJit, bool parambreakOnDe } #endif // !FEATURE_PAL -//Load Library + // Load Library hLib = ::LoadLibraryA(PathToTempJit); - if(hLib == 0) + if (hLib == 0) { LogError("LoadLibrary failed (0x%08x)", ::GetLastError()); return E_FAIL; } -//get entry points + // get entry points pngetJit = (PgetJit)::GetProcAddress(hLib, "getJit"); - if(pngetJit == 0) + if (pngetJit == 0) { LogError("GetProcAddress 'getJit' failed (0x%08x)", ::GetLastError()); return -1; } pnsxsJitStartup = (PsxsJitStartup)::GetProcAddress(hLib, "sxsJitStartup"); - if(pnsxsJitStartup == 0) + if (pnsxsJitStartup == 0) { LogError("GetProcAddress 'sxsJitStartup' failed (0x%08x)", ::GetLastError()); return -1; } pnjitStartup = (PjitStartup)::GetProcAddress(hLib, "jitStartup"); - //Setup CoreClrCallbacks and call sxsJitStartup - CoreClrCallbacks *cccallbacks = InitCoreClrCallbacks(); + // Setup CoreClrCallbacks and call sxsJitStartup + CoreClrCallbacks* cccallbacks = InitCoreClrCallbacks(); pnsxsJitStartup(*cccallbacks); // Setup ICorJitHost and call jitStartup if necessary if (pnjitStartup != nullptr) { - mc = firstContext; + mc = firstContext; jitHost = new JitHost(*this); pnjitStartup(jitHost); } pJitInstance = pngetJit(); - if(pJitInstance == nullptr) + if (pJitInstance == nullptr) { LogError("pngetJit gave us null"); return -1; @@ -202,7 +205,6 @@ HRESULT JitInstance::StartUp(char * PathToJit, bool copyJit, bool parambreakOnDe return -1; } - icji = InitICorJitInfo(this); return S_OK; @@ -212,43 +214,43 @@ bool JitInstance::reLoad(MethodContext* firstContext) { FreeLibrary(hLib); -//Load Library + // Load Library hLib = ::LoadLibraryA(PathToTempJit); - if(hLib == 0) + if (hLib == 0) { LogError("LoadLibrary failed (0x%08x)", ::GetLastError()); return false; } -//get entry points + // get entry points pngetJit = (PgetJit)::GetProcAddress(hLib, "getJit"); - if(pngetJit == 0) + if (pngetJit == 0) { LogError("GetProcAddress 'getJit' failed (0x%08x)", ::GetLastError()); return false; } pnsxsJitStartup = (PsxsJitStartup)::GetProcAddress(hLib, "sxsJitStartup"); - if(pnsxsJitStartup == 0) + if (pnsxsJitStartup == 0) { LogError("GetProcAddress 'sxsJitStartup' failed (0x%08x)", ::GetLastError()); return false; } pnjitStartup = (PjitStartup)::GetProcAddress(hLib, "jitStartup"); - //Setup CoreClrCallbacks and call sxsJitStartup - CoreClrCallbacks *cccallbacks = InitCoreClrCallbacks(); + // Setup CoreClrCallbacks and call sxsJitStartup + CoreClrCallbacks* cccallbacks = InitCoreClrCallbacks(); pnsxsJitStartup(*cccallbacks); // Setup ICorJitHost and call jitStartup if necessary if (pnjitStartup != nullptr) { - mc = firstContext; + mc = firstContext; jitHost = new JitHost(*this); pnjitStartup(jitHost); } pJitInstance = pngetJit(); - if(pJitInstance == nullptr) + if (pJitInstance == nullptr) { LogError("pngetJit gave us null"); return false; @@ -259,7 +261,7 @@ bool JitInstance::reLoad(MethodContext* firstContext) return true; } -JitInstance::Result JitInstance::CompileMethod(MethodContext *MethodToCompile, int mcIndex, bool collectThroughput) +JitInstance::Result JitInstance::CompileMethod(MethodContext* MethodToCompile, int mcIndex, bool collectThroughput) { struct Param : FilterSuperPMIExceptionsParam_CaptureException { @@ -270,24 +272,24 @@ JitInstance::Result JitInstance::CompileMethod(MethodContext *MethodToCompile, i int mcIndex; bool collectThroughput; } param; - param.pThis = this; - param.result = RESULT_SUCCESS; // assume success - param.flags = 0; - param.mcIndex = mcIndex; + param.pThis = this; + param.result = RESULT_SUCCESS; // assume success + param.flags = 0; + param.mcIndex = mcIndex; param.collectThroughput = collectThroughput; - //store to instance field our raw values, so we can figure things out a bit later... + // store to instance field our raw values, so we can figure things out a bit later... mc = MethodToCompile; times[0] = 0; times[1] = 0; - mc->repEnvironmentSet(); //Sets envvars + mc->repEnvironmentSet(); // Sets envvars stj.Start(); PAL_TRY(Param*, pParam, ¶m) { - BYTE *NEntryBlock = nullptr; + BYTE* NEntryBlock = nullptr; ULONG NCodeSizeBlock = 0; pParam->pThis->mc->repCompileMethod(&pParam->info, &pParam->flags); @@ -295,7 +297,8 @@ JitInstance::Result JitInstance::CompileMethod(MethodContext *MethodToCompile, i { pParam->pThis->lt.Start(); } - CorJitResult temp = pParam->pThis->pJitInstance->compileMethod(pParam->pThis->icji, &pParam->info, pParam->flags, &NEntryBlock, &NCodeSizeBlock); + CorJitResult temp = pParam->pThis->pJitInstance->compileMethod(pParam->pThis->icji, &pParam->info, + pParam->flags, &NEntryBlock, &NCodeSizeBlock); if (pParam->collectThroughput) { pParam->pThis->lt.Stop(); @@ -308,7 +311,7 @@ JitInstance::Result JitInstance::CompileMethod(MethodContext *MethodToCompile, i } if (temp == CORJIT_OK) { - //capture the results of compilation + // capture the results of compilation pParam->pThis->mc->cr->recCompileMethod(&NEntryBlock, &NCodeSizeBlock, temp); pParam->pThis->mc->cr->recAllocMemCapture(); pParam->pThis->mc->cr->recAllocGCInfoCapture(); @@ -327,7 +330,7 @@ JitInstance::Result JitInstance::CompileMethod(MethodContext *MethodToCompile, i if (e.GetCode() == EXCEPTIONCODE_MC) { - char *message = e.GetExceptionMessage(); + char* message = e.GetExceptionMessage(); LogMissing("Method context %d failed to replay: %s", mcIndex, message); e.DeleteMessage(); param.result = RESULT_MISSING; @@ -346,7 +349,7 @@ JitInstance::Result JitInstance::CompileMethod(MethodContext *MethodToCompile, i // If we get here, we know it compiles timeResult(param.info, param.flags); } - mc->repEnvironmentUnset(); //Unsets envvars + mc->repEnvironmentUnset(); // Unsets envvars mc->cr->secondsToCompile = stj.GetSeconds(); @@ -355,7 +358,7 @@ JitInstance::Result JitInstance::CompileMethod(MethodContext *MethodToCompile, i void JitInstance::timeResult(CORINFO_METHOD_INFO info, unsigned flags) { - BYTE *NEntryBlock = nullptr; + BYTE* NEntryBlock = nullptr; ULONG NCodeSizeBlock = 0; int sampleSize = 10; @@ -398,39 +401,31 @@ void JitInstance::timeResult(CORINFO_METHOD_INFO info, unsigned flags) // Used to allocate memory that needs to handed to the EE. // For eg, use this to allocated memory for reporting debug info, // which will be handed to the EE by setVars() and setBoundaries() -void * JitInstance::allocateArray( - ULONG cBytes - ) +void* JitInstance::allocateArray(ULONG cBytes) { mc->cr->AddCall("allocateArray"); - return HeapAlloc(mc->cr->getCodeHeap(),0,cBytes); + return HeapAlloc(mc->cr->getCodeHeap(), 0, cBytes); } // Used to allocate memory that needs to live as long as the jit // instance does. -void * JitInstance::allocateLongLivedArray( - ULONG cBytes - ) +void* JitInstance::allocateLongLivedArray(ULONG cBytes) { - return HeapAlloc(ourHeap,0,cBytes); + return HeapAlloc(ourHeap, 0, cBytes); } // JitCompiler will free arrays passed by the EE using this // For eg, The EE returns memory in getVars() and getBoundaries() // to the JitCompiler, which the JitCompiler should release using // freeArray() -void JitInstance::freeArray( - void *array - ) +void JitInstance::freeArray(void* array) { mc->cr->AddCall("freeArray"); - HeapFree(mc->cr->getCodeHeap(),0,array); + HeapFree(mc->cr->getCodeHeap(), 0, array); } // Used to free memory allocated by JitInstance::allocateLongLivedArray. -void JitInstance::freeLongLivedArray( - void *array - ) +void JitInstance::freeLongLivedArray(void* array) { - HeapFree(ourHeap,0,array); + HeapFree(ourHeap, 0, array); } |