Skip to content

Commit b069719

Browse files
authored
Fix method context number seen by the jit with parallel SPMI (#51753)
The jit can see the SPMI method context number by querying the jit host for `SuperPMIMethodContextNumber`. Update the way this value is computed, so it gives the same answer when running SPMI in parallel that it does when running serially.
1 parent 603dac4 commit b069719

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,24 @@ unsigned int MethodContext::saveToFile(HANDLE hFile)
180180
// (and sets *ppmc with new MethodContext), false on failure.
181181
//
182182
// static
183-
bool MethodContext::Initialize(int loadedCount, unsigned char* buff, DWORD size, /* OUT */ MethodContext** ppmc)
183+
bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size, /* OUT */ MethodContext** ppmc)
184184
{
185185
MethodContext* mc = new MethodContext();
186-
mc->index = loadedCount;
186+
mc->index = mcIndex;
187187
*ppmc = mc;
188-
return mc->Initialize(loadedCount, buff, size);
188+
return mc->Initialize(mcIndex, buff, size);
189189
}
190190

191191
// static
192-
bool MethodContext::Initialize(int loadedCount, HANDLE hFile, /* OUT */ MethodContext** ppmc)
192+
bool MethodContext::Initialize(int mcIndex, HANDLE hFile, /* OUT */ MethodContext** ppmc)
193193
{
194194
MethodContext* mc = new MethodContext();
195-
mc->index = loadedCount;
195+
mc->index = mcIndex;
196196
*ppmc = mc;
197-
return mc->Initialize(loadedCount, hFile);
197+
return mc->Initialize(mcIndex, hFile);
198198
}
199199

200-
bool MethodContext::Initialize(int loadedCount, unsigned char* buff, DWORD size)
200+
bool MethodContext::Initialize(int mcIndex, unsigned char* buff, DWORD size)
201201
{
202202
bool result = true;
203203

@@ -217,15 +217,15 @@ bool MethodContext::Initialize(int loadedCount, unsigned char* buff, DWORD size)
217217
}
218218
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CatchMC)
219219
{
220-
LogError("Method %d is of low integrity.", loadedCount);
220+
LogError("Method %d is of low integrity.", mcIndex);
221221
result = false;
222222
}
223223
PAL_ENDTRY
224224

225225
return result;
226226
}
227227

228-
bool MethodContext::Initialize(int loadedCount, HANDLE hFile)
228+
bool MethodContext::Initialize(int mcIndex, HANDLE hFile)
229229
{
230230
bool result = true;
231231

@@ -243,7 +243,7 @@ bool MethodContext::Initialize(int loadedCount, HANDLE hFile)
243243
}
244244
PAL_EXCEPT_FILTER(FilterSuperPMIExceptions_CatchMC)
245245
{
246-
LogError("Method %d is of low integrity.", loadedCount);
246+
LogError("Method %d is of low integrity.", mcIndex);
247247
result = false;
248248
}
249249
PAL_ENDTRY

src/coreclr/ToolBox/superpmi/superpmi-shared/methodcontext.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -72,14 +72,14 @@ class MethodContext
7272
void MethodInitHelper(unsigned char* buff, unsigned int totalLen);
7373
void MethodInitHelperFile(HANDLE hFile);
7474

75-
bool Initialize(int loadedCount, unsigned char* buff, DWORD size);
76-
bool Initialize(int loadedCount, HANDLE hFile);
75+
bool Initialize(int mcIndex, unsigned char* buff, DWORD size);
76+
bool Initialize(int mcIndex, HANDLE hFile);
7777

7878
int dumpMD5HashToBuffer(BYTE* pBuffer, int bufLen, char* buff, int len);
7979

8080
public:
81-
static bool Initialize(int loadedCount, unsigned char* buff, DWORD size, /* OUT */ MethodContext** ppmc);
82-
static bool Initialize(int loadedCount, HANDLE hFile, /* OUT */ MethodContext** ppmc);
81+
static bool Initialize(int mcIndex, unsigned char* buff, DWORD size, /* OUT */ MethodContext** ppmc);
82+
static bool Initialize(int mcIndex, HANDLE hFile, /* OUT */ MethodContext** ppmc);
8383
~MethodContext();
8484
void Destroy();
8585

src/coreclr/ToolBox/superpmi/superpmi/superpmi.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,8 @@ int __cdecl main(int argc, char* argv[])
293293
// Now read the data into a MethodContext. This could throw if the method context data is corrupt.
294294

295295
loadedCount++;
296-
if (!MethodContext::Initialize(loadedCount, mcb.buff, mcb.size, &mc))
296+
const int mcIndex = reader->GetMethodContextIndex();
297+
if (!MethodContext::Initialize(mcIndex, mcb.buff, mcb.size, &mc))
297298
{
298299
return (int)SpmiResult::GeneralFailure;
299300
}

0 commit comments

Comments
 (0)