2005-03-03 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mono / metadata / class-internals.h
index d010d7f33d80640ae7a150f00a03b46c5737a89d..01a6f038fd27ce4e0fc80d4c7494721443a14cc6 100644 (file)
@@ -2,6 +2,7 @@
 #define __MONO_METADATA_CLASS_INTERBALS_H__
 
 #include <mono/metadata/class.h>
+#include <mono/metadata/object.h>
 #include <mono/io-layer/io-layer.h>
 
 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
@@ -17,6 +18,9 @@ typedef struct _MonoMethodWrapper MonoMethodWrapper;
 typedef struct _MonoMethodInflated MonoMethodInflated;
 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
 
+/*
+ * remember to update wrapper_type_names if you change something here
+ */
 typedef enum {
        MONO_WRAPPER_NONE,
        MONO_WRAPPER_DELEGATE_INVOKE,
@@ -31,6 +35,8 @@ typedef enum {
        MONO_WRAPPER_XDOMAIN_DISPATCH,
        MONO_WRAPPER_LDFLD,
        MONO_WRAPPER_STFLD,
+       MONO_WRAPPER_LDFLD_REMOTE,
+       MONO_WRAPPER_STFLD_REMOTE,
        MONO_WRAPPER_SYNCHRONIZED,
        MONO_WRAPPER_DYNAMIC_METHOD,
        MONO_WRAPPER_ISINST,
@@ -52,7 +58,6 @@ struct _MonoMethod {
        guint32 token;
        MonoClass *klass;
        MonoMethodSignature *signature;
-       gpointer info; /* runtime info */
        /* name is useful mostly for debugging */
        const char *name;
        /* this is used by the inlining algorithm */
@@ -63,7 +68,7 @@ struct _MonoMethod {
        unsigned int save_lmf:1;
        unsigned int dynamic:1; /* created & destroyed during runtime */
        unsigned int is_inflated:1;
-       gint slot : 21;
+       signed int slot : 21;
 };
 
 struct _MonoMethodNormal {
@@ -74,7 +79,7 @@ struct _MonoMethodNormal {
 
 struct _MonoMethodWrapper {
        MonoMethodNormal method;
-       GList *data;
+       void *method_data;
 };
 
 struct _MonoMethodInflated {
@@ -152,6 +157,8 @@ typedef struct {
 typedef struct {
        guint32 native_size;
        guint32 num_fields;
+       MonoMethod *ptr_to_str;
+       MonoMethod *str_to_ptr;
        MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
 } MonoMarshalType;
 
@@ -173,6 +180,23 @@ struct _MonoEvent {
        guint32 attrs;
 };
 
+/* type of exception being "on hold" for later processing (see exception_type) */
+enum {
+       MONO_EXCEPTION_NONE = 0,
+       MONO_EXCEPTION_SECURITY_LINKDEMAND = 1,
+       MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND = 2
+       /* add other exception type */
+};
+
+/* This struct collects the info needed for the runtime use of a class,
+ * like the vtables for a domain, the GC descriptor, etc.
+ */
+typedef struct {
+       guint16 max_domain;
+       /* domain_vtables is indexed by the domain id and the size is max_domain + 1 */
+       MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
+} MonoClassRuntimeInfo;
+
 struct _MonoClass {
        MonoImage *image;
 
@@ -183,7 +207,7 @@ struct _MonoClass {
        /* used for subtype checks */
        MonoClass *cast_class; 
        /* array dimension */
-       guint32    rank;          
+       guint    rank;          
 
        guint inited          : 1;
        /* We use init_pending to detect cyclic calls to mono_class_init */
@@ -213,8 +237,15 @@ struct _MonoClass {
        guint contextbound    : 1; /* class is a ContextBoundObject */
        guint delegate        : 1; /* class is a Delegate */
        guint gc_descr_inited : 1; /* gc_descr is initialized */
+       guint has_cctor       : 1; /* class has a cctor */
        guint dummy           : 1; /* temporary hack */
-       guint32 declsec_flags;     /* declarative security attributes flags */
+       /* next byte */
+       guint has_references  : 1; /* it has GC-tracked references in the instance */
+       guint has_static_refs : 1; /* it has static fields that are GC-tracked */
+
+       guint32    declsec_flags;       /* declarative security attributes flags */
+       guint32    exception_type;      /* MONO_EXCEPTION_* */
+       void*      exception_data;      /* Additional information about the exception */
 
        MonoClass  *parent;
        MonoClass  *nested_in;
@@ -224,15 +255,15 @@ struct _MonoClass {
        const char *name;
        const char *name_space;
        
-       guint       interface_count;
-       guint       interface_id;        /* unique inderface id (for interfaces) */
-       guint       max_interface_id;
-        gint       *interface_offsets;   
-       MonoClass **interfaces;
-
        /* for fast subtype checks */
-       guint       idepth;
        MonoClass **supertypes;
+       guint16     idepth;
+
+       guint16     interface_count;
+       guint16     interface_id;        /* unique inderface id (for interfaces) */
+       guint16     max_interface_id;
+        gint       *interface_offsets;   
+       MonoClass **interfaces;
 
        /*
         * Computed object instance size, total.
@@ -258,8 +289,10 @@ 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;
@@ -274,13 +307,11 @@ struct _MonoClass {
        void *reflection_info;
 
        void *gc_descr;
-       guint64 gc_bitmap;
 
-       MonoMethod *ptr_to_str;
-       MonoMethod *str_to_ptr;
+       MonoClassRuntimeInfo *runtime_info;
 
-       MonoVTable *cached_vtable;
-        MonoMethod **vtable;   
+       /* Generic vtable. Initialized by a call to mono_class_setup_vtable () */
+       MonoMethod **vtable;    
 };
 
 struct MonoVTable {
@@ -291,10 +322,11 @@ struct MonoVTable {
         */
        void *gc_descr;         
        MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
-       guint32       max_interface_id;
         gpointer   *interface_offsets;   
         gpointer    data; /* to store static class data */
         gpointer    type; /* System.Type type for klass */
+       guint16     max_interface_id;
+       guint8      rank;
        guint remote          : 1; /* class is remotely activated */
        guint initialized     : 1; /* cctor has been run */
        /* do not add any fields after vtable, the structure is dynamically extended */
@@ -305,9 +337,10 @@ struct MonoVTable {
  * Generic instantiation data type encoding.
  */
 struct _MonoGenericInst {
-       int id;
-       int type_argc  : 23;
-       int is_open    : 1;
+       guint id;
+       guint type_argc    : 22;
+       guint is_open      :  1;
+       guint is_reference :  1;
        MonoType **type_argv;
 };
 
@@ -318,8 +351,6 @@ struct _MonoGenericClass {
        MonoClass *klass;
        MonoType *parent;
        guint count_ifaces  : 29;
-       guint initialized   :  1;
-       guint init_pending  :  1;
        guint is_dynamic    :  1;
        MonoType **ifaces;
 };
@@ -336,6 +367,7 @@ struct _MonoDynamicGenericClass {
        MonoProperty *properties;
        int count_events;
        MonoEvent *events;
+       guint initialized;
 };
 
 struct _MonoGenericMethod {
@@ -371,6 +403,22 @@ struct _MonoGenericParam {
        MonoClass** constraints; /* NULL means end of list */
 };
 
+/*
+ * 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
+ * (class->vtable) in most cases, saving time and avoiding creation of lots of
+ * MonoMethod structures.
+ */
+typedef struct MonoCachedClassInfo {
+       guint32 vtable_size;
+       guint has_finalize : 1;
+       guint ghcimpl : 1;
+       guint has_cctor : 1;
+       guint32 cctor_token;
+       MonoImage *finalize_image;
+       guint32 finalize_token;
+} MonoCachedClassInfo;
+
 typedef struct {
        const char *name;
        gconstpointer func;
@@ -387,6 +435,7 @@ typedef struct {
        gulong class_vtable_size;
        gulong class_static_data_size;
        gulong generic_instance_count;
+       gulong generic_class_count;
        gulong inflated_method_count;
        gulong inflated_method_count_2;
        gulong inflated_type_count;
@@ -401,6 +450,8 @@ typedef gpointer (*MonoRemotingTrampoline)       (MonoMethod *method, MonoRemoti
 
 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
 
+typedef gboolean (*MonoGetCachedClassInfo) (MonoClass *klass, MonoCachedClassInfo *res);
+
 void
 mono_classes_init (void);
 
@@ -408,7 +459,13 @@ void
 mono_class_layout_fields   (MonoClass *klass);
 
 void
-mono_class_setup_vtable    (MonoClass *klass, MonoMethod **overrides, int onum);
+mono_class_setup_vtable_general (MonoClass *klass, MonoMethod **overrides, int onum);
+
+void
+mono_class_setup_vtable (MonoClass *klass);
+
+void
+mono_class_setup_methods (MonoClass *klass);
 
 void
 mono_class_setup_mono_type (MonoClass *klass);
@@ -428,6 +485,12 @@ mono_class_is_open_constructed_type (MonoType *t);
 MonoMethod**
 mono_class_get_overrides   (MonoImage *image, guint32 type_token, gint32 *num_overrides);
 
+MonoMethod*
+mono_class_get_cctor (MonoClass *klass);
+
+MonoMethod*
+mono_class_get_finalizer (MonoClass *klass);
+
 gboolean
 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
 
@@ -444,10 +507,10 @@ void
 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
 
 void
-mono_class_create_generic (MonoGenericClass *gclass);
+mono_install_get_cached_class_info (MonoGetCachedClassInfo func);
 
 void
-mono_class_create_generic_2 (MonoGenericClass *gclass);
+mono_class_create_generic (MonoGenericClass *gclass);
 
 typedef struct {
        MonoImage *corlib;
@@ -512,10 +575,13 @@ void
 mono_loader_lock           (void);
 
 void
-mono_loader_unlock           (void);
+mono_loader_unlock         (void);
 
 void 
-mono_init_icall            (void);
+mono_icall_init            (void);
+
+void
+mono_icall_cleanup         (void);
 
 gpointer
 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
@@ -523,6 +589,9 @@ mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
 void
 mono_install_stack_walk (MonoStackWalkImpl func);
 
+gboolean
+mono_metadata_has_generic_params (MonoImage *image, guint32 token);
+
 MonoGenericContainer *mono_metadata_load_generic_params (MonoImage *image, guint32 token,
                                                         MonoGenericContainer *parent_container);
 
@@ -547,5 +616,11 @@ mono_class_inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig
 MonoGenericClass *
 mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic);
 
+gboolean
+mono_class_set_failure (MonoClass *klass, guint32 ex_type, void *ex_data);
+
+MonoException*
+mono_class_get_exception_for_failure (MonoClass *klass);
+
 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */