2008-09-25 Dick Porter <dick@ximian.com>
[mono.git] / mono / metadata / class-internals.h
1 #ifndef __MONO_METADATA_CLASS_INTERBALS_H__
2 #define __MONO_METADATA_CLASS_INTERBALS_H__
3
4 #include <mono/metadata/class.h>
5 #include <mono/metadata/object.h>
6 #include <mono/metadata/mempool.h>
7 #include <mono/io-layer/io-layer.h>
8 #include "mono/utils/mono-compiler.h"
9
10 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
11
12 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
13
14 extern gboolean mono_print_vtable;
15
16 extern gboolean mono_setup_vtable_in_class_init;
17
18 typedef void     (*MonoStackWalkImpl) (MonoStackWalk func, gboolean do_il_offset, gpointer user_data);
19
20 typedef struct _MonoMethodNormal MonoMethodNormal;
21 typedef struct _MonoMethodWrapper MonoMethodWrapper;
22 typedef struct _MonoMethodInflated MonoMethodInflated;
23 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
24
25 /* Properties that applies to a group of structs should better use a higher number
26  * to avoid colision with type specific properties.
27  * 
28  * This prop applies to class, method, property, event, assembly and image.
29  */
30 #define MONO_PROP_DYNAMIC_CATTR 0x1000
31
32 typedef enum {
33 #define WRAPPER(e,n) MONO_WRAPPER_ ## e,
34 #include "wrapper-types.h"
35 #undef WRAPPER
36         MONO_WRAPPER_NUM
37 } MonoWrapperType;
38
39 typedef enum {
40         MONO_TYPE_NAME_FORMAT_IL,
41         MONO_TYPE_NAME_FORMAT_REFLECTION,
42         MONO_TYPE_NAME_FORMAT_FULL_NAME,
43         MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED
44 } MonoTypeNameFormat;
45
46 typedef enum {
47         MONO_REMOTING_TARGET_UNKNOWN,
48         MONO_REMOTING_TARGET_APPDOMAIN,
49         MONO_REMOTING_TARGET_COMINTEROP
50 } MonoRemotingTarget;
51
52 #define MONO_METHOD_PROP_GENERIC_CONTAINER 0
53
54 struct _MonoMethod {
55         guint16 flags;  /* method flags */
56         guint16 iflags; /* method implementation flags */
57         guint32 token;
58         MonoClass *klass;
59         MonoMethodSignature *signature;
60         /* name is useful mostly for debugging */
61         const char *name;
62         /* this is used by the inlining algorithm */
63         unsigned int inline_info:1;
64         unsigned int inline_failure:1;
65         unsigned int wrapper_type:5;
66         unsigned int string_ctor:1;
67         unsigned int save_lmf:1;
68         unsigned int dynamic:1; /* created & destroyed during runtime */
69         unsigned int is_generic:1; /* whenever this is a generic method definition */
70         unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
71         unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
72         unsigned int verification_success:1; /* whether this method has been verified successfully.*/
73         signed int slot : 18;
74
75         /*
76          * If is_generic is TRUE, the generic_container is stored in image->property_hash, 
77          * using the key MONO_METHOD_PROP_GENERIC_CONTAINER.
78          */
79 };
80
81 struct _MonoMethodNormal {
82         MonoMethod method;
83         MonoMethodHeader *header;
84 };
85
86 struct _MonoMethodWrapper {
87         MonoMethodNormal method;
88         void *method_data;
89 };
90
91 struct _MonoMethodPInvoke {
92         MonoMethod method;
93         gpointer addr;
94         /* add marshal info */
95         guint16 piflags;  /* pinvoke flags */
96         guint16 implmap_idx;  /* index into IMPLMAP */
97 };
98
99 typedef struct {
100         MonoType *generic_type;
101         gpointer reflection_info;
102 } MonoInflatedField;
103
104 /*
105  * MonoClassField is just a runtime representation of the metadata for
106  * field, it doesn't contain the data directly.  Static fields are
107  * stored in MonoVTable->data.  Instance fields are allocated in the
108  * objects after the object header.
109  */
110 struct _MonoClassField {
111         /* Type of the field */
112         MonoType        *type;
113
114         /* If this is an instantiated generic type, this is the
115          * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
116          * it was instantiated from.
117          */
118         MonoInflatedField  *generic_info;
119
120         /*
121          * Offset where this field is stored; if it is an instance
122          * field, it's the offset from the start of the object, if
123          * it's static, it's from the start of the memory chunk
124          * allocated for statics for the class.
125          */
126         int              offset;
127
128         const char      *name;
129
130         /*
131          * If the field is constant, pointer to the metadata constant
132          * value.
133          * If the field has an RVA flag, pointer to the data.
134          * Else, invalid.
135          */
136         const char      *data;
137
138         /* Type where the field was defined */
139         MonoClass       *parent;
140
141         /*
142          * If the field is constant, the type of the constant.
143          */
144         MonoTypeEnum     def_type;
145 };
146
147 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
148 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
149                                       && (strcmp ((field)->name, "_Deleted") == 0))
150
151 typedef struct {
152         MonoClassField *field;
153         guint32 offset;
154         MonoMarshalSpec *mspec;
155 } MonoMarshalField;
156
157 typedef struct {
158         guint32 native_size;
159         guint32 num_fields;
160         MonoMethod *ptr_to_str;
161         MonoMethod *str_to_ptr;
162         MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
163 } MonoMarshalType;
164
165 struct _MonoProperty {
166         MonoClass *parent;
167         const char *name;
168         MonoMethod *get;
169         MonoMethod *set;
170         guint32 attrs;
171 };
172
173 struct _MonoEvent {
174         MonoClass *parent;
175         const char *name;
176         MonoMethod *add;
177         MonoMethod *remove;
178         MonoMethod *raise;
179         MonoMethod **other;
180         guint32 attrs;
181 };
182
183 /* type of exception being "on hold" for later processing (see exception_type) */
184 enum {
185         MONO_EXCEPTION_NONE = 0,
186         MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
187         MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2,
188         MONO_EXCEPTION_INVALID_PROGRAM = 3,
189         MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
190         MONO_EXCEPTION_MISSING_METHOD = 5,
191         MONO_EXCEPTION_MISSING_FIELD = 6,
192         MONO_EXCEPTION_TYPE_LOAD = 7,
193         MONO_EXCEPTION_FILE_NOT_FOUND = 8,
194         MONO_EXCEPTION_METHOD_ACCESS = 9,
195         MONO_EXCEPTION_FIELD_ACCESS = 10,
196         MONO_EXCEPTION_GENERIC_SHARING_FAILED = 11,
197         MONO_EXCEPTION_BAD_IMAGE = 12,
198         MONO_EXCEPTION_OBJECT_SUPPLIED = 13 /*The exception object is already created.*/
199         /* add other exception type */
200 };
201
202 /* This struct collects the info needed for the runtime use of a class,
203  * like the vtables for a domain, the GC descriptor, etc.
204  */
205 typedef struct {
206         guint16 max_domain;
207         /* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
208         MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
209 } MonoClassRuntimeInfo;
210
211 enum {
212         MONO_RGCTX_INFO_STATIC_DATA,
213         MONO_RGCTX_INFO_KLASS,
214         MONO_RGCTX_INFO_VTABLE,
215         MONO_RGCTX_INFO_TYPE,
216         MONO_RGCTX_INFO_REFLECTION_TYPE,
217         MONO_RGCTX_INFO_METHOD,
218         MONO_RGCTX_INFO_GENERIC_METHOD_CODE,
219         MONO_RGCTX_INFO_CLASS_FIELD,
220         MONO_RGCTX_INFO_METHOD_RGCTX
221 };
222
223 typedef struct _MonoRuntimeGenericContextOtherInfoTemplate {
224         int info_type;
225         gpointer data;
226         struct _MonoRuntimeGenericContextOtherInfoTemplate *next;
227 } MonoRuntimeGenericContextOtherInfoTemplate;
228
229 typedef struct {
230         MonoClass *next_subclass;
231         MonoRuntimeGenericContextOtherInfoTemplate *other_infos;
232         GSList *method_templates;
233 } MonoRuntimeGenericContextTemplate;
234
235 typedef struct {
236         MonoVTable *class_vtable; /* must be the first element */
237         MonoGenericInst *method_inst;
238         gpointer infos [MONO_ZERO_LEN_ARRAY];
239 } MonoMethodRuntimeGenericContext;
240
241 #define MONO_RGCTX_SLOT_MAKE_RGCTX(i)   (i)
242 #define MONO_RGCTX_SLOT_MAKE_MRGCTX(i)  ((i) | 0x80000000)
243 #define MONO_RGCTX_SLOT_INDEX(s)        ((s) & 0x7fffffff)
244 #define MONO_RGCTX_SLOT_IS_MRGCTX(s)    (((s) & 0x80000000) ? TRUE : FALSE)
245
246
247 #define MONO_CLASS_PROP_EXCEPTION_DATA 0
248
249 struct _MonoClass {
250         /* element class for arrays and enum */
251         MonoClass *element_class; 
252         /* used for subtype checks */
253         MonoClass *cast_class; 
254
255         /* for fast subtype checks */
256         MonoClass **supertypes;
257         guint16     idepth;
258
259         /* array dimension */
260         guint8     rank;          
261
262         int        instance_size; /* object instance size */
263
264         guint inited          : 1;
265         /* We use init_pending to detect cyclic calls to mono_class_init */
266         guint init_pending    : 1;
267
268         /* A class contains static and non static data. Static data can be
269          * of the same type as the class itselfs, but it does not influence
270          * the instance size of the class. To avoid cyclic calls to 
271          * mono_class_init (from mono_class_instance_size ()) we first 
272          * initialise all non static fields. After that we set size_inited 
273          * to 1, because we know the instance size now. After that we 
274          * initialise all static fields.
275          */
276         guint size_inited     : 1;
277         guint valuetype       : 1; /* derives from System.ValueType */
278         guint enumtype        : 1; /* derives from System.Enum */
279         guint blittable       : 1; /* class is blittable */
280         guint unicode         : 1; /* class uses unicode char when marshalled */
281         guint wastypebuilder  : 1; /* class was created at runtime from a TypeBuilder */
282         /* next byte */
283         guint min_align       : 4;
284         guint packing_size    : 4;
285         /* next byte */
286         guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
287         guint has_finalize    : 1; /* class has its own Finalize impl */ 
288         guint marshalbyref    : 1; /* class is a MarshalByRefObject */
289         guint contextbound    : 1; /* class is a ContextBoundObject */
290         guint delegate        : 1; /* class is a Delegate */
291         guint gc_descr_inited : 1; /* gc_descr is initialized */
292         guint has_cctor       : 1; /* class has a cctor */
293         guint has_references  : 1; /* it has GC-tracked references in the instance */
294         /* next byte */
295         guint has_static_refs : 1; /* it has static fields that are GC-tracked */
296         guint no_special_static_fields : 1; /* has no thread/context static fields */
297         /* directly or indirectly derives from ComImport attributed class.
298          * this means we need to create a proxy for instances of this class
299          * for COM Interop. set this flag on loading so all we need is a quick check
300          * during object creation rather than having to traverse supertypes
301          */
302         guint is_com_object : 1; 
303         guint nested_classes_inited : 1; /* Whenever nested_class is initialized */
304
305         guint8     exception_type;      /* MONO_EXCEPTION_* */
306
307         /* Additional information about the exception */
308         /* Stored as property MONO_CLASS_PROP_EXCEPTION_DATA */
309         //void       *exception_data;
310
311         MonoClass  *parent;
312         MonoClass  *nested_in;
313         GList      *nested_classes;
314
315         MonoImage *image;
316         const char *name;
317         const char *name_space;
318
319         /* The underlying type of the enum */
320         MonoType *enum_basetype;
321
322         guint32    declsec_flags;       /* declarative security attributes flags */
323         guint32    type_token;
324         int        vtable_size; /* number of slots */
325
326         guint16     interface_count;
327         guint16     interface_id;        /* unique inderface id (for interfaces) */
328         guint16     max_interface_id;
329         
330         guint16     interface_offsets_count;
331         MonoClass **interfaces_packed;
332         guint16    *interface_offsets_packed;
333         guint8     *interface_bitmap;
334         
335         MonoClass **interfaces;
336
337         union {
338                 int class_size; /* size of area for static fields */
339                 int element_size; /* for array types */
340                 int generic_param_token; /* for generic param types, both var and mvar */
341         } sizes;
342
343         /*
344          * From the TypeDef table
345          */
346         guint32    flags;
347         struct {
348                 guint32 first, count;
349         } field, method, property, event;
350
351         /* loaded on demand */
352         MonoMarshalType *marshal_info;
353
354         /*
355          * Field information: Type and location from object base
356          */
357         MonoClassField *fields;
358
359         /* Initialized by a call to mono_class_setup_properties () */
360         MonoProperty *properties;
361
362         /* Initialized by a call to mono_class_setup_events () */
363         MonoEvent *events;
364
365         MonoMethod **methods;
366
367         /* used as the type of the this argument and when passing the arg by value */
368         MonoType this_arg;
369         MonoType byval_arg;
370
371         MonoGenericClass *generic_class;
372         MonoGenericContainer *generic_container;
373
374         void *reflection_info;
375
376         void *gc_descr;
377
378         MonoClassRuntimeInfo *runtime_info;
379
380         /* next element in the class_cache hash list (in MonoImage) */
381         MonoClass *next_class_cache;
382
383         /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
384         MonoMethod **vtable;    
385 };
386
387 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && ((k)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
388 int mono_class_interface_offset (MonoClass *klass, MonoClass *itf);
389
390 typedef gpointer MonoRuntimeGenericContext;
391
392 /* the interface_offsets array is stored in memory before this struct */
393 struct MonoVTable {
394         MonoClass  *klass;
395          /*
396          * According to comments in gc_gcj.h, this should be the second word in
397          * the vtable.
398          */
399         void *gc_descr;         
400         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
401         gpointer    data; /* to store static class data */
402         gpointer    type; /* System.Type type for klass */
403         guint8     *interface_bitmap;
404         guint16     max_interface_id;
405         guint8      rank;
406         guint remote          : 1; /* class is remotely activated */
407         guint initialized     : 1; /* cctor has been run */
408         guint init_failed     : 1; /* cctor execution failed */
409         guint32     imt_collisions_bitmap;
410         MonoRuntimeGenericContext *runtime_generic_context;
411         /* do not add any fields after vtable, the structure is dynamically extended */
412         gpointer    vtable [MONO_ZERO_LEN_ARRAY];       
413 };
414
415 #define MONO_VTABLE_IMPLEMENTS_INTERFACE(vt,uiid) (((uiid) <= (vt)->max_interface_id) && ((vt)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
416
417 /*
418  * Generic instantiation data type encoding.
419  */
420
421 /*
422  * A particular generic instantiation:
423  *
424  * All instantiations are cached and we don't distinguish between class and method
425  * instantiations here.
426  */
427 struct _MonoGenericInst {
428         guint id;                       /* unique ID for debugging */
429         guint type_argc    : 22;        /* number of type arguments */
430         guint is_open      :  1;        /* if this is an open type */
431         MonoType **type_argv;
432 };
433
434 /*
435  * The generic context: an instantiation of a set of class and method generic parameters.
436  *
437  * NOTE: Never allocate this directly on the heap.  It have to be either allocated on the stack,
438  *       or embedded within other objects.  Don't store pointers to this, because it may be on the stack.
439  *       If you really have to, ensure you store a pointer to the embedding object along with it.
440  */
441 struct _MonoGenericContext {
442         /* The instantiation corresponding to the class generic parameters */
443         MonoGenericInst *class_inst;
444         /* The instantiation corresponding to the method generic parameters */
445         MonoGenericInst *method_inst;
446 };
447
448 /*
449  * Inflated generic method.
450  */
451 struct _MonoMethodInflated {
452         union {
453                 MonoMethod method;
454                 MonoMethodNormal normal;
455                 MonoMethodPInvoke pinvoke;
456         } method;
457         MonoMethod *declaring;          /* the generic method definition. */
458         MonoGenericContext context;     /* The current instantiation */
459
460         /* TODO we MUST get rid of this field, it's an ugly hack nobody is proud of. */
461         guint is_mb_open : 1;           /* This is the fully open instantiation of a generic method_builder. Worse than is_tb_open, but it's temporary */
462 };
463
464 /*
465  * A particular instantiation of a generic type.
466  */
467 struct _MonoGenericClass {
468         MonoClass *container_class;     /* the generic type definition */
469         MonoGenericContext context;     /* a context that contains the type instantiation doesn't contain any method instantiation */
470         guint is_dynamic  : 1;          /* We're a MonoDynamicGenericClass */
471         guint is_tb_open  : 1;          /* This is the fully open instantiation for a type_builder. Quite ugly, but it's temporary.*/
472         MonoClass *cached_class;        /* if present, the MonoClass corresponding to the instantiation.  */
473 };
474
475 /*
476  * This is used when instantiating a generic type definition which is
477  * a TypeBuilder.
478  */
479 struct _MonoDynamicGenericClass {
480         MonoGenericClass generic_class;
481         int count_methods;
482         MonoMethod **methods;
483         int count_ctors;
484         MonoMethod **ctors;
485         int count_fields;
486         MonoClassField *fields;
487         int count_properties;
488         MonoProperty *properties;
489         int count_events;
490         MonoEvent *events;
491         guint initialized;
492 };
493
494 /*
495  * The generic container.
496  *
497  * Stores the type parameters of a generic type definition or a generic method definition.
498  */
499 struct _MonoGenericContainer {
500         MonoGenericContext context;
501         /* If we're a generic method definition in a generic type definition,
502            the generic container of the containing class. */
503         MonoGenericContainer *parent;
504         /* the generic type definition or the generic method definition corresponding to this container */
505         union {
506                 MonoClass *klass;
507                 MonoMethod *method;
508         } owner;
509         int type_argc    : 31;
510         /* If true, we're a generic method, otherwise a generic type definition. */
511         /* Invariant: parent != NULL => is_method */
512         int is_method    : 1;
513         /* Our type parameters. */
514         MonoGenericParam *type_params;
515 };
516
517 /*
518  * A type parameter.
519  */
520 struct _MonoGenericParam {
521         MonoGenericContainer *owner;    /* Type or method this parameter was defined in. */
522         MonoClass *pklass;              /* The corresponding `MonoClass'. */
523         const char *name;
524         guint16 flags;
525         guint16 num;
526         MonoClass** constraints; /* NULL means end of list */
527         /* If owner is NULL, this is the image whose mempool this struct was allocated from */
528         MonoImage *image;
529 };
530
531 /*
532  * Class information which might be cached by the runtime in the AOT file for
533  * example. Caching this allows us to avoid computing a generic vtable
534  * (class->vtable) in most cases, saving time and avoiding creation of lots of
535  * MonoMethod structures.
536  */
537 typedef struct MonoCachedClassInfo {
538         guint32 vtable_size;
539         guint has_finalize : 1;
540         guint ghcimpl : 1;
541         guint has_cctor : 1;
542         guint has_nested_classes : 1;
543         guint blittable : 1;
544         guint has_references : 1;
545         guint has_static_refs : 1;
546         guint no_special_static_fields : 1;
547         guint32 cctor_token;
548         MonoImage *finalize_image;
549         guint32 finalize_token;
550         guint32 instance_size;
551         guint32 class_size;
552         guint32 packing_size;
553         guint32 min_align;
554 } MonoCachedClassInfo;
555
556 typedef struct {
557         const char *name;
558         gconstpointer func;
559         gconstpointer wrapper;
560         gconstpointer trampoline;
561         MonoMethodSignature *sig;
562 } MonoJitICallInfo;
563
564 typedef struct {
565         guint8 exception_type;
566         char *class_name; /* If kind == TYPE */
567         char *assembly_name; /* If kind == TYPE or ASSEMBLY */
568         MonoClass *klass; /* If kind != TYPE */
569         const char *member_name; /* If kind != TYPE */
570         gboolean ref_only; /* If kind == ASSEMBLY */
571         char *msg; /* If kind == BAD_IMAGE */
572 } MonoLoaderError;
573
574 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
575
576 typedef struct {
577         gulong new_object_count;
578         gulong initialized_class_count;
579         gulong generic_vtable_count;
580         gulong used_class_count;
581         gulong method_count;
582         gulong class_vtable_size;
583         gulong class_static_data_size;
584         gulong generic_instance_count;
585         gulong generic_class_count;
586         gulong inflated_method_count;
587         gulong inflated_method_count_2;
588         gulong inflated_type_count;
589         gulong generics_metadata_size;
590         gulong dynamic_code_alloc_count;
591         gulong dynamic_code_bytes_count;
592         gulong dynamic_code_frees_count;
593         gulong delegate_creations;
594         gulong imt_tables_size;
595         gulong imt_number_of_tables;
596         gulong imt_number_of_methods;
597         gulong imt_used_slots;
598         gulong imt_slots_with_collisions;
599         gulong imt_max_collisions_in_slot;
600         gulong imt_method_count_when_max_collisions;
601         gulong imt_thunks_size;
602         gulong jit_info_table_insert_count;
603         gulong jit_info_table_remove_count;
604         gulong jit_info_table_lookup_count;
605         gulong hazardous_pointer_count;
606         gulong generics_sharable_methods;
607         gulong generics_unsharable_methods;
608         gulong generics_shared_methods;
609         gulong minor_gc_count;
610         gulong major_gc_count;
611         gulong minor_gc_time_usecs;
612         gulong major_gc_time_usecs;
613         gboolean enabled;
614 } MonoStats;
615
616 /* 
617  * new structure to hold performace counters values that are exported
618  * to managed code.
619  * Note: never remove fields from this structure and only add them to the end.
620  * Size of fields and type should not be changed as well.
621  */
622 typedef struct {
623         /* JIT category */
624         guint32 jit_methods;
625         guint32 jit_bytes;
626         guint32 jit_time;
627         guint32 jit_failures;
628         /* Exceptions category */
629         guint32 exceptions_thrown;
630         guint32 exceptions_filters;
631         guint32 exceptions_finallys;
632         guint32 exceptions_depth;
633         guint32 aspnet_requests_queued;
634         /* Memory category */
635         guint32 gc_collections0;
636         guint32 gc_collections1;
637         guint32 gc_collections2;
638         guint32 gc_promotions0;
639         guint32 gc_promotions1;
640         guint32 gc_promotion_finalizers;
641         guint32 gc_gen0size;
642         guint32 gc_gen1size;
643         guint32 gc_gen2size;
644         guint32 gc_lossize;
645         guint32 gc_fin_survivors;
646         guint32 gc_num_handles;
647         guint32 gc_allocated;
648         guint32 gc_induced;
649         guint32 gc_time;
650         guint32 gc_total_bytes;
651         guint32 gc_committed_bytes;
652         guint32 gc_reserved_bytes;
653         guint32 gc_num_pinned;
654         guint32 gc_sync_blocks;
655         /* Remoting category */
656         guint32 remoting_calls;
657         guint32 remoting_channels;
658         guint32 remoting_proxies;
659         guint32 remoting_classes;
660         guint32 remoting_objects;
661         guint32 remoting_contexts;
662         /* Loader category */
663         guint32 loader_classes;
664         guint32 loader_total_classes;
665         guint32 loader_appdomains;
666         guint32 loader_total_appdomains;
667         guint32 loader_assemblies;
668         guint32 loader_total_assemblies;
669         guint32 loader_failures;
670         guint32 loader_bytes;
671         guint32 loader_appdomains_uloaded;
672         /* Threads and Locks category  */
673         guint32 thread_contentions;
674         guint32 thread_queue_len;
675         guint32 thread_queue_max;
676         guint32 thread_num_logical;
677         guint32 thread_num_physical;
678         guint32 thread_cur_recognized;
679         guint32 thread_num_recognized;
680         /* Interop category */
681         guint32 interop_num_ccw;
682         guint32 interop_num_stubs;
683         guint32 interop_num_marshals;
684         /* Security category */
685         guint32 security_num_checks;
686         guint32 security_num_link_checks;
687         guint32 security_time;
688         guint32 security_depth;
689         guint32 unused;
690 } MonoPerfCounters;
691
692 extern MonoPerfCounters *mono_perfcounters MONO_INTERNAL;
693
694 void mono_perfcounters_init (void);
695
696 /*
697  * The definition of the first field in SafeHandle,
698  * Keep in sync with SafeHandle.cs, this is only used
699  * to access the `handle' parameter.
700  */
701 typedef struct {
702         MonoObject  base;
703         void       *handle;
704 } MonoSafeHandle;
705
706 /*
707  * Keep in sync with HandleRef.cs
708  */
709 typedef struct {
710         MonoObject *wrapper;
711         void       *handle;
712 } MonoHandleRef;
713
714 enum {
715         MONO_GENERIC_SHARING_NONE,
716         MONO_GENERIC_SHARING_COLLECTIONS,
717         MONO_GENERIC_SHARING_CORLIB,
718         MONO_GENERIC_SHARING_ALL
719 };
720
721 /*
722  * Flags for which contexts were used in inflating a generic.
723  */
724 enum {
725         MONO_GENERIC_CONTEXT_USED_CLASS = 1,
726         MONO_GENERIC_CONTEXT_USED_METHOD = 2
727 };
728
729 #define MONO_GENERIC_CONTEXT_USED_BOTH          (MONO_GENERIC_CONTEXT_USED_CLASS | MONO_GENERIC_CONTEXT_USED_METHOD)
730
731 extern MonoStats mono_stats MONO_INTERNAL;
732
733 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
734 typedef gpointer (*MonoJumpTrampoline)       (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper);
735 typedef gpointer (*MonoRemotingTrampoline)       (MonoMethod *method, MonoRemotingTarget target);
736 typedef gpointer (*MonoDelegateTrampoline)       (MonoClass *klass);
737
738 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
739
740 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
741
742 typedef gboolean (*MonoGetClassFromName) (MonoImage *image, const char *name_space, const char *name, MonoClass **res);
743
744 void
745 mono_classes_init (void) MONO_INTERNAL;
746
747 void
748 mono_classes_cleanup (void) MONO_INTERNAL;
749
750 void
751 mono_class_layout_fields   (MonoClass *klass) MONO_INTERNAL;
752
753 void
754 mono_class_setup_interface_offsets (MonoClass *klass) MONO_INTERNAL;
755
756 void
757 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum) MONO_INTERNAL;
758
759 void
760 mono_class_setup_vtable (MonoClass *klass) MONO_INTERNAL;
761
762 void
763 mono_class_setup_methods (MonoClass *klass) MONO_INTERNAL;
764
765 void
766 mono_class_setup_mono_type (MonoClass *klass) MONO_INTERNAL;
767
768 void
769 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
770
771 void
772 mono_class_setup_supertypes (MonoClass *klass) MONO_INTERNAL;
773
774 MonoMethod*
775 mono_class_get_method_by_index (MonoClass *class, int index) MONO_INTERNAL;
776
777 GPtrArray*
778 mono_class_get_implemented_interfaces (MonoClass *klass) MONO_INTERNAL;
779
780 gboolean
781 mono_class_is_open_constructed_type (MonoType *t) MONO_INTERNAL;
782
783 gboolean
784 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
785                                MonoGenericContext *generic_context) MONO_INTERNAL;
786
787 MonoMethod*
788 mono_class_get_cctor (MonoClass *klass) MONO_INTERNAL;
789
790 MonoMethod*
791 mono_class_get_finalizer (MonoClass *klass) MONO_INTERNAL;
792
793 gboolean
794 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller) MONO_INTERNAL;
795
796 gboolean
797 mono_class_field_is_special_static (MonoClassField *field) MONO_INTERNAL;
798
799 gboolean
800 mono_class_has_special_static_fields (MonoClass *klass) MONO_INTERNAL;
801
802 const char*
803 mono_class_get_field_default_value (MonoClassField *field, MonoTypeEnum *def_type) MONO_INTERNAL;
804
805 void
806 mono_install_trampoline (MonoTrampoline func) MONO_INTERNAL;
807
808 void
809 mono_install_jump_trampoline (MonoJumpTrampoline func) MONO_INTERNAL;
810
811 void
812 mono_install_remoting_trampoline (MonoRemotingTrampoline func) MONO_INTERNAL;
813
814 void
815 mono_install_delegate_trampoline (MonoDelegateTrampoline func) MONO_INTERNAL;
816
817 gpointer
818 mono_lookup_dynamic_token (MonoImage *image, guint32 token, MonoGenericContext *context) MONO_INTERNAL;
819
820 gpointer
821 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, gboolean check_token, MonoClass **handle_class, MonoGenericContext *context) MONO_INTERNAL;
822
823 void
824 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func) MONO_INTERNAL;
825
826 gpointer
827 mono_runtime_create_jump_trampoline (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper) MONO_INTERNAL;
828
829 gpointer
830 mono_runtime_create_delegate_trampoline (MonoClass *klass) MONO_INTERNAL;
831
832 void
833 mono_install_get_cached_class_info (MonoGetCachedClassInfo func) MONO_INTERNAL;
834
835 void
836 mono_install_get_class_from_name (MonoGetClassFromName func) MONO_INTERNAL;
837
838 MonoGenericContext*
839 mono_class_get_context (MonoClass *class) MONO_INTERNAL;
840
841 MonoGenericContext*
842 mono_method_get_context (MonoMethod *method) MONO_INTERNAL;
843
844 /* Used by monodis, thus cannot be MONO_INTERNAL */
845 MonoGenericContainer*
846 mono_method_get_generic_container (MonoMethod *method);
847
848 MonoGenericContext*
849 mono_generic_class_get_context (MonoGenericClass *gclass) MONO_INTERNAL;
850
851 MonoClass*
852 mono_generic_class_get_class (MonoGenericClass *gclass) MONO_INTERNAL;
853
854 void
855 mono_method_set_generic_container (MonoMethod *method, MonoGenericContainer* container) MONO_INTERNAL;
856
857 MonoMethod*
858 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
859
860 MonoMethodInflated*
861 mono_method_inflated_lookup (MonoMethodInflated* method, gboolean cache) MONO_INTERNAL;
862
863 MonoMethodSignature *
864 mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context);
865
866 MonoType*
867 mono_class_inflate_generic_type_with_mempool (MonoMemPool *mempool, MonoType *type, MonoGenericContext *context) MONO_INTERNAL;
868
869 void
870 mono_metadata_free_inflated_signature (MonoMethodSignature *sig);
871
872 typedef struct {
873         MonoImage *corlib;
874         MonoClass *object_class;
875         MonoClass *byte_class;
876         MonoClass *void_class;
877         MonoClass *boolean_class;
878         MonoClass *sbyte_class;
879         MonoClass *int16_class;
880         MonoClass *uint16_class;
881         MonoClass *int32_class;
882         MonoClass *uint32_class;
883         MonoClass *int_class;
884         MonoClass *uint_class;
885         MonoClass *int64_class;
886         MonoClass *uint64_class;
887         MonoClass *single_class;
888         MonoClass *double_class;
889         MonoClass *char_class;
890         MonoClass *string_class;
891         MonoClass *enum_class;
892         MonoClass *array_class;
893         MonoClass *delegate_class;
894         MonoClass *multicastdelegate_class;
895         MonoClass *asyncresult_class;
896         MonoClass *waithandle_class;
897         MonoClass *typehandle_class;
898         MonoClass *fieldhandle_class;
899         MonoClass *methodhandle_class;
900         MonoClass *systemtype_class;
901         MonoClass *monotype_class;
902         MonoClass *exception_class;
903         MonoClass *threadabortexception_class;
904         MonoClass *thread_class;
905         MonoClass *transparent_proxy_class;
906         MonoClass *real_proxy_class;
907         MonoClass *mono_method_message_class;
908         MonoClass *appdomain_class;
909         MonoClass *field_info_class;
910         MonoClass *method_info_class;
911         MonoClass *stringbuilder_class;
912         MonoClass *math_class;
913         MonoClass *stack_frame_class;
914         MonoClass *stack_trace_class;
915         MonoClass *marshal_class;
916         MonoClass *iserializeable_class;
917         MonoClass *serializationinfo_class;
918         MonoClass *streamingcontext_class;
919         MonoClass *typed_reference_class;
920         MonoClass *argumenthandle_class;
921         MonoClass *marshalbyrefobject_class;
922         MonoClass *monitor_class;
923         MonoClass *iremotingtypeinfo_class;
924         MonoClass *runtimesecurityframe_class;
925         MonoClass *executioncontext_class;
926         MonoClass *internals_visible_class;
927         MonoClass *generic_ilist_class;
928         MonoClass *generic_nullable_class;
929         MonoClass *variant_class;
930         MonoClass *com_object_class;
931         MonoClass *com_interop_proxy_class;
932         MonoClass *iunknown_class;
933         MonoClass *idispatch_class;
934         MonoClass *safehandle_class;
935         MonoClass *handleref_class;
936         MonoClass *attribute_class;
937         MonoClass *customattribute_data_class;
938 } MonoDefaults;
939
940 extern MonoDefaults mono_defaults MONO_INTERNAL;
941
942 void
943 mono_loader_init           (void) MONO_INTERNAL;
944
945 void
946 mono_loader_cleanup        (void) MONO_INTERNAL;
947
948 void
949 mono_loader_lock           (void) MONO_INTERNAL;
950
951 void
952 mono_loader_unlock         (void) MONO_INTERNAL;
953
954 void
955 mono_loader_set_error_assembly_load (const char *assembly_name, gboolean ref_only) MONO_INTERNAL;
956
957 void
958 mono_loader_set_error_type_load (const char *class_name, const char *assembly_name) MONO_INTERNAL;
959
960 void
961 mono_loader_set_error_method_load (const char *class_name, const char *member_name) MONO_INTERNAL;
962
963 void
964 mono_loader_set_error_field_load (MonoClass *klass, const char *member_name) MONO_INTERNAL;
965 void
966 mono_loader_set_error_bad_image (char *msg) MONO_INTERNAL;
967
968 MonoException *
969 mono_loader_error_prepare_exception (MonoLoaderError *error) MONO_INTERNAL;
970
971 MonoLoaderError *
972 mono_loader_get_last_error (void) MONO_INTERNAL;
973
974 void
975 mono_loader_clear_error    (void) MONO_INTERNAL;
976
977 void
978 mono_reflection_init       (void) MONO_INTERNAL;
979
980 void
981 mono_icall_init            (void) MONO_INTERNAL;
982
983 void
984 mono_icall_cleanup         (void) MONO_INTERNAL;
985
986 gpointer
987 mono_method_get_wrapper_data (MonoMethod *method, guint32 id) MONO_INTERNAL;
988
989 void
990 mono_install_stack_walk (MonoStackWalkImpl func) MONO_INTERNAL;
991
992 gboolean
993 mono_metadata_has_generic_params (MonoImage *image, guint32 token) MONO_INTERNAL;
994
995 MonoGenericContainer *
996 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
997                                    MonoGenericContainer *parent_container);
998
999 void
1000 mono_metadata_load_generic_param_constraints (MonoImage *image, guint32 token,
1001                                               MonoGenericContainer *container);
1002
1003 MonoMethodSignature*
1004 mono_create_icall_signature (const char *sigstr) MONO_INTERNAL;
1005
1006 MonoJitICallInfo *
1007 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save) MONO_INTERNAL;
1008
1009 void
1010 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper) MONO_INTERNAL;
1011
1012 MonoJitICallInfo *
1013 mono_find_jit_icall_by_name (const char *name) MONO_INTERNAL;
1014
1015 MonoJitICallInfo *
1016 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_INTERNAL;
1017
1018 GHashTable*
1019 mono_get_jit_icall_info (void) MONO_INTERNAL;
1020
1021 gboolean
1022 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data) MONO_INTERNAL;
1023
1024 gpointer
1025 mono_class_get_exception_data (MonoClass *klass) MONO_INTERNAL;
1026
1027 MonoException*
1028 mono_class_get_exception_for_failure (MonoClass *klass) MONO_INTERNAL;
1029
1030 char*
1031 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format) MONO_INTERNAL;
1032
1033 char*
1034 mono_type_get_full_name (MonoClass *class) MONO_INTERNAL;
1035
1036 MonoArrayType *mono_dup_array_type (MonoMemPool *mp, MonoArrayType *a) MONO_INTERNAL;
1037 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoMemPool *mp, MonoMethodSignature *sig) MONO_INTERNAL;
1038
1039 void
1040 mono_image_init_name_cache (MonoImage *image);
1041
1042 gboolean mono_class_is_nullable (MonoClass *klass) MONO_INTERNAL;
1043 MonoClass *mono_class_get_nullable_param (MonoClass *klass) MONO_INTERNAL;
1044
1045 /* object debugging functions, for use inside gdb */
1046 void mono_object_describe        (MonoObject *obj);
1047 void mono_object_describe_fields (MonoObject *obj);
1048 void mono_value_describe_fields  (MonoClass* klass, const char* addr);
1049 void mono_class_describe_statics (MonoClass* klass);
1050
1051 /*Enum validation related functions*/
1052 gboolean
1053 mono_type_is_valid_enum_basetype (MonoType * type);
1054
1055 gboolean
1056 mono_class_is_valid_enum (MonoClass *klass);
1057
1058 MonoType *
1059 mono_type_get_full        (MonoImage *image, guint32 type_token, MonoGenericContext *context) MONO_INTERNAL;
1060
1061 gboolean
1062 mono_generic_class_is_generic_type_definition (MonoGenericClass *gklass) MONO_INTERNAL;
1063
1064 MonoMethod*
1065 mono_method_get_declaring_generic_method (MonoMethod *method) MONO_INTERNAL;
1066
1067 MonoMethod*
1068 mono_class_get_method_generic (MonoClass *klass, MonoMethod *method) MONO_INTERNAL;
1069
1070 MonoType*
1071 mono_type_get_basic_type_from_generic (MonoType *type) MONO_INTERNAL;
1072
1073 gboolean
1074 mono_class_generic_sharing_enabled (MonoClass *class) MONO_INTERNAL;
1075
1076 gpointer
1077 mono_class_fill_runtime_generic_context (MonoVTable *class_vtable, guint32 slot) MONO_INTERNAL;
1078
1079 gpointer
1080 mono_method_fill_runtime_generic_context (MonoMethodRuntimeGenericContext *mrgctx, guint32 slot) MONO_INTERNAL;
1081
1082 MonoMethodRuntimeGenericContext*
1083 mono_method_lookup_rgctx (MonoVTable *class_vtable, MonoGenericInst *method_inst) MONO_INTERNAL;
1084
1085 gboolean
1086 mono_method_needs_static_rgctx_invoke (MonoMethod *method, gboolean allow_type_vars) MONO_INTERNAL;
1087
1088 int
1089 mono_class_rgctx_get_array_size (int n, gboolean mrgctx) MONO_INTERNAL;
1090
1091 guint32
1092 mono_method_lookup_or_register_other_info (MonoMethod *method, gboolean in_mrgctx, gpointer data,
1093         int info_type, MonoGenericContext *generic_context) MONO_INTERNAL;
1094
1095 int
1096 mono_generic_context_check_used (MonoGenericContext *context) MONO_INTERNAL;
1097
1098 int
1099 mono_class_check_context_used (MonoClass *class) MONO_INTERNAL;
1100
1101 gboolean
1102 mono_generic_context_is_sharable (MonoGenericContext *context, gboolean allow_type_vars) MONO_INTERNAL;
1103
1104 gboolean
1105 mono_method_is_generic_impl (MonoMethod *method) MONO_INTERNAL;
1106 gboolean
1107 mono_method_is_generic_sharable_impl (MonoMethod *method, gboolean allow_type_vars) MONO_INTERNAL;
1108
1109 void
1110 mono_class_unregister_image_generic_subclasses (MonoImage *image) MONO_INTERNAL;
1111
1112 gboolean
1113 mono_method_can_access_method_full (MonoMethod *method, MonoMethod *called, MonoClass *context_klass) MONO_INTERNAL;
1114
1115 gboolean
1116 mono_method_can_access_field_full (MonoMethod *method, MonoClassField *field, MonoClass *context_klass) MONO_INTERNAL;
1117
1118 MonoClass *
1119 mono_class_get_generic_type_definition (MonoClass *klass) MONO_INTERNAL;
1120
1121 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */