Repository: dotnet/runtime
File: src/coreclr/vm/jitinterface.cpp (C++)

Code before:

    PCODE ret = (PCODE)NULL;
    NormalizedTimer timer;
    int64_t c100nsTicksInJit = 0;

    COOPERATIVE_TRANSITION_BEGIN();

    LogJitMethodBegin(ftn);

    timer.Start();

    ULONG sizeOfILCode = 0;

#ifdef FEATURE_INTERPRETER
    InterpreterJitManager* interpreterMgr = ExecutionManager::GetInterpreterJitManager();
    if (!interpreterMgr->IsInterpreterLoaded() && g_pConfig->EnableInterpreter())
    {
        if (
            !interpreterMgr->LoadInterpreter())
        {
            EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_EXECUTIONENGINE, W("Failed to load interpreter"));
        }
    }

    // If the interpreter was loaded, use it.
    if (interpreterMgr->IsInterpreterLoaded() && (!ftn->IsILStub() || !ftn->AsDynamicMethodDesc()->IsAsyncResumeStub())) // Async resume stubs cannot be generated by the interpreter
    {
        CInterpreterJitInfo interpreterJitInfo{ config, ftn, ILHeader, interpreterMgr };
        ret = UnsafeJitFunctionWorker(interpreterMgr, &interpreterJitInfo, nativeCodeVersion, pSizeOfCode);

        // If successful, record data.
        if (ret)
        {
            sizeOfILCode = interpreterJitInfo.getMethodInfoInternal()->ILCodeSize;

#ifdef FEATURE_PORTABLE_ENTRYPOINTS
            PCODE portableEntryPoint = ftn->GetPortableEntryPoint();
            _ASSERTE(portableEntryPoint != NULL);
            PortableEntryPoint::SetInterpreterData(portableEntryPoint, ret);
            ret = portableEntryPoint;

#else // !FEATURE_PORTABLE_ENTRYPOINTS
            InterpreterPrecode* pPrecode = NULL;
            AllocMemTracker amt;
            if (ftn->IsDynamicMethod())
            {
                // For LCG methods, the precode is stashed in the DynamicMethodDesc, and is shared across all future uses of the DynamicMethodDesc
                DynamicMethodDesc* pDMD = ftn->AsDynamicMethodDesc();
                if (pDMD->m_interpreterPrecode != NULL)
                {
                    pPrecode = pDMD->m_interpreterPrecode;

Review comment (suggestion):
I wonder if we should handle that in the interpreter compiler instead. I would expect the logic here to be agnostic of what interpreter compiler can and cannot generate.

Code after:

    PCODE ret = (PCODE)NULL;
    NormalizedTimer timer;
    int64_t c100nsTicksInJit = 0;

    COOPERATIVE_TRANSITION_BEGIN();

    LogJitMethodBegin(ftn);

    timer.Start();

    ULONG sizeOfILCode = 0;

#ifdef FEATURE_INTERPRETER
    InterpreterJitManager* interpreterMgr = ExecutionManager::GetInterpreterJitManager();
    if (!interpreterMgr->IsInterpreterLoaded() && g_pConfig->EnableInterpreter())
    {
        if (
            !interpreterMgr->LoadInterpreter())
        {
            EEPOLICY_HANDLE_FATAL_ERROR_WITH_MESSAGE(COR_E_EXECUTIONENGINE, W("Failed to load interpreter"));
        }
    }

    // If the interpreter was loaded, use it.
    if (interpreterMgr->IsInterpreterLoaded())
    {
        CInterpreterJitInfo interpreterJitInfo{ config, ftn, ILHeader, interpreterMgr };
        ret = UnsafeJitFunctionWorker(interpreterMgr, &interpreterJitInfo, nativeCodeVersion, pSizeOfCode);

        // If successful, record data.
        if (ret)
        {
            sizeOfILCode = interpreterJitInfo.getMethodInfoInternal()->ILCodeSize;

#ifdef FEATURE_PORTABLE_ENTRYPOINTS
            PCODE portableEntryPoint = ftn->GetPortableEntryPoint();
            _ASSERTE(portableEntryPoint != NULL);
            PortableEntryPoint::SetInterpreterData(portableEntryPoint, ret);
            ret = portableEntryPoint;

#else // !FEATURE_PORTABLE_ENTRYPOINTS
            InterpreterPrecode* pPrecode = NULL;
            AllocMemTracker amt;
            if (ftn->IsDynamicMethod())
            {
                // For LCG methods, the precode is stashed in the DynamicMethodDesc, and is shared across all future uses of the DynamicMethodDesc
                DynamicMethodDesc* pDMD = ftn->AsDynamicMethodDesc();
                if (pDMD->m_interpreterPrecode != NULL)
                {
                    pPrecode = pDMD->m_interpreterPrecode;