Hi,

I recently discovered a bug in my IL-rewriting profiler. A method in a generic type is being re-JITted given different generic parameters. For example, the methods MyType<int>.Foobar() and MyType<string>.Foobar() will each be JITted once with unique FunctionIDs but identical mdTokens. Let's say my simplified profiler code looks like

HRESULT
ProfilerCallback::JITCompilationStarted(FunctionID functionID, BOOL isSafeToBlock)
{
    ModuleID moduleID;
    mdToken token;
    LPBYTE original;
    ULONG sz;
    LPBYTE updated;

    fProfilerInfo->getFunctionInfo(functionID, NULL, &moduleID, &token);
    fProfilerInfo->GetILFunctionBody(moduleID, token, (LPCBYTE*)&original, (ULONG*)&sz);

    // ... insert IL equivalent of Console.WriteLine("Hello World");  ...

    fProfilerInfo->SetILFunctionBody(moduleID, token, updated);
    return S_OK;
}

My questions are

1. In the case where MyType<int>.Foobar() and MyType<string>.Foobar() are called, this code would cause MyType<string>.Foobar() to be instrumented twice. When I invoke MyType<string>.Foobar(), "Hello World" would be printed twice. To the callback JITCompilationStarted, modifying IL for (identical) method token fetched from the two (unique) function ID does not make sense, so why is it being JIT-ted multiple times?
2. Did re-JIT just work??? Or was this a lucky accident?

Yitao