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