Skip to content

Commit 1ffa574

Browse files
Fix SuperPMI collect with getIntConfigValue (#53442)
* Fix SuperPMI collect with getIntConfigValue PR #52427 introduced a per-compilation call to getIntConfigValue on "SuperPMIMethodContextNumber". This pseudo-config should not be collected. It exposed a pre-existing multi-threading issue in the superpmi collector shim. I got rid of the per-compilation override of the jithost MethodContext, which is problematic, and currently unneeded, but documented the considerations around collecting per-compilation data. Fixes #53440 * Update src/coreclr/ToolBox/superpmi/superpmi-shim-collector/jithost.cpp Co-authored-by: Kunal Pathak <[email protected]> Co-authored-by: Kunal Pathak <[email protected]>
1 parent 9580011 commit 1ffa574

File tree

3 files changed

+23
-17
lines changed

3 files changed

+23
-17
lines changed

src/coreclr/ToolBox/superpmi/superpmi-shim-collector/icorjitcompiler.cpp

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,6 @@ CorJitResult interceptor_ICJC::compileMethod(ICorJitInfo* comp,
2121
our_ICorJitInfo.original_ICorJitInfo = comp;
2222

2323
auto* mc = new MethodContext();
24-
if (g_ourJitHost != nullptr)
25-
{
26-
g_ourJitHost->setMethodContext(mc);
27-
}
28-
2924
our_ICorJitInfo.mc = mc;
3025
our_ICorJitInfo.mc->cr->recProcessName(GetCommandLineA());
3126

@@ -74,11 +69,6 @@ CorJitResult interceptor_ICJC::compileMethod(ICorJitInfo* comp,
7469

7570
delete mc;
7671

77-
if (g_ourJitHost != nullptr)
78-
{
79-
g_ourJitHost->setMethodContext(g_globalContext);
80-
}
81-
8272
return temp;
8373
}
8474

src/coreclr/ToolBox/superpmi/superpmi-shim-collector/jithost.cpp

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,20 @@
66
#include "spmiutil.h"
77
#include "jithost.h"
88

9+
// There is a single JitHost object created during the one-time initialization of the JIT (function jitStartup),
10+
// and shared amongst all subsequent compilations. Any calls to the getIntConfigValue/getStringConfigValue
11+
// APIs get recorded in a single, global MethodContext/CompileResult, and are copied to the
12+
// per-compilation MethodContext in the shim implementation of compileMethod (using recGlobalContext()).
13+
// This works because the JIT eagerly asks for all config values once, in the one-time jitStartup
14+
// function. If the JIT were to ask for config values later, during the per-compilation phase,
15+
// they would get recorded here in the global MethodContext, and copied to all subsequent
16+
// compilation MethodContexts. This would be incorrect. A solution would be to use a per-compilation
17+
// MethodContext in addition to the global MethodContext, but we have to allow for multi-threading. That is,
18+
// there could be multiple JIT compilations happening concurrently, so we can't just replace the global
19+
// MethodContext with a per-compilation MethodContext. Perhaps per-compilation MethodContext could be
20+
// stored in a map from OS thread id to MethodContext, and looked up here based on thread id. The host APIs
21+
// have no per-compilation knowledge.
22+
923
JitHost* g_ourJitHost;
1024

1125
// RecordVariable: return `true` if the given COMPlus variable `key` should be recorded
@@ -39,11 +53,6 @@ JitHost::JitHost(ICorJitHost* wrappedHost, MethodContext* methodContext) : wrapp
3953
{
4054
}
4155

42-
void JitHost::setMethodContext(MethodContext* methodContext)
43-
{
44-
this->mc = methodContext;
45-
}
46-
4756
void* JitHost::allocateMemory(size_t size)
4857
{
4958
return wrappedHost->allocateMemory(size);
@@ -56,6 +65,15 @@ void JitHost::freeMemory(void* block)
5665

5766
int JitHost::getIntConfigValue(const WCHAR* key, int defaultValue)
5867
{
68+
// Special-case handling: don't collect this pseudo-variable, and don't
69+
// even record that it was called (since it would get recorded into the
70+
// global state). (See the superpmi.exe tool implementation of JitHost::getIntConfigValue()
71+
// for the special-case implementation of this.)
72+
if (wcscmp(key, W("SuperPMIMethodContextNumber")) == 0)
73+
{
74+
return defaultValue;
75+
}
76+
5977
mc->cr->AddCall("getIntConfigValue");
6078
int result = wrappedHost->getIntConfigValue(key, defaultValue);
6179

src/coreclr/ToolBox/superpmi/superpmi-shim-collector/jithost.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ class JitHost : public ICorJitHost
99
public:
1010
JitHost(ICorJitHost* wrappedHost, MethodContext* methodContext);
1111

12-
void setMethodContext(MethodContext* methodContext);
13-
1412
#include "icorjithostimpl.h"
1513

1614
private:

0 commit comments

Comments
 (0)