2009-07-30 Rodrigo Kumpera <rkumpera@novell.com>
[mono.git] / mono / metadata / class-internals.h
index 46b56608d96c3d9ec564df45578f907100296754..5a5476138dc7dab79bc462e51306f1f4bd6896d8 100644 (file)
@@ -9,6 +9,8 @@
 
 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
 
+#define MONO_CLASS_HAS_STATIC_METADATA(klass) ((klass)->type_token && !(klass)->image->dynamic && !(klass)->generic_class)
+
 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
 
 extern gboolean mono_print_vtable;
@@ -70,7 +72,9 @@ struct _MonoMethod {
        unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
        unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
        unsigned int verification_success:1; /* whether this method has been verified successfully.*/
-       signed int slot : 18;
+       /* TODO we MUST get rid of this field, it's an ugly hack nobody is proud of. */
+       unsigned int is_mb_open : 1;            /* This is the fully open instantiation of a generic method_builder. Worse than is_tb_open, but it's temporary */
+       signed int slot : 17;
 
        /*
         * If is_generic is TRUE, the generic_container is stored in image->property_hash, 
@@ -96,10 +100,23 @@ struct _MonoMethodPInvoke {
        guint16 implmap_idx;  /* index into IMPLMAP */
 };
 
-typedef struct {
-       MonoType *generic_type;
-       gpointer reflection_info;
-} MonoInflatedField;
+/* 
+ * Stores the default value / RVA of fields.
+ * This information is rarely needed, so it is stored separately from 
+ * MonoClassField.
+ */
+typedef struct MonoFieldDefaultValue {
+       /*
+        * If the field is constant, pointer to the metadata constant
+        * value.
+        * If the field has an RVA flag, pointer to the data.
+        * Else, invalid.
+        */
+       const char      *data;
+
+       /* If the field is constant, the type of the constant. */
+       MonoTypeEnum     def_type;
+} MonoFieldDefaultValue;
 
 /*
  * MonoClassField is just a runtime representation of the metadata for
@@ -111,42 +128,24 @@ struct _MonoClassField {
        /* Type of the field */
        MonoType        *type;
 
-       /* If this is an instantiated generic type, this is the
-        * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
-        * it was instantiated from.
-        */
-       MonoInflatedField  *generic_info;
+       const char      *name;
+
+       /* Type where the field was defined */
+       MonoClass       *parent;
 
        /*
         * Offset where this field is stored; if it is an instance
         * field, it's the offset from the start of the object, if
         * it's static, it's from the start of the memory chunk
         * allocated for statics for the class.
+        * For special static fields, this is set to -1 during vtable construction.
         */
        int              offset;
-
-       const char      *name;
-
-       /*
-        * If the field is constant, pointer to the metadata constant
-        * value.
-        * If the field has an RVA flag, pointer to the data.
-        * Else, invalid.
-        */
-       const char      *data;
-
-       /* Type where the field was defined */
-       MonoClass       *parent;
-
-       /*
-        * If the field is constant, the type of the constant.
-        */
-       MonoTypeEnum     def_type;
 };
 
 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
 #define mono_field_is_deleted(field) (((field)->type->attrs & (FIELD_ATTRIBUTE_SPECIAL_NAME | FIELD_ATTRIBUTE_RT_SPECIAL_NAME)) \
