Revert "Revert "Merge branch 'master' of https://github.com/mono/mono""
[mono.git] / mono / metadata / domain-internals.h
index 815f605c4457d321b4fcda6e46a51c352c300029..09c6479c03d3805e5e1f6f12a43ba7f530168154 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Appdomain-related internal data structures and functions.
+ * Copyright 2012 Xamarin Inc (http://www.xamarin.com)
  */
 #ifndef __MONO_METADATA_DOMAIN_INTERNALS_H__
 #define __MONO_METADATA_DOMAIN_INTERNALS_H__
@@ -90,16 +91,43 @@ typedef struct {
 } MonoJitExceptionInfo;
 
 /*
- * Will contain information on the generic type arguments in the
- * future.  For now, all arguments are always reference types.
+ * Contains information about the type arguments for generic shared methods.
  */
 typedef struct {
-       int dummy;
+       /*
+        * If not NULL, determines whenever the class type arguments of the gshared method are references or vtypes.
+        * The array length is equal to class_inst->type_argv.
+        */
+       gboolean *var_is_vt;
+       /* Same for method type parameters */
+       gboolean *mvar_is_vt;
 } MonoGenericSharingContext;
 
+/* Simplified DWARF location list entry */
+typedef struct {
+       /* Whenever the value is in a register */
+       gboolean is_reg;
+       /*
+        * If is_reg is TRUE, the register which contains the value. Otherwise
+        * the base register.
+        */
+       int reg;
+       /*
+        * If is_reg is FALSE, the offset of the stack location relative to 'reg'.
+        * Otherwise, 0.
+        */
+       int offset;
+       /*
+        * Offsets of the PC interval where the value is in this location.
+        */
+       int from, to;
+} MonoDwarfLocListEntry;
+
 typedef struct
 {
        MonoGenericSharingContext *generic_sharing_context;
+       int nlocs;
+       MonoDwarfLocListEntry *locations;
        gint32 this_offset;
        guint8 this_reg;
        gboolean has_this:1;
@@ -142,12 +170,31 @@ typedef struct
        MonoTryBlockHoleJitInfo holes [MONO_ZERO_LEN_ARRAY];
 } MonoTryBlockHoleTableJitInfo;
 
+typedef struct
+{
+       guint32 stack_size;
+} MonoArchEHJitInfo;
+
+typedef struct {
+       gboolean    cas_inited:1;
+       gboolean    cas_class_assert:1;
+       gboolean    cas_class_deny:1;
+       gboolean    cas_class_permitonly:1;
+       gboolean    cas_method_assert:1;
+       gboolean    cas_method_deny:1;
+       gboolean    cas_method_permitonly:1;
+} MonoMethodCasInfo;
+
 struct _MonoJitInfo {
        /* NOTE: These first two elements (method and
           next_jit_code_hash) must be in the same order and at the
           same offset as in RuntimeMethod, because of the jit_code_hash
           internal hash table in MonoDomain. */
-       MonoMethod *method;
+       union {
+               MonoMethod *method;
+               MonoImage *image;
+               gpointer aot_info;
+       } d;
        struct _MonoJitInfo *next_jit_code_hash;
        gpointer    code_start;
        /* This might contain an id for the unwind info instead of a register mask */
@@ -156,17 +203,20 @@ struct _MonoJitInfo {
        guint32     num_clauses:15;
        /* Whenever the code is domain neutral or 'shared' */
        gboolean    domain_neutral:1;
-       gboolean    cas_inited:1;
-       gboolean    cas_class_assert:1;
-       gboolean    cas_class_deny:1;
-       gboolean    cas_class_permitonly:1;
-       gboolean    cas_method_assert:1;
-       gboolean    cas_method_deny:1;
-       gboolean    cas_method_permitonly:1;
+       gboolean    has_cas_info:1;
        gboolean    has_generic_jit_info:1;
        gboolean    has_try_block_holes:1;
+       gboolean    has_arch_eh_info:1;
        gboolean    from_aot:1;
        gboolean    from_llvm:1;
+       gboolean    dbg_hidden_inited:1;
+       gboolean    dbg_hidden:1;
+       /* Whenever this jit info was loaded in async context */
+       gboolean    async:1;
+       gboolean    dbg_step_through_inited:1;
+       gboolean    dbg_step_through:1;
+       gboolean    dbg_non_user_code_inited:1;
+       gboolean    dbg_non_user_code:1;
 
        /* FIXME: Embed this after the structure later*/
        gpointer    gc_info; /* Currently only used by SGen */
@@ -174,6 +224,7 @@ struct _MonoJitInfo {
        MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
        /* There is an optional MonoGenericJitInfo after the clauses */
        /* There is an optional MonoTryBlockHoleTableJitInfo after MonoGenericJitInfo clauses*/
+       /* There is an optional MonoArchEHJitInfo after MonoTryBlockHoleTableJitInfo */
 };
 
 #define MONO_SIZEOF_JIT_INFO (offsetof (struct _MonoJitInfo, clauses))
@@ -185,6 +236,17 @@ struct _MonoAppContext {
        gpointer *static_data;
 };
 
+/* Lock-free allocator */
+typedef struct {
+       guint8 *mem;
+       gpointer prev;
+       int size, pos;
+} LockFreeMempoolChunk;
+
+typedef struct {
+       LockFreeMempoolChunk *current, *chunks;
+} LockFreeMempool;
+
 /*
  * We have two unloading states because the domain
  * must remain fully functional while AppDomain::DomainUnload is
@@ -207,6 +269,13 @@ typedef struct _MonoThunkFreeList {
 
 typedef struct _MonoJitCodeHash MonoJitCodeHash;
 
+typedef struct _MonoTlsDataRecord MonoTlsDataRecord;
+struct _MonoTlsDataRecord {
+       MonoTlsDataRecord *next;
+       guint32 tls_offset;
+       guint32 size;
+};
+
 struct _MonoDomain {
        /*
         * This lock must never be taken before the loader lock,
@@ -267,28 +336,30 @@ struct _MonoDomain {
        int                 num_jit_info_tables;
        MonoJitInfoTable * 
          volatile          jit_info_table;
+       /*
+        * Contains information about AOT loaded code.
+        * Only used in the root domain.
+        */
+       MonoJitInfoTable *
+         volatile          aot_modules;
        GSList             *jit_info_free_queue;
        /* Used when loading assemblies */
        gchar **search_path;
        gchar *private_bin_path;
+       LockFreeMempool *lock_free_mp;
        
        /* Used by remoting proxies */
        MonoMethod         *create_proxy_for_type_method;
        MonoMethod         *private_invoke_method;
        /* Used to store offsets of thread and context static fields */
        GHashTable         *special_static_fields;
+       MonoTlsDataRecord  *tlsrec_list;
        /* 
         * This must be a GHashTable, since these objects can't be finalized
         * if the hashtable contains a GC visible reference to them.
         */
        GHashTable         *finalizable_objects_hash;
 
-       /* These two are boehm only */
-       /* Maps MonoObjects to a GSList of WeakTrackResurrection GCHandles pointing to them */
-       GHashTable         *track_resurrection_objects_hash;
-       /* Maps WeakTrackResurrection GCHandles to the MonoObjects they point to */
-       GHashTable         *track_resurrection_handles_hash;
-
        /* Protects the three hashes above */
        CRITICAL_SECTION   finalizable_objects_hash_lock;
        /* Used when accessing 'domain_assemblies' */
@@ -299,6 +370,8 @@ struct _MonoDomain {
        GHashTable         *generic_virtual_cases;
        MonoThunkFreeList **thunk_free_lists;
 
+       GHashTable     *generic_virtual_thunks;
+
        /* Information maintained by the JIT engine */
        gpointer runtime_info;
 
@@ -327,11 +400,16 @@ struct _MonoDomain {
 
        /* Used by threadpool.c */
        MonoImage *system_image;
-       MonoImage *system_net_dll;
        MonoClass *corlib_asyncresult_class;
        MonoClass *socket_class;
        MonoClass *ad_unloaded_ex_class;
        MonoClass *process_class;
+
+       /* Cache function pointers for architectures  */
+       /* that require wrappers */
+       GHashTable *ftnptrs_hash;
+
+       guint32 execution_context_field_offset;
 };
 
 typedef struct  {
@@ -342,7 +420,7 @@ typedef struct  {
 typedef struct  {
        const char runtime_version [12];
        const char framework_version [4];
-       const AssemblyVersionSet version_sets [3];
+       const AssemblyVersionSet version_sets [4];
 } MonoRuntimeInfo;
 
 #define mono_domain_lock(domain) mono_locks_acquire(&(domain)->lock, DomainLock)
@@ -370,9 +448,6 @@ typedef void (*MonoFreeDomainFunc) (MonoDomain *domain);
 void
 mono_install_free_domain_hook (MonoFreeDomainFunc func) MONO_INTERNAL;
 
-void 
-mono_init_com_types (void) MONO_INTERNAL;
-
 void 
 mono_cleanup (void) MONO_INTERNAL;
 
@@ -397,9 +472,6 @@ mono_jit_info_get_generic_sharing_context (MonoJitInfo *ji) MONO_INTERNAL;
 void
 mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingContext *gsctx) MONO_INTERNAL;
 
-MonoJitInfo*
-mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
-
 char *
 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
 
@@ -412,6 +484,9 @@ mono_domain_alloc  (MonoDomain *domain, guint size) MONO_INTERNAL;
 gpointer
 mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
 
+gpointer
+mono_domain_alloc0_lock_free (MonoDomain *domain, guint size) MONO_INTERNAL;
+
 void*
 mono_domain_code_reserve (MonoDomain *domain, int size) MONO_LLVM_INTERNAL;
 
@@ -439,6 +514,12 @@ mono_domain_set_internal_with_options (MonoDomain *domain, gboolean migrate_exce
 MonoTryBlockHoleTableJitInfo*
 mono_jit_info_get_try_block_hole_table_info (MonoJitInfo *ji) MONO_INTERNAL;
 
+MonoArchEHJitInfo*
+mono_jit_info_get_arch_eh_info (MonoJitInfo *ji) MONO_INTERNAL;
+
+MonoMethodCasInfo*
+mono_jit_info_get_cas_info (MonoJitInfo *ji) MONO_INTERNAL;
+
 /* 
  * Installs a new function which is used to return a MonoJitInfo for a method inside
  * an AOT module.
@@ -555,7 +636,7 @@ MonoImage *mono_assembly_open_from_bundle (const char *filename,
                                           MonoImageOpenStatus *status,
                                           gboolean refonly) MONO_INTERNAL;
 
-void
+MONO_API void
 mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
 
 MonoReflectionAssembly *
@@ -572,6 +653,10 @@ int mono_framework_version (void) MONO_INTERNAL;
 
 void mono_reflection_cleanup_domain (MonoDomain *domain) MONO_INTERNAL;
 
-void mono_assembly_cleanup_domain_bindings (guint32 domain_id) MONO_INTERNAL;;
+void mono_assembly_cleanup_domain_bindings (guint32 domain_id) MONO_INTERNAL;
+
+MonoJitInfo* mono_jit_info_table_find_internal (MonoDomain *domain, char *addr, gboolean try_aot) MONO_INTERNAL;
+
+void mono_enable_debug_domain_unload (gboolean enable);
 
 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */