object-layout 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. Object and VTable layout
  2. ========================
  3. The first pointer inside an Object points to a MonoVtable structure. Objects
  4. also contains a MonoThreadsSync structure which is used by the mono Thread
  5. implementation.
  6. typedef struct {
  7. MonoVTable *vtable;
  8. MonoThreadsSync synchronisation;
  9. /* object specific data goes here */
  10. } MonoObject;
  11. The MonoVtable contains the vtable, interface offsets and a pointer to static
  12. class data. Each object/vtable belongs to exactly one AppDomain.
  13. typedef struct {
  14. MonoClass *klass;
  15. MonoDomain *domain;
  16. gpointer *interface_offsets;
  17. /* a pointer to static data */
  18. gpointer data;
  19. /* the variable sized vtable is included at the end */
  20. gpointer vtable [0];
  21. } MonoVTable;
  22. The MonoClass contains domain independent Class infos.
  23. typedef struct {
  24. /* various class infos */
  25. MonoClass *parent;
  26. const char *name;
  27. const char *name_space;
  28. ...
  29. } MonoClass;
  30. Calling virtual functions:
  31. ==========================
  32. Each MonoMethod (if virtual) has an associated slot, which is an index into the
  33. VTable. So we can use the following code to compute the address of a virtual
  34. function:
  35. method_addr = object->vtable->vtable [method->slot];
  36. Calling interface methods:
  37. ==========================
  38. Each interface class is associated with an unique ID. The following code
  39. computes the address of an interface function:
  40. method_addr = *(object->vtable->interface_offsets [interface_id] + method->slot*4);