This commit was manufactured by cvs2svn to create branch 'mono-1-0'.
[mono.git] / mono / metadata / class-internals.h
1 #ifndef __MONO_METADATA_CLASS_INTERBALS_H__
2 #define __MONO_METADATA_CLASS_INTERBALS_H__
3
4 #include <mono/metadata/class.h>
5 #include <mono/io-layer/io-layer.h>
6
7 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
8
9 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
10
11 extern gboolean mono_print_vtable;
12
13 typedef void     (*MonoStackWalkImpl) (MonoStackWalk func, gpointer user_data);
14
15 typedef struct _MonoMethodNormal MonoMethodNormal;
16 typedef struct _MonoMethodWrapper MonoMethodWrapper;
17 typedef struct _MonoMethodInflated MonoMethodInflated;
18 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
19
20 typedef enum {
21         MONO_WRAPPER_NONE,
22         MONO_WRAPPER_DELEGATE_INVOKE,
23         MONO_WRAPPER_DELEGATE_BEGIN_INVOKE,
24         MONO_WRAPPER_DELEGATE_END_INVOKE,
25         MONO_WRAPPER_RUNTIME_INVOKE,
26         MONO_WRAPPER_NATIVE_TO_MANAGED,
27         MONO_WRAPPER_MANAGED_TO_NATIVE,
28         MONO_WRAPPER_REMOTING_INVOKE,
29         MONO_WRAPPER_REMOTING_INVOKE_WITH_CHECK,
30         MONO_WRAPPER_LDFLD,
31         MONO_WRAPPER_STFLD,
32         MONO_WRAPPER_SYNCHRONIZED,
33         MONO_WRAPPER_DYNAMIC_METHOD,
34         MONO_WRAPPER_UNKNOWN
35 } MonoWrapperType;
36
37 struct _MonoMethod {
38         guint16 flags;  /* method flags */
39         guint16 iflags; /* method implementation flags */
40         guint32 token;
41         MonoClass *klass;
42         MonoMethodSignature *signature;
43         gpointer addr;
44         gpointer info; /* runtime info */
45         gpointer remoting_tramp; 
46         gint slot;
47         /* name is useful mostly for debugging */
48         const char *name;
49         /* this is used by the inlining algorithm */
50         unsigned int inline_info:1;
51         unsigned int uses_this:1;
52         unsigned int wrapper_type:4;
53         unsigned int string_ctor:1;
54         unsigned int save_lmf:1;
55         gint16 inline_count;
56 };
57
58 struct _MonoMethodNormal {
59         MonoMethod method;
60         MonoMethodHeader *header;
61 };
62
63 struct _MonoMethodWrapper {
64         MonoMethodNormal method;
65         GList *data;
66 };
67
68 struct _MonoMethodInflated {
69         MonoMethodNormal nmethod;
70         MonoGenericContext *context;
71         MonoMethod *declaring;
72 };
73
74 struct _MonoMethodPInvoke {
75         MonoMethod method;
76         void  (*code) (void);
77         /* add marshal info */
78         guint16 piflags;  /* pinvoke flags */
79         guint16 implmap_idx;  /* index into IMPLMAP */
80 };
81
82 typedef struct {
83         MonoTypeEnum type;
84         gpointer value;
85 } MonoConstant;
86
87 typedef struct {
88         MonoType *generic_type;
89         gpointer reflection_info;
90 } MonoInflatedField;
91
92 /*
93  * MonoClassField is just a runtime representation of the metadata for
94  * field, it doesn't contain the data directly.  Static fields are
95  * stored in MonoVTable->data.  Instance fields are allocated in the
96  * objects after the object header.
97  */
98 struct _MonoClassField {
99         /* Type of the field */
100         MonoType        *type;
101
102         /* If this is an instantiated generic type, this is the
103          * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
104          * it was instantiated from.
105          */
106         MonoInflatedField  *generic_info;
107
108         /*
109          * Offset where this field is stored; if it is an instance
110          * field, it's the offset from the start of the object, if
111          * it's static, it's from the start of the memory chunk
112          * allocated for statics for the class.
113          */
114         int              offset;
115
116         const char      *name;
117
118         /*
119          * Pointer to the data (from the RVA address, valid only for
120          * fields with the has rva flag).
121          */
122         const char      *data;
123
124         /* Type where the field was defined */
125         MonoClass       *parent;
126
127         /*
128          * If the field is constant, pointer to the metadata where the
129          * constant value can be loaded. Initialized lazily during vtable creation.
130          */
131         MonoConstant    *def_value;
132 };
133
134 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
135 #define mono_field_is_deleted(field) ((field)->name[0] == '_' && ((field)->type->attrs & 0x600) && (strcmp ((field)->name, "_Deleted") == 0))
136
137 typedef struct {
138         MonoClassField *field;
139         guint32 offset;
140         MonoMarshalSpec *mspec;
141 } MonoMarshalField;
142
143 typedef struct {
144         guint32 native_size;
145         guint32 num_fields;
146         MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
147 } MonoMarshalType;
148
149 struct _MonoProperty {
150         MonoClass *parent;
151         const char *name;
152         MonoMethod *get;
153         MonoMethod *set;
154         guint32 attrs;
155 };
156
157 struct _MonoEvent {
158         MonoClass *parent;
159         const char *name;
160         MonoMethod *add;
161         MonoMethod *remove;
162         MonoMethod *raise;
163         MonoMethod **other;
164         guint32 attrs;
165 };
166
167 struct _MonoClass {
168         MonoImage *image;
169
170         /* The underlying type of the enum */
171         MonoType *enum_basetype;
172         /* element class for arrays and enum */
173         MonoClass *element_class; 
174         /* used for subtype checks */
175         MonoClass *cast_class; 
176         /* array dimension */
177         guint32    rank;          
178
179         guint inited          : 1;
180         /* We use init_pending to detect cyclic calls to mono_class_init */
181         guint init_pending    : 1;
182
183         /* A class contains static and non static data. Static data can be
184          * of the same type as the class itselfs, but it does not influence
185          * the instance size of the class. To avoid cyclic calls to 
186          * mono_class_init (from mono_class_instance_size ()) we first 
187          * initialise all non static fields. After that we set size_inited 
188          * to 1, because we know the instance size now. After that we 
189          * initialise all static fields.
190          */
191         guint size_inited     : 1;
192         guint valuetype       : 1; /* derives from System.ValueType */
193         guint enumtype        : 1; /* derives from System.Enum */
194         guint blittable       : 1; /* class is blittable */
195         guint unicode         : 1; /* class uses unicode char when marshalled */
196         guint wastypebuilder  : 1; /* class was created at runtime from a TypeBuilder */
197         /* next byte */
198         guint min_align       : 4;
199         guint packing_size    : 4;
200         /* next byte */
201         guint ghcimpl         : 1; /* class has its own GetHashCode impl */ 
202         guint has_finalize    : 1; /* class has its own Finalize impl */ 
203         guint marshalbyref    : 1; /* class is a MarshalByRefObject */
204         guint contextbound    : 1; /* class is a ContextBoundObject */
205         guint delegate        : 1; /* class is a Delegate */
206         guint gc_descr_inited : 1; /* gc_descr is initialized */
207         guint dummy           : 1; /* temporary hack */
208
209         MonoClass  *parent;
210         MonoClass  *nested_in;
211         GList      *nested_classes;
212
213         guint32    type_token;
214         const char *name;
215         const char *name_space;
216         
217         guint       interface_count;
218         guint       interface_id;        /* unique inderface id (for interfaces) */
219         guint       max_interface_id;
220         gint       *interface_offsets;   
221         MonoClass **interfaces;
222
223         /* for fast subtype checks */
224         guint       idepth;
225         MonoClass **supertypes;
226
227         /*
228          * Computed object instance size, total.
229          */
230         int        instance_size;
231         int        class_size;
232         int        vtable_size; /* number of slots */
233
234         /*
235          * From the TypeDef table
236          */
237         guint32    flags;
238         struct {
239                 guint32 first, last;
240                 int count;
241         } field, method, property, event;
242
243         /* loaded on demand */
244         MonoMarshalType *marshal_info;
245
246         /*
247          * Field information: Type and location from object base
248          */
249         MonoClassField *fields;
250
251         MonoProperty *properties;
252         
253         MonoEvent *events;
254
255         MonoMethod **methods;
256
257         /* used as the type of the this argument and when passing the arg by value */
258         MonoType this_arg;
259         MonoType byval_arg;
260
261         MonoGenericInst *generic_inst;
262         MonoGenericParam *gen_params;
263         guint16 num_gen_params;
264
265         void *reflection_info;
266
267         void *gc_descr;
268         guint64 gc_bitmap;
269
270         MonoMethod *ptr_to_str;
271         MonoMethod *str_to_ptr;
272
273         MonoVTable *cached_vtable;
274         MonoMethod **vtable;    
275 };
276
277 struct MonoVTable {
278         MonoClass  *klass;
279     /*
280          * According to comments in gc_gcj.h, this should be the second word in
281          * the vtable.
282          */
283         void *gc_descr;         
284         MonoDomain *domain;  /* each object/vtable belongs to exactly one domain */
285         guint       max_interface_id;
286         gpointer   *interface_offsets;   
287         gpointer    data; /* to store static class data */
288         gpointer    type; /* System.Type type for klass */
289         guint remote          : 1; /* class is remotely activated */
290         guint initialized     : 1; /* cctor has been run */
291         /* do not add any fields after vtable, the structure is dynamically extended */
292         gpointer    vtable [MONO_ZERO_LEN_ARRAY];       
293 };
294
295 /*
296  * Generic instantiation data type encoding.
297  */
298 struct _MonoGenericInst {
299         MonoGenericContext *context;
300         MonoClass *klass;
301         MonoType *parent;
302         int count_ifaces;
303         MonoType **ifaces;
304         MonoType *generic_type;
305         MonoDynamicGenericInst *dynamic_info;
306         int type_argc;
307         MonoType **type_argv;
308         guint is_open       : 1;
309         guint initialized   : 1;
310         guint init_pending  : 1;
311         guint is_dynamic    : 1;
312 };
313
314 struct _MonoDynamicGenericInst {
315         int count_methods;
316         MonoMethod **methods;
317         int count_ctors;
318         MonoMethod **ctors;
319         int count_fields;
320         MonoClassField *fields;
321         int count_properties;
322         MonoProperty *properties;
323         int count_events;
324         MonoEvent *events;
325 };
326
327 struct _MonoGenericMethod {
328         gpointer reflection_info;
329         int mtype_argc;
330         MonoType **mtype_argv;
331         guint is_open       : 1;
332 };
333
334 struct _MonoGenericContext {
335         MonoGenericInst *ginst;
336         MonoGenericMethod *gmethod;
337 };
338
339 struct _MonoGenericParam {
340         MonoClass *pklass;
341         MonoMethod *method;
342         const char *name;
343         guint16 flags;
344         guint16 num;
345         MonoClass** constraints; /* NULL means end of list */
346 };
347
348 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
349
350 typedef struct {
351         gulong new_object_count;
352         gulong initialized_class_count;
353         gulong used_class_count;
354         gulong class_vtable_size;
355         gulong class_static_data_size;
356         gulong generic_instance_count;
357         gulong inflated_method_count;
358         gulong inflated_type_count;
359         gulong generics_metadata_size;
360 } MonoStats;
361
362 extern MonoStats mono_stats;
363
364 typedef gpointer (*MonoTrampoline)       (MonoMethod *method);
365
366 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
367
368 void
369 mono_classes_init (void);
370
371 void
372 mono_class_layout_fields   (MonoClass *klass);
373
374 void
375 mono_class_setup_vtable    (MonoClass *klass, MonoMethod **overrides, int onum);
376
377 void
378 mono_class_setup_mono_type (MonoClass *klass);
379
380 void
381 mono_class_setup_parent    (MonoClass *klass, MonoClass *parent);
382
383 void
384 mono_class_setup_supertypes (MonoClass *klass);
385
386 gboolean
387 mono_class_is_open_constructed_type (MonoType *t);
388
389 MonoMethod**
390 mono_class_get_overrides   (MonoImage *image, guint32 type_token, gint32 *num_overrides);
391
392 gboolean
393 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
394
395 void
396 mono_install_trampoline (MonoTrampoline func);
397
398 void
399 mono_install_remoting_trampoline (MonoTrampoline func);
400
401 gpointer
402 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
403
404 void
405 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
406
407 typedef struct {
408         MonoImage *corlib;
409         MonoClass *object_class;
410         MonoClass *byte_class;
411         MonoClass *void_class;
412         MonoClass *boolean_class;
413         MonoClass *sbyte_class;
414         MonoClass *int16_class;
415         MonoClass *uint16_class;
416         MonoClass *int32_class;
417         MonoClass *uint32_class;
418         MonoClass *int_class;
419         MonoClass *uint_class;
420         MonoClass *int64_class;
421         MonoClass *uint64_class;
422         MonoClass *single_class;
423         MonoClass *double_class;
424         MonoClass *char_class;
425         MonoClass *string_class;
426         MonoClass *enum_class;
427         MonoClass *array_class;
428         MonoClass *delegate_class;
429         MonoClass *multicastdelegate_class;
430         MonoClass *asyncresult_class;
431         MonoClass *waithandle_class;
432         MonoClass *typehandle_class;
433         MonoClass *fieldhandle_class;
434         MonoClass *methodhandle_class;
435         MonoClass *monotype_class;
436         MonoClass *exception_class;
437         MonoClass *threadabortexception_class;
438         MonoClass *thread_class;
439         MonoClass *transparent_proxy_class;
440         MonoClass *real_proxy_class;
441         MonoClass *mono_method_message_class;
442         MonoClass *appdomain_class;
443         MonoClass *field_info_class;
444         MonoClass *method_info_class;
445         MonoClass *stringbuilder_class;
446         MonoClass *math_class;
447         MonoClass *stack_frame_class;
448         MonoClass *stack_trace_class;
449         MonoClass *marshal_class;
450         MonoClass *iserializeable_class;
451         MonoClass *serializationinfo_class;
452         MonoClass *streamingcontext_class;
453         MonoClass *typed_reference_class;
454         MonoClass *argumenthandle_class;
455         MonoClass *marshalbyrefobject_class;
456         MonoClass *monitor_class;
457         MonoClass *iremotingtypeinfo_class;
458 } MonoDefaults;
459
460 extern MonoDefaults mono_defaults;
461
462 void
463 mono_loader_init           (void);
464
465 void
466 mono_loader_lock           (void);
467
468 void
469 mono_loader_unlock           (void);
470
471 void 
472 mono_init_icall            (void);
473
474 gpointer
475 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
476
477 void
478 mono_install_stack_walk (MonoStackWalkImpl func);
479
480 MonoGenericParam *mono_metadata_load_generic_params (MonoImage *image, guint32 token, guint32 *num);
481
482 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */
483