2009-02-27 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / metadata / domain-internals.h
index 072138e9b829f9dd0e23927bcb41e94c225dd11f..482a84f1be5e2b506a257497bee0521f69d25502 100644 (file)
@@ -5,6 +5,7 @@
 #define __MONO_METADATA_DOMAIN_INTERNALS_H__
 
 #include <mono/metadata/appdomain.h>
+#include <mono/metadata/lock-tracer.h>
 #include <mono/utils/mono-codeman.h>
 #include <mono/utils/mono-hash.h>
 #include <mono/utils/mono-compiler.h>
@@ -12,6 +13,7 @@
 #include <mono/io-layer/io-layer.h>
 
 extern CRITICAL_SECTION mono_delegate_section;
+extern CRITICAL_SECTION mono_strtod_mutex;
 
 /*
  * If this is set, the memory belonging to appdomains is not freed when a domain is
@@ -106,9 +108,10 @@ struct _MonoJitInfo {
        MonoMethod *method;
        struct _MonoJitInfo *next_jit_code_hash;
        gpointer    code_start;
+       /* This might contain an id for the unwind info instead of a register mask */
        guint32     used_regs;
        int         code_size;
-       guint32     num_clauses:16;
+       guint32     num_clauses:15;
        /* Whenever the code is domain neutral or 'shared' */
        gboolean    domain_neutral:1;
        gboolean    cas_inited:1;
@@ -119,15 +122,11 @@ struct _MonoJitInfo {
        gboolean    cas_method_deny:1;
        gboolean    cas_method_permitonly:1;
        gboolean    has_generic_jit_info:1;
+       gboolean    from_aot:1;
        MonoJitExceptionInfo clauses [MONO_ZERO_LEN_ARRAY];
        /* There is an optional MonoGenericJitInfo after the clauses */
 };
 
-typedef struct {
-       MonoJitInfo *ji;
-       MonoCodeManager *code_mp;
-} MonoJitDynamicMethodInfo;
-
 struct _MonoAppContext {
        MonoObject obj;
        gint32 domain_id;
@@ -135,15 +134,34 @@ struct _MonoAppContext {
        gpointer *static_data;
 };
 
+/*
+ * We have two unloading states because the domain
+ * must remain fully functional while AppDomain::DomainUnload is
+ * processed.
+ * After that unloading began and all domain facilities are teared down
+ * such as execution of new threadpool jobs.  
+ */
 typedef enum {
        MONO_APPDOMAIN_CREATED,
+       MONO_APPDOMAIN_UNLOADING_START,
        MONO_APPDOMAIN_UNLOADING,
        MONO_APPDOMAIN_UNLOADED
 } MonoAppDomainState;
 
+typedef struct _MonoThunkFreeList {
+       guint32 size;
+       int length;             /* only valid for the wait list */
+       struct _MonoThunkFreeList *next;
+} MonoThunkFreeList;
+
 typedef struct _MonoJitCodeHash MonoJitCodeHash;
 
 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.
+        */
        CRITICAL_SECTION    lock;
        MonoMemPool        *mp;
        MonoCodeManager    *code_mp;
@@ -170,7 +188,9 @@ struct _MonoDomain {
        MonoGHashTable    *type_init_exception_hash;
        /* maps delegate trampoline addr -> delegate object */
        MonoGHashTable     *delegate_hash_table;
-#define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
+       /* typeof (void) */
+       MonoObject         *typeof_void;
+#define MONO_DOMAIN_LAST_GC_TRACKED typeof_void
        guint32            state;
        /* Needed by Thread:GetDomainID() */
        gint32             domain_id;
@@ -185,8 +205,6 @@ struct _MonoDomain {
        /* Protected by 'jit_code_hash_lock' */
        MonoInternalHashTable jit_code_hash;
        CRITICAL_SECTION    jit_code_hash_lock;
-       /* maps MonoMethod -> MonoJitDynamicMethodInfo */
-       GHashTable         *dynamic_code_hash;
        int                 num_jit_info_tables;
        MonoJitInfoTable * 
          volatile          jit_info_table;
@@ -200,11 +218,6 @@ struct _MonoDomain {
        MonoMethod         *private_invoke_method;
        /* Used to store offsets of thread and context static fields */
        GHashTable         *special_static_fields;
-       GHashTable         *jump_target_hash;
-       GHashTable         *class_init_trampoline_hash;
-       GHashTable         *jump_trampoline_hash;
-       GHashTable         *jit_trampoline_hash;
-       GHashTable         *delegate_trampoline_hash;
        /* 
         * This must be a GHashTable, since these objects can't be finalized
         * if the hashtable contains a GC visible reference to them.
@@ -213,12 +226,17 @@ struct _MonoDomain {
        /* Used when accessing 'domain_assemblies' */
        CRITICAL_SECTION    assemblies_lock;
 
-       GHashTable         *shared_generics_hash;
        GHashTable         *method_rgctx_hash;
-       GHashTable     *method_code_hash;
+
+       GHashTable         *generic_virtual_cases;
+       MonoThunkFreeList **thunk_free_lists;
 
        /* Information maintained by the JIT engine */
        gpointer runtime_info;
+
+       /*thread pool jobs, used to coordinate shutdown.*/
+       int                                     threadpool_jobs;
+       HANDLE                          cleanup_semaphore;
 };
 
 typedef struct  {
@@ -232,12 +250,12 @@ typedef struct  {
        const AssemblyVersionSet version_sets [2];
 } MonoRuntimeInfo;
 
-#define mono_domain_lock(domain)   EnterCriticalSection(&(domain)->lock)
-#define mono_domain_unlock(domain) LeaveCriticalSection(&(domain)->lock)
-#define mono_domain_assemblies_lock(domain)   EnterCriticalSection(&(domain)->assemblies_lock)
-#define mono_domain_assemblies_unlock(domain) LeaveCriticalSection(&(domain)->assemblies_lock)
-#define mono_domain_jit_code_hash_lock(domain)   EnterCriticalSection(&(domain)->jit_code_hash_lock)
-#define mono_domain_jit_code_hash_unlock(domain) LeaveCriticalSection(&(domain)->jit_code_hash_lock)
+#define mono_domain_lock(domain) mono_locks_acquire(&(domain)->lock, DomainLock)
+#define mono_domain_unlock(domain) mono_locks_release(&(domain)->lock, DomainLock)
+#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)
 
 typedef MonoDomain* (*MonoLoadFunc) (const char *filename, const char *runtime_version);
 
@@ -287,11 +305,29 @@ mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingCo
 MonoJitInfo*
 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
 
+char *
+mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
+
+gboolean
+mono_is_shadow_copy_enabled (MonoDomain *domain, const gchar *dir_name) MONO_INTERNAL;
+
+gpointer
+mono_domain_alloc  (MonoDomain *domain, guint size) MONO_INTERNAL;
+
+gpointer
+mono_domain_alloc0 (MonoDomain *domain, guint size) MONO_INTERNAL;
+
+void*
+mono_domain_code_reserve (MonoDomain *domain, int size) MONO_INTERNAL;
+
+void*
+mono_domain_code_reserve_align (MonoDomain *domain, int size, int alignment) MONO_INTERNAL;
+
 void
-mono_domain_register_shared_generic (MonoDomain *domain, MonoMethod *method, MonoJitInfo *jit_info) MONO_INTERNAL;
+mono_domain_code_commit (MonoDomain *domain, void *data, int size, int newsize) MONO_INTERNAL;
 
-char *
-mono_make_shadow_copy (const char *filename);
+void
+mono_domain_code_foreach (MonoDomain *domain, MonoCodeManagerFunc func, void *user_data) MONO_INTERNAL;
 
 /* 
  * Installs a new function which is used to return a MonoJitInfo for a method inside
@@ -423,4 +459,8 @@ MonoAssembly* mono_assembly_load_full_nosearch (MonoAssemblyName *aname,
                                                MonoImageOpenStatus *status,
                                                gboolean refonly) MONO_INTERNAL;
 
+void mono_set_private_bin_path_from_config (MonoDomain *domain) MONO_INTERNAL;
+
+int mono_framework_version (void) MONO_INTERNAL;
+
 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */