Do TLS using pthreads if __thread keyword not supported.
[mono.git] / mono / metadata / class-internals.h
index 6285da830d98dcef2c0896520b0b8da4f00e1b03..f537354ab1e3fc0f6bacf9c7ea2e93ebf862df76 100644 (file)
@@ -72,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, 
@@ -100,7 +102,8 @@ struct _MonoMethodPInvoke {
 
 /* 
  * Stores the default value / RVA of fields.
- * This information is rarely needed, so it is stored separately from MonoClassField.
+ * This information is rarely needed, so it is stored separately from 
+ * MonoClassField.
  */
 typedef struct MonoFieldDefaultValue {
        /*
@@ -135,6 +138,7 @@ struct _MonoClassField {
         * 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;
 };
@@ -242,6 +246,31 @@ 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 basetype for enums */
        MonoClass *element_class; 
@@ -299,6 +328,7 @@ struct _MonoClass {
         */
        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 */
@@ -311,13 +341,11 @@ struct _MonoClass {
 
        MonoClass  *parent;
        MonoClass  *nested_in;
-       GList      *nested_classes;
 
        MonoImage *image;
        const char *name;
        const char *name_space;
 
-       guint32    declsec_flags;       /* declarative security attributes flags */
        guint32    type_token;
        int        vtable_size; /* number of slots */
 
@@ -344,7 +372,7 @@ struct _MonoClass {
        guint32    flags;
        struct {
                guint32 first, count;
-       } field, method, property, event;
+       } field, method;
 
        /* loaded on demand */
        MonoMarshalType *marshal_info;
@@ -354,12 +382,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 */
@@ -381,9 +403,8 @@ struct _MonoClass {
        /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
        MonoMethod **vtable;
 
-       /* Default values/RVA for fields */
-       /* Accessed using mono_class_get_field_default_value () / mono_field_get_data () */
-       MonoFieldDefaultValue *field_def_values;
+       /* 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))))
@@ -458,9 +479,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 */
 };
 
 /*
@@ -497,6 +515,30 @@ struct _MonoDynamicGenericClass {
        MonoObject **field_objects;
 };
 
+/*
+ * A type parameter.
+ */
+struct _MonoGenericParam {
+       MonoGenericContainer *owner;    /* Type or method this parameter was defined in. */
+       guint16 num;
+       /* If owner is NULL, this is the image whose mempool this struct was allocated from */
+       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.
  *
@@ -517,22 +559,17 @@ 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 */
-       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
@@ -851,6 +888,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;
 
@@ -877,7 +917,7 @@ MonoMethodSignature *
 mono_metadata_get_inflated_signature (MonoMethodSignature *sig, MonoGenericContext *context);
 
 MonoType*
-mono_class_inflate_generic_type_with_mempool (MonoMemPool *mempool, MonoType *type, MonoGenericContext *context) MONO_INTERNAL;
+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;
@@ -951,6 +991,7 @@ typedef struct {
        MonoClass *handleref_class;
        MonoClass *attribute_class;
        MonoClass *customattribute_data_class;
+       MonoClass *critical_finalizer_object;
 } MonoDefaults;
 
 extern MonoDefaults mono_defaults MONO_INTERNAL;
@@ -1049,8 +1090,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);
@@ -1086,6 +1127,9 @@ mono_class_get_method_generic (MonoClass *klass, MonoMethod *method) MONO_INTERN
 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;
 
@@ -1108,6 +1152,9 @@ 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;
 
@@ -1155,4 +1202,10 @@ 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__ */