object-layout 1.5 KB

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