docs/design/mono/runtime-ilgen.md
The mono runtime makes extensive use of generating IL methods at runtime. These
methods are called 'wrappers' in the runtime code, because some of them 'wrap' other
methods, like a managed-to-native wrapper would wrap the native function being called.
Wrappers have the MonoMethod.wrapper_type field set to the type of the wrapper.
wrapper-types.h: Enumeration of wrapper typesmarshal*: Functions for generating wrappersmethod-builder*: Low level functions for creating new IL methods/code at runtimeEvery wrapper has an associated WrapperInfo structure which describes the wrapper.
This can be retrieved using the mono_marshal_get_wrapper_info () function.
Some wrappers have subtypes, these are stored in WrapperInfo.subtype.
Wrappers should be unique, i.e. there should be only one instance of every wrapper. This is
achieved by caching wrappers in wrapper type specific hash tables, which are stored in
MonoMemoryManager.wrapper_caches.
Wrappers for generic instances should be created by doing: instance method -> generic method definition -> generic wrapper -> inflated wrapper
In full-aot mode, the AOT compiler will collect and emit the wrappers needed by the
application at runtime. This involves serializing/deserializing the WrapperInfo structure.
These wrappers are used to make calls to native code. They are responsible for marshalling arguments and result values, setting up EH structures etc.
These wrappers are used to call managed methods from native code. When a delegate is passed to native code, the native code receives a native-to-managed wrapper.
Used to handle more complicated cases of delegate invocation that the fastpaths in the JIT can't handle.
Used to wrap synchronized methods. The wrapper does the locking.
Used to implement mono_runtime_invoke ().
These are not really wrappers, but methods created by user code using the DynamicMethod class.
Note that these have no associated WrapperInfo structure.
SGEN allocator methods.
SGEN write barrier methods.
Used to implement complex casts.
Used to implement stelem.ref.
Used to unbox the receiver before calling a method.
The rest of the wrappers, distinguished by their subtype.
Used to implement string ctors, the first argument is ignored, and a new string is allocated.
Used to implement ldelema in multi-dimensional arrays.
Used to implement the implicit interfaces on arrays like IList<T> etc. Delegate to helper methods on the Array class.
Used to implement Marshal.StructureToPtr.
Used to implement Marshal.PtrToStructure.