Tue Sep 11 16:08:08 CEST 2007 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / class-internals.h
index 748bbca8a215e43643a5be80e4222427a7a561a1..90a1e4d5279c512e3b4db106c869a3bc38a30a89 100644 (file)
@@ -78,19 +78,6 @@ struct _MonoMethodPInvoke {
        guint16 implmap_idx;  /* index into IMPLMAP */
 };
 
-/*
- * Inflated generic method.
- */
-struct _MonoMethodInflated {
-       union {
-               MonoMethod method;
-               MonoMethodNormal normal;
-               MonoMethodPInvoke pinvoke;
-       } method;
-       MonoGenericContext *context;    /* The current context. */
-       MonoMethod *declaring;          /* the generic method definition. */
-};
-
 typedef struct {
        MonoType *generic_type;
        gpointer reflection_info;
@@ -184,7 +171,10 @@ enum {
        MONO_EXCEPTION_UNVERIFIABLE_IL = 4,
        MONO_EXCEPTION_MISSING_METHOD = 5,
        MONO_EXCEPTION_MISSING_FIELD = 6,
-       MONO_EXCEPTION_TYPE_LOAD = 7
+       MONO_EXCEPTION_TYPE_LOAD = 7,
+       MONO_EXCEPTION_FILE_NOT_FOUND = 8,
+       MONO_EXCEPTION_METHOD_ACCESS = 9,
+       MONO_EXCEPTION_FIELD_ACCESS = 10,
        /* add other exception type */
 };
 
@@ -323,6 +313,9 @@ struct _MonoClass {
 
        MonoClassRuntimeInfo *runtime_info;
 
+       /* next element in the class_cache hash list (in MonoImage) */
+       MonoClass *next_class_cache;
+
        /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
        MonoMethod **vtable;    
 };
@@ -347,10 +340,13 @@ struct MonoVTable {
        guint remote          : 1; /* class is remotely activated */
        guint initialized     : 1; /* cctor has been run */
        guint init_failed     : 1; /* cctor execution failed */
+       guint32     imt_collisions_bitmap;
        /* do not add any fields after vtable, the structure is dynamically extended */
         gpointer    vtable [MONO_ZERO_LEN_ARRAY];      
 };
 
+#define MONO_VTABLE_IMPLEMENTS_INTERFACE(vt,uiid) (((uiid) <= (vt)->max_interface_id) && ((vt)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
+
 /*
  * Generic instantiation data type encoding.
  */
@@ -365,17 +361,43 @@ 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 */
-       guint is_reference :  1;        /* if this is a reference type */
        MonoType **type_argv;
 };
 
+/*
+ * The generic context: an instantiation of a set of class and method generic parameters.
+ *
+ * NOTE: Never allocate this directly on the heap.  It have to be either allocated on the stack,
+ *      or embedded within other objects.  Don't store pointers to this, because it may be on the stack.
+ *      If you really have to, ensure you store a pointer to the embedding object along with it.
+ */
+struct _MonoGenericContext {
+       /* The instantiation corresponding to the class generic parameters */
+       MonoGenericInst *class_inst;
+       /* The instantiation corresponding to the method generic parameters */
+       MonoGenericInst *method_inst;
+};
+
+/*
+ * Inflated generic method.
+ */
+struct _MonoMethodInflated {
+       union {
+               MonoMethod method;
+               MonoMethodNormal normal;
+               MonoMethodPInvoke pinvoke;
+       } method;
+       MonoMethod *declaring;          /* the generic method definition. */
+       MonoGenericContext context;     /* The current instantiation */
+       gpointer reflection_info;
+};
+
 /*
  * A particular instantiation of a generic type.
  */
 struct _MonoGenericClass {
-       MonoGenericInst *inst;          /* the instantiation */
        MonoClass *container_class;     /* the generic type definition */
-       MonoGenericContext *cached_context;     /* if present, a "trivial" context that doesn't contain any method instantiation */
+       MonoGenericContext context;     /* a context that contains the type instantiation doesn't contain any method instantiation */
        guint is_dynamic  : 1;          /* We're a MonoDynamicGenericClass */
        MonoClass *cached_class;        /* if present, the MonoClass corresponding to the instantiation.  */
 };
@@ -399,26 +421,6 @@ struct _MonoDynamicGenericClass {
        guint initialized;
 };
 
-/*
- * A particular instantiation of a generic method.
- */
-struct _MonoGenericMethod {
-       MonoGenericInst *inst;                  /* the instantiation */
-       MonoGenericInst *class_inst;            /* if we're in a generic type, the instantiation of that type */
-       MonoGenericContainer *container;        /* type parameters */
-       gpointer reflection_info;
-};
-
-/*
- * The generic context: an instantiation of a set of class and method generic parameters.
- */
-struct _MonoGenericContext {
-       /* The instantiation corresponding to the class generic parameters */
-       MonoGenericInst *class_inst;
-       /* The current generic method */
-       MonoGenericMethod *gmethod;
-};
-
 /*
  * The generic container.
  *
@@ -429,8 +431,6 @@ struct _MonoGenericContainer {
        /* If we're a generic method definition in a generic type definition,
           the generic container of the containing class. */
        MonoGenericContainer *parent;
