[Mono-dev] Mono class loader

Zoltan Varga vargaz at gmail.com
Fri Mar 17 09:46:27 EST 2006


   The type loading process is based on the CLI specification. It
works something like this:
- the JIT starts to compile a method
- the method contains embedded metadata tokens referring to types,
methods, fields etc.
- the JIT calls one of the loading functions like mono_class_get (),
which will determine
  the type of the token, and calls:
  - mono_class_from_typedef if it is a TYPEDEF token
  - mono_class_from_typeref if it is a TYPEREF token
  - If the token is a typeref token, then the typeref table contains
the assembly where
    the type resides, along with its name. Then the runtime loads the
referenced assembly,
    and looks up the type in that assembly using the
mono_class_from_name function.

The metadata loading functionality is spit into multiple files,
something like this:
- metadata.c contains functions to read data from the metadata tables,
and to decode
  various metadata structures from the on-disk representation into the
runtime representation
  like MonoType and MonoMethodSignature.
- class.c contains functions for loading classes from the metadata
- loader.c contains functions for loading stuff other than classes
from the metadata

These files are interleaved, the functions there make calls to each
other, so a call to a
function in class.c might call another in metadata.c, which will
in-turn call another one in
class.c etc. So these files would need some reorganization.

As for aspect weaving, you would be better of trying a fully managed
solution, using the
AssemblyLoad event of appdomains to intercept assembly loading and using either
Reflection.Emit or Cecil to manipulate the IL code.


On 3/17/06, unmiserable at gmail.com <unmiserable at gmail.com> wrote:
>  As part of a graduate course project, I need to modify the loader component
> of Mono (it has to do with load time aspect weaving, for the curious).
> Unfortunately, after wrestling with the code for a while and attempting to
> sift through it with tools like Red Hat's Source Navigator, I'm still pretty
> much stumped: There seem to be an awful lot of functions involved in the
> loading process (mono_class_from_name, mono_class_from_typeref,
> mono_class_create_from_typedef ...), and it's not what one would call
> abundantly clear to me what, exactly, does what.
>  If anyone could clarify what the most important function calls are -- the
> ones involved in the process of loading assemblies, reading the CIL, and
> creating the in-memory objects -- I would be profusely grateful. If it
> matters, I am (at present) preliminarily more interested in the interpreter
> than the JIT -- speed is a secondary concern for the nonce.
>  Any hints would be appreciated! Thank you in advance.
>  --
>  Petter Häggholm
>  University of British Columbia
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list

More information about the Mono-devel-list mailing list