2009-02-27 Zoltan Varga <vargaz@gmail.com>
[mono.git] / mono / metadata / domain-internals.h
index fe9c90d2257e5d6630ae44de52182237d5ade631..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,6 +122,7 @@ 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 */
 };
@@ -130,8 +134,16 @@ 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;
@@ -145,6 +157,11 @@ typedef struct _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;
@@ -209,7 +226,6 @@ struct _MonoDomain {
        /* Used when accessing 'domain_assemblies' */
        CRITICAL_SECTION    assemblies_lock;
 
-       GHashTable         *shared_generics_hash;
        GHashTable         *method_rgctx_hash;
 
        GHashTable         *generic_virtual_cases;
@@ -234,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);
 
@@ -289,9 +305,6 @@ mono_jit_info_set_generic_sharing_context (MonoJitInfo *ji, MonoGenericSharingCo
 MonoJitInfo*
 mono_domain_lookup_shared_generic (MonoDomain *domain, MonoMethod *method) MONO_INTERNAL;
 
-void
-mono_domain_register_shared_generic (MonoDomain *domain, MonoMethod *method, MonoJitInfo *jit_info) MONO_INTERNAL;
-
 char *
 mono_make_shadow_copy (const char *filename) MONO_INTERNAL;
 
@@ -304,6 +317,18 @@ 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_code_commit (MonoDomain *domain, void *data, int size, int newsize) MONO_INTERNAL;
+
+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
  * an AOT module.