Merge pull request #5714 from alexischr/update_bockbuild
[mono.git] / docs / object-layout
1 Author: Dietmar Maurer (dietmar@ximian.com)
2 (C) 2001 Ximian, Inc.
3
4 Object and VTable layout
5 ========================
6
7 The first pointer inside an Object points to a MonoVtable structure. Objects
8 also contains a MonoThreadsSync structure which is used by the mono Thread
9 implementation. 
10  
11 typedef struct {
12         MonoVTable *vtable;
13         MonoThreadsSync synchronisation;
14         
15         /* object specific data goes here */
16 } MonoObject;
17
18 The MonoVtable contains the vtable, interface offsets and a pointer to static
19 class data. Each object/vtable belongs to exactly one AppDomain.
20
21 typedef struct {
22         MonoClass  *klass;
23         MonoDomain *domain;  
24         gpointer   *interface_offsets;   
25         /* a pointer to static data */
26         gpointer    data;
27         /* the variable sized vtable is included at the end */
28         gpointer    vtable [0]; 
29 } MonoVTable;
30
31 The MonoClass contains domain independent Class infos.
32
33 typedef struct {
34         /* various class infos */
35         MonoClass  *parent;
36         const char *name;
37         const char *name_space;
38         ...
39 } MonoClass;
40
41
42 Calling virtual functions:
43 ==========================
44
45 Each MonoMethod (if virtual) has an associated slot, which is an index into the
46 VTable. So we can use the following code to compute the address of a virtual
47 function: 
48  
49 method_addr = object->vtable->vtable [method->slot];
50
51
52 Calling interface methods:
53 ==========================
54
55 Each interface class is associated with an unique ID. The following code
56 computes the address of an interface function:
57
58 method_addr = *(object->vtable->interface_offsets [interface_id] + method->slot*4);
59
60
61
62
63