JitInterface is the binary interface that is used to communicate with the JIT. The bulk of the interface consists of the ICorStaticInfo and ICorDynamicInfo interfaces and enums/structs used by those interfaces.
The JitInterface serves two purposes:
- Standardizes the interface between the runtime and the JIT (potentially allowing mixing and matching JITs and runtimes)
- Allows the JIT to be used elsewhere (outside of the runtime)
There are several components that consume the JIT outside of the runtime. Since those components don't consume the JIT using the header, changes to the JIT have to be ported manually.
The JitInterface is versioned by a GUID. Any change to JitInterface is required to update the JitInterface GUID located in jiteeversionguid.h (look for JITEEVersionIdentifier). Not doing so has consequences that are sometimes hard to debug.
It's a good idea to choose an existing API that is similar to the one you want to add and use it as a template. The following steps are required to add a new JIT-VM API:
- Start from adding a new entry in the
ThunkInput.txtfile. This file is used to generate the JIT-VM interface and is located insrc/coreclr/tools/Common/JitInterface/ThunkGenerator/. For complex types, you may need to also configure type mapping in the beginning of the file. - Invoke the
gen.shscript (orgen.baton Windows) to update the auto-generated files*_generated.*and update the JIT-EE guid. - Open
src/coreclr/inc/corinfo.hand add the new API inICorStaticInfo - Open
src/coreclr/tools/Common/JitInterface/CorInfoImpl.csand add the new API inCorInfoImplclass. If the implementation is not shared for NativeAOT and R2R, useCorInfoImpl.RyuJit.csandCorInfoImpl.ReadyToRun.csto implement the API. - Open
src/coreclr/vm/jitinterface.cppand add the CoreCLR-specific implementation - Open
lwmlist.hand add a definition of "input-args" - "output-args" map. Either use the genericDLD-like structs or create new ones inagnostic.h - Open
src/coreclr/tools/superpmi/superpmi-shared/methodcontext.hand add the necessary recording, dumping, and replaying methods for the new API and then implement them inmethodcontext.cpp - Update
enum mcPacketsinsrc/coreclr/tools/superpmi/superpmi-shared/methodcontext.hto include an entry for the new API and bump the max value of the enum - Use the
rec*andrep*methods insrc/coreclr/tools/superpmi/superpmi/icorjitinfo.cppandsrc/coreclr/tools/superpmi/superpmi-shim-collector/icorjitinfo.cppaccordingly
add-new-jit-ee-api.prompt.md contains a prompt that can be used to add a new JIT-VM API through an agent. Example usage in VSCode:
- Open the Copilot Chat Window
- Type "/add-new-jit-ee-api.prompt" and either hit enter and follow the instructions or provide the API signature directly. Gpt-4.1 and Claude Sonnet 4 or 3.7 are recommended for this task.