[clr-interp] Use getJustMyCodeHandle to gate INTOP_DEBUG_METHOD_ENTER per method
- Dominant language
- C#
- Stars
- 18.3k
- Forks
- 5.6k
- PR merge metrics
- PR metrics pending
Description
## Background
The JIT calls `ICorJitInfo::getJustMyCodeHandle` per method to obtain a per-method flag pointer and emits `if (*pFlag != 0) JIT_DbgIsJustMyCode()` at method entry. The debugger sets the flag only on user-code methods that the stepper is actively interested in, so `OnMethodEnter` fires only when needed and almost always on the thread the stepper is bound to.
The interpreter has no JMC handle plumbing. `INTOP_DEBUG_METHOD_ENTER` is emitted unconditionally on every method (`compiler.cpp:8103`), and the call is gated at runtime on a single global `g_pDebugInterface->IsMethodEnterEnabled()` check (`interpexec.cpp:1432`). `IsMethodEnterEnabled` returns true whenever any stepper has MethodEnter enabled, regardless of thread or method, so the interpreter dispatches `OnMethodEnter` on every method entry on every thread whenever any stepper is active.
This costs a debugger callback per method per thread when only a single stepper on a single thread on a few methods needs it.
## Proposed fix
Mirror the JIT pattern.
1. In `InterpCompiler` for each compiled method, call `m_compHnd->getJustMyCodeHandle(m_methodInfo->ftn, ...)` to obtain a per-method `pFlag` (and indirection if applicable).
2. Replace the unconditional `INTOP_DEBUG_METHOD_ENTER` emission with one of:
- Skip the emission entirely if `getJustMyCodeHandle` returned NULL (method is not subject to JMC).
- Emit a new opcode (or extend `INTOP_DEBUG_METHOD_ENTER`) that takes the `pFlag` as a data item and reads `*pFlag` at runtime, calling `OnMethodEnter` only when non-zero.
3. Drop the global `IsMethodEnterEnabled()` check from `INTOP_DEBUG_METHOD_ENTER` dispatch in `interpexec.cpp` once the per-method flag is in place.
Contributor guide
Assessment
This issue has not been assessed yet.