[loader] Move typespec_cache to a lock-free-reads hashtable.
authorRodrigo Kumpera <kumpera@gmail.com>
Tue, 22 Nov 2016 09:41:46 +0000 (01:41 -0800)
committerRodrigo Kumpera <kumpera@gmail.com>
Tue, 11 Apr 2017 23:03:18 +0000 (16:03 -0700)
mono/metadata/image.c
mono/metadata/metadata-internals.h
mono/metadata/metadata.c

index eb4d686412e586b822e0f064748cc7e7117c2b64..46063fc395f6958d685e308fb80e6e7dcd62f649 100644 (file)
@@ -803,7 +803,7 @@ mono_image_init (MonoImage *image)
                                       class_next_value);
        image->field_cache = mono_conc_hashtable_new (NULL, NULL);
 
-       image->typespec_cache = g_hash_table_new (NULL, NULL);
+       image->typespec_cache = mono_conc_hashtable_new (NULL, NULL);
        image->memberref_signatures = g_hash_table_new (NULL, NULL);
        image->helper_signatures = g_hash_table_new (g_str_hash, g_str_equal);
        image->method_signatures = g_hash_table_new (NULL, NULL);
@@ -2077,7 +2077,7 @@ mono_image_close_except_pools (MonoImage *image)
        free_hash (image->pinvoke_scopes);
        free_hash (image->pinvoke_scope_filenames);
        free_hash (image->native_func_wrapper_cache);
-       free_hash (image->typespec_cache);
+       mono_conc_hashtable_destroy (image->typespec_cache);
 
        mono_wrapper_caches_free (&image->wrapper_caches);
 
index 3ed3136236cc98661bb1758e92879596222f332a..a81b48b64fca4b5f96cb27f562b975cfe06ea492 100644 (file)
@@ -305,7 +305,7 @@ struct _MonoImage {
        MonoConcurrentHashTable *field_cache; /*protected by the image lock*/
 
        /* indexed by typespec tokens. */
-       GHashTable *typespec_cache; /* protected by the image lock */
+       MonoConcurrentHashTable *typespec_cache; /* protected by the image lock */
        /* indexed by token */
        GHashTable *memberref_signatures;
        GHashTable *helper_signatures;
index 963d412f0e4c67b290dca1aa0fdf6e36dbc0a471..5e70d67a993e65521194dd3a7178dfa3ef607032 100644 (file)
@@ -5794,9 +5794,7 @@ mono_type_create_from_typespec_checked (MonoImage *image, guint32 type_spec, Mon
 
        error_init (error);
 
-       mono_image_lock (image);
-       type = (MonoType *)g_hash_table_lookup (image->typespec_cache, GUINT_TO_POINTER (type_spec));
-       mono_image_unlock (image);
+       type = (MonoType *)mono_conc_hashtable_lookup (image->typespec_cache, GUINT_TO_POINTER (type_spec));
        if (type)
                return type;
 
@@ -5820,12 +5818,12 @@ mono_type_create_from_typespec_checked (MonoImage *image, guint32 type_spec, Mon
        mono_metadata_free_type (type);
 
        mono_image_lock (image);
-       type = (MonoType *)g_hash_table_lookup (image->typespec_cache, GUINT_TO_POINTER (type_spec));
+
        /* We might leak some data in the image mempool if found */
-       if (!type) {
-               g_hash_table_insert (image->typespec_cache, GUINT_TO_POINTER (type_spec), type2);
+       type = mono_conc_hashtable_insert (image->typespec_cache, GUINT_TO_POINTER (type_spec), type2);
+       if (!type)
                type = type2;
-       }
+
        mono_image_unlock (image);
 
        return type;