2008-07-28 Marek Habersack <mhabersack@novell.com>
[mono.git] / mono / metadata / class-internals.h
index 8ba1f1d5ff67a6a70c679f9a95635b450b6f321c..54d5f3a0f424c6b114400747c3ecfe56810c61c2 100644 (file)
@@ -3,6 +3,7 @@
 
 #include <mono/metadata/class.h>
 #include <mono/metadata/object.h>
+#include <mono/metadata/mempool.h>
 #include <mono/io-layer/io-layer.h>
 #include "mono/utils/mono-compiler.h"
 
@@ -12,6 +13,8 @@
 
 extern gboolean mono_print_vtable;
 
+extern gboolean mono_setup_vtable_in_class_init;
+
 typedef void     (*MonoStackWalkImpl) (MonoStackWalk func, gboolean do_il_offset, gpointer user_data);
 
 typedef struct _MonoMethodNormal MonoMethodNormal;
@@ -19,6 +22,13 @@ typedef struct _MonoMethodWrapper MonoMethodWrapper;
 typedef struct _MonoMethodInflated MonoMethodInflated;
 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
 
+/* Properties that applies to a group of structs should better use a higher number
+ * to avoid colision with type specific properties.
+ * 
+ * This prop applies to class, method, property, event, assembly and image.
+ */
+#define MONO_PROP_DYNAMIC_CATTR 0x1000
+
 typedef enum {
 #define WRAPPER(e,n) MONO_WRAPPER_ ## e,
 #include "wrapper-types.h"
@@ -39,13 +49,14 @@ typedef enum {
        MONO_REMOTING_TARGET_COMINTEROP
 } MonoRemotingTarget;
 
+#define MONO_METHOD_PROP_GENERIC_CONTAINER 0
+
 struct _MonoMethod {
        guint16 flags;  /* method flags */
        guint16 iflags; /* method implementation flags */
        guint32 token;
        MonoClass *klass;
        MonoMethodSignature *signature;
-       MonoGenericContainer *generic_container;
        /* name is useful mostly for debugging */
        const char *name;
        /* this is used by the inlining algorithm */
@@ -55,9 +66,16 @@ struct _MonoMethod {
        unsigned int string_ctor:1;
        unsigned int save_lmf:1;
        unsigned int dynamic:1; /* created & destroyed during runtime */
+       unsigned int is_generic:1; /* whenever this is a generic method definition */
        unsigned int is_inflated:1; /* whether we're a MonoMethodInflated */
        unsigned int skip_visibility:1; /* whenever to skip JIT visibility checks */
-       signed int slot : 20;
+       unsigned int verification_success:1; /* whether this method has been verified successfully.*/
+       signed int slot : 18;
+
+       /*
+        * If is_generic is TRUE, the generic_container is stored in image->property_hash, 
+        * using the key MONO_METHOD_PROP_GENERIC_CONTAINER.
+        */
 };
 
 struct _MonoMethodNormal {
@@ -176,7 +194,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 */
 };
 
@@ -189,15 +208,16 @@ typedef struct {
        MonoVTable *domain_vtables [MONO_ZERO_LEN_ARRAY];
 } MonoClassRuntimeInfo;
 
-#define MONO_RGCTX_MAX_OTHER_INFOS     2
-
 enum {
        MONO_RGCTX_INFO_STATIC_DATA,
        MONO_RGCTX_INFO_KLASS,
        MONO_RGCTX_INFO_VTABLE,
+       MONO_RGCTX_INFO_TYPE,
        MONO_RGCTX_INFO_REFLECTION_TYPE,
        MONO_RGCTX_INFO_METHOD,
-       MONO_RGCTX_INFO_GENERIC_METHOD_CODE
+       MONO_RGCTX_INFO_GENERIC_METHOD_CODE,
+       MONO_RGCTX_INFO_CLASS_FIELD,
+       MONO_RGCTX_INFO_METHOD_RGCTX
 };
 
 typedef struct _MonoRuntimeGenericContextOtherInfoTemplate {
@@ -207,12 +227,25 @@ typedef struct _MonoRuntimeGenericContextOtherInfoTemplate {
 } MonoRuntimeGenericContextOtherInfoTemplate;
 
 typedef struct {
-       int num_arg_infos;
        MonoClass *next_subclass;
        MonoRuntimeGenericContextOtherInfoTemplate *other_infos;
-       MonoType *arg_infos [MONO_ZERO_LEN_ARRAY];
+       GSList *method_templates;
 } MonoRuntimeGenericContextTemplate;
 
+typedef struct {
+       MonoVTable *class_vtable; /* must be the first element */
+       MonoGenericInst *method_inst;
+       gpointer infos [MONO_ZERO_LEN_ARRAY];
+} MonoMethodRuntimeGenericContext;
+
+#define MONO_RGCTX_SLOT_MAKE_RGCTX(i)  (i)
+#define MONO_RGCTX_SLOT_MAKE_MRGCTX(i) ((i) | 0x80000000)
+#define MONO_RGCTX_SLOT_INDEX(s)       ((s) & 0x7fffffff)
+#define MONO_RGCTX_SLOT_IS_MRGCTX(s)   (((s) & 0x80000000) ? TRUE : FALSE)
+
+
+#define MONO_CLASS_PROP_EXCEPTION_DATA 0
+
 struct _MonoClass {
        /* element class for arrays and enum */
        MonoClass *element_class; 
@@ -269,7 +302,10 @@ struct _MonoClass {
        guint is_com_object : 1; 
 
        guint8     exception_type;      /* MONO_EXCEPTION_* */
-       void*      exception_data;      /* Additional information about the exception */
+
+       /* Additional information about the exception */
+       /* Stored as property MONO_CLASS_PROP_EXCEPTION_DATA */
+       //void       *exception_data;
 
        MonoClass  *parent;
        MonoClass  *nested_in;
@@ -300,6 +336,7 @@ struct _MonoClass {
        union {
                int class_size; /* size of area for static fields */
                int element_size; /* for array types */
+               int generic_param_token; /* for generic param types, both var and mvar */
        } sizes;
 
        /*
@@ -349,37 +386,7 @@ struct _MonoClass {
 #define MONO_CLASS_IMPLEMENTS_INTERFACE(k,uiid) (((uiid) <= (k)->max_interface_id) && ((k)->interface_bitmap [(uiid) >> 3] & (1 << ((uiid)&7))))
 int mono_class_interface_offset (MonoClass *klass, MonoClass *itf);
 
-typedef struct {
-       gpointer static_data;
-       MonoClass *klass;
-       MonoVTable *vtable;
-} MonoRuntimeGenericSuperInfo;
-
-typedef struct {
-       gpointer static_data;
-       MonoClass *klass;
-       MonoVTable *vtable;
-} MonoRuntimeGenericArgInfo;
-
-typedef struct {
-       MonoDomain *domain;
-       MonoVTable *vtable;
-       gpointer other_infos [MONO_RGCTX_MAX_OTHER_INFOS];
-       gpointer *extra_other_infos;
-       MonoRuntimeGenericArgInfo arg_infos [MONO_ZERO_LEN_ARRAY];
-} MonoRuntimeGenericContext;
-
-#define MONO_RGCTX_ENCODE_DIRECT_OFFSET(o)     ((guint32)(o) & 0x00ffffff)
-#define MONO_RGCTX_ENCODE_INDIRECT_OFFSET(o)   (((guint32)(o) & 0x00ffffff) | 0x01000000)
-
-#define MONO_RGCTX_OFFSET_INDIRECT_SLOT(s)     ((gint32)(((guint32)(s))>>24) - 1)
-#define MONO_RGCTX_OFFSET_IS_INDIRECT(s)       (MONO_RGCTX_OFFSET_INDIRECT_SLOT((s)) >= 0)
-
-#define MONO_RGCTX_OFFSET_OFFSET_PART(s)       ((guint32)(s) & 0x00ffffff)
-#define MONO_RGCTX_OFFSET_DIRECT_OFFSET(s)     ((MONO_RGCTX_OFFSET_OFFSET_PART((s)) & 0x00800000) ? \
-                       (gint32)(MONO_RGCTX_OFFSET_OFFSET_PART((s)) | 0xff000000) : \
-                       (gint32)MONO_RGCTX_OFFSET_OFFSET_PART((s)))
-#define MONO_RGCTX_OFFSET_INDIRECT_OFFSET(s)    MONO_RGCTX_OFFSET_DIRECT_OFFSET((s))
+typedef gpointer MonoRuntimeGenericContext;
 
 /* the interface_offsets array is stored in memory before this struct */
 struct MonoVTable {
@@ -640,6 +647,7 @@ typedef struct {
 
 enum {
        MONO_GENERIC_SHARING_NONE,
+       MONO_GENERIC_SHARING_COLLECTIONS,
        MONO_GENERIC_SHARING_CORLIB,
        MONO_GENERIC_SHARING_ALL
 };
@@ -697,6 +705,9 @@ mono_class_setup_parent    (MonoClass *klass, MonoClass *parent) MONO_INTERNAL;
 void
 mono_class_setup_supertypes (MonoClass *klass) MONO_INTERNAL;
 
+MonoMethod*
+mono_class_get_method_by_index (MonoClass *class, int index) MONO_INTERNAL;
+
 GPtrArray*
 mono_class_get_implemented_interfaces (MonoClass *klass) MONO_INTERNAL;
 
@@ -716,6 +727,9 @@ mono_class_get_finalizer (MonoClass *klass) MONO_INTERNAL;
 gboolean
 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller) MONO_INTERNAL;
 
+gboolean
+mono_class_field_is_special_static (MonoClassField *field) MONO_INTERNAL;
+
 gboolean
 mono_class_has_special_static_fields (MonoClass *klass) MONO_INTERNAL;
 
@@ -761,12 +775,19 @@ mono_class_get_context (MonoClass *class) MONO_INTERNAL;
 MonoGenericContext*
 mono_method_get_context (MonoMethod *method) MONO_INTERNAL;
 
+/* Used by monodis, thus cannot be MONO_INTERNAL */
+MonoGenericContainer*
+mono_method_get_generic_container (MonoMethod *method);
+
 MonoGenericContext*
 mono_generic_class_get_context (MonoGenericClass *gclass) MONO_INTERNAL;
 
 MonoClass*
 mono_generic_class_get_class (MonoGenericClass *gclass) MONO_INTERNAL;
 
+void
+mono_method_set_generic_container (MonoMethod *method, MonoGenericContainer* container) MONO_INTERNAL;
+
 MonoMethod*
 mono_class_inflate_generic_method_full (MonoMethod *method, MonoClass *klass_hint, MonoGenericContext *context);
 
@@ -776,6 +797,9 @@ 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 (MonoMemPool *mempool, MonoType *type, MonoGenericContext *context) MONO_INTERNAL;
+
 void
 mono_metadata_free_inflated_signature (MonoMethodSignature *sig);
 
@@ -925,9 +949,15 @@ 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;
 
+gpointer
+mono_class_get_exception_data (MonoClass *klass) MONO_INTERNAL;
+
 MonoException*
 mono_class_get_exception_for_failure (MonoClass *klass) MONO_INTERNAL;
 
@@ -937,8 +967,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 (MonoArrayType *a) MONO_INTERNAL;
-MonoMethodSignature *mono_metadata_signature_deep_dup (MonoMethodSignature *sig) 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;
 
 void
 mono_image_init_name_cache (MonoImage *image);
@@ -965,23 +995,33 @@ mono_type_get_full        (MonoImage *image, guint32 type_token, MonoGenericCont
 gboolean
 mono_generic_class_is_generic_type_definition (MonoGenericClass *gklass) MONO_INTERNAL;
 
+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;
 
 gboolean
 mono_class_generic_sharing_enabled (MonoClass *class) MONO_INTERNAL;
 
-MonoRuntimeGenericContextTemplate*
-mono_class_get_runtime_generic_context_template (MonoClass *class) MONO_INTERNAL;
+gpointer
+mono_class_fill_runtime_generic_context (MonoVTable *class_vtable, guint32 slot) MONO_INTERNAL;
 
-void
-mono_class_setup_runtime_generic_context (MonoClass *class, MonoDomain *domain) MONO_INTERNAL;
+gpointer
+mono_method_fill_runtime_generic_context (MonoMethodRuntimeGenericContext *mrgctx, guint32 slot) MONO_INTERNAL;
 
-void
-mono_class_fill_runtime_generic_context (MonoRuntimeGenericContext *rgctx) MONO_INTERNAL;
+MonoMethodRuntimeGenericContext*
+mono_method_lookup_rgctx (MonoVTable *class_vtable, MonoGenericInst *method_inst) MONO_INTERNAL;
 
-gboolean
-mono_class_lookup_or_register_other_info (MonoClass *class, gpointer data, int info_type, MonoGenericContext *generic_context) MONO_INTERNAL;
+int
+mono_class_rgctx_get_array_size (int n, gboolean mrgctx) MONO_INTERNAL;
+
+guint32
+mono_method_lookup_or_register_other_info (MonoMethod *method, gboolean in_mrgctx, gpointer data,
+       int info_type, MonoGenericContext *generic_context) MONO_INTERNAL;
 
 int
 mono_generic_context_check_used (MonoGenericContext *context) MONO_INTERNAL;
@@ -992,7 +1032,13 @@ mono_class_check_context_used (MonoClass *class) MONO_INTERNAL;
 void
 mono_class_unregister_image_generic_subclasses (MonoImage *image) MONO_INTERNAL;
 
-void
-mono_class_unregister_domain_generic_vtables (MonoDomain *domain) MONO_INTERNAL;
+gboolean
+mono_method_can_access_method_full (MonoMethod *method, MonoMethod *called, MonoClass *context_klass) MONO_INTERNAL;
+
+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;
 
 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */