Fix spurious SuperPMI asm diffs (#86132)
authorBruce Forstall <brucefo@microsoft.com>
Fri, 12 May 2023 04:02:48 +0000 (21:02 -0700)
committerGitHub <noreply@github.com>
Fri, 12 May 2023 04:02:48 +0000 (21:02 -0700)
Under ELT profiler stress, we encode the un-relocated address
of the `DummyProfilerELTStub` function in the JIT codebase into
the generated code. This can lead to spurious diffs if the address
is different between base and diff JITs (which is likely).

To avoid this, under SuperPMI replay (which we only know in DEBUG
builds currently), use a fixed constant for this address. The code
isn't executed during SuperPMI replay, so it doesn't need to be a
valid code address.

src/coreclr/jit/compiler.cpp
src/coreclr/jit/compiler.h

index ac817b3..1935e31 100644 (file)
@@ -3149,7 +3149,25 @@ void Compiler::compInitOptions(JitFlags* jitFlags)
     // TBD: Exclude PInvoke stubs
     if (opts.compJitELTHookEnabled)
     {
-        compProfilerMethHnd           = (void*)DummyProfilerELTStub;
+#if defined(DEBUG) // We currently only know if we're running under SuperPMI in DEBUG
+        // We don't want to get spurious SuperPMI asm diffs because profile stress kicks in and we use
+        // the address of `DummyProfilerELTStub` in the JIT binary, without relocation. So just use
+        // a fixed address in this case. It's SuperPMI replay, so the generated code won't be run.
+        if (RunningSuperPmiReplay())
+        {
+#ifdef HOST_64BIT
+            static_assert_no_msg(sizeof(void*) == 8);
+            compProfilerMethHnd = (void*)0x0BADF00DBEADCAFE;
+#else
+            static_assert_no_msg(sizeof(void*) == 4);
+            compProfilerMethHnd = (void*)0x0BADF00D;
+#endif
+        }
+        else
+#endif // DEBUG
+        {
+            compProfilerMethHnd = (void*)DummyProfilerELTStub;
+        }
         compProfilerMethHndIndirected = false;
     }
 
index 60e2129..02bf9d2 100644 (file)
@@ -9919,6 +9919,14 @@ public:
 
     } info;
 
+#if defined(DEBUG)
+    // Are we running a replay under SuperPMI?
+    bool RunningSuperPmiReplay() const
+    {
+        return info.compMethodSuperPMIIndex != -1;
+    }
+#endif // DEBUG
+
     ReturnTypeDesc compRetTypeDesc; // ABI return type descriptor for the method
 
     //------------------------------------------------------------------------