2009-01-26 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 struct _MonoClass {
246         /* element class for arrays and enum */
247         MonoClass *element_class; 
248         /* used for subtype checks */
249         MonoClass *cast_class; 
250
251         /* for fast subtype checks */
252         MonoClass **supertypes;
253         guint16     idepth;
254
255         /* array dimension */
256         guint8     rank;          
257
258         int        instance_size; /* object instance size */
259
260         guint inited          : 1;
261         /* We use init_pending to detect cyclic calls to mono_class_init */
262         guint init_pending    : 1;
263
264         /* A class contains static and non static data. Static data can be
265          * of the same type as the class itselfs, but it does not influence
266          * the instance size of the class. To avoid cyclic calls to 
267          * mono_class_init (from mono_class_instance_size ()) we first 
268          * initialise all non static fields. After that we set size_inited 
269          * to 1, because we know the instance size now. After that we 
270          * initialise all static fields.
271          */
272         guint size_inited     : 1;
273         guint valuetype       : 1; /* derives from System.ValueType */
274         guint enumtype        : 1; /* derives from System.Enum */
275         guint blittable       : 1; /* class is blittable */
276         guint unicode         : 1; /* class uses unicode char when marshalled */
277         guint wastypebuilder  : 1; /* class was created at runtime from a TypeBuilder */
278         /* next byte */
279         guint8 min_align;
280         /* next byte */
281         guint packing_size    : 4;
282         /* still 4 bits free */
283         /* next byte */
284         guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
285         guint has_finalize    : 1; /* class has its own Finalize impl */ 
286         guint marshalbyref    : 1; /* class is a MarshalByRefObject */
287         guint contextbound    : 1; /* class is a ContextBoundObject */
288         guint delegate        : 1; /* class is a Delegate */
289         guint gc_descr_inited : 1; /* gc_descr is initialized */
290         guint has_cctor       : 1; /* class has a cctor */
291         guint has_references  : 1; /* it has GC-tracked references in the instance */
292         /* next byte */
293         guint has_static_refs : 1; /* it has static fields that are GC-tracked */
294         guint no_special_static_fields : 1; /* has no thread/context static fields */
295         /* directly or indirectly derives from ComImport attributed class.
296          * this means we need to create a proxy for instances of this class
297          * for COM Interop. set this flag on loading so all we need is a quick check
298          * during object creation rather than having to traverse supertypes
299          */
300         guint is_com_object : 1; 
301         guint nested_classes_inited : 1; /* Whenever nested_class is initialized */
302         guint simd_type : 1; /* class is a simd intrinsic type */
303
304         guint8     exception_type;      /* MONO_EXCEPTION_* */
305
306         /* Additional information about the exception */
307         /* Stored as property MONO_CLASS_PROP_EXCEPTION_DATA */
308         //void       *exception_data;
309
310         MonoClass  *parent;
311         MonoClass  *nested_in;
312         GList      *nested_classes;
313
314         MonoImage *image;
315         const char *name;
316         const char *name_space;
317
318         /* The underlying type of the enum */
319         MonoType *enum_basetype;
320
321         guint32    declsec_flags;       /* declarative security attributes flags */
322         guint32    type_token;
323         int        vtable_size; /* number of slots */
324
325         guint16     interface_count;
326         guint16     interface_id;        /* unique inderface id (for interfaces) */
327         guint16     max_interface_id;
328         
329         guint16     interface_offsets_count;
330         MonoClass **interfaces_packed;
331         guint16    *interface_offsets_packed;
332         guint8     *interface_bitmap;
333         
334         MonoClass **interfaces;
335
336         union {
337                 int class_size; /* size of area for static fields */
338                 int element_size; /* for array types */
339                 int generic_param_token; /* for generic param types, both var and mvar */
340         } sizes;
341
342         /*
343          * From the TypeDef table
344          */
345         guint32    flags;
346         struct {
347                 guint32 first, count;
348         } field, method, property, event;
349
350         /* loaded on demand */
351         MonoMarshalType *marshal_info;
352
353         /*
354          * Field information: Type and location from object base
355          */
356         MonoClassField *fields;
357
358         /* Initialized by a call to mono_class_setup_properties () */
359         MonoProperty *properties;
360
361         /* Initialized by a call to mono_class_setup_events () */
362         MonoEvent *events;
363
364         MonoMethod **methods;
365
366         /* used as the type of the this argument and when passing the arg by value */
367         MonoType this_arg;
368         MonoType byval_arg;
369
370         MonoGenericClass *generic_class;
371         MonoGenericContainer *generic_container;
372
373         void *reflection_info;
374
375         void *gc_descr;
376
377         MonoClassRuntimeInfo *runtime_info;
378
379         /* next element in the class_cache hash list (in MonoImage) */
380         MonoClass *next_class_cache;
381
382         /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
383         MonoMethod **vtable;
384
385         /* Default values/RVA for fields */
386         /* Accessed using mono_class_get_field_default_value () / mono_field_get_data () */
387         MonoFieldDefaultValue *field_def_values;
388 };
389
390 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && ((k)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
391 int mono_class_interface_offset (MonoClass *klass, MonoClass *itf);
392
393 typedef gpointer MonoRuntimeGenericContext;
394
395 /* the interface_offsets array is stored in memory before this struct */
396 struct MonoVTable {
397         MonoClass  *klass;
398          /*
399          * According to comments in gc_gcj.h, this should be the second word in
400          * the vtable.
401          */
402         void *gc_descr;         
403         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
404         gpointer    data; /* to store static class data */
405         gpointer    type; /* System.Type type for klass */
406         guint8     *interface_bitmap;
407         guint16     max_interface_id;
408         guint8      rank;
409         guint remote          : 1; /* class is remotely activated */
410         guint initialized     : 1; /* cctor has been run */
411         guint init_failed     : 1; /* cctor execution failed */
412         guint32     imt_collisions_bitmap;
413         MonoRuntimeGenericContext *runtime_generic_context;
414         /* do not add any fields after vtable, the structure is dynamically extended */
415         gpointer    vtable [MONO_ZERO_LEN_ARRAY];       
416 };
417
418 #define MONO_VTABLE_IMPLEMENTS_INTERFACE(vt,uiid) (((uiid) <= (vt)->max_interface_id) && ((vt)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
419
420 /*
421  * Generic instantiation data type encoding.
422  */
423
424 /*
425  * A particular generic instantiation:
426  *
427  * All instantiations are cached and we don't distinguish between class and method
428  * instantiations here.
429  */
430 struct _MonoGenericInst {
431         guint id;                       /* unique ID for debugging */
432         guint type_argc    : 22;        /* number of type arguments */
433         guint is_open      :  1;        /* if this is an open type */
434         MonoType **type_argv;
435 };
436
437 /*
438  * The generic context: an instantiation of a set of class and method generic parameters.
439  *
440  * NOTE: Never allocate this directly on the heap.  It have to be either allocated on the stack,
441  *       or embedded within other objects.  Don't store pointers to this, because it may be on the stack.
442  *       If you really have to, ensure you store a pointer to the embedding object along with it.
443  */
444 struct _MonoGenericContext {
445         /* The instantiation corresponding to the class generic parameters */
446         MonoGenericInst *class_inst;
447         /* The instantiation corresponding to the method generic parameters */
448         MonoGenericInst *method_inst;
449 };
450
451 /*
452  * Inflated generic method.
453  */
454 struct _MonoMethodInflated {
455         union {
456                 MonoMethod method;
457                 MonoMethodNormal normal;
458                 MonoMethodPInvoke pinvoke;
459         } method;
460         MonoMethod *declaring;          /* the generic method definition. */
461         MonoGenericContext context;     /* The current instantiation */
462
463         /* TODO we MUST get rid of this field, it's an ugly hack nobody is proud of. */
464         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 */
465 };
466
467 /*
468  * A particular instantiation of a generic type.
469  */
470 struct _MonoGenericClass {
471         MonoClass *container_class;     /* the generic type definition */
472         MonoGenericContext context;     /* a context that contains the type instantiation doesn't contain any method instantiation */
473         guint is_dynamic  : 1;          /* We're a MonoDynamicGenericClass */
474         guint is_tb_open  : 1;          /* This is the fully open instantiation for a type_builder. Quite ugly, but it's temporary.*/
475         MonoClass *cached_class;        /* if present, the MonoClass corresponding to the instantiation.  */
476 };
477
478 /*
479  * This is used when instantiating a generic type definition which is
480  * a TypeBuilder.
481  */
482 struct _MonoDynamicGenericClass {
483         MonoGenericClass generic_class;
484         int count_methods;
485         MonoMethod **methods;
486         int count_ctors;
487         MonoMethod **ctors;
488         int count_fields;
489         MonoClassField *fields;
490         int count_properties;
491         MonoProperty *properties;
492         int count_events;
493         MonoEvent *events;
494         guint initialized;
495         /* The non-inflated types of the fields */
496         MonoType **field_generic_types;
497         /* The managed objects representing the fields */
498         MonoObject **field_objects;
499 };
500
501 /*
502  * The generic container.
503  *
504  * Stores the type parameters of a generic type definition or a generic method definition.
505  */
506 struct _MonoGenericContainer {
507         MonoGenericContext context;
508         /* If we're a generic method definition in a generic type definition,
509            the generic container of the containing class. */
510         MonoGenericContainer *parent;
511         /* the generic type definition or the generic method definition corresponding to this container */
512         union {
513                 MonoClass *klass;
514                 MonoMethod *method;
515         } owner;
516         int type_argc    : 31;
517         /* If true, we're a generic method, otherwise a generic type definition. */
518         /* Invariant: parent != NULL => is_method */
519         int is_method    : 1;
520         /* Our type parameters. */
521         MonoGenericParam *type_params;
522 };
523
524 /*
525  * A type parameter.
526  */
527 struct _MonoGenericParam {
528         MonoGenericContainer *owner;    /* Type or method this parameter was defined in. */
529         MonoClass *pklass;              /* The corresponding `MonoClass'. */
530         const char *name;
531         guint16 flags;
532         guint16 num;
533         MonoClass** constraints; /* NULL means end of list */
534         /* If owner is NULL, this is the image whose mempool this struct was allocated from */
535         MonoImage *image;
536 };
537
538 /*
539  * Class information which might be cached by the runtime in the AOT file for
540  * example. Caching this allows us to avoid computing a generic vtable
541  * (class->vtable) in most cases, saving time and avoiding creation of lots of
542  * MonoMethod structures.
543  */
544 typedef struct MonoCachedClassInfo {
545         guint32 vtable_size;
546         guint has_finalize : 1;
547         guint ghcimpl : 1;
548         guint has_cctor : 1;
549         guint has_nested_classes : 1;
550         guint blittable : 1;
551         guint has_references : 1;
552         guint has_static_refs : 1;
553         guint no_special_static_fields : 1;
554         guint32 cctor_token;
555         MonoImage *finalize_image;
556         guint32 finalize_token;
557         guint32 instance_size;
558         guint32 class_size;
559         guint32 packing_size;
560         guint32 min_align;
561 } MonoCachedClassInfo;
562
563 typedef struct {
564         const char *name;
565         gconstpointer func;
566         gconstpointer wrapper;
567         gconstpointer trampoline;
568         MonoMethodSignature *sig;
569 } MonoJitICallInfo;
570
571 typedef struct {
572         guint8 exception_type;
573         char *class_name; /* If kind == TYPE */
574         char *assembly_name; /* If kind == TYPE or ASSEMBLY */
575         MonoClass *klass; /* If kind != TYPE */
576         const char *member_name; /* If kind != TYPE */
577         gboolean ref_only; /* If kind == ASSEMBLY */
578         char *msg; /* If kind == BAD_IMAGE */
579 } MonoLoaderError;
580
581 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
582
583 typedef struct {
584         gulong new_object_count;
585         gulong initialized_class_count;
586         gulong generic_vtable_count;
587         gulong used_class_count;
588         gulong method_count;
589         gulong class_vtable_size;
590         gulong class_static_data_size;
591         gulong generic_instance_count;
592         gulong generic_class_count;
593         gulong inflated_method_count;
594         gulong inflated_method_count_2;
595         gulong inflated_type_count;
596         gulong generics_metadata_size;
597         gulong dynamic_code_alloc_count;
598         gulong dynamic_code_bytes_count;
599         gulong dynamic_code_frees_count;
600         gulong delegate_creations;
601         gulong imt_tables_size;
602         gulong imt_number_of_tables;
603         gulong imt_number_of_methods;
604         gulong imt_used_slots;
605         gulong imt_slots_with_collisions;
606         gulong imt_max_collisions_in_slot;
607         gulong imt_method_count_when_max_collisions;
608         gulong imt_thunks_size;
609         gulong jit_info_table_insert_count;
610         gulong jit_info_table_remove_count;
611         gulong jit_info_table_lookup_count;
612         gulong hazardous_pointer_count;
613         gulong generics_sharable_methods;
614         gulong generics_unsharable_methods;
615         gulong generics_shared_methods;
616         gulong minor_gc_count;
617         gulong major_gc_count;
618         gulong minor_gc_time_usecs;
619         gulong major_gc_time_usecs;
620         gboolean enabled;
621 } MonoStats;
622
623 /* 
624  * new structure to hold performace counters values that are exported
625  * to managed code.
626  * Note: never remove fields from this structure and only add them to the end.
627  * Size of fields and type should not be changed as well.
628  */
629 typedef struct {
630         /* JIT category */
631         guint32 jit_methods;
632         guint32 jit_bytes;
633         guint32 jit_time;
634         guint32 jit_failures;
635         /* Exceptions category */
636         guint32 exceptions_thrown;
637         guint32 exceptions_filters;
638         guint32 exceptions_finallys;
639         guint32 exceptions_depth;
640         guint32 aspnet_requests_queued;
641         guint32 aspnet_requests;
642         /* Memory category */
643         guint32 gc_collections0;
644         guint32 gc_collections1;
645         guint32 gc_collections2;
646         guint32 gc_promotions0;
647         guint32 gc_promotions1;
648         guint32 gc_promotion_finalizers;
649         guint32 gc_gen0size;
650         guint32 gc_gen1size;
651         guint32 gc_gen2size;
652         guint32 gc_lossize;
653         guint32 gc_fin_survivors;
654         guint32 gc_num_handles;
655         guint32 gc_allocated;
656         guint32 gc_induced;
657         guint32 gc_time;
658         guint32 gc_total_bytes;
659         guint32 gc_committed_bytes;
660         guint32 gc_reserved_bytes;
661         guint32 gc_num_pinned;
662         guint32 gc_sync_blocks;
663         /* Remoting category */
664         guint32 remoting_calls;
665         guint32 remoting_channels;
666         guint32 remoting_proxies;
667         guint32 remoting_classes;
668         guint32 remoting_objects;
669         guint32 remoting_contexts;
670         /* Loader category */
671         guint32 loader_classes;
672         guint32 loader_total_classes;
673         guint32 loader_appdomains;
674         guint32 loader_total_appdomains;
675         guint32 loader_assemblies;
676         guint32 loader_total_assemblies;
677         guint32 loader_failures;
678         guint32 loader_bytes;
679         guint32 loader_appdomains_uloaded;
680         /* Threads and Locks category  */
681         guint32 thread_contentions;
682         guint32 thread_queue_len;
683         guint32 thread_queue_max;
684         guint32 thread_num_logical;
685         guint32 thread_num_physical;
686         guint32 thread_cur_recognized;
687         guint32 thread_num_recognized;
688         /* Interop category */
689         guint32 interop_num_ccw;
690         guint32 interop_num_stubs;
691         guint32 interop_num_marshals;
692         /* Security category */
693         guint32 security_num_checks;
694         guint32 security_num_link_checks;
695         guint32 security_time;
696         guint32 security_depth;
697         guint32 unused;
698 } MonoPerfCounters;
699
700 extern MonoPerfCounters *mono_perfcounters MONO_INTERNAL;
701
702 void mono_perfcounters_init (void);
703
704 /*
705  * The definition of the first field in SafeHandle,
706  * Keep in sync with SafeHandle.cs, this is only used
707  * to access the `handle' parameter.
708  */
709 typedef struct {
710         MonoObject  base;
711         void       *handle;
712 } MonoSafeHandle;
713
714 /*
715  * Keep in sync with HandleRef.cs
716  */
717 typedef struct {
718         MonoObject *wrapper;
719         void       *handle;
720 } MonoHandleRef;
721
722 enum {
723         MONO_GENERIC_SHARING_NONE,
724         MONO_GENERIC_SHARING_COLLECTIONS,
725         MONO_GENERIC_SHARING_CORLIB,
726         MONO_GENERIC_SHARING_ALL
727 };
728
729 /*
730  * Flags for which contexts were used in inflating a generic.
731  */
732 enum {
733         MONO_GENERIC_CONTEXT_USED_CLASS = 1,
734         MONO_GENERIC_CONTEXT_USED_METHOD = 2
735 };
736
737 #define MONO_GENERIC_CONTEXT_USED_BOTH          (MONO_GENERIC_CONTEXT_USED_CLASS | MONO_GENERIC_CONTEXT_USED_METHOD)
738
739 extern MonoStats mono_stats MONO_INTERNAL;
740
741 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
742 typedef gpointer (*MonoJumpTrampoline)       (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper);
743 typedef gpointer (*MonoRemotingTrampoline)       (MonoDomain *domain, MonoMethod *method, MonoRemotingTarget target);
744 typedef gpointer (*MonoDelegateTrampoline)       (MonoClass *klass);
745
746 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
747
748 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
749
750 typedef gboolean (*MonoGetClassFromName) (MonoImage *image, const char *name_space, const char *name, MonoClass **res);
751
752 void
753 mono_classes_init (void) MONO_INTERNAL;
754
755 void
756 mono_classes_cleanup (void) MONO_INTERNAL;
757
758 void
759 mono_class_layout_fields   (MonoClass *klass) MONO_INTERNAL;
760
761 void
762 mono_class_setup_interface_offsets (MonoClass *klass) MONO_INTERNAL;
763
764 void
765 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum) MONO_INTERNAL;
766
767 void
768 mono_class_setup_vtable (MonoClass *klass) MONO_INTERNAL;
769
770 void
771 mono_class_setup_methods (MonoClass *klass) MONO_INTERNAL;
772
773 void
774 mono_class_setup_mono_type (MonoClass *klass) MONO_INTERNAL;
775
776 void
777 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
778
779 void
780 mono_class_setup_supertypes (MonoClass *klass) MONO_INTERNAL;
781
782 MonoMethod*
783 mono_class_get_method_by_index (MonoClass *class, int index) MONO_INTERNAL;
784
785 MonoMethod*
786 mono_class_get_inflated_method (MonoClass *class, MonoMethod *method) MONO_INTERNAL;
787
788 MonoMethod*
789 mono_class_get_vtable_entry (MonoClass *class, int offset) MONO_INTERNAL;
790
791 GPtrArray*
792 mono_class_get_implemented_interfaces (MonoClass *klass) MONO_INTERNAL;
793
794 gboolean
795 mono_class_is_open_constructed_type (MonoType *t) MONO_INTERNAL;
796
797 gboolean
798 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
799                                MonoGenericContext *generic_context) MONO_INTERNAL;
800
801 MonoMethod*
802 mono_class_get_cctor (MonoClass *klass) MONO_INTERNAL;
803
804 MonoMethod*
805 mono_class_get_finalizer (MonoClass *klass) MONO_INTERNAL;
806
807 gboolean
808 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller) MONO_INTERNAL;
809
810 gboolean
811 mono_class_field_is_special_static (MonoClassField *field) MONO_INTERNAL;
812
813 gboolean
814 mono_class_has_special_static_fields (MonoClass *klass) MONO_INTERNAL;
815
816 const char*
817 mono_class_get_field_default_value (MonoClassField *field, MonoTypeEnum *def_type) MONO_INTERNAL;
818
819 void
820 mono_install_trampoline (MonoTrampoline func) MONO_INTERNAL;
821
822 void
823 mono_install_jump_trampoline (MonoJumpTrampoline func) MONO_INTERNAL;
824
825 void
826 mono_install_remoting_trampoline (MonoRemotingTrampoline func) MONO_INTERNAL;
827
828 void
829 mono_install_delegate_trampoline (MonoDelegateTrampoline func) MONO_INTERNAL;
830
831 gpointer
832 mono_lookup_dynamic_token (MonoImage *image, guint32 token, MonoGenericContext *context) MONO_INTERNAL;
833
834 gpointer
835 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, gboolean check_token, MonoClass **handle_class, MonoGenericContext *context) MONO_INTERNAL;
836
837 void
838 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func) MONO_INTERNAL;
839
840 gpointer
841 mono_runtime_create_jump_trampoline (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper) MONO_INTERNAL;
842
843 gpointer
844 mono_runtime_create_delegate_trampoline (MonoClass *klass) MONO_INTERNAL;
845
846 void
847 mono_install_get_cached_class_info (MonoGetCachedClassInfo func) MONO_INTERNAL;
848
849 void
850 mono_install_get_class_from_name (MonoGetClassFromName func) MONO_INTERNAL;
851
852 MonoGenericContext*
853 mono_class_get_context (MonoClass *class) MONO_INTERNAL;
854
855 MonoGenericContext*
856 mono_method_get_context (MonoMethod *method) MONO_INTERNAL;
857
858 /* Used by monodis, thus cannot be MONO_INTERNAL */
859 MonoGenericContainer*
860 mono_method_get_generic_container (MonoMethod *method);
861
862 MonoGenericContext*
863 mono_generic_class_get_context (MonoGenericClass *gclass) MONO_INTERNAL;
864
865 MonoClass*
866 mono_generic_class_get_class (MonoGenericClass *gclass) MONO_INTERNAL;
867
868 void
869 mono_method_set_generic_container (MonoMethod *method, MonoGenericContainer* container) MONO_INTERNAL;
870
871 MonoMethod*
872 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
873
874 MonoMethodInflated*
875 mono_method_inflated_lookup (MonoMethodInflated* method, gboolean cache) MONO_INTERNAL;
876
877 MonoMethodSignature *
878 mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context);
879
880 MonoType*
881 mono_class_inflate_generic_type_with_mempool (MonoMemPool *mempool, MonoType *type, MonoGenericContext *context) MONO_INTERNAL;
882
883 void
884 mono_metadata_free_inflated_signature (MonoMethodSignature *sig);
885
886 typedef struct {
887         MonoImage *corlib;
888         MonoClass *object_class;
889         MonoClass *byte_class;
890         MonoClass *void_class;
891         MonoClass *boolean_class;
892         MonoClass *sbyte_class;
893         MonoClass *int16_class;
894         MonoClass *uint16_class;
895         MonoClass *int32_class;
896         MonoClass *uint32_class;
897         MonoClass *int_class;
898         MonoClass *uint_class;
899         MonoClass *int64_class;
900         MonoClass *uint64_class;
901         MonoClass *single_class;
902         MonoClass *double_class;
903         MonoClass *char_class;
904         MonoClass *string_class;
905         MonoClass *enum_class;
906         MonoClass *array_class;
907         MonoClass *delegate_class;
908         MonoClass *multicastdelegate_class;
909         MonoClass *asyncresult_class;
910         MonoClass *waithandle_class;
911         MonoClass *typehandle_class;
912         MonoClass *fieldhandle_class;
913         MonoClass *methodhandle_class;
914         MonoClass *systemtype_class;
915         MonoClass *monotype_class;
916         MonoClass *exception_class;
917         MonoClass *threadabortexception_class;
918         MonoClass *thread_class;
919         MonoClass *transparent_proxy_class;
920         MonoClass *real_proxy_class;
921         MonoClass *mono_method_message_class;
922         MonoClass *appdomain_class;
923         MonoClass *field_info_class;
924         MonoClass *method_info_class;
925         MonoClass *stringbuilder_class;
926         MonoClass *math_class;
927         MonoClass *stack_frame_class;
928         MonoClass *stack_trace_class;
929         MonoClass *marshal_class;
930         MonoClass *iserializeable_class;
931         MonoClass *serializationinfo_class;
932         MonoClass *streamingcontext_class;
933         MonoClass *typed_reference_class;
934         MonoClass *argumenthandle_class;
935         MonoClass *marshalbyrefobject_class;
936         MonoClass *monitor_class;
937         MonoClass *iremotingtypeinfo_class;
938         MonoClass *runtimesecurityframe_class;
939         MonoClass *executioncontext_class;
940         MonoClass *internals_visible_class;
941         MonoClass *generic_ilist_class;
942         MonoClass *generic_nullable_class;
943         MonoClass *variant_class;
944         MonoClass *com_object_class;
945         MonoClass *com_interop_proxy_class;
946         MonoClass *iunknown_class;
947         MonoClass *idispatch_class;
948         MonoClass *safehandle_class;
949         MonoClass *handleref_class;
950         MonoClass *attribute_class;
951         MonoClass *customattribute_data_class;
952 } MonoDefaults;
953
954 extern MonoDefaults mono_defaults MONO_INTERNAL;
955
956 void
957 mono_loader_init           (void) MONO_INTERNAL;
958
959 void
960 mono_loader_cleanup        (void) MONO_INTERNAL;
961
962 void
963 mono_loader_lock           (void) MONO_INTERNAL;
964
965 void
966 mono_loader_unlock         (void) MONO_INTERNAL;
967
968 void
969 mono_loader_set_error_assembly_load (const char *assembly_name, gboolean ref_only) MONO_INTERNAL;
970
971 void
972 mono_loader_set_error_type_load (const char *class_name, const char *assembly_name) MONO_INTERNAL;
973
974 void
975 mono_loader_set_error_method_load (const char *class_name, const char *member_name) MONO_INTERNAL;
976
977 void
978 mono_loader_set_error_field_load (MonoClass *klass, const char *member_name) MONO_INTERNAL;
979 void
980 mono_loader_set_error_bad_image (char *msg) MONO_INTERNAL;
981
982 MonoException *
983 mono_loader_error_prepare_exception (MonoLoaderError *error) MONO_INTERNAL;
984
985 MonoLoaderError *
986 mono_loader_get_last_error (void) MONO_INTERNAL;
987
988 void
989 mono_loader_clear_error    (void) MONO_INTERNAL;
990
991 void
992 mono_reflection_init       (void) MONO_INTERNAL;
993
994 void
995 mono_icall_init            (void) MONO_INTERNAL;
996
997 void
998 mono_icall_cleanup         (void) MONO_INTERNAL;
999
1000 gpointer
1001 mono_method_get_wrapper_data (MonoMethod *method, guint32 id) MONO_INTERNAL;
1002
1003 void
1004 mono_install_stack_walk (MonoStackWalkImpl func) MONO_INTERNAL;
1005
1006 gboolean
1007 mono_metadata_has_generic_params (MonoImage *image, guint32 token) MONO_INTERNAL;
1008
1009 MonoGenericContainer *
1010 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
1011                                    MonoGenericContainer *parent_container);
1012
1013 void
1014 mono_metadata_load_generic_param_constraints (MonoImage *image, guint32 token,
1015                                               MonoGenericContainer *container);
1016
1017 MonoMethodSignature*
1018 mono_create_icall_signature (const char *sigstr) MONO_INTERNAL;
1019
1020 MonoJitICallInfo *
1021 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save) MONO_INTERNAL;
1022
1023 void
1024 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper) MONO_INTERNAL;
1025
1026 MonoJitICallInfo *
1027 mono_find_jit_icall_by_name (const char *name) MONO_INTERNAL;
1028
1029 MonoJitICallInfo *
1030 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_INTERNAL;
1031
1032 GHashTable*
1033 mono_get_jit_icall_info (void) MONO_INTERNAL;
1034
1035 gboolean
1036 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data) MONO_INTERNAL;
1037
1038 gpointer
1039 mono_class_get_exception_data (MonoClass *klass) MONO_INTERNAL;
1040
1041 MonoException*
1042 mono_class_get_exception_for_failure (MonoClass *klass) MONO_INTERNAL;
1043
1044 char*
1045 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format) MONO_INTERNAL;
1046
1047 char*
1048 mono_type_get_full_name (MonoClass *class) MONO_INTERNAL;
1049
1050 MonoArrayType *mono_dup_array_type (MonoMemPool *mp, MonoArrayType *a) MONO_INTERNAL;
1051 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoMemPool *mp, MonoMethodSignature *sig) MONO_INTERNAL;
1052
1053 void
1054 mono_image_init_name_cache (MonoImage *image);
1055
1056 gboolean mono_class_is_nullable (MonoClass *klass) MONO_INTERNAL;
1057 MonoClass *mono_class_get_nullable_param (MonoClass *klass) MONO_INTERNAL;
1058
1059 /* object debugging functions, for use inside gdb */
1060 void mono_object_describe        (MonoObject *obj);
1061 void mono_object_describe_fields (MonoObject *obj);
1062 void mono_value_describe_fields  (MonoClass* klass, const char* addr);
1063 void mono_class_describe_statics (MonoClass* klass);
1064
1065 /*Enum validation related functions*/
1066 gboolean
1067 mono_type_is_valid_enum_basetype (MonoType * type);
1068
1069 gboolean
1070 mono_class_is_valid_enum (MonoClass *klass);
1071
1072 MonoType *
1073 mono_type_get_full        (MonoImage *image, guint32 type_token, MonoGenericContext *context) MONO_INTERNAL;
1074
1075 gboolean
1076 mono_generic_class_is_generic_type_definition (MonoGenericClass *gklass) MONO_INTERNAL;
1077
1078 MonoMethod*
1079 mono_method_get_declaring_generic_method (MonoMethod *method) MONO_INTERNAL;
1080
1081 MonoMethod*
1082 mono_class_get_method_generic (MonoClass *klass, MonoMethod *method) MONO_INTERNAL;
1083
1084 MonoType*
1085 mono_type_get_basic_type_from_generic (MonoType *type) MONO_INTERNAL;
1086
1087 gboolean
1088 mono_class_generic_sharing_enabled (MonoClass *class) MONO_INTERNAL;
1089
1090 gpointer
1091 mono_class_fill_runtime_generic_context (MonoVTable *class_vtable, guint32 slot) MONO_INTERNAL;
1092
1093 gpointer
1094 mono_method_fill_runtime_generic_context (MonoMethodRuntimeGenericContext *mrgctx, guint32 slot) MONO_INTERNAL;
1095
1096 MonoMethodRuntimeGenericContext*
1097 mono_method_lookup_rgctx (MonoVTable *class_vtable, MonoGenericInst *method_inst) MONO_INTERNAL;
1098
1099 gboolean
1100 mono_method_needs_static_rgctx_invoke (MonoMethod *method, gboolean allow_type_vars) MONO_INTERNAL;
1101
1102 int
1103 mono_class_rgctx_get_array_size (int n, gboolean mrgctx) MONO_INTERNAL;
1104
1105 guint32
1106 mono_method_lookup_or_register_other_info (MonoMethod *method, gboolean in_mrgctx, gpointer data,
1107         int info_type, MonoGenericContext *generic_context) MONO_INTERNAL;
1108
1109 int
1110 mono_generic_context_check_used (MonoGenericContext *context) MONO_INTERNAL;
1111
1112 int
1113 mono_class_check_context_used (MonoClass *class) MONO_INTERNAL;
1114
1115 gboolean
1116 mono_generic_context_is_sharable (MonoGenericContext *context, gboolean allow_type_vars) MONO_INTERNAL;
1117
1118 gboolean
1119 mono_method_is_generic_impl (MonoMethod *method) MONO_INTERNAL;
1120 gboolean
1121 mono_method_is_generic_sharable_impl (MonoMethod *method, gboolean allow_type_vars) MONO_INTERNAL;
1122
1123 void
1124 mono_class_unregister_image_generic_subclasses (MonoImage *image) MONO_INTERNAL;
1125
1126 gboolean
1127 mono_method_can_access_method_full (MonoMethod *method, MonoMethod *called, MonoClass *context_klass) MONO_INTERNAL;
1128
1129 gboolean
1130 mono_method_can_access_field_full (MonoMethod *method, MonoClassField *field, MonoClass *context_klass) MONO_INTERNAL;
1131
1132 MonoClass *
1133 mono_class_get_generic_type_definition (MonoClass *klass) MONO_INTERNAL;
1134
1135 gboolean
1136 mono_class_has_parent_and_ignore_generics (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
1137
1138 int
1139 mono_method_get_vtable_slot (MonoMethod *method) MONO_INTERNAL;
1140
1141 int
1142 mono_method_get_vtable_index (MonoMethod *method) MONO_INTERNAL;
1143
1144 MonoMethod*
1145 mono_method_search_in_array_class (MonoClass *klass, const char *name, MonoMethodSignature *sig) MONO_INTERNAL;
1146
1147 void
1148 mono_class_setup_interface_id (MonoClass *class) MONO_INTERNAL;
1149
1150 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */