object-layout 1.3 KB

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