2008-07-03 Mark Probst <mark.probst@gmail.com>
[mono.git] / docs / generic-sharing
1 Generic code sharing
2 ====================
3
4 Getting generics information about a stack frame
5 ------------------------------------------------
6
7 If a method is compiled with generic sharing, its MonoJitInfo has
8 has_generic_jit_info set.  In that case, the MonoJitInfo is followed
9 (after the MonoJitExceptionInfo array) by a MonoGenericJitInfo.
10
11 The MonoGenericJitInfo contains information about the location of the
12 this/vtable/MRGCTX variable, if the has_this flag is set.  If that is
13 the case, there are two possibilites:
14
15   1. this_in_reg is set.  this_reg is the number of the register where
16      the variable is stored.
17
18   2. this_in_reg is not set.  The variable is stored at offset
19      this_offset from the address in the register with number
20      this_reg.
21
22 The variable can either point to the "this" object, to a vtable or to
23 an MRGCTX:
24
25   1. If the method is a non-generic non-static method of a reference
26      type, the variable points to the "this" object.
27
28   2. If the method is a non-generic static method or a non-generic
29      method of a value type, the variable points to the vtable of the
30      class.
31
32   3. If the method is a generic method, the variable points to the
33      MRGCTX of the method.
34
35
36 Layout of the MRGCTX
37 --------------------
38
39 The MRGCTX is a structure that starts with
40 MonoMethodRuntimeGenericContext, which contains a pointer to the
41 vtable of the class and a pointer to the MonoGenericInst with the type
42 arguments for the method.
43
44
45 Blog posts about generic code sharing
46 -------------------------------------
47
48 http://schani.wordpress.com/2007/09/22/generics-sharing-in-mono/
49 http://schani.wordpress.com/2007/10/12/the-trouble-with-shared-generics/
50 http://schani.wordpress.com/2007/10/15/a-quick-generics-sharing-update/
51 http://schani.wordpress.com/2008/01/29/other-types/
52 http://schani.wordpress.com/2008/02/25/generic-types-are-lazy/
53 http://schani.wordpress.com/2008/03/10/sharing-static-methods/
54 http://schani.wordpress.com/2008/04/22/sharing-everything-and-saving-memory/
55 http://schani.wordpress.com/2008/06/02/sharing-generic-methods/
56 http://schani.wordpress.com/2008/06/27/another-generic-sharing-update/