2 * Copyright 2012 Xamarin Inc
3 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
5 #ifndef __MONO_METADATA_CLASS_INTERNALS_H__
6 #define __MONO_METADATA_CLASS_INTERNALS_H__
8 #include <mono/metadata/class.h>
9 #include <mono/metadata/object.h>
10 #include <mono/metadata/mempool.h>
11 #include <mono/metadata/metadata-internals.h>
12 #include <mono/io-layer/io-layer.h>
13 #include "mono/utils/mono-compiler.h"
14 #include "mono/utils/mono-error.h"
15 #include "mono/sgen/gc-internal-agnostic.h"
17 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
19 #define MONO_CLASS_HAS_STATIC_METADATA(klass) ((klass)->type_token && !(klass)->image->dynamic && !(klass)->generic_class)
21 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
23 extern gboolean mono_print_vtable;
24 extern gboolean mono_align_small_structs;
26 typedef struct _MonoMethodWrapper MonoMethodWrapper;
27 typedef struct _MonoMethodInflated MonoMethodInflated;
28 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
30 /* Properties that applies to a group of structs should better use a higher number
31 * to avoid colision with type specific properties.
33 * This prop applies to class, method, property, event, assembly and image.
35 #define MONO_PROP_DYNAMIC_CATTR 0x1000
37 #ifdef ENABLE_ICALL_EXPORT
38 #pragma GCC diagnostic ignored "-Wmissing-prototypes"
39 #define ICALL_EXPORT MONO_API
41 #define ICALL_EXPORT static
45 #define WRAPPER(e,n) MONO_WRAPPER_ ## e,
46 #include "wrapper-types.h"
52 MONO_TYPE_NAME_FORMAT_IL,
53 MONO_TYPE_NAME_FORMAT_REFLECTION,
54 MONO_TYPE_NAME_FORMAT_FULL_NAME,
55 MONO_TYPE_NAME_FORMAT_ASSEMBLY_QUALIFIED
59 MONO_REMOTING_TARGET_UNKNOWN,
60 MONO_REMOTING_TARGET_APPDOMAIN,
61 MONO_REMOTING_TARGET_COMINTEROP
64 #define MONO_METHOD_PROP_GENERIC_CONTAINER 0
67 guint16 flags; /* method flags */
68 guint16 iflags; /* method implementation flags */
70 MonoClass *klass; /* To what class does this method belong */
71 MonoMethodSignature *signature;
72 /* name is useful mostly for debugging */
74 /* this is used by the inlining algorithm */
75 unsigned int inline_info:1;
76 unsigned int inline_failure:1;
77 unsigned int wrapper_type:5;
78 unsigned int string_ctor:1;
79 unsigned int save_lmf:1;
80 unsigned int dynamic:1; /* created & destroyed during runtime */
81 unsigned int sre_method:1; /* created at runtime using Reflection.Emit */
82 unsigned int is_generic:1; /* whenever this is a generic method definition */
83 unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
84 unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
85 unsigned int verification_success:1; /* whether this method has been verified successfully.*/
89 * If is_generic is TRUE, the generic_container is stored in image->property_hash,
90 * using the key MONO_METHOD_PROP_GENERIC_CONTAINER.
94 struct _MonoMethodWrapper {
96 MonoMethodHeader *header;
100 struct _MonoMethodPInvoke {
103 /* add marshal info */
104 guint16 piflags; /* pinvoke flags */
105 guint16 implmap_idx; /* index into IMPLMAP */
109 * Stores the default value / RVA of fields.
110 * This information is rarely needed, so it is stored separately from
113 typedef struct MonoFieldDefaultValue {
115 * If the field is constant, pointer to the metadata constant
117 * If the field has an RVA flag, pointer to the data.
122 /* If the field is constant, the type of the constant. */
123 MonoTypeEnum def_type;
124 } MonoFieldDefaultValue;
127 * MonoClassField is just a runtime representation of the metadata for
128 * field, it doesn't contain the data directly. Static fields are
129 * stored in MonoVTable->data. Instance fields are allocated in the
130 * objects after the object header.
132 struct _MonoClassField {
133 /* Type of the field */
138 /* Type where the field was defined */
142 * Offset where this field is stored; if it is an instance
143 * field, it's the offset from the start of the object, if
144 * it's static, it's from the start of the memory chunk
145 * allocated for statics for the class.
146 * For special static fields, this is set to -1 during vtable construction.
151 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
152 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
153 && (strcmp (mono_field_get_name (field), "_Deleted") == 0))
155 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
156 /* Try to avoid loading the field's type */
157 #define mono_field_is_deleted_with_flags(field, flags) (((flags) & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
158 && (strcmp (mono_field_get_name (field), "_Deleted") == 0))
161 MonoClassField *field;
163 MonoMarshalSpec *mspec;
167 guint32 native_size, min_align;
169 MonoMethod *ptr_to_str;
170 MonoMethod *str_to_ptr;
171 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
174 #define MONO_SIZEOF_MARSHAL_TYPE (offsetof (MonoMarshalType, fields))
176 struct _MonoProperty {
190 #ifndef MONO_SMALL_CONFIG
196 /* type of exception being "on hold" for later processing (see exception_type) */
198 MONO_EXCEPTION_NONE = 0,
199 MONO_EXCEPTION_INVALID_PROGRAM = 3,
200 MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
201 MONO_EXCEPTION_MISSING_METHOD = 5,
202 MONO_EXCEPTION_MISSING_FIELD = 6,
203 MONO_EXCEPTION_TYPE_LOAD = 7,
204 MONO_EXCEPTION_FILE_NOT_FOUND = 8,
205 MONO_EXCEPTION_METHOD_ACCESS = 9,
206 MONO_EXCEPTION_FIELD_ACCESS = 10,
207 MONO_EXCEPTION_GENERIC_SHARING_FAILED = 11,
208 MONO_EXCEPTION_BAD_IMAGE = 12,
209 MONO_EXCEPTION_OBJECT_SUPPLIED = 13, /*The exception object is already created.*/
210 MONO_EXCEPTION_OUT_OF_MEMORY = 14,
211 MONO_EXCEPTION_INLINE_FAILED = 15,
212 MONO_EXCEPTION_MONO_ERROR = 16,
213 /* add other exception type */
216 /* This struct collects the info needed for the runtime use of a class,
217 * like the vtables for a domain, the GC descriptor, etc.
221 /* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
222 MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
223 } MonoClassRuntimeInfo;
225 #define MONO_SIZEOF_CLASS_RUNTIME_INFO (sizeof (MonoClassRuntimeInfo) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
227 #define MONO_CLASS_PROP_EXCEPTION_DATA 0
230 * This structure contains the rarely used fields of MonoClass
231 * Since using just one field causes the whole structure to be allocated, it should
232 * be used for fields which are only used in like 5% of all classes.
236 #if MONO_SMALL_CONFIG
237 guint16 first, count;
239 guint32 first, count;
243 /* Initialized by a call to mono_class_setup_properties () */
244 MonoProperty *properties;
246 /* Initialized by a call to mono_class_setup_events () */
249 guint32 declsec_flags; /* declarative security attributes flags */
251 /* Default values/RVA for fields and properties */
252 /* Accessed using mono_class_get_field_default_value () / mono_field_get_data () */
253 MonoFieldDefaultValue *field_def_values;
254 MonoFieldDefaultValue *prop_def_values;
256 GList *nested_classes;
260 /* element class for arrays and enum basetype for enums */
261 MonoClass *element_class;
262 /* used for subtype checks */
263 MonoClass *cast_class;
265 /* for fast subtype checks */
266 MonoClass **supertypes;
269 /* array dimension */
272 int instance_size; /* object instance size */
276 /* A class contains static and non static data. Static data can be
277 * of the same type as the class itselfs, but it does not influence
278 * the instance size of the class. To avoid cyclic calls to
279 * mono_class_init (from mono_class_instance_size ()) we first
280 * initialise all non static fields. After that we set size_inited
281 * to 1, because we know the instance size now. After that we
282 * initialise all static fields.
284 /* size_inited is accessed without locks, so it needs a memory barrier */
285 guint size_inited : 1;
286 guint valuetype : 1; /* derives from System.ValueType */
287 guint enumtype : 1; /* derives from System.Enum */
288 guint blittable : 1; /* class is blittable */
289 guint unicode : 1; /* class uses unicode char when marshalled */
290 guint wastypebuilder : 1; /* class was created at runtime from a TypeBuilder */
295 guint packing_size : 4;
296 guint ghcimpl : 1; /* class has its own GetHashCode impl */
297 guint has_finalize : 1; /* class has its own Finalize impl */
298 #ifndef DISABLE_REMOTING
299 guint marshalbyref : 1; /* class is a MarshalByRefObject */
300 guint contextbound : 1; /* class is a ContextBoundObject */
303 guint delegate : 1; /* class is a Delegate */
304 guint gc_descr_inited : 1; /* gc_descr is initialized */
305 guint has_cctor : 1; /* class has a cctor */
306 guint has_references : 1; /* it has GC-tracked references in the instance */
307 guint has_static_refs : 1; /* it has static fields that are GC-tracked */
308 guint no_special_static_fields : 1; /* has no thread/context static fields */
309 /* directly or indirectly derives from ComImport attributed class.
310 * this means we need to create a proxy for instances of this class
311 * for COM Interop. set this flag on loading so all we need is a quick check
312 * during object creation rather than having to traverse supertypes
314 guint is_com_object : 1;
315 guint nested_classes_inited : 1; /* Whenever nested_class is initialized */
318 guint interfaces_inited : 1; /* interfaces is initialized */
319 guint simd_type : 1; /* class is a simd intrinsic type */
320 guint is_generic : 1; /* class is a generic type definition */
321 guint is_inflated : 1; /* class is a generic instance */
322 guint has_finalize_inited : 1; /* has_finalize is initialized */
323 guint fields_inited : 1; /* setup_fields () has finished */
324 guint has_failure : 1; /* See MONO_CLASS_PROP_EXCEPTION_DATA for a MonoErrorBoxed with the details */
327 MonoClass *nested_in;
331 const char *name_space;
334 int vtable_size; /* number of slots */
336 guint16 interface_count;
337 guint16 interface_id; /* unique inderface id (for interfaces) */
338 guint16 max_interface_id;
340 guint16 interface_offsets_count;
341 MonoClass **interfaces_packed;
342 guint16 *interface_offsets_packed;
343 /* enabled only with small config for now: we might want to do it unconditionally */
344 #ifdef MONO_SMALL_CONFIG
345 #define COMPRESSED_INTERFACE_BITMAP 1
347 guint8 *interface_bitmap;
349 MonoClass **interfaces;
352 int class_size; /* size of area for static fields */
353 int element_size; /* for array types */
354 int generic_param_token; /* for generic param types, both var and mvar */
358 * From the TypeDef table
362 #if MONO_SMALL_CONFIG
363 guint16 first, count;
365 guint32 first, count;
369 /* A GC handle pointing to the corresponding type builder/generic param builder */
370 guint32 ref_info_handle;
372 /* loaded on demand */
373 MonoMarshalType *marshal_info;
376 * Field information: Type and location from object base
378 MonoClassField *fields;
380 MonoMethod **methods;
382 /* used as the type of the this argument and when passing the arg by value */
386 MonoGenericClass *generic_class;
387 MonoGenericContainer *generic_container;
389 MonoGCDescriptor gc_descr;
391 MonoClassRuntimeInfo *runtime_info;
393 /* next element in the class_cache hash list (in MonoImage) */
394 MonoClass *next_class_cache;
396 /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
399 /* Rarely used fields of classes */
403 #ifdef COMPRESSED_INTERFACE_BITMAP
404 int mono_compress_bitmap (uint8_t *dest, const uint8_t *bitmap, int size);
405 int mono_class_interface_match (const uint8_t *bitmap, int id);
407 #define mono_class_interface_match(bmap,uiid) ((bmap) [(uiid) >> 3] & (1 << ((uiid)&7)))
410 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && mono_class_interface_match ((k)->interface_bitmap, (uiid)))
412 #define MONO_VTABLE_AVAILABLE_GC_BITS 4
414 #ifdef DISABLE_REMOTING
415 #define mono_class_is_marshalbyref(klass) (FALSE)
416 #define mono_class_is_contextbound(klass) (FALSE)
417 #define mono_vtable_is_remote(vtable) (FALSE)
418 #define mono_vtable_set_is_remote(vtable,enable) do {} while (0)
420 #define mono_class_is_marshalbyref(klass) ((klass)->marshalbyref)
421 #define mono_class_is_contextbound(klass) ((klass)->contextbound)
422 #define mono_vtable_is_remote(vtable) ((vtable)->remote)
423 #define mono_vtable_set_is_remote(vtable,enable) do { (vtable)->remote = enable ? 1 : 0; } while (0)
427 #define mono_class_is_com_object(klass) (FALSE)
428 #define mono_class_set_is_com_object(klass) do {} while (0)
430 #define mono_class_is_com_object(klass) ((klass)->is_com_object)
431 #define mono_class_set_is_com_object(klass) do { (klass)->is_com_object = 1; } while (0)
435 MONO_API int mono_class_interface_offset (MonoClass *klass, MonoClass *itf);
436 int mono_class_interface_offset_with_variance (MonoClass *klass, MonoClass *itf, gboolean *non_exact_match);
438 typedef gpointer MonoRuntimeGenericContext;
440 /* the interface_offsets array is stored in memory before this struct */
444 * According to comments in gc_gcj.h, this should be the second word in
447 MonoGCDescriptor gc_descr;
448 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
449 gpointer type; /* System.Type type for klass */
450 guint8 *interface_bitmap;
451 guint16 max_interface_id;
453 guint remote : 1; /* class is remotely activated */
454 guint initialized : 1; /* cctor has been run */
455 guint init_failed : 1; /* cctor execution failed */
456 guint has_static_fields : 1; /* pointer to the data stored at the end of the vtable array */
457 guint gc_bits : MONO_VTABLE_AVAILABLE_GC_BITS; /* Those bits are reserved for the usaged of the GC */
459 guint32 imt_collisions_bitmap;
460 MonoRuntimeGenericContext *runtime_generic_context;
461 /* do not add any fields after vtable, the structure is dynamically extended */
462 /* vtable contains function pointers to methods or their trampolines, at the
463 end there may be a slot containing the pointer to the static fields */
464 gpointer vtable [MONO_ZERO_LEN_ARRAY];
467 #define MONO_SIZEOF_VTABLE (sizeof (MonoVTable) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
469 #define MONO_VTABLE_IMPLEMENTS_INTERFACE(vt,uiid) (((uiid) <= (vt)->max_interface_id) && mono_class_interface_match ((vt)->interface_bitmap, (uiid)))
472 * Generic instantiation data type encoding.
476 * A particular generic instantiation:
478 * All instantiations are cached and we don't distinguish between class and method
479 * instantiations here.
481 struct _MonoGenericInst {
482 #ifndef MONO_SMALL_CONFIG
483 guint id; /* unique ID for debugging */
485 guint type_argc : 22; /* number of type arguments */
486 guint is_open : 1; /* if this is an open type */
487 MonoType *type_argv [MONO_ZERO_LEN_ARRAY];
490 #define MONO_SIZEOF_GENERIC_INST (sizeof (MonoGenericInst) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
492 * The generic context: an instantiation of a set of class and method generic parameters.
494 * NOTE: Never allocate this directly on the heap. It have to be either allocated on the stack,
495 * or embedded within other objects. Don't store pointers to this, because it may be on the stack.
496 * If you really have to, ensure you store a pointer to the embedding object along with it.
498 struct _MonoGenericContext {
499 /* The instantiation corresponding to the class generic parameters */
500 MonoGenericInst *class_inst;
501 /* The instantiation corresponding to the method generic parameters */
502 MonoGenericInst *method_inst;
506 * Inflated generic method.
508 struct _MonoMethodInflated {
511 MonoMethodPInvoke pinvoke;
513 MonoMethod *declaring; /* the generic method definition. */
514 MonoGenericContext context; /* The current instantiation */
515 MonoImageSet *owner; /* The image set that the inflated method belongs to. */
519 * A particular instantiation of a generic type.
521 struct _MonoGenericClass {
522 MonoClass *container_class; /* the generic type definition */
523 MonoGenericContext context; /* a context that contains the type instantiation doesn't contain any method instantiation */ /* FIXME: Only the class_inst member of "context" is ever used, so this field could be replaced with just a monogenericinst */
524 guint is_dynamic : 1; /* Contains dynamic types */
525 guint is_tb_open : 1; /* This is the fully open instantiation for a type_builder. Quite ugly, but it's temporary.*/
526 guint need_sync : 1; /* Only if dynamic. Need to be synchronized with its container class after its finished. */
527 MonoClass *cached_class; /* if present, the MonoClass corresponding to the instantiation. */
530 * The image set which owns this generic class. Memory owned by the generic class
531 * including cached_class should be allocated from the mempool of the image set,
532 * so it is easy to free.
540 struct _MonoGenericParam {
542 * Type or method this parameter was defined in.
544 MonoGenericContainer *owner;
547 * If != NULL, this is a generated generic param used by the JIT to implement generic
550 MonoType *gshared_constraint;
553 /* Additional details about a MonoGenericParam */
554 /* Keep in sync with managed Mono.RuntimeStructs.GenericParamInfo */
556 MonoClass *pklass; /* The corresponding `MonoClass'. */
559 // See GenericParameterAttributes
564 // Constraints on type parameters
565 MonoClass** constraints; /* NULL means end of list */
566 } MonoGenericParamInfo;
569 MonoGenericParam param;
570 MonoGenericParamInfo info;
571 } MonoGenericParamFull;
574 * The generic container.
576 * Stores the type parameters of a generic type definition or a generic method definition.
578 struct _MonoGenericContainer {
579 MonoGenericContext context;
580 /* If we're a generic method definition in a generic type definition,
581 the generic container of the containing class. */
582 MonoGenericContainer *parent;
583 /* the generic type definition or the generic method definition corresponding to this container */
584 /* Union rules: If is_anonymous, image field is valid; else if is_method, method field is valid; else klass is valid. */
590 int type_argc : 29; // Per the ECMA spec, this value is capped at 16 bits
591 /* If true, we're a generic method, otherwise a generic type definition. */
592 /* Invariant: parent != NULL => is_method */
594 /* If true, this container has no associated class/method and only the image is known. This can happen:
595 1. For the special anonymous containers kept by MonoImage.
596 2. During container creation via the mono_metadata_load_generic_params path-- in this case the caller
597 sets the owner, so temporarily while load_generic_params is completing the container is anonymous.
598 3. When user code creates a generic parameter via SRE, but has not yet set an owner. */
599 int is_anonymous : 1;
600 /* If false, all params in this container are full-size. If true, all params are just param structs. */
601 /* This field is always == to the is_anonymous field, except in "temporary" cases (2) and (3) above. */
602 /* TODO: Merge GenericParam and GenericParamFull, remove this field. Benefit is marginal. */
603 int is_small_param : 1;
604 /* Our type parameters. */
605 MonoGenericParamFull *type_params;
608 static inline MonoGenericParam *
609 mono_generic_container_get_param (MonoGenericContainer *gc, int i)
611 return (MonoGenericParam *) &gc->type_params [i];
614 static inline MonoGenericParamInfo *
615 mono_generic_container_get_param_info (MonoGenericContainer *gc, int i)
617 return &gc->type_params [i].info;
620 static inline MonoGenericContainer *
621 mono_generic_param_owner (MonoGenericParam *p)
627 mono_generic_param_num (MonoGenericParam *p)
632 static inline gboolean
633 mono_generic_param_is_fullsize (MonoGenericParam *p)
635 return !mono_generic_param_owner (p)->is_small_param;
638 static inline MonoGenericParamInfo *
639 mono_generic_param_info (MonoGenericParam *p)
641 if (mono_generic_param_is_fullsize (p))
642 return &((MonoGenericParamFull *) p)->info;
646 static inline const char *
647 mono_generic_param_name (MonoGenericParam *p)
649 if (mono_generic_param_is_fullsize (p))
650 return ((MonoGenericParamFull *) p)->info.name;
654 static inline MonoGenericContainer *
655 mono_type_get_generic_param_owner (MonoType *t)
657 return mono_generic_param_owner (t->data.generic_param);
661 mono_type_get_generic_param_num (MonoType *t)
663 return mono_generic_param_num (t->data.generic_param);
667 * Class information which might be cached by the runtime in the AOT file for
668 * example. Caching this allows us to avoid computing a generic vtable
669 * (class->vtable) in most cases, saving time and avoiding creation of lots of
670 * MonoMethod structures.
672 typedef struct MonoCachedClassInfo {
674 guint has_finalize : 1;
677 guint has_nested_classes : 1;
679 guint has_references : 1;
680 guint has_static_refs : 1;
681 guint no_special_static_fields : 1;
682 guint is_generic_container : 1;
684 MonoImage *finalize_image;
685 guint32 finalize_token;
686 guint32 instance_size;
688 guint32 packing_size;
690 } MonoCachedClassInfo;
695 gconstpointer wrapper;
696 gconstpointer trampoline;
697 MonoMethodSignature *sig;
698 const char *c_symbol;
699 MonoMethod *wrapper_method;
704 mono_class_setup_supertypes (MonoClass *klass);
707 mono_class_setup_fields (MonoClass *klass);
710 * Only call this function if you can ensure both @klass and @parent
711 * have supertype information initialized.
712 * This can be accomplished by mono_class_setup_supertypes or mono_class_init.
713 * If unsure, use mono_class_has_parent.
715 static inline gboolean
716 mono_class_has_parent_fast (MonoClass *klass, MonoClass *parent)
718 return (klass->idepth >= parent->idepth) && (klass->supertypes [parent->idepth - 1] == parent);
721 static inline gboolean
722 mono_class_has_parent (MonoClass *klass, MonoClass *parent)
724 if (G_UNLIKELY (!klass->supertypes))
725 mono_class_setup_supertypes (klass);
727 if (G_UNLIKELY (!parent->supertypes))
728 mono_class_setup_supertypes (parent);
730 return mono_class_has_parent_fast (klass, parent);
734 MonoVTable *default_vtable;
735 MonoVTable *xdomain_vtable;
736 MonoClass *proxy_class;
737 char* proxy_class_name;
738 uint32_t interface_count;
739 MonoClass *interfaces [MONO_ZERO_LEN_ARRAY];
742 #define MONO_SIZEOF_REMOTE_CLASS (sizeof (MonoRemoteClass) - MONO_ZERO_LEN_ARRAY * SIZEOF_VOID_P)
745 guint64 new_object_count;
746 size_t initialized_class_count;
747 size_t generic_vtable_count;
748 size_t used_class_count;
750 size_t class_vtable_size;
751 size_t class_static_data_size;
752 size_t generic_instance_count;
753 size_t generic_class_count;
754 size_t inflated_method_count;
755 size_t inflated_method_count_2;
756 size_t inflated_type_count;
757 size_t generics_metadata_size;
758 size_t delegate_creations;
759 size_t imt_tables_size;
760 size_t imt_number_of_tables;
761 size_t imt_number_of_methods;
762 size_t imt_used_slots;
763 size_t imt_slots_with_collisions;
764 size_t imt_max_collisions_in_slot;
765 size_t imt_method_count_when_max_collisions;
766 size_t imt_trampolines_size;
767 size_t jit_info_table_insert_count;
768 size_t jit_info_table_remove_count;
769 size_t jit_info_table_lookup_count;
770 size_t generics_sharable_methods;
771 size_t generics_unsharable_methods;
772 size_t generics_shared_methods;
773 size_t gsharedvt_methods;
774 size_t minor_gc_count;
775 size_t major_gc_count;
776 size_t minor_gc_time_usecs;
777 size_t major_gc_time_usecs;
782 * new structure to hold performace counters values that are exported
784 * Note: never remove fields from this structure and only add them to the end.
785 * Size of fields and type should not be changed as well.
792 guint32 jit_failures;
793 /* Exceptions category */
794 guint32 exceptions_thrown;
795 guint32 exceptions_filters;
796 guint32 exceptions_finallys;
797 guint32 exceptions_depth;
798 guint32 aspnet_requests_queued;
799 guint32 aspnet_requests;
800 /* Memory category */
801 guint32 gc_collections0;
802 guint32 gc_collections1;
803 guint32 gc_collections2;
804 guint32 gc_promotions0;
805 guint32 gc_promotions1;
806 guint32 gc_promotion_finalizers;
811 guint32 gc_fin_survivors;
812 guint32 gc_num_handles;
813 guint32 gc_allocated;
816 guint32 gc_total_bytes;
817 guint32 gc_committed_bytes;
818 guint32 gc_reserved_bytes;
819 guint32 gc_num_pinned;
820 guint32 gc_sync_blocks;
821 /* Remoting category */
822 guint32 remoting_calls;
823 guint32 remoting_channels;
824 guint32 remoting_proxies;
825 guint32 remoting_classes;
826 guint32 remoting_objects;
827 guint32 remoting_contexts;
828 /* Loader category */
829 guint32 loader_classes;
830 guint32 loader_total_classes;
831 guint32 loader_appdomains;
832 guint32 loader_total_appdomains;
833 guint32 loader_assemblies;
834 guint32 loader_total_assemblies;
835 guint32 loader_failures;
836 guint32 loader_bytes;
837 guint32 loader_appdomains_uloaded;
838 /* Threads and Locks category */
839 guint32 thread_contentions;
840 guint32 thread_queue_len;
841 guint32 thread_queue_max;
842 guint32 thread_num_logical;
843 guint32 thread_num_physical;
844 guint32 thread_cur_recognized;
845 guint32 thread_num_recognized;
846 /* Interop category */
847 guint32 interop_num_ccw;
848 guint32 interop_num_stubs;
849 guint32 interop_num_marshals;
850 /* Security category */
851 guint32 security_num_checks;
852 guint32 security_num_link_checks;
853 guint32 security_time;
854 guint32 security_depth;
857 guint64 threadpool_workitems;
858 guint64 threadpool_ioworkitems;
859 guint threadpool_threads;
860 guint threadpool_iothreads;
863 extern MonoPerfCounters *mono_perfcounters;
865 MONO_API void mono_perfcounters_init (void);
868 * The definition of the first field in SafeHandle,
869 * Keep in sync with SafeHandle.cs, this is only used
870 * to access the `handle' parameter.
878 * Keep in sync with HandleRef.cs
885 extern MonoStats mono_stats;
887 typedef gpointer (*MonoRemotingTrampoline) (MonoDomain *domain, MonoMethod *method, MonoRemotingTarget target, MonoError *error);
888 typedef gpointer (*MonoDelegateTrampoline) (MonoDomain *domain, MonoClass *klass);
890 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
892 typedef gboolean (*MonoGetClassFromName) (MonoImage *image, const char *name_space, const char *name, MonoClass **res);
894 static inline gboolean
895 method_is_dynamic (MonoMethod *method)
897 #ifdef DISABLE_REFLECTION_EMIT
900 return method->dynamic;
905 mono_classes_init (void);
908 mono_classes_cleanup (void);
911 mono_class_layout_fields (MonoClass *klass, int base_instance_size, int packing_size, gboolean sre);
914 mono_class_setup_interface_offsets (MonoClass *klass);
917 mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum, GList *in_setup);
920 mono_class_setup_vtable (MonoClass *klass);
923 mono_class_setup_methods (MonoClass *klass);
926 mono_class_setup_mono_type (MonoClass *klass);
929 mono_class_setup_parent (MonoClass *klass, MonoClass *parent);
932 mono_class_get_method_by_index (MonoClass *klass, int index);
935 mono_class_get_inflated_method (MonoClass *klass, MonoMethod *method);
938 mono_class_get_vtable_entry (MonoClass *klass, int offset);
941 mono_class_get_implemented_interfaces (MonoClass *klass, MonoError *error);
944 mono_class_get_vtable_size (MonoClass *klass);
947 mono_class_is_open_constructed_type (MonoType *t);
950 mono_class_get_overrides_full (MonoImage *image, guint32 type_token, MonoMethod ***overrides, gint32 *num_overrides,
951 MonoGenericContext *generic_context);
954 mono_class_get_cctor (MonoClass *klass);
957 mono_class_get_finalizer (MonoClass *klass);
960 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
963 mono_class_field_is_special_static (MonoClassField *field);
966 mono_class_field_get_special_static_type (MonoClassField *field);
969 mono_class_has_special_static_fields (MonoClass *klass);
972 mono_class_get_field_default_value (MonoClassField *field, MonoTypeEnum *def_type);
975 mono_class_get_property_default_value (MonoProperty *property, MonoTypeEnum *def_type);
978 mono_install_delegate_trampoline (MonoDelegateTrampoline func);
981 mono_lookup_dynamic_token (MonoImage *image, guint32 token, MonoGenericContext *context, MonoError *error);
984 mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, gboolean check_token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error);
987 mono_runtime_create_jump_trampoline (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper, MonoError *error);
990 mono_runtime_create_delegate_trampoline (MonoClass *klass);
993 mono_install_get_cached_class_info (MonoGetCachedClassInfo func);
996 mono_install_get_class_from_name (MonoGetClassFromName func);
999 mono_class_get_context (MonoClass *klass);
1001 MonoMethodSignature*
1002 mono_method_signature_checked (MonoMethod *m, MonoError *err);
1005 mono_method_get_context_general (MonoMethod *method, gboolean uninflated);
1008 mono_method_get_context (MonoMethod *method);
1010 /* Used by monodis, thus cannot be MONO_INTERNAL */
1011 MONO_API MonoGenericContainer*
1012 mono_method_get_generic_container (MonoMethod *method);
1015 mono_generic_class_get_context (MonoGenericClass *gclass);
1018 mono_generic_class_get_class (MonoGenericClass *gclass);
1021 mono_method_set_generic_container (MonoMethod *method, MonoGenericContainer* container);
1024 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
1027 mono_class_inflate_generic_method_full_checked (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context, MonoError *error);
1030 mono_class_inflate_generic_method_checked (MonoMethod *method, MonoGenericContext *context, MonoError *error);
1033 mono_metadata_get_image_set_for_method (MonoMethodInflated *method);
1035 MONO_API MonoMethodSignature *
1036 mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context);
1039 mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context, MonoError *error);
1042 mono_class_inflate_generic_type_checked (MonoType *type, MonoGenericContext *context, MonoError *error);
1045 mono_metadata_free_inflated_signature (MonoMethodSignature *sig);
1047 MonoMethodSignature*
1048 mono_inflate_generic_signature (MonoMethodSignature *sig, MonoGenericContext *context, MonoError *error);
1052 MonoClass *object_class;
1053 MonoClass *byte_class;
1054 MonoClass *void_class;
1055 MonoClass *boolean_class;
1056 MonoClass *sbyte_class;
1057 MonoClass *int16_class;
1058 MonoClass *uint16_class;
1059 MonoClass *int32_class;
1060 MonoClass *uint32_class;
1061 MonoClass *int_class;
1062 MonoClass *uint_class;
1063 MonoClass *int64_class;
1064 MonoClass *uint64_class;
1065 MonoClass *single_class;
1066 MonoClass *double_class;
1067 MonoClass *char_class;
1068 MonoClass *string_class;
1069 MonoClass *enum_class;
1070 MonoClass *array_class;
1071 MonoClass *delegate_class;
1072 MonoClass *multicastdelegate_class;
1073 MonoClass *asyncresult_class;
1074 MonoClass *manualresetevent_class;
1075 MonoClass *typehandle_class;
1076 MonoClass *fieldhandle_class;
1077 MonoClass *methodhandle_class;
1078 MonoClass *systemtype_class;
1079 MonoClass *runtimetype_class;
1080 MonoClass *exception_class;
1081 MonoClass *threadabortexception_class;
1082 MonoClass *thread_class;
1083 MonoClass *internal_thread_class;
1084 #ifndef DISABLE_REMOTING
1085 MonoClass *transparent_proxy_class;
1086 MonoClass *real_proxy_class;
1087 MonoClass *marshalbyrefobject_class;
1088 MonoClass *iremotingtypeinfo_class;
1090 MonoClass *mono_method_message_class;
1091 MonoClass *appdomain_class;
1092 MonoClass *field_info_class;
1093 MonoClass *method_info_class;
1094 MonoClass *stringbuilder_class;
1095 MonoClass *math_class;
1096 MonoClass *stack_frame_class;
1097 MonoClass *stack_trace_class;
1098 MonoClass *marshal_class;
1099 MonoClass *typed_reference_class;
1100 MonoClass *argumenthandle_class;
1101 MonoClass *monitor_class;
1102 MonoClass *generic_ilist_class;
1103 MonoClass *generic_nullable_class;
1104 MonoClass *handleref_class;
1105 MonoClass *attribute_class;
1106 MonoClass *customattribute_data_class;
1107 MonoClass *critical_finalizer_object; /* MAYBE NULL */
1108 MonoClass *generic_ireadonlylist_class;
1109 MonoClass *threadpool_wait_callback_class;
1110 MonoMethod *threadpool_perform_wait_callback_method;
1113 #ifdef DISABLE_REMOTING
1114 #define mono_class_is_transparent_proxy(klass) (FALSE)
1115 #define mono_class_is_real_proxy(klass) (FALSE)
1116 #define mono_object_is_transparent_proxy(object) (FALSE)
1119 mono_remote_class (MonoDomain *domain, MonoString *class_name, MonoClass *proxy_class, MonoError *error);
1122 mono_install_remoting_trampoline (MonoRemotingTrampoline func);
1124 #define mono_class_is_transparent_proxy(klass) ((klass) == mono_defaults.transparent_proxy_class)
1125 #define mono_class_is_real_proxy(klass) ((klass) == mono_defaults.real_proxy_class)
1126 #define mono_object_is_transparent_proxy(object) (((MonoObject*)object)->vtable->klass == mono_defaults.transparent_proxy_class)
1130 #define GENERATE_GET_CLASS_WITH_CACHE_DECL(shortname) \
1131 MonoClass* mono_class_get_##shortname##_class (void);
1133 #define GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL(shortname) \
1134 MonoClass* mono_class_try_get_##shortname##_class (void);
1136 #define GENERATE_GET_CLASS_WITH_CACHE(shortname,namespace,name) \
1138 mono_class_get_##shortname##_class (void) \
1140 static MonoClass *tmp_class; \
1141 MonoClass *klass = tmp_class; \
1143 klass = mono_class_load_from_name (mono_defaults.corlib, #namespace, #name); \
1144 mono_memory_barrier (); \
1145 tmp_class = klass; \
1150 #define GENERATE_TRY_GET_CLASS_WITH_CACHE(shortname,namespace,name) \
1152 mono_class_try_get_##shortname##_class (void) \
1154 static volatile MonoClass *tmp_class; \
1155 static volatile gboolean inited; \
1156 MonoClass *klass = (MonoClass *)tmp_class; \
1157 mono_memory_barrier (); \
1159 klass = mono_class_try_load_from_name (mono_defaults.corlib, #namespace, #name); \
1160 tmp_class = klass; \
1161 mono_memory_barrier (); \
1167 GENERATE_TRY_GET_CLASS_WITH_CACHE_DECL (safehandle)
1171 GENERATE_GET_CLASS_WITH_CACHE_DECL (interop_proxy)
1172 GENERATE_GET_CLASS_WITH_CACHE_DECL (idispatch)
1173 GENERATE_GET_CLASS_WITH_CACHE_DECL (iunknown)
1174 GENERATE_GET_CLASS_WITH_CACHE_DECL (com_object)
1175 GENERATE_GET_CLASS_WITH_CACHE_DECL (variant)
1179 extern MonoDefaults mono_defaults;
1182 mono_loader_init (void);
1185 mono_loader_cleanup (void);
1188 mono_loader_lock (void) MONO_LLVM_INTERNAL;
1191 mono_loader_unlock (void) MONO_LLVM_INTERNAL;
1194 mono_loader_lock_track_ownership (gboolean track);
1197 mono_loader_lock_is_owned_by_self (void);
1200 mono_loader_lock_if_inited (void);
1203 mono_loader_unlock_if_inited (void);
1206 mono_reflection_init (void);
1209 mono_icall_init (void);
1212 mono_icall_cleanup (void);
1215 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
1218 mono_metadata_has_generic_params (MonoImage *image, guint32 token);
1220 MONO_API MonoGenericContainer *
1221 mono_metadata_load_generic_params (MonoImage *image, guint32 token,
1222 MonoGenericContainer *parent_container);
1225 mono_metadata_load_generic_param_constraints_checked (MonoImage *image, guint32 token,
1226 MonoGenericContainer *container, MonoError *error);
1228 MonoMethodSignature*
1229 mono_create_icall_signature (const char *sigstr);
1232 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
1235 mono_register_jit_icall_full (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save, gboolean no_raise, const char *c_symbol);
1238 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper);
1241 mono_find_jit_icall_by_name (const char *name) MONO_LLVM_INTERNAL;
1244 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_LLVM_INTERNAL;
1247 mono_get_jit_icall_info (void);
1250 mono_lookup_jit_icall_symbol (const char *name);
1253 mono_class_set_type_load_failure (MonoClass *klass, const char * fmt, ...) MONO_ATTR_FORMAT_PRINTF(2,3);
1256 mono_class_get_exception_for_failure (MonoClass *klass);
1259 mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format);
1262 mono_type_get_full_name (MonoClass *klass);
1265 mono_method_get_name_full (MonoMethod *method, gboolean signature, gboolean ret, MonoTypeNameFormat format);
1268 mono_method_get_full_name (MonoMethod *method);
1270 MonoArrayType *mono_dup_array_type (MonoImage *image, MonoArrayType *a);
1271 MonoMethodSignature *mono_metadata_signature_deep_dup (MonoImage *image, MonoMethodSignature *sig);
1274 mono_image_init_name_cache (MonoImage *image);
1276 gboolean mono_class_is_nullable (MonoClass *klass);
1277 MonoClass *mono_class_get_nullable_param (MonoClass *klass);
1279 /* object debugging functions, for use inside gdb */
1280 MONO_API void mono_object_describe (MonoObject *obj);
1281 MONO_API void mono_object_describe_fields (MonoObject *obj);
1282 MONO_API void mono_value_describe_fields (MonoClass* klass, const char* addr);
1283 MONO_API void mono_class_describe_statics (MonoClass* klass);
1285 /* method debugging functions, for use inside gdb */
1286 MONO_API void mono_method_print_code (MonoMethod *method);
1288 char *mono_signature_full_name (MonoMethodSignature *sig);
1290 /*Enum validation related functions*/
1292 mono_type_is_valid_enum_basetype (MonoType * type);
1295 mono_class_is_valid_enum (MonoClass *klass);
1298 mono_type_get_checked (MonoImage *image, guint32 type_token, MonoGenericContext *context, MonoError *error);
1301 mono_generic_class_is_generic_type_definition (MonoGenericClass *gklass);
1304 mono_class_get_method_generic (MonoClass *klass, MonoMethod *method);
1307 mono_type_get_basic_type_from_generic (MonoType *type);
1310 mono_method_can_access_method_full (MonoMethod *method, MonoMethod *called, MonoClass *context_klass);
1313 mono_method_can_access_field_full (MonoMethod *method, MonoClassField *field, MonoClass *context_klass);
1316 mono_class_can_access_class (MonoClass *access_class, MonoClass *target_class);
1319 mono_class_get_generic_type_definition (MonoClass *klass);
1322 mono_class_has_parent_and_ignore_generics (MonoClass *klass, MonoClass *parent);
1325 mono_method_get_vtable_slot (MonoMethod *method);
1328 mono_method_get_vtable_index (MonoMethod *method);
1331 mono_method_search_in_array_class (MonoClass *klass, const char *name, MonoMethodSignature *sig);
1334 mono_class_setup_interface_id (MonoClass *klass);
1336 MonoGenericContainer*
1337 mono_class_get_generic_container (MonoClass *klass);
1340 mono_class_get_generic_class (MonoClass *klass);
1343 mono_class_alloc (MonoClass *klass, int size);
1346 mono_class_alloc0 (MonoClass *klass, int size);
1349 mono_class_alloc_ext (MonoClass *klass);
1352 mono_class_setup_interfaces (MonoClass *klass, MonoError *error);
1355 mono_class_get_field_from_name_full (MonoClass *klass, const char *name, MonoType *type);
1358 mono_class_vtable_full (MonoDomain *domain, MonoClass *klass, MonoError *error);
1361 mono_class_is_assignable_from_slow (MonoClass *target, MonoClass *candidate);
1364 mono_class_has_variant_generic_params (MonoClass *klass);
1367 mono_class_is_variant_compatible (MonoClass *klass, MonoClass *oklass, gboolean check_for_reference_conv);
1369 gboolean mono_is_corlib_image (MonoImage *image);
1372 mono_field_get_type_checked (MonoClassField *field, MonoError *error);
1375 mono_class_get_fields_lazy (MonoClass* klass, gpointer *iter);
1378 mono_class_check_vtable_constraints (MonoClass *klass, GList *in_setup);
1381 mono_class_has_finalizer (MonoClass *klass);
1384 mono_unload_interface_id (MonoClass *klass);
1387 mono_class_get_methods_by_name (MonoClass *klass, const char *name, guint32 bflags, gboolean ignore_case, gboolean allow_ctors, MonoError *error);
1390 mono_class_full_name (MonoClass *klass);
1393 mono_class_inflate_generic_class_checked (MonoClass *gklass, MonoGenericContext *context, MonoError *error);
1396 mono_class_get_checked (MonoImage *image, guint32 type_token, MonoError *error);
1399 mono_class_get_and_inflate_typespec_checked (MonoImage *image, guint32 type_token, MonoGenericContext *context, MonoError *error);
1402 mono_class_from_name_checked (MonoImage *image, const char* name_space, const char *name, MonoError *error);
1405 mono_class_from_name_case_checked (MonoImage *image, const char* name_space, const char *name, MonoError *error);
1408 mono_field_from_token_checked (MonoImage *image, uint32_t token, MonoClass **retklass, MonoGenericContext *context, MonoError *error);
1411 mono_ldtoken_checked (MonoImage *image, guint32 token, MonoClass **handle_class, MonoGenericContext *context, MonoError *error);
1414 mono_class_from_generic_parameter_internal (MonoGenericParam *param);
1417 get_image_for_generic_param (MonoGenericParam *param);
1420 make_generic_name_string (MonoImage *image, int num);
1423 mono_class_load_from_name (MonoImage *image, const char* name_space, const char *name) MONO_LLVM_INTERNAL;
1426 mono_class_try_load_from_name (MonoImage *image, const char* name_space, const char *name);
1429 mono_error_set_for_class_failure (MonoError *orerror, const MonoClass *klass);
1432 mono_class_has_failure (const MonoClass *klass);
1434 #endif /* __MONO_METADATA_CLASS_INTERNALS_H__ */