2007-09-11 Mark Probst <mark.probst@gmail.com>
[mono.git] / mono / metadata / domain-internals.h
index fbbbda745242d7bcf16e4386a342e7650d5bd920..bdbb7517c63f35ff30346b7b5b5f4b79cd23decb 100644 (file)
@@ -7,6 +7,8 @@
 #include <mono/metadata/appdomain.h>
 #include <mono/utils/mono-codeman.h>
 #include <mono/utils/mono-hash.h>
+#include <mono/utils/mono-compiler.h>
+#include <mono/utils/mono-internal-hash.h>
 #include <mono/io-layer/io-layer.h>
 
 extern CRITICAL_SECTION mono_delegate_section;
@@ -29,9 +31,34 @@ typedef struct {
        int loader_optimization;
        MonoBoolean disallow_binding_redirects;
        MonoBoolean disallow_code_downloads;
+       MonoObject *activation_arguments; /* it is System.Object in 1.x, ActivationArguments in 2.0 */
+       MonoObject *domain_initializer;
+       MonoArray *domain_initializer_args;
+       MonoObject *application_trust; /* it is System.Object in 1.x, ApplicationTrust in 2.0 */
+       MonoBoolean disallow_appbase_probe;
+       MonoArray *configuration_bytes;
 } MonoAppDomainSetup;
 
