2005-01-24 Ben Maurer <bmaurer@ximian.com>
[mono-project.git] / mono / metadata / class-internals.h
blobb2933c61990f79166070b8aaffa8aab10a911cd5
1 #ifndef __MONO_METADATA_CLASS_INTERBALS_H__
2 #define __MONO_METADATA_CLASS_INTERBALS_H__
4 #include <mono/metadata/class.h>
5 #include <mono/io-layer/io-layer.h>
7 #define MONO_CLASS_IS_ARRAY(c) ((c)->rank)
9 #define MONO_DEFAULT_SUPERTABLE_SIZE 6
11 extern gboolean mono_print_vtable;
13 typedef void (*MonoStackWalkImpl) (MonoStackWalk func, gboolean do_il_offset, gpointer user_data);
15 typedef struct _MonoMethodNormal MonoMethodNormal;
16 typedef struct _MonoMethodWrapper MonoMethodWrapper;
17 typedef struct _MonoMethodInflated MonoMethodInflated;
18 typedef struct _MonoMethodPInvoke MonoMethodPInvoke;
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_XDOMAIN_INVOKE,
31 MONO_WRAPPER_XDOMAIN_DISPATCH,
32 MONO_WRAPPER_LDFLD,
33 MONO_WRAPPER_STFLD,
34 MONO_WRAPPER_SYNCHRONIZED,
35 MONO_WRAPPER_DYNAMIC_METHOD,
36 MONO_WRAPPER_ISINST,
37 MONO_WRAPPER_CASTCLASS,
38 MONO_WRAPPER_PROXY_ISINST,
39 MONO_WRAPPER_STELEMREF,
40 MONO_WRAPPER_UNBOX,
41 MONO_WRAPPER_UNKNOWN
42 } MonoWrapperType;
44 typedef enum {
45 MONO_REMOTING_TARGET_UNKNOWN,
46 MONO_REMOTING_TARGET_APPDOMAIN
47 } MonoRemotingTarget;
49 struct _MonoMethod {
50 guint16 flags; /* method flags */
51 guint16 iflags; /* method implementation flags */
52 guint32 token;
53 MonoClass *klass;
54 MonoMethodSignature *signature;
55 gpointer info; /* runtime info */
56 /* name is useful mostly for debugging */
57 const char *name;
58 /* this is used by the inlining algorithm */
59 unsigned int inline_info:1;
60 unsigned int uses_this:1;
61 unsigned int wrapper_type:5;
62 unsigned int string_ctor:1;
63 unsigned int save_lmf:1;
64 unsigned int dynamic:1; /* created & destroyed during runtime */
65 unsigned int is_inflated:1;
66 signed int slot : 21;
69 struct _MonoMethodNormal {
70 MonoMethod method;
71 MonoGenericContainer *generic_container;
72 MonoMethodHeader *header;
75 struct _MonoMethodWrapper {
76 MonoMethodNormal method;
77 void *method_data;
80 struct _MonoMethodInflated {
81 MonoMethodNormal nmethod;
82 MonoGenericContext *context;
83 MonoMethod *declaring;
84 MonoMethodInflated *inflated;
87 struct _MonoMethodPInvoke {
88 MonoMethod method;
89 gpointer addr;
90 /* add marshal info */
91 guint16 piflags; /* pinvoke flags */
92 guint16 implmap_idx; /* index into IMPLMAP */
95 typedef struct {
96 MonoType *generic_type;
97 gpointer reflection_info;
98 } MonoInflatedField;
101 * MonoClassField is just a runtime representation of the metadata for
102 * field, it doesn't contain the data directly. Static fields are
103 * stored in MonoVTable->data. Instance fields are allocated in the
104 * objects after the object header.
106 struct _MonoClassField {
107 /* Type of the field */
108 MonoType *type;
110 /* If this is an instantiated generic type, this is the
111 * "original" type, ie. the MONO_TYPE_VAR or MONO_TYPE_GENERICINST
112 * it was instantiated from.
114 MonoInflatedField *generic_info;
117 * Offset where this field is stored; if it is an instance
118 * field, it's the offset from the start of the object, if
119 * it's static, it's from the start of the memory chunk
120 * allocated for statics for the class.
122 int offset;
124 const char *name;
127 * If the field is constant, pointer to the metadata constant
128 * value.
129 * If the field has an RVA flag, pointer to the data.
130 * Else, invalid.
132 const char *data;
134 /* Type where the field was defined */
135 MonoClass *parent;
138 * If the field is constant, the type of the constant.
140 MonoTypeEnum def_type;
143 /* a field is ignored if it's named "_Deleted" and it has the specialname and rtspecialname flags set */
144 #define mono_field_is_deleted(field) ((field)->name[0] == '_' && ((field)->type->attrs & 0x600) && (strcmp ((field)->name, "_Deleted") == 0))
146 typedef struct {
147 MonoClassField *field;
148 guint32 offset;
149 MonoMarshalSpec *mspec;
150 } MonoMarshalField;
152 typedef struct {
153 guint32 native_size;
154 guint32 num_fields;
155 MonoMethod *ptr_to_str;
156 MonoMethod *str_to_ptr;
157 MonoMarshalField fields [MONO_ZERO_LEN_ARRAY];
158 } MonoMarshalType;
160 struct _MonoProperty {
161 MonoClass *parent;
162 const char *name;
163 MonoMethod *get;
164 MonoMethod *set;
165 guint32 attrs;
168 struct _MonoEvent {
169 MonoClass *parent;
170 const char *name;
171 MonoMethod *add;
172 MonoMethod *remove;
173 MonoMethod *raise;
174 MonoMethod **other;
175 guint32 attrs;
178 struct _MonoClass {
179 MonoImage *image;
181 /* The underlying type of the enum */
182 MonoType *enum_basetype;
183 /* element class for arrays and enum */
184 MonoClass *element_class;
185 /* used for subtype checks */
186 MonoClass *cast_class;
187 /* array dimension */
188 guint8 rank;
190 guint inited : 1;
191 /* We use init_pending to detect cyclic calls to mono_class_init */
192 guint init_pending : 1;
194 /* A class contains static and non static data. Static data can be
195 * of the same type as the class itselfs, but it does not influence
196 * the instance size of the class. To avoid cyclic calls to
197 * mono_class_init (from mono_class_instance_size ()) we first
198 * initialise all non static fields. After that we set size_inited
199 * to 1, because we know the instance size now. After that we
200 * initialise all static fields.
202 guint size_inited : 1;
203 guint valuetype : 1; /* derives from System.ValueType */
204 guint enumtype : 1; /* derives from System.Enum */
205 guint blittable : 1; /* class is blittable */
206 guint unicode : 1; /* class uses unicode char when marshalled */
207 guint wastypebuilder : 1; /* class was created at runtime from a TypeBuilder */
208 /* next byte */
209 guint min_align : 4;
210 guint packing_size : 4;
211 /* next byte */
212 guint ghcimpl : 1; /* class has its own GetHashCode impl */
213 guint has_finalize : 1; /* class has its own Finalize impl */
214 guint marshalbyref : 1; /* class is a MarshalByRefObject */
215 guint contextbound : 1; /* class is a ContextBoundObject */
216 guint delegate : 1; /* class is a Delegate */
217 guint gc_descr_inited : 1; /* gc_descr is initialized */
218 guint dummy : 1; /* temporary hack */
219 guint32 declsec_flags; /* declarative security attributes flags */
221 MonoClass *parent;
222 MonoClass *nested_in;
223 GList *nested_classes;
225 guint32 type_token;
226 const char *name;
227 const char *name_space;
229 /* for fast subtype checks */
230 MonoClass **supertypes;
231 guint16 idepth;
233 guint16 interface_count;
234 guint16 interface_id; /* unique inderface id (for interfaces) */
235 guint16 max_interface_id;
236 gint *interface_offsets;
237 MonoClass **interfaces;
240 * Computed object instance size, total.
242 int instance_size;
243 int class_size;
244 int vtable_size; /* number of slots */
247 * From the TypeDef table
249 guint32 flags;
250 struct {
251 guint32 first, last;
252 int count;
253 } field, method, property, event;
255 /* loaded on demand */
256 MonoMarshalType *marshal_info;
259 * Field information: Type and location from object base
261 MonoClassField *fields;
263 MonoProperty *properties;
265 MonoEvent *events;
267 MonoMethod **methods;
269 /* used as the type of the this argument and when passing the arg by value */
270 MonoType this_arg;
271 MonoType byval_arg;
273 MonoGenericClass *generic_class;
274 MonoGenericContainer *generic_container;
276 void *reflection_info;
278 void *gc_descr;
279 guint64 gc_bitmap;
281 MonoVTable *cached_vtable;
282 MonoMethod **vtable;
285 struct MonoVTable {
286 MonoClass *klass;
288 * According to comments in gc_gcj.h, this should be the second word in
289 * the vtable.
291 void *gc_descr;
292 MonoDomain *domain; /* each object/vtable belongs to exactly one domain */
293 gpointer *interface_offsets;
294 gpointer data; /* to store static class data */
295 gpointer type; /* System.Type type for klass */
296 guint16 max_interface_id;
297 guint8 rank;
298 guint remote : 1; /* class is remotely activated */
299 guint initialized : 1; /* cctor has been run */
300 /* do not add any fields after vtable, the structure is dynamically extended */
301 gpointer vtable [MONO_ZERO_LEN_ARRAY];
305 * Generic instantiation data type encoding.
307 struct _MonoGenericInst {
308 guint id;
309 guint type_argc : 22;
310 guint is_open : 1;
311 guint is_reference : 1;
312 MonoType **type_argv;
315 struct _MonoGenericClass {
316 MonoGenericInst *inst;
317 MonoClass *container_class;
318 MonoGenericContext *context;
319 MonoClass *klass;
320 MonoType *parent;
321 guint count_ifaces : 29;
322 guint is_dynamic : 1;
323 MonoType **ifaces;
326 struct _MonoDynamicGenericClass {
327 MonoGenericClass generic_class;
328 int count_methods;
329 MonoMethod **methods;
330 int count_ctors;
331 MonoMethod **ctors;
332 int count_fields;
333 MonoClassField *fields;
334 int count_properties;
335 MonoProperty *properties;
336 int count_events;
337 MonoEvent *events;
338 guint initialized;
341 struct _MonoGenericMethod {
342 MonoGenericInst *inst;
343 MonoGenericContainer *container;
344 gpointer reflection_info;
347 struct _MonoGenericContext {
348 MonoGenericContainer *container;
349 MonoGenericClass *gclass;
350 MonoGenericMethod *gmethod;
353 struct _MonoGenericContainer {
354 MonoGenericContext context;
355 MonoGenericContainer *parent;
356 GHashTable *method_hash;
357 MonoClass *klass;
358 int type_argc : 6;
359 int is_method : 1;
360 int is_signature : 1;
361 MonoGenericParam *type_params;
364 struct _MonoGenericParam {
365 MonoGenericContainer *owner;
366 MonoClass *pklass;
367 MonoMethod *method;
368 const char *name;
369 guint16 flags;
370 guint16 num;
371 MonoClass** constraints; /* NULL means end of list */
374 typedef struct {
375 const char *name;
376 gconstpointer func;
377 gconstpointer wrapper;
378 MonoMethodSignature *sig;
379 } MonoJitICallInfo;
381 #define mono_class_has_parent(klass,parent) (((klass)->idepth >= (parent)->idepth) && ((klass)->supertypes [(parent)->idepth - 1] == (parent)))
383 typedef struct {
384 gulong new_object_count;
385 gulong initialized_class_count;
386 gulong used_class_count;
387 gulong class_vtable_size;
388 gulong class_static_data_size;
389 gulong generic_instance_count;
390 gulong generic_class_count;
391 gulong inflated_method_count;
392 gulong inflated_method_count_2;
393 gulong inflated_type_count;
394 gulong generics_metadata_size;
395 gboolean enabled;
396 } MonoStats;
398 extern MonoStats mono_stats;
400 typedef gpointer (*MonoTrampoline) (MonoMethod *method);
401 typedef gpointer (*MonoRemotingTrampoline) (MonoMethod *method, MonoRemotingTarget target);
403 typedef gpointer (*MonoLookupDynamicToken) (MonoImage *image, guint32 token);
405 void
406 mono_classes_init (void);
408 void
409 mono_class_layout_fields (MonoClass *klass);
411 void
412 mono_class_setup_vtable (MonoClass *klass, MonoMethod **overrides, int onum);
414 void
415 mono_class_setup_mono_type (MonoClass *klass);
417 void
418 mono_class_setup_parent (MonoClass *klass, MonoClass *parent);
420 void
421 mono_class_setup_supertypes (MonoClass *klass);
423 GPtrArray*
424 mono_class_get_implemented_interfaces (MonoClass *klass);
426 gboolean
427 mono_class_is_open_constructed_type (MonoType *t);
429 MonoMethod**
430 mono_class_get_overrides (MonoImage *image, guint32 type_token, gint32 *num_overrides);
432 gboolean
433 mono_class_needs_cctor_run (MonoClass *klass, MonoMethod *caller);
435 void
436 mono_install_trampoline (MonoTrampoline func);
438 void
439 mono_install_remoting_trampoline (MonoRemotingTrampoline func);
441 gpointer
442 mono_lookup_dynamic_token (MonoImage *image, guint32 token);
444 void
445 mono_install_lookup_dynamic_token (MonoLookupDynamicToken func);
447 void
448 mono_class_create_generic (MonoGenericClass *gclass);
450 typedef struct {
451 MonoImage *corlib;
452 MonoClass *object_class;
453 MonoClass *byte_class;
454 MonoClass *void_class;
455 MonoClass *boolean_class;
456 MonoClass *sbyte_class;
457 MonoClass *int16_class;
458 MonoClass *uint16_class;
459 MonoClass *int32_class;
460 MonoClass *uint32_class;
461 MonoClass *int_class;
462 MonoClass *uint_class;
463 MonoClass *int64_class;
464 MonoClass *uint64_class;
465 MonoClass *single_class;
466 MonoClass *double_class;
467 MonoClass *char_class;
468 MonoClass *string_class;
469 MonoClass *enum_class;
470 MonoClass *array_class;
471 MonoClass *delegate_class;
472 MonoClass *multicastdelegate_class;
473 MonoClass *asyncresult_class;
474 MonoClass *waithandle_class;
475 MonoClass *typehandle_class;
476 MonoClass *fieldhandle_class;
477 MonoClass *methodhandle_class;
478 MonoClass *monotype_class;
479 MonoClass *exception_class;
480 MonoClass *threadabortexception_class;
481 MonoClass *thread_class;
482 MonoClass *transparent_proxy_class;
483 MonoClass *real_proxy_class;
484 MonoClass *mono_method_message_class;
485 MonoClass *appdomain_class;
486 MonoClass *field_info_class;
487 MonoClass *method_info_class;
488 MonoClass *stringbuilder_class;
489 MonoClass *math_class;
490 MonoClass *stack_frame_class;
491 MonoClass *stack_trace_class;
492 MonoClass *marshal_class;
493 MonoClass *iserializeable_class;
494 MonoClass *serializationinfo_class;
495 MonoClass *streamingcontext_class;
496 MonoClass *typed_reference_class;
497 MonoClass *argumenthandle_class;
498 MonoClass *marshalbyrefobject_class;
499 MonoClass *monitor_class;
500 MonoClass *iremotingtypeinfo_class;
501 MonoClass *runtimesecurityframe_class;
502 } MonoDefaults;
504 extern MonoDefaults mono_defaults;
506 void
507 mono_loader_init (void);
509 void
510 mono_loader_lock (void);
512 void
513 mono_loader_unlock (void);
515 void
516 mono_icall_init (void);
518 void
519 mono_icall_cleanup (void);
521 gpointer
522 mono_method_get_wrapper_data (MonoMethod *method, guint32 id);
524 void
525 mono_install_stack_walk (MonoStackWalkImpl func);
527 MonoGenericContainer *mono_metadata_load_generic_params (MonoImage *image, guint32 token,
528 MonoGenericContainer *parent_container);
530 MonoMethodSignature*
531 mono_create_icall_signature (const char *sigstr);
533 MonoJitICallInfo *
534 mono_register_jit_icall (gconstpointer func, const char *name, MonoMethodSignature *sig, gboolean is_save);
536 void
537 mono_register_jit_icall_wrapper (MonoJitICallInfo *info, gconstpointer wrapper);
539 MonoJitICallInfo *
540 mono_find_jit_icall_by_name (const char *name);
542 MonoJitICallInfo *
543 mono_find_jit_icall_by_addr (gconstpointer addr);
545 MonoMethodSignature*
546 mono_class_inflate_generic_signature (MonoImage *image, MonoMethodSignature *sig, MonoGenericContext *context);
548 MonoGenericClass *
549 mono_get_shared_generic_class (MonoGenericContainer *container, gboolean is_dynamic);
551 #endif /* __MONO_METADATA_CLASS_INTERBALS_H__ */