Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 58 additions & 11 deletions src/ToolBox/superpmi/superpmi/jitinstance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,11 @@ HRESULT JitInstance::StartUp(char* PathToJit,
{
mc = firstContext;
jitHost = new JitHost(*this);
pnjitStartup(jitHost);
if (!callJitStartup(jitHost))
{
LogError("jitStartup failed");
return -1;
}
}

pJitInstance = pngetJit();
Expand Down Expand Up @@ -256,7 +260,11 @@ bool JitInstance::reLoad(MethodContext* firstContext)
{
mc = firstContext;
jitHost = new JitHost(*this);
pnjitStartup(jitHost);
if (!callJitStartup(jitHost))
{
LogError("jitStartup failed");
return false;
}
}

pJitInstance = pngetJit();
Expand Down Expand Up @@ -465,17 +473,56 @@ void JitInstance::freeLongLivedArray(void* array)
HeapFree(ourHeap, 0, array);
}

// Helper for calling pnjitStartup. Needed to allow SEH here.
bool JitInstance::callJitStartup(ICorJitHost* jithost)
{
// Calling into the collection, which could fail, especially
// for altjits. So protect the call.

struct Param : FilterSuperPMIExceptionsParam_CaptureException
{
JitInstance* pThis;
ICorJitHost* jithost;
bool result;
} param;
param.pThis = this;
param.jithost = jithost;
param.result = false;

PAL_TRY(Param*, pParam, &param)
{
pParam->pThis->pnjitStartup(pParam->jithost);
pParam->result = true;
}
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CaptureExceptionAndStop)
{
SpmiException e(&param.exceptionPointers);

LogError("failed to call jitStartup.");
e.ShowAndDeleteMessage();
}
PAL_ENDTRY

return param.result;
}

// Reset JitConfig, that stores Enviroment variables.
bool JitInstance::resetConfig(MethodContext* firstContext)
{
if (pnjitStartup != nullptr)
if (pnjitStartup == nullptr)
{
return false;
}

mc = firstContext;
ICorJitHost* newHost = new JitHost(*this);

if (!callJitStartup(newHost))
{
mc = firstContext;
ICorJitHost* newHost = new JitHost(*this);
pnjitStartup(newHost);
delete static_cast<JitHost*>(jitHost);
jitHost = newHost;
return true;
return false;
}
return false;
}

delete static_cast<JitHost*>(jitHost);
jitHost = newHost;
return true;
}
2 changes: 2 additions & 0 deletions src/ToolBox/superpmi/superpmi/jitinstance.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ class JitInstance
HRESULT StartUp(char* PathToJit, bool copyJit, bool breakOnDebugBreakorAV, MethodContext* firstContext);
bool reLoad(MethodContext* firstContext);

bool callJitStartup(ICorJitHost* newHost);

bool resetConfig(MethodContext* firstContext);

Result CompileMethod(MethodContext* MethodToCompile, int mcIndex, bool collectThroughput);
Expand Down