-       /* If we're a generic method definition, caches all their instantiations. */
-       GHashTable *method_hash;
        /* the generic type definition or the generic method definition corresponding to this container */
        union {
                MonoClass *klass;
@@ -489,18 +489,8 @@ typedef struct {
        MonoMethodSignature *sig;
 } MonoJitICallInfo;
 
-/*
- * Information about a type load error encountered by the loader.
- */
-typedef enum {
-       MONO_LOADER_ERROR_TYPE,
-       MONO_LOADER_ERROR_METHOD,
-       MONO_LOADER_ERROR_FIELD,
-       MONO_LOADER_ERROR_ASSEMBLY
-} MonoLoaderErrorKind;
-
 typedef struct {
-       MonoLoaderErrorKind kind;
+       guint8 exception_type;
        char *class_name; /* If kind == TYPE */
        char *assembly_name; /* If kind == TYPE or ASSEMBLY */
        MonoClass *klass; /* If kind != TYPE */
@@ -524,6 +514,21 @@ typedef struct {
        gulong inflated_method_count_2;
        gulong inflated_type_count;
        gulong generics_metadata_size;
+       gulong dynamic_code_alloc_count;
+       gulong dynamic_code_bytes_count;
+       gulong dynamic_code_frees_count;
+       gulong imt_tables_size;
+       gulong imt_number_of_tables;
+       gulong imt_number_of_methods;
+       gulong imt_used_slots;
+       gulong imt_slots_with_collisions;
+       gulong imt_max_collisions_in_slot;
+       gulong imt_method_count_when_max_collisions;
+       gulong imt_thunks_size;
+       gulong jit_info_table_insert_count;
+       gulong jit_info_table_remove_count;
+       gulong jit_info_table_lookup_count;
+       gulong hazardous_pointer_count;
        gboolean enabled;
 } MonoStats;
 
@@ -549,9 +554,9 @@ extern MonoStats mono_stats MONO_INTERNAL;
 
 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
 typedef gpointer (*MonoRemotingTrampoline)       (MonoMethod *method, MonoRemotingTarget target);
-typedef gpointer (*MonoDelegateTrampoline)       (MonoMethod *method, gpointer addr);
+typedef gpointer (*MonoDelegateTrampoline)       (MonoClass *klass);
 
-typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, MonoClass **handle_class);
+typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token, MonoClass **handle_class, MonoGenericContext *context);
 
 typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
 
@@ -619,10 +624,10 @@ void
 mono_install_delegate_trampoline (MonoDelegateTrampoline func) MONO_INTERNAL;
 
 gpointer
-mono_lookup_dynamic_token (MonoImage *image, guint32 token) MONO_INTERNAL;
+mono_lookup_dynamic_token (MonoImage *image, guint32 token, MonoGenericContext *context) MONO_INTERNAL;
 
 gpointer
-mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass **handle_class) MONO_INTERNAL;
+mono_lookup_dynamic_token_class (MonoImage *image, guint32 token, MonoClass **handle_class, MonoGenericContext *context) MONO_INTERNAL;
 
 void
 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func) MONO_INTERNAL;
@@ -648,6 +653,8 @@ mono_generic_class_get_class (MonoGenericClass *gclass) MONO_INTERNAL;
 MonoMethod*
 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
 
+MonoMethodInflated*
+mono_method_inflated_lookup (MonoMethodInflated* method, gboolean cache) MONO_INTERNAL;
 
 typedef struct {
        MonoImage *corlib;
@@ -713,6 +720,8 @@ typedef struct {
        MonoClass *idispatch_class;
        MonoClass *safehandle_class;
        MonoClass *handleref_class;
+       MonoClass *attribute_class;
+       MonoClass *customattribute_data_class;
 } MonoDefaults;
 
 extern MonoDefaults mono_defaults MONO_INTERNAL;
@@ -791,15 +800,6 @@ mono_find_jit_icall_by_name (const char *name) MONO_INTERNAL;
 MonoJitICallInfo *
 mono_find_jit_icall_by_addr (gconstpointer addr) MONO_INTERNAL;
 
-MonoGenericInst *
-mono_get_shared_generic_inst (MonoGenericContainer *container) MONO_INTERNAL;
-
-MonoGenericClass *
-mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic) MONO_INTERNAL;
-
-MonoGenericMethod *
-mono_get_shared_generic_method (MonoGenericContainer *container) MONO_INTERNAL;
-
 gboolean
 mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data) MONO_INTERNAL;
 
@@ -827,5 +827,15 @@ void mono_object_describe_fields (MonoObject *obj);
 void mono_value_describe_fields  (MonoClass* klass, const char* addr);
 void mono_class_describe_statics (MonoClass* klass);
 
+/*Enum validation related functions*/
+gboolean
+mono_type_is_valid_enum_basetype (MonoType * type);
+
+gboolean
+mono_class_is_valid_enum (MonoClass *klass);
+
+MonoType *
+mono_type_get_full        (MonoImage *image, guint32 type_token, MonoGenericContext *context) MONO_INTERNAL;
+
 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */