Merge pull request #2034 from alexrp/ctx-cleanup
[mono.git] / mono / metadata / domain-internals.h
index a5fc96dec612bcc55e66d709aff4f89e8cef9f67..4cb4af6c02d1aca82dfca8f81fd08e5c0a867688 100644 (file)
@@ -9,17 +9,12 @@
 #include <mono/metadata/mempool.h>
 #include <mono/metadata/lock-tracer.h>
 #include <mono/utils/mono-codeman.h>
-#include <mono/utils/mono-mutex.h>
 #include <mono/metadata/mono-hash.h>
 #include <mono/utils/mono-compiler.h>
 #include <mono/utils/mono-internal-hash.h>
 #include <mono/io-layer/io-layer.h>
 #include <mono/metadata/mempool-internals.h>
 
-
-extern mono_mutex_t mono_delegate_section;
-extern mono_mutex_t mono_strtod_mutex;
-
 /*
  * If this is set, the memory belonging to appdomains is not freed when a domain is
  * unloaded, and assemblies loaded by the appdomain are not unloaded either. This
@@ -90,6 +85,10 @@ typedef struct {
         * associated with this handler.
         */
        int clause_index;
+       uint32_t try_offset;
+       uint32_t try_len;
+       uint32_t handler_offset;
+       uint32_t handler_len;
        union {
                MonoClass *catch_class;
                gpointer filter;
@@ -101,13 +100,7 @@ typedef struct {
  * Contains information about the type arguments for generic shared methods.
  */
 typedef struct {
-       /*
-        * 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;
+       gboolean is_gsharedvt;
 } MonoGenericSharingContext;
 
 /* Simplified DWARF location list entry */
@@ -184,21 +177,17 @@ typedef struct
 } 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;
+       /* Relative to code_start */
+       int thunks_offset;
+       int thunks_size;
+} MonoThunkJitInfo;
 
 typedef enum {
        JIT_INFO_NONE = 0,
-       JIT_INFO_HAS_CAS_INFO = (1 << 0),
-       JIT_INFO_HAS_GENERIC_JIT_INFO = (1 << 1),
-       JIT_INFO_HAS_TRY_BLOCK_HOLES = (1 << 2),
-       JIT_INFO_HAS_ARCH_EH_INFO = (1 << 3)
+       JIT_INFO_HAS_GENERIC_JIT_INFO = (1 << 0),
+       JIT_INFO_HAS_TRY_BLOCK_HOLES = (1 << 1),
+       JIT_INFO_HAS_ARCH_EH_INFO = (1 << 2),
+       JIT_INFO_HAS_THUNK_INFO = (1 << 3)
 } MonoJitInfoFlags;
 
 struct _MonoJitInfo {
@@ -219,10 +208,10 @@ struct _MonoJitInfo {
        guint32     num_clauses:15;
        /* Whenever the code is domain neutral or 'shared' */
        gboolean    domain_neutral: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    has_thunk_info:1;
        gboolean    from_aot:1;
        gboolean    from_llvm:1;
        gboolean    dbg_attrs_inited:1;
@@ -244,15 +233,22 @@ struct _MonoJitInfo {
        /* There is an optional MonoGenericJitInfo after the clauses */
        /* There is an optional MonoTryBlockHoleTableJitInfo after MonoGenericJitInfo clauses*/
        /* There is an optional MonoArchEHJitInfo after MonoTryBlockHoleTableJitInfo */
+       /* There is an optional MonoThunkJitInfo after MonoArchEHJitInfo */
 };
 
 #define MONO_SIZEOF_JIT_INFO (offsetof (struct _MonoJitInfo, clauses))
 
+typedef struct {
+       gpointer *static_data; /* Used to free the static data without going through the MonoAppContext object itself. */
+       uint32_t gc_handle;
+} ContextStaticData;
+
 struct _MonoAppContext {
        MonoObject obj;
        gint32 domain_id;
        gint32 context_id;
        gpointer *static_data;
+       ContextStaticData *data;
 };
 
 /* Lock-free allocator */
@@ -288,20 +284,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,
         * i.e. if both are taken by the same thread, the loader lock
         * must taken first.
         */
-       mono_mutex_t    lock;
+       MonoCoopMutex    lock;
        MonoMemPool        *mp;
        MonoCodeManager    *code_mp;
        /*
@@ -372,7 +361,6 @@ struct _MonoDomain {
        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.
@@ -417,17 +405,13 @@ struct _MonoDomain {
        MonoClass *sockaddr_class;
        MonoClassField *sockaddr_data_field;
 
-       /* Used by threadpool.c */
-       MonoImage *system_image;
-       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;
 
+       /* Maps MonoMethod* to weak links to DynamicMethod objects */
+       GHashTable *method_to_dyn_method;
+
        guint32 execution_context_field_offset;
 };
 
@@ -442,10 +426,10 @@ typedef struct  {
        const AssemblyVersionSet version_sets [4];
 } MonoRuntimeInfo;
 
-#define mono_domain_assemblies_lock(domain) mono_locks_acquire(&(domain)->assemblies_lock, DomainAssembliesLock)
-#define mono_domain_assemblies_unlock(domain) mono_locks_release(&(domain)->assemblies_lock, DomainAssembliesLock)
-#define mono_domain_jit_code_hash_lock(domain) mono_locks_acquire(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
-#define mono_domain_jit_code_hash_unlock(domain) mono_locks_release(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
+#define mono_domain_assemblies_lock(domain) mono_locks_os_acquire(&(domain)->assemblies_lock, DomainAssembliesLock)
+#define mono_domain_assemblies_unlock(domain) mono_locks_os_release(&(domain)->assemblies_lock, DomainAssembliesLock)
+#define mono_domain_jit_code_hash_lock(domain) mono_locks_os_acquire(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
+#define mono_domain_jit_code_hash_unlock(domain) mono_locks_os_release(&(domain)->jit_code_hash_lock, DomainJitCodeHashLock)
 
 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
 
@@ -550,8 +534,8 @@ mono_jit_info_get_try_block_hole_table_info (MonoJitInfo *ji);
 MonoArchEHJitInfo*
 mono_jit_info_get_arch_eh_info (MonoJitInfo *ji);
 
-MonoMethodCasInfo*
-mono_jit_info_get_cas_info (MonoJitInfo *ji);
+MonoThunkJitInfo*
+mono_jit_info_get_thunk_info (MonoJitInfo *ji);
 
 /* 
  * Installs a new function which is used to return a MonoJitInfo for a method inside
@@ -615,6 +599,9 @@ ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id);
 void
 ves_icall_System_AppDomain_InternalUnload          (gint32 domain_id);
 
+void
+ves_icall_System_AppDomain_DoUnhandledException (MonoException *exc);
+
 gint32
 ves_icall_System_AppDomain_ExecuteAssembly         (MonoAppDomain *ad, 
                                                                                                        MonoReflectionAssembly *refass,