2004-05-28 Gonzalo Paniagua Javier <gonzalo@ximian.com>
[mono.git] / mono / metadata / domain.c
index 3a54247e572682d11e845003586c8b85b60591da..8eea630cf79897635adf5c2fb3c3cb730b1ac018 100644 (file)
@@ -22,6 +22,8 @@
 #include <mono/metadata/cil-coff.h>
 #include <mono/metadata/rawbuffer.h>
 
+//#define DEBUG_DOMAIN_UNLOAD
+
 static guint32 appdomain_thread_id = -1;
 static guint32 context_thread_id = -1;
 
@@ -135,6 +137,8 @@ ldstr_hash (const char* str)
 static gboolean
 ldstr_equal (const char *str1, const char *str2) {
        int len, len2;
+       if (str1 == str2)
+               return TRUE;
        len = mono_metadata_decode_blob_size (str1, NULL) - 1;
        len2 = mono_metadata_decode_blob_size (str2, NULL) - 1;
        if (len != len2)
@@ -193,15 +197,17 @@ mono_domain_create (void)
        domain->search_path = NULL;
 
        domain->mp = mono_mempool_new ();
-       domain->code_mp = mono_mempool_new ();
+       domain->code_mp = mono_code_manager_new ();
        domain->env = mono_g_hash_table_new ((GHashFunc)mono_string_hash, (GCompareFunc)mono_string_equal);
        domain->assemblies = g_hash_table_new (g_str_hash, g_str_equal);
        domain->class_vtable_hash = mono_g_hash_table_new (NULL, NULL);
-       domain->proxy_vtable_hash = mono_g_hash_table_new (NULL, NULL);
+       domain->proxy_vtable_hash = mono_g_hash_table_new ((GHashFunc)mono_string_hash, (GCompareFunc)mono_string_equal);
        domain->static_data_hash = mono_g_hash_table_new (NULL, NULL);
        domain->jit_code_hash = g_hash_table_new (NULL, NULL);
        domain->ldstr_table = mono_g_hash_table_new ((GHashFunc)ldstr_hash, (GCompareFunc)ldstr_equal);
        domain->jit_info_table = mono_jit_info_table_new ();
+       domain->class_init_trampoline_hash = mono_g_hash_table_new (NULL, NULL);
+       domain->finalizable_objects_hash = g_hash_table_new (NULL, NULL);
        domain->domain_id = InterlockedIncrement (&appdomain_id_counter);
 
        InitializeCriticalSection (&domain->lock);
@@ -242,6 +248,7 @@ mono_init (const char *filename)
        mono_raw_buffer_init ();
        mono_images_init ();
        mono_assemblies_init ();
+       mono_loader_init ();
 
        // FIXME: When should we release this memory?
        appdomains_list = mono_g_hash_table_new (g_direct_hash, g_direct_equal);
@@ -252,19 +259,22 @@ mono_init (const char *filename)
        TlsSetValue (appdomain_thread_id, domain);
 
        /* find the corlib */
-       corlib_aname.name = "corlib";
+       corlib_aname.name = "mscorlib";
        ass = mono_assembly_load (&corlib_aname, NULL, &status);
        if ((status != MONO_IMAGE_OK) || (ass == NULL)) {
                switch (status){
                case MONO_IMAGE_ERROR_ERRNO:
-                       g_print ("The assembly corlib.dll was not found or could not be loaded.\n");
-                       g_print ("It should have been installed in the `%s' directory.\n", MONO_ASSEMBLIES);
+                       g_print ("The assembly mscorlib.dll was not found or could not be loaded.\n");
+                       g_print ("It should have been installed in the `%s' directory.\n",
+                                mono_assembly_getrootdir ());
                        break;
                case MONO_IMAGE_IMAGE_INVALID:
-                       g_print ("The file %s/corlib.dll is an invalid CIL image\n", MONO_ASSEMBLIES);
+                       g_print ("The file %s/mscorlib.dll is an invalid CIL image\n",
+                                mono_assembly_getrootdir ());
                        break;
                case MONO_IMAGE_MISSING_ASSEMBLYREF:
-                       g_print ("Minning assembly reference in %s/corlib.dll\n", MONO_ASSEMBLIES);
+                       g_print ("Missing assembly reference in %s/mscorlib.dll\n",
+                                mono_assembly_getrootdir ());
                        break;
                case MONO_IMAGE_OK:
                        /* to suppress compiler warning */
@@ -468,6 +478,10 @@ mono_init (const char *filename)
                mono_defaults.corlib, "System.Threading", "Monitor");
        g_assert (mono_defaults.monitor_class != 0);
 
+       mono_defaults.iremotingtypeinfo_class = mono_class_from_name (
+               mono_defaults.corlib, "System.Runtime.Remoting", "IRemotingTypeInfo");
+       g_assert (mono_defaults.iremotingtypeinfo_class != 0);
+
        domain->friendly_name = g_path_get_basename (filename);
 
        return domain;
@@ -485,13 +499,13 @@ mono_domain_get ()
 }
 
 /**
- * mono_domain_set:
+ * mono_domain_set_internal:
  * @domain: the new domain
  *
  * Sets the current domain to @domain.
  */
 inline void
-mono_domain_set (MonoDomain *domain)
+mono_domain_set_internal (MonoDomain *domain)
 {
        TlsSetValue (appdomain_thread_id, domain);
        TlsSetValue (context_thread_id, domain->default_context);
@@ -579,7 +593,7 @@ delete_jump_list (gpointer key, gpointer value, gpointer user_data)
 }
 
 void
-mono_domain_unload (MonoDomain *domain, gboolean force)
+mono_domain_free (MonoDomain *domain, gboolean force)
 {
        if ((domain == mono_root_domain) && !force) {
                g_warning ("cant unload root domain");
@@ -587,7 +601,7 @@ mono_domain_unload (MonoDomain *domain, gboolean force)
        }
 
        EnterCriticalSection (&appdomains_mutex);
-       mono_g_hash_table_remove(appdomains_list, GINT_TO_POINTER(domain->domain_id));
+       mono_g_hash_table_remove (appdomains_list, GINT_TO_POINTER(domain->domain_id));
        LeaveCriticalSection (&appdomains_mutex);
        
        g_free (domain->friendly_name);
@@ -601,14 +615,21 @@ mono_domain_unload (MonoDomain *domain, gboolean force)
        g_hash_table_destroy (domain->jit_code_hash);
        mono_g_hash_table_destroy (domain->ldstr_table);
        mono_jit_info_table_free (domain->jit_info_table);
+#ifdef DEBUG_DOMAIN_UNLOAD
+       mono_mempool_invalidate (domain->mp);
+       mono_code_manager_invalidate (domain->code_mp);
+#else
        mono_mempool_destroy (domain->mp);
-       mono_mempool_destroy (domain->code_mp);
+       mono_code_manager_destroy (domain->code_mp);
+#endif 
        if (domain->jump_target_hash) {
                g_hash_table_foreach (domain->jump_target_hash, delete_jump_list, NULL);
                g_hash_table_destroy (domain->jump_target_hash);
        }
-       if (domain->thread_static_fields)
-               g_hash_table_destroy (domain->thread_static_fields);
+       mono_g_hash_table_destroy (domain->class_init_trampoline_hash);
+       g_hash_table_destroy (domain->finalizable_objects_hash);
+       if (domain->special_static_fields)
+               g_hash_table_destroy (domain->special_static_fields);
        DeleteCriticalSection (&domain->lock);
        domain->setup = NULL;