Welcome to mirror list, hosted at ThFree Co, Russian Federation.

object-layout « docs - github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 1a066453ada71c746e0a9bb0c1268a6c3d871a84 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
Object and VTable layout
========================

The first pointer inside an Object points to a MonoClass structure. Objects
also contains a MonoThreadsSync structure which is used by the mono Thread
implementation. 
 
typedef struct {
	MonoClass *class;
	MonoThreadsSync synchronisation;
	
	/* object specific data goes here */
} MonoObject;

The MonoClass contains all Class infos, the VTable and a pointer to static
class data.

typedef struct {
	/* various class infos */
	MonoClass  *parent;
	const char *name;
	const char *name_space;

	...

	/* interface offset table */
	gint  *interface_offsets;

	gpointer data; /* a pointer to static data */

	/* the variable sized vtable is included at the end */
	gpointer vtable [vtable_size];
} MonoClass;


Calling virtual functions:
==========================

Each MonoMethod (if virtual) has an associated slot, which is an index into the
VTable. So we can use the following code to compute the address of a virtual
function: 
 
method_addr = object->class->vtable [method->slot];


Calling interface methods:
==========================

Each interface class is associated with an unique ID. The following code
computes the address of an interface function:

offset_into_vtable = object->class->interface_offsets [interface_id];
method_addr = object->class->vtable [offset_into_vtable + method->slot];