-typedef GArray MonoJitInfoTable;
+typedef struct _MonoJitInfoTable MonoJitInfoTable;
+typedef struct _MonoJitInfoTableChunk MonoJitInfoTableChunk;
+
+#define MONO_JIT_INFO_TABLE_CHUNK_SIZE         64
+
+struct _MonoJitInfoTableChunk
+{
+       int                    refcount;
+       volatile int           num_elements;
+       volatile gint8        *last_code_end;
+       MonoJitInfo * volatile data [MONO_JIT_INFO_TABLE_CHUNK_SIZE];
+};
+
+struct _MonoJitInfoTable
+{
+       int                     num_chunks;
+       MonoJitInfoTableChunk  *chunks [MONO_ZERO_LEN_ARRAY];
+};
+
+typedef GArray MonoAotModuleInfoTable;
 
 typedef struct {
        guint32  flags;
@@ -46,7 +73,12 @@ typedef struct {
 } MonoJitExceptionInfo;
 
 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;
+       struct _MonoJitInfo *next_jit_code_hash;
        gpointer    code_start;
        guint32     used_regs;
        int         code_size;
@@ -81,53 +113,74 @@ typedef enum {
        MONO_APPDOMAIN_UNLOADED
 } MonoAppDomainState;
 
+typedef struct _MonoJitCodeHash MonoJitCodeHash;
+
 struct _MonoDomain {
-       MonoAppDomain      *domain;
        CRITICAL_SECTION    lock;
        MonoMemPool        *mp;
        MonoCodeManager    *code_mp;
-       MonoGHashTable     *env;
-       GSList             *domain_assemblies;
-       MonoAssembly       *entry_assembly;
+       /*
+        * keep all the managed objects close to each other for the precise GC
+        * For the Boehm GC we additionally keep close also other GC-tracked pointers.
+        */
+#define MONO_DOMAIN_FIRST_OBJECT setup
        MonoAppDomainSetup *setup;
-       char               *friendly_name;
-       guint32            state;
+       MonoAppDomain      *domain;
+       MonoAppContext     *default_context;
+       MonoException      *out_of_memory_ex;
+       MonoException      *null_reference_ex;
+       MonoException      *stack_overflow_ex;
+#define MONO_DOMAIN_FIRST_GC_TRACKED env
+       MonoGHashTable     *env;
        MonoGHashTable     *ldstr_table;
-       GHashTable         *class_vtable_hash;
-       /* maps MonoString -> MonoRemoteClass */
-       MonoGHashTable     *proxy_vtable_hash;
-       MonoGHashTable     *static_data_hash;
-       GHashTable         *jit_code_hash;
-       /* maps MonoMethod -> MonoJitDynamicMethodInfo */
-       GHashTable         *dynamic_code_hash;
-       /* maps delegate trampoline addr -> delegate object */
-       MonoGHashTable     *delegate_hash_table;
-       MonoJitInfoTable   *jit_info_table;
        /* hashtables for Reflection handles */
        MonoGHashTable     *type_hash;
        MonoGHashTable     *refobject_hash;
+       /* a GC-tracked array to keep references to the static fields of types */
+       gpointer           *static_data_array;
+       /* maps class -> type initialization exception object */
+       MonoGHashTable    *type_init_exception_hash;
+       /* maps delegate trampoline addr -> delegate object */
+       MonoGHashTable     *delegate_hash_table;
+#define MONO_DOMAIN_LAST_GC_TRACKED delegate_hash_table
+       guint32            state;
        /* Needed by Thread:GetDomainID() */
        gint32             domain_id;
+       gint32             shadow_serial;
+       GSList             *domain_assemblies;
+       MonoAssembly       *entry_assembly;
+       char               *friendly_name;
+       GHashTable         *class_vtable_hash;
+       /* maps remote class key -> MonoRemoteClass */
+       GHashTable         *proxy_vtable_hash;
+       MonoInternalHashTable jit_code_hash;
+       /* maps MonoMethod -> MonoJitDynamicMethodInfo */
+       GHashTable         *dynamic_code_hash;
+       MonoJitInfoTable * 
+         volatile          jit_info_table;
        /* Used when loading assemblies */
        gchar **search_path;
+       gchar *private_bin_path;
+       
        /* Used by remoting proxies */
        MonoMethod         *create_proxy_for_type_method;
        MonoMethod         *private_invoke_method;
-       MonoAppContext     *default_context;
-       MonoException      *out_of_memory_ex;
-       MonoException      *null_reference_ex;
-       MonoException      *stack_overflow_ex;
        /* 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;
+       GHashTable         *delegate_invoke_impl_with_target_hash;
+       GHashTable         *delegate_invoke_impl_no_target_hash;
        /* 
         * 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;
+       /* Used when accessing 'domain_assemblies' */
+       CRITICAL_SECTION    assemblies_lock;
 };
 
 typedef struct  {
@@ -143,111 +196,139 @@ typedef struct  {
 
 #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)
+
+void 
+mono_init_com_types (void) MONO_INTERNAL;
+
+void 
+mono_cleanup (void) MONO_INTERNAL;
+
+void
+mono_jit_info_table_add    (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
+
+void
+mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji) MONO_INTERNAL;
 
 void
-mono_jit_info_table_add    (MonoDomain *domain, MonoJitInfo *ji);
+mono_jit_info_add_aot_module (MonoImage *image, gpointer start, gpointer end) MONO_INTERNAL;
+
+/* 
+ * Installs a new function which is used to return a MonoJitInfo for a method inside
+ * an AOT module.
+ */
+typedef MonoJitInfo *(*MonoJitInfoFindInAot)         (MonoDomain *domain, MonoImage *image, gpointer addr);
+void          mono_install_jit_info_find_in_aot (MonoJitInfoFindInAot func) MONO_INTERNAL;
 
 void
-mono_jit_info_table_remove (MonoDomain *domain, MonoJitInfo *ji);
+mono_jit_code_hash_init (MonoInternalHashTable *jit_code_hash) MONO_INTERNAL;
 
 MonoAppDomain *
-ves_icall_System_AppDomain_getCurDomain            (void);
+ves_icall_System_AppDomain_getCurDomain            (void) MONO_INTERNAL;
 
 MonoAppDomain *
-ves_icall_System_AppDomain_getRootDomain           (void);
+ves_icall_System_AppDomain_getRootDomain           (void) MONO_INTERNAL;
 
 MonoAppDomain *
 ves_icall_System_AppDomain_createDomain            (MonoString         *friendly_name,
-                                                   MonoAppDomainSetup *setup);
+                                                   MonoAppDomainSetup *setup) MONO_INTERNAL;
 
 MonoObject *
 ves_icall_System_AppDomain_GetData                 (MonoAppDomain *ad, 
-                                                   MonoString    *name);
+                                                   MonoString    *name) MONO_INTERNAL;
 
 MonoReflectionAssembly *
 ves_icall_System_AppDomain_LoadAssemblyRaw         (MonoAppDomain *ad,
                                                    MonoArray *raw_assembly, 
                                                    MonoArray *raw_symbol_store,
                                                    MonoObject *evidence,
-                                                   MonoBoolean refonly);
+                                                   MonoBoolean refonly) MONO_INTERNAL;
 
 void
 ves_icall_System_AppDomain_SetData                 (MonoAppDomain *ad, 
                                                    MonoString    *name, 
-                                                   MonoObject    *data);
+                                                   MonoObject    *data) MONO_INTERNAL;
 
 MonoAppDomainSetup *
-ves_icall_System_AppDomain_getSetup                (MonoAppDomain *ad);
+ves_icall_System_AppDomain_getSetup                (MonoAppDomain *ad) MONO_INTERNAL;
 
 MonoString *
-ves_icall_System_AppDomain_getFriendlyName         (MonoAppDomain *ad);
+ves_icall_System_AppDomain_getFriendlyName         (MonoAppDomain *ad) MONO_INTERNAL;
 
 MonoArray *
 ves_icall_System_AppDomain_GetAssemblies           (MonoAppDomain *ad,
-                                                   MonoBoolean refonly);
+                                                   MonoBoolean refonly) MONO_INTERNAL;
 
 MonoReflectionAssembly *
 ves_icall_System_Reflection_Assembly_LoadFrom      (MonoString *fname,
-                                                   MonoBoolean refonly);
+                                                   MonoBoolean refonly) MONO_INTERNAL;
 
 MonoReflectionAssembly *
 ves_icall_System_AppDomain_LoadAssembly            (MonoAppDomain *ad, 
                                                    MonoString *assRef,
                                                    MonoObject    *evidence,
-                                                   MonoBoolean refonly);
+                                                   MonoBoolean refonly) MONO_INTERNAL;
 
 gboolean
-ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id);
+ves_icall_System_AppDomain_InternalIsFinalizingForUnload (gint32 domain_id) MONO_INTERNAL;
 
 void
-ves_icall_System_AppDomain_InternalUnload          (gint32 domain_id);
+ves_icall_System_AppDomain_InternalUnload          (gint32 domain_id) MONO_INTERNAL;
 
 gint32
 ves_icall_System_AppDomain_ExecuteAssembly         (MonoAppDomain *ad, 
                                                    MonoString    *file, 
                                                    MonoObject    *evidence,
-                                                   MonoArray     *args);
+                                                   MonoArray     *args) MONO_INTERNAL;
 
 MonoAppDomain * 
-ves_icall_System_AppDomain_InternalSetDomain      (MonoAppDomain *ad);
+ves_icall_System_AppDomain_InternalSetDomain      (MonoAppDomain *ad) MONO_INTERNAL;
 
 MonoAppDomain * 
-ves_icall_System_AppDomain_InternalSetDomainByID   (gint32 domainid);
+ves_icall_System_AppDomain_InternalSetDomainByID   (gint32 domainid) MONO_INTERNAL;
 
 void
-ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad);
+ves_icall_System_AppDomain_InternalPushDomainRef (MonoAppDomain *ad) MONO_INTERNAL;
 
 void
-ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id);
+ves_icall_System_AppDomain_InternalPushDomainRefByID (gint32 domain_id) MONO_INTERNAL;
 
 void
-ves_icall_System_AppDomain_InternalPopDomainRef (void);
+ves_icall_System_AppDomain_InternalPopDomainRef (void) MONO_INTERNAL;
 
 MonoAppContext * 
-ves_icall_System_AppDomain_InternalGetContext      (void);
+ves_icall_System_AppDomain_InternalGetContext      (void) MONO_INTERNAL;
 
 MonoAppContext * 
-ves_icall_System_AppDomain_InternalGetDefaultContext      (void);
+ves_icall_System_AppDomain_InternalGetDefaultContext      (void) MONO_INTERNAL;
 
 MonoAppContext * 
-ves_icall_System_AppDomain_InternalSetContext     (MonoAppContext *mc);
+ves_icall_System_AppDomain_InternalSetContext     (MonoAppContext *mc) MONO_INTERNAL;
 
 gint32 
-ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad);
+ves_icall_System_AppDomain_GetIDFromDomain (MonoAppDomain * ad) MONO_INTERNAL;
 
 MonoString *
-ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid);
+ves_icall_System_AppDomain_InternalGetProcessGuid (MonoString* newguid) MONO_INTERNAL;
 
 MonoAssembly *
-mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status);
+mono_assembly_load_corlib (const MonoRuntimeInfo *runtime, MonoImageOpenStatus *status) MONO_INTERNAL;
 
 const MonoRuntimeInfo*
-mono_get_runtime_info (void);
+mono_get_runtime_info (void) MONO_INTERNAL;
 
 gboolean
-mono_assembly_name_parse (const char *name, MonoAssemblyName *aname);
+mono_assembly_name_parse (const char *name, MonoAssemblyName *aname) MONO_INTERNAL;
+
+void
+mono_assembly_name_free (MonoAssemblyName *aname) MONO_INTERNAL;
+
+MonoImage *mono_assembly_open_from_bundle (const char *filename,
+                                          MonoImageOpenStatus *status,
+                                          gboolean refonly) MONO_INTERNAL;
 
 void
-mono_assembly_name_free (MonoAssemblyName *aname);
+mono_domain_add_class_static_data (MonoDomain *domain, MonoClass *klass, gpointer data, guint32 *bitmap);
 
 #endif /* __MONO_METADATA_DOMAIN_INTERNALS_H__ */