-                                     && (strcmp ((field)->name, "_Deleted") == 0))
+                                     && (strcmp (mono_field_get_name (field), "_Deleted") == 0))
 
 typedef struct {
        MonoClassField *field;
@@ -155,7 +154,7 @@ typedef struct {
 } MonoMarshalField;
 
 typedef struct {
-       guint32 native_size;
+       guint32 native_size, min_align;
        guint32 num_fields;
        MonoMethod *ptr_to_str;
        MonoMethod *str_to_ptr;
@@ -194,7 +193,8 @@ enum {
        MONO_EXCEPTION_METHOD_ACCESS = 9,
        MONO_EXCEPTION_FIELD_ACCESS = 10,
        MONO_EXCEPTION_GENERIC_SHARING_FAILED = 11,
-       MONO_EXCEPTION_BAD_IMAGE = 12
+       MONO_EXCEPTION_BAD_IMAGE = 12,
+       MONO_EXCEPTION_OBJECT_SUPPLIED = 13 /*The exception object is already created.*/
        /* add other exception type */
 };
 
@@ -216,7 +216,9 @@ enum {
        MONO_RGCTX_INFO_METHOD,
        MONO_RGCTX_INFO_GENERIC_METHOD_CODE,
        MONO_RGCTX_INFO_CLASS_FIELD,
-       MONO_RGCTX_INFO_METHOD_RGCTX
+       MONO_RGCTX_INFO_METHOD_RGCTX,
+       MONO_RGCTX_INFO_METHOD_CONTEXT,
+       MONO_RGCTX_INFO_REMOTING_INVOKE_WITH_CHECK
 };
 
 typedef struct _MonoRuntimeGenericContextOtherInfoTemplate {
@@ -245,8 +247,33 @@ typedef struct {
 
 #define MONO_CLASS_PROP_EXCEPTION_DATA 0
 
+/* 
+ * This structure contains the rarely used fields of MonoClass
+ * Since using just one field causes the whole structure to be allocated, it should
+ * be used for fields which are only used in like 5% of all classes.
+ */
+typedef struct {
+       struct {
+               guint32 first, count;
+       } property, event;
+
+       /* Initialized by a call to mono_class_setup_properties () */
+       MonoProperty *properties;
+
+       /* Initialized by a call to mono_class_setup_events () */
+       MonoEvent *events;
+
+       guint32    declsec_flags;       /* declarative security attributes flags */
+
+       /* Default values/RVA for fields */
+       /* Accessed using mono_class_get_field_default_value () / mono_field_get_data () */
+       MonoFieldDefaultValue *field_def_values;
+
+       GList      *nested_classes;
+} MonoClassExt;
+
 struct _MonoClass {
-       /* element class for arrays and enum */
+       /* element class for arrays and enum basetype for enums */
        MonoClass *element_class; 
        /* used for subtype checks */
        MonoClass *cast_class; 
@@ -279,8 +306,10 @@ struct _MonoClass {
        guint unicode         : 1; /* class uses unicode char when marshalled */
        guint wastypebuilder  : 1; /* class was created at runtime from a TypeBuilder */
        /* next byte */
-       guint min_align       : 4;
+       guint8 min_align;
+       /* next byte */
        guint packing_size    : 4;
+       /* still 4 bits free */
        /* next byte */
        guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
        guint has_finalize    : 1; /* class has its own Finalize impl */ 
@@ -299,6 +328,11 @@ struct _MonoClass {
         * during object creation rather than having to traverse supertypes
         */
        guint is_com_object : 1; 
+       guint nested_classes_inited : 1; /* Whenever nested_class is initialized */
+       guint interfaces_inited : 1; /* interfaces is initialized */
+       guint simd_type : 1; /* class is a simd intrinsic type */
+       guint is_generic : 1; /* class is a generic type definition */
+       guint is_inflated : 1; /* class is a generic instance */
 
        guint8     exception_type;      /* MONO_EXCEPTION_* */
 
@@ -308,16 +342,11 @@ struct _MonoClass {
 
        MonoClass  *parent;
        MonoClass  *nested_in;
-       GList      *nested_classes;
 
        MonoImage *image;
        const char *name;
        const char *name_space;
 
-       /* The underlying type of the enum */
-       MonoType *enum_basetype;
-
-       guint32    declsec_flags;       /* declarative security attributes flags */
        guint32    type_token;
        int        vtable_size; /* number of slots */
 
@@ -344,7 +373,7 @@ struct _MonoClass {
        guint32    flags;
        struct {
                guint32 first, count;
-       } field, method, property, event;
+       } field, method;
 
        /* loaded on demand */
        MonoMarshalType *marshal_info;
@@ -354,12 +383,6 @@ struct _MonoClass {
         */
        MonoClassField *fields;
 
-       /* Initialized by a call to mono_class_setup_properties () */
-       MonoProperty *properties;
-
-       /* Initialized by a call to mono_class_setup_events () */
-       MonoEvent *events;
-
        MonoMethod **methods;
 
        /* used as the type of the this argument and when passing the arg by value */
@@ -379,7 +402,10 @@ struct _MonoClass {
        MonoClass *next_class_cache;
 
        /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
-       MonoMethod **vtable;    
+       MonoMethod **vtable;
+
+       /* Rarely used fields of classes */
+       MonoClassExt *ext;
 };
 
 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && ((k)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
@@ -426,7 +452,7 @@ struct _MonoGenericInst {
        guint id;                       /* unique ID for debugging */
        guint type_argc    : 22;        /* number of type arguments */
        guint is_open      :  1;        /* if this is an open type */
-       MonoType **type_argv;
+       MonoType *type_argv [MONO_ZERO_LEN_ARRAY];
 };
 
 /*
@@ -454,9 +480,6 @@ struct _MonoMethodInflated {
        } method;
        MonoMethod *declaring;          /* the generic method definition. */
        MonoGenericContext context;     /* The current instantiation */
-
-       /* TODO we MUST get rid of this field, it's an ugly hack nobody is proud of. */
-       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 */
 };
 
 /*
@@ -487,8 +510,41 @@ struct _MonoDynamicGenericClass {
        int count_events;
        MonoEvent *events;
        guint initialized;
+       /* The non-inflated types of the fields */
+       MonoType **field_generic_types;
+       /* The managed objects representing the fields */
+       MonoObject **field_objects;
+};
+
+/*
+ * A type parameter.
+ */
+struct _MonoGenericParam {
+       MonoGenericContainer *owner;    /* Type or method this parameter was defined in. */
+       guint16 num;
+       /* 
+        * If owner is NULL, or owner is 'owned' by this gparam,
+        * then this is the image whose mempool this struct was allocated from.
+        * The second case happens for gparams created in
+        * mono_reflection_initialize_generic_parameter ().
+        */
+       MonoImage *image;
 };
 
+/* Additional details about a MonoGenericParam */
+typedef struct {
+       MonoClass *pklass;              /* The corresponding `MonoClass'. */
+       const char *name;
+       guint16 flags;
+       guint32 token;
+       MonoClass** constraints; /* NULL means end of list */
+} MonoGenericParamInfo;
+
+typedef struct {
+       MonoGenericParam param;
+       MonoGenericParamInfo info;
+} MonoGenericParamFull;
+
 /*
  * The generic container.
  *
@@ -509,23 +565,24 @@ struct _MonoGenericContainer {
        /* Invariant: parent != NULL => is_method */
        int is_method    : 1;
        /* Our type parameters. */
-       MonoGenericParam *type_params;
-};
+       MonoGenericParamFull *type_params;
 
-/*
- * A type parameter.
- */
-struct _MonoGenericParam {
-       MonoGenericContainer *owner;    /* Type or method this parameter was defined in. */
-       MonoClass *pklass;              /* The corresponding `MonoClass'. */
-       const char *name;
-       guint16 flags;
-       guint16 num;
-       MonoClass** constraints; /* NULL means end of list */
-       /* If owner is NULL, this is the image whose mempool this struct was allocated from */
+       /* 
+        * For owner-less containers created by SRE, the image the container was
+        * allocated from.
+        */
        MonoImage *image;
 };
 
+#define mono_generic_container_get_param(gc, i) ((MonoGenericParam *) ((gc)->type_params + (i)))
+#define mono_generic_container_get_param_info(gc, i) (&((gc)->type_params + (i))->info)
+
+#define mono_generic_param_owner(p)            ((p)->owner)
+#define mono_generic_param_num(p)              ((p)->num)
+#define mono_generic_param_info(p)             (mono_generic_param_owner (p) ? &((MonoGenericParamFull *) p)->info : NULL)
+#define mono_type_get_generic_param_owner(t)   (mono_generic_param_owner ((t)->data.generic_param))
+#define mono_type_get_generic_param_num(t)     (mono_generic_param_num   ((t)->data.generic_param))
+
 /*
  * Class information which might be cached by the runtime in the AOT file for
  * example. Caching this allows us to avoid computing a generic vtable
@@ -618,8 +675,74 @@ typedef struct {
  * Size of fields and type should not be changed as well.
  */
 typedef struct {
-       gulong methods_jitted;
-       gulong aspnet_requests_queued;
+       /* JIT category */
+       guint32 jit_methods;
+       guint32 jit_bytes;
+       guint32 jit_time;
+       guint32 jit_failures;
+       /* Exceptions category */
+       guint32 exceptions_thrown;
+       guint32 exceptions_filters;
+       guint32 exceptions_finallys;
+       guint32 exceptions_depth;
+       guint32 aspnet_requests_queued;
+       guint32 aspnet_requests;
+       /* Memory category */
+       guint32 gc_collections0;
+       guint32 gc_collections1;
+       guint32 gc_collections2;
+       guint32 gc_promotions0;
+       guint32 gc_promotions1;
+       guint32 gc_promotion_finalizers;
+       guint32 gc_gen0size;
+       guint32 gc_gen1size;
+       guint32 gc_gen2size;
+       guint32 gc_lossize;
+       guint32 gc_fin_survivors;
+       guint32 gc_num_handles;
+       guint32 gc_allocated;
+       guint32 gc_induced;
+       guint32 gc_time;
+       guint32 gc_total_bytes;
+       guint32 gc_committed_bytes;
+       guint32 gc_reserved_bytes;
+       guint32 gc_num_pinned;
+       guint32 gc_sync_blocks;
+       /* Remoting category */
+       guint32 remoting_calls;
+       guint32 remoting_channels;
+       guint32 remoting_proxies;
+       guint32 remoting_classes;
+       guint32 remoting_objects;
+       guint32 remoting_contexts;
+       /* Loader category */
+       guint32 loader_classes;
+       guint32 loader_total_classes;
+       guint32 loader_appdomains;
+       guint32 loader_total_appdomains;
+       guint32 loader_assemblies;
+       guint32 loader_total_assemblies;
+       guint32 loader_failures;
+       guint32 loader_bytes;
+       guint32 loader_appdomains_uloaded;
+       /* Threads and Locks category  */
+       guint32 thread_contentions;
+       guint32 thread_queue_len;
+       guint32 thread_queue_max;
+       guint32 thread_num_logical;
+       guint32 thread_num_physical;
+       guint32 thread_cur_recognized;
+       guint32 thread_num_recognized;
+       /* Interop category */
+       guint32 interop_num_ccw;
+       guint32 interop_num_stubs;
+       guint32 interop_num_marshals;
+       /* Security category */
+       guint32 security_num_checks;
+       guint32 security_num_link_checks;
+       guint32 security_time;
+       guint32 security_depth;
+       guint32 unused;
 } MonoPerfCounters;
 
 extern MonoPerfCounters *mono_perfcounters MONO_INTERNAL;
@@ -646,6 +769,7 @@ typedef struct {
 
 enum {
        MONO_GENERIC_SHARING_NONE,
+       MONO_GENERIC_SHARING_COLLECTIONS,
        MONO_GENERIC_SHARING_CORLIB,
        MONO_GENERIC_SHARING_ALL
 };
@@ -664,7 +788,7 @@ extern MonoStats mono_stats MONO_INTERNAL;
 
 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
 typedef gpointer (*MonoJumpTrampoline)       (MonoDomain *domain, MonoMethod *method, gboolean add_sync_wrapper);
-typedef gpointer (*MonoRemotingTrampoline)       (MonoMethod *method, MonoRemotingTarget target);
+typedef gpointer (*MonoRemotingTrampoline)       (MonoDomain *domain, MonoMethod *method, MonoRemotingTarget target);
 typedef gpointer (*MonoDelegateTrampoline)       (MonoClass *klass);
 
 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context);
@@ -706,9 +830,18 @@ mono_class_setup_supertypes (MonoClass *klass) MONO_INTERNAL;
 MonoMethod*
 mono_class_get_method_by_index (MonoClass *class, int index) MONO_INTERNAL;
 
+MonoMethod*
+mono_class_get_inflated_method (MonoClass *class, MonoMethod *method) MONO_INTERNAL;
+
+MonoMethod*
+mono_class_get_vtable_entry (MonoClass *class, int offset) MONO_INTERNAL;
+
 GPtrArray*
 mono_class_get_implemented_interfaces (MonoClass *klass) MONO_INTERNAL;
 
+int
+mono_class_get_vtable_size (MonoClass *klass) MONO_INTERNAL;
+
 gboolean
 mono_class_is_open_constructed_type (MonoType *t) MONO_INTERNAL;
 
@@ -770,6 +903,9 @@ mono_install_get_class_from_name (MonoGetClassFromName func) MONO_INTERNAL;
 MonoGenericContext*
 mono_class_get_context (MonoClass *class) MONO_INTERNAL;
 
+MonoGenericContext*
+mono_method_get_context_general (MonoMethod *method, gboolean uninflated) MONO_INTERNAL;
+
 MonoGenericContext*
 mono_method_get_context (MonoMethod *method) MONO_INTERNAL;
 
@@ -795,6 +931,12 @@ mono_method_inflated_lookup (MonoMethodInflated* method, gboolean cache) MONO_IN
 MonoMethodSignature *
 mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context);
 
+MonoType*
+mono_class_inflate_generic_type_with_mempool (MonoImage *image, MonoType *type, MonoGenericContext *context) MONO_INTERNAL;
+
+MonoClass*
+mono_class_inflate_generic_class (MonoClass *gklass, MonoGenericContext *context) MONO_INTERNAL;
+
 void
 mono_metadata_free_inflated_signature (MonoMethodSignature *sig);
 
@@ -864,6 +1006,7 @@ typedef struct {
        MonoClass *handleref_class;
        MonoClass *attribute_class;
        MonoClass *customattribute_data_class;
+       MonoClass *critical_finalizer_object;
 } MonoDefaults;
 
 extern MonoDefaults mono_defaults MONO_INTERNAL;
@@ -944,6 +1087,9 @@ mono_find_jit_icall_by_name (const char *name) MONO_INTERNAL;
 MonoJitICallInfo *
 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_INTERNAL;
 
+GHashTable*
+mono_get_jit_icall_info (void) MONO_INTERNAL;
+
 gboolean
 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data) MONO_INTERNAL;
 
@@ -959,8 +1105,8 @@ mono_type_get_name_full (MonoType *type, MonoTypeNameFormat format) MONO_INTERNA
 char*
 mono_type_get_full_name (MonoClass *class) MONO_INTERNAL;
 
-MonoArrayType *mono_dup_array_type (MonoMemPool *mp, MonoArrayType *a) MONO_INTERNAL;
-MonoMethodSignature *mono_metadata_signature_deep_dup (MonoMemPool *mp, MonoMethodSignature *sig) MONO_INTERNAL;
+MonoArrayType *mono_dup_array_type (MonoImage *image, MonoArrayType *a) MONO_INTERNAL;
+MonoMethodSignature *mono_metadata_signature_deep_dup (MonoImage *image, MonoMethodSignature *sig) MONO_INTERNAL;
 
 void
 mono_image_init_name_cache (MonoImage *image);
@@ -990,9 +1136,15 @@ mono_generic_class_is_generic_type_definition (MonoGenericClass *gklass) MONO_IN
 MonoMethod*
 mono_method_get_declaring_generic_method (MonoMethod *method) MONO_INTERNAL;
 
+MonoMethod*
+mono_class_get_method_generic (MonoClass *klass, MonoMethod *method) MONO_INTERNAL;
+
 MonoType*
 mono_type_get_basic_type_from_generic (MonoType *type) MONO_INTERNAL;
 
+void
+mono_set_generic_sharing_supported (gboolean supported) MONO_INTERNAL;
+
 gboolean
 mono_class_generic_sharing_enabled (MonoClass *class) MONO_INTERNAL;
 
@@ -1005,6 +1157,9 @@ mono_method_fill_runtime_generic_context (MonoMethodRuntimeGenericContext *mrgct
 MonoMethodRuntimeGenericContext*
 mono_method_lookup_rgctx (MonoVTable *class_vtable, MonoGenericInst *method_inst) MONO_INTERNAL;
 
+gboolean
+mono_method_needs_static_rgctx_invoke (MonoMethod *method, gboolean allow_type_vars) MONO_INTERNAL;
+
 int
 mono_class_rgctx_get_array_size (int n, gboolean mrgctx) MONO_INTERNAL;
 
@@ -1012,12 +1167,23 @@ guint32
 mono_method_lookup_or_register_other_info (MonoMethod *method, gboolean in_mrgctx, gpointer data,
        int info_type, MonoGenericContext *generic_context) MONO_INTERNAL;
 
+MonoGenericContext
+mono_method_construct_object_context (MonoMethod *method) MONO_INTERNAL;
+
 int
 mono_generic_context_check_used (MonoGenericContext *context) MONO_INTERNAL;
 
 int
 mono_class_check_context_used (MonoClass *class) MONO_INTERNAL;
 
+gboolean
+mono_generic_context_is_sharable (MonoGenericContext *context, gboolean allow_type_vars) MONO_INTERNAL;
+
+gboolean
+mono_method_is_generic_impl (MonoMethod *method) MONO_INTERNAL;
+gboolean
+mono_method_is_generic_sharable_impl (MonoMethod *method, gboolean allow_type_vars) MONO_INTERNAL;
+
 void
 mono_class_unregister_image_generic_subclasses (MonoImage *image) MONO_INTERNAL;
 
@@ -1027,4 +1193,34 @@ mono_method_can_access_method_full (MonoMethod *method, MonoMethod *called, Mono
 gboolean
 mono_method_can_access_field_full (MonoMethod *method, MonoClassField *field, MonoClass *context_klass) MONO_INTERNAL;
 
+MonoClass *
+mono_class_get_generic_type_definition (MonoClass *klass) MONO_INTERNAL;
+
+gboolean
+mono_class_has_parent_and_ignore_generics (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
+
+int
+mono_method_get_vtable_slot (MonoMethod *method) MONO_INTERNAL;
+
+int
+mono_method_get_vtable_index (MonoMethod *method) MONO_INTERNAL;
+
+MonoMethod*
+mono_method_search_in_array_class (MonoClass *klass, const char *name, MonoMethodSignature *sig) MONO_INTERNAL;
+
+void
+mono_class_setup_interface_id (MonoClass *class) MONO_INTERNAL;
+
+MonoGenericContainer*
+mono_class_get_generic_container (MonoClass *klass) MONO_INTERNAL;
+
+MonoGenericClass*
+mono_class_get_generic_class (MonoClass *klass) MONO_INTERNAL;
+
+void
+mono_class_alloc_ext (MonoClass *klass) MONO_INTERNAL;
+
+void
+mono_class_setup_interfaces (MonoClass *klass) MONO_INTERNAL;
+
 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */