Merge pull request #4381 from BrzVlad/feature-generational-hash
authorVlad Brezae <brezaevlad@gmail.com>
Tue, 28 Feb 2017 12:30:18 +0000 (14:30 +0200)
committerGitHub <noreply@github.com>
Tue, 28 Feb 2017 12:30:18 +0000 (14:30 +0200)
[sgen] Generational MonoGHashTable

21 files changed:
mono/metadata/boehm-gc.c
mono/metadata/domain.c
mono/metadata/metadata.c
mono/metadata/mono-hash.c
mono/metadata/mono-hash.h
mono/metadata/null-gc.c
mono/metadata/reflection.c
mono/metadata/sgen-mono.c
mono/metadata/threadpool-io.c
mono/mini/debugger-agent.c
mono/sgen/gc-internal-agnostic.h
mono/sgen/sgen-cardtable.c
mono/sgen/sgen-cardtable.h
mono/sgen/sgen-debug.c
mono/sgen/sgen-descriptor.c
mono/sgen/sgen-descriptor.h
mono/sgen/sgen-gc.c
mono/sgen/sgen-gc.h
mono/sgen/sgen-marksweep-drain-gray-stack.h
mono/sgen/sgen-marksweep.c
mono/utils/mono-conc-hashtable.c

index dcfd310f6490ebdd894c863b32e8c65d6ff52f6d..f0fa3579f72bcfd9b456132a305819cc8cc5e075 100644 (file)
@@ -617,6 +617,12 @@ mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits)
                return (gpointer)GC_make_descriptor ((GC_bitmap)bitmap, numbits);
 }
 
+void*
+mono_gc_make_vector_descr (void)
+{
+       return NULL;
+}
+
 void*
 mono_gc_make_root_descr_all_refs (int numbits)
 {
index 810d41197919ce7d0700169d2d080fced5c6db26..0785369e0c65662c1e35da8696d3ab2ecf47789c 100644 (file)
@@ -494,6 +494,8 @@ mono_init_internal (const char *filename, const char *exe_filename, const char *
        mono_counters_register ("Max code space allocated in a domain", MONO_COUNTER_INT|MONO_COUNTER_JIT, &max_domain_code_alloc);
        mono_counters_register ("Total code space allocated", MONO_COUNTER_INT|MONO_COUNTER_JIT, &total_domain_code_alloc);
 
+       mono_counters_register ("Max HashTable Chain Length", MONO_COUNTER_INT|MONO_COUNTER_METADATA, &mono_g_hash_table_max_chain_length);
+
        mono_gc_base_init ();
        mono_thread_info_attach (&dummy);
 
index 7ef3b74c5eb07bcab5f27c55df5877d91108ea6f..545b917177bf45472e6df6c8d7eacc5d344cedd1 100644 (file)
@@ -6714,7 +6714,8 @@ mono_signature_explicit_this (MonoMethodSignature *sig)
 guint
 mono_aligned_addr_hash (gconstpointer ptr)
 {
-       return GPOINTER_TO_UINT (ptr) >> 3;
+       /* Same hashing we use for objects */
+       return (GPOINTER_TO_UINT (ptr) >> 3) * 2654435761u;
 }
 
 /*
index 00f7afab0ccea8eb71d5cb11bdc7adef687aa1a4..9c6cdb44101c6479dfbc36381aefc2252a7fb074 100644 (file)
@@ -34,6 +34,8 @@
 #include <mono/utils/checked-build.h>
 #include <mono/utils/mono-threads-coop.h>
 
+int mono_g_hash_table_max_chain_length;
+
 #ifdef HAVE_BOEHM_GC
 #define mg_new0(type,n)  ((type *) GC_MALLOC(sizeof(type) * (n)))
 #define mg_new(type,n)   ((type *) GC_MALLOC(sizeof(type) * (n)))
 #define mg_free(x)       g_free(x)
 #endif
 
-typedef struct _Slot Slot;
-
-struct _Slot {
-       MonoObject *key;
-       MonoObject *value;
-       Slot    *next;
-};
-
-static gpointer KEYMARKER_REMOVED = &KEYMARKER_REMOVED;
-
 struct _MonoGHashTable {
        GHashFunc      hash_func;
        GEqualFunc     key_equal_func;
 
-       Slot **table;
+       MonoObject **keys;
+       MonoObject **values;
        int   table_size;
        int   in_use;
-       int   threshold;
-       int   last_rehash;
        GDestroyNotify value_destroy_func, key_destroy_func;
        MonoGHashGCType gc_type;
        MonoGCRootSource source;
        const char *msg;
 };
 
-#ifdef HAVE_SGEN_GC
-static MonoGCDescriptor table_hash_descr = MONO_GC_DESCRIPTOR_NULL;
-
-static void mono_g_hash_mark (void *addr, MonoGCMarkFunc mark_func, void *gc_data);
-#endif
-
-static Slot*
-new_slot (MonoGHashTable *hash)
-{
-       return mg_new (Slot, 1);
-}
-
-static void
-free_slot (MonoGHashTable *hash, Slot *slot)
-{
-       mg_free (slot);
-}
-
 #if UNUSED
 static gboolean
 test_prime (int x)
@@ -107,7 +80,7 @@ static int
 calc_prime (int x)
 {
        int i;
-       
+
        for (i = (x & (~1))-1; i< G_MAXINT32; i += 2) {
                if (test_prime (i))
                        return i;
@@ -116,15 +89,67 @@ calc_prime (int x)
 }
 #endif
 
+#define HASH_TABLE_MAX_LOAD_FACTOR 0.7f
+/* We didn't really do compaction before, keep it lenient for now */
+#define HASH_TABLE_MIN_LOAD_FACTOR 0.05f
+/* We triple the table size at rehash time, similar with previous implementation */
+#define HASH_TABLE_RESIZE_RATIO 3
+
+static inline void mono_g_hash_table_key_store (MonoGHashTable *hash, int slot, MonoObject* key)
+{
+       MonoObject **key_addr = &hash->keys [slot];
+       if (hash->gc_type & MONO_HASH_KEY_GC)
+               mono_gc_wbarrier_generic_store (key_addr, key);
+       else
+               *key_addr = key;
+}
+
+static inline void mono_g_hash_table_value_store (MonoGHashTable *hash, int slot, MonoObject* value)
+{
+       MonoObject **value_addr = &hash->values [slot];
+       if (hash->gc_type & MONO_HASH_VALUE_GC)
+               mono_gc_wbarrier_generic_store (value_addr, value);
+       else
+               *value_addr = value;
+}
+
+/* Returns position of key or of an empty slot for it */
+static inline int mono_g_hash_table_find_slot (MonoGHashTable *hash, const MonoObject *key)
+{
+       guint start = ((*hash->hash_func) (key)) % hash->table_size;
+       guint i = start;
+
+       if (hash->key_equal_func) {
+               GEqualFunc equal = hash->key_equal_func;
+
+               while (hash->keys [i] && !(*equal) (hash->keys [i], key)) {
+                       i++;
+                       if (i == hash->table_size)
+                               i = 0;
+               }
+       } else {
+               while (hash->keys [i] && hash->keys [i] != key) {
+                       i++;
+                       if (i == hash->table_size)
+                               i = 0;
+               }
+       }
+
+       if (i > start && (i - start) > mono_g_hash_table_max_chain_length)
+               mono_g_hash_table_max_chain_length = i - start;
+       else if (i < start && (hash->table_size - (start - i)) > mono_g_hash_table_max_chain_length)
+               mono_g_hash_table_max_chain_length = hash->table_size - (start - i);
+       return i;
+}
+
+
 MonoGHashTable *
 mono_g_hash_table_new_type (GHashFunc hash_func, GEqualFunc key_equal_func, MonoGHashGCType type, MonoGCRootSource source, const char *msg)
 {
        MonoGHashTable *hash;
 
-       if (hash_func == NULL)
+       if (!hash_func)
                hash_func = g_direct_hash;
-       if (key_equal_func == NULL)
-               key_equal_func = g_direct_equal;
 
 #ifdef HAVE_SGEN_GC
        hash = mg_new0 (MonoGHashTable, 1);
@@ -136,8 +161,8 @@ mono_g_hash_table_new_type (GHashFunc hash_func, GEqualFunc key_equal_func, Mono
        hash->key_equal_func = key_equal_func;
 
        hash->table_size = g_spaced_primes_closest (1);
-       hash->table = mg_new0 (Slot *, hash->table_size);
-       hash->last_rehash = hash->table_size;
+       hash->keys = mg_new0 (MonoObject*, hash->table_size);
+       hash->values = mg_new0 (MonoObject*, hash->table_size);
 
        hash->gc_type = type;
        hash->source = source;
@@ -147,13 +172,10 @@ mono_g_hash_table_new_type (GHashFunc hash_func, GEqualFunc key_equal_func, Mono
                g_error ("wrong type for gc hashtable");
 
 #ifdef HAVE_SGEN_GC
-       /*
-        * We use a user defined marking function to avoid having to register a GC root for
-        * each hash node.
-        */
-       if (!table_hash_descr)
-               table_hash_descr = mono_gc_make_root_descr_user (mono_g_hash_mark);
-       mono_gc_register_root_wbarrier ((char*)hash, sizeof (MonoGHashTable), table_hash_descr, source, msg);
+       if (hash->gc_type & MONO_HASH_KEY_GC)
+               mono_gc_register_root_wbarrier ((char*)hash->keys, sizeof (MonoObject*) * hash->table_size, mono_gc_make_vector_descr (), hash->source, hash->msg);
+       if (hash->gc_type & MONO_HASH_VALUE_GC)
+               mono_gc_register_root_wbarrier ((char*)hash->values, sizeof (MonoObject*) * hash->table_size, mono_gc_make_vector_descr (), hash->source, hash->msg);
 #endif
 
        return hash;
@@ -162,7 +184,8 @@ mono_g_hash_table_new_type (GHashFunc hash_func, GEqualFunc key_equal_func, Mono
 typedef struct {
        MonoGHashTable *hash;
        int new_size;
-       Slot **table;
+       MonoObject **keys;
+       MonoObject **values;
 } RehashData;
 
 static void*
@@ -171,28 +194,24 @@ do_rehash (void *_data)
        RehashData *data = (RehashData *)_data;
        MonoGHashTable *hash = data->hash;
        int current_size, i;
-       Slot **table;
+       MonoObject **old_keys;
+       MonoObject **old_values;
 
-       /* printf ("Resizing diff=%d slots=%d\n", hash->in_use - hash->last_rehash, hash->table_size); */
-       hash->last_rehash = hash->table_size;
        current_size = hash->table_size;
        hash->table_size = data->new_size;
-       /* printf ("New size: %d\n", hash->table_size); */
-       table = hash->table;
-       hash->table = data->table;
-
-       for (i = 0; i < current_size; i++){
-               Slot *s, *next;
-
-               for (s = table [i]; s != NULL; s = next){
-                       guint hashcode = ((*hash->hash_func) (s->key)) % hash->table_size;
-                       next = s->next;
-
-                       s->next = hash->table [hashcode];
-                       hash->table [hashcode] = s;
+       old_keys = hash->keys;
+       old_values = hash->values;
+       hash->keys = data->keys;
+       hash->values = data->values;
+
+       for (i = 0; i < current_size; i++) {
+               if (old_keys [i]) {
+                       int slot = mono_g_hash_table_find_slot (hash, old_keys [i]);
+                       mono_g_hash_table_key_store (hash, slot, old_keys [i]);
+                       mono_g_hash_table_value_store (hash, slot, old_values [i]);
                }
        }
-       return table;
+       return NULL;
 }
 
 static void
@@ -200,35 +219,48 @@ rehash (MonoGHashTable *hash)
 {
        MONO_REQ_GC_UNSAFE_MODE; //we must run in unsafe mode to make rehash safe
 
-       int diff = ABS (hash->last_rehash - hash->in_use);
        RehashData data;
-       void *old_table G_GNUC_UNUSED; /* unused on Boehm */
-
-       /* These are the factors to play with to change the rehashing strategy */
-       /* I played with them with a large range, and could not really get */
-       /* something that was too good, maybe the tests are not that great */
-       if (!(diff * 0.75 > hash->table_size * 2))
-               return;
+       void *old_keys G_GNUC_UNUSED = hash->keys; /* unused on Boehm */
+       void *old_values G_GNUC_UNUSED = hash->values; /* unused on Boehm */
 
        data.hash = hash;
-       data.new_size = g_spaced_primes_closest (hash->in_use);
-       data.table = mg_new0 (Slot *, data.new_size);
+       /*
+        * Rehash to a size that can fit the current elements. Rehash relative to in_use
+        * to allow also for compaction.
+        */
+       data.new_size = g_spaced_primes_closest (hash->in_use / HASH_TABLE_MAX_LOAD_FACTOR * HASH_TABLE_RESIZE_RATIO);
+       data.keys = mg_new0 (MonoObject*, data.new_size);
+       data.values = mg_new0 (MonoObject*, data.new_size);
+
+#ifdef HAVE_SGEN_GC
+       if (hash->gc_type & MONO_HASH_KEY_GC)
+               mono_gc_register_root_wbarrier ((char*)data.keys, sizeof (MonoObject*) * data.new_size, mono_gc_make_vector_descr (), hash->source, hash->msg);
+       if (hash->gc_type & MONO_HASH_VALUE_GC)
+               mono_gc_register_root_wbarrier ((char*)data.values, sizeof (MonoObject*) * data.new_size, mono_gc_make_vector_descr (), hash->source, hash->msg);
+#endif
 
        if (!mono_threads_is_coop_enabled ()) {
-               old_table = mono_gc_invoke_with_gc_lock (do_rehash, &data);
+               mono_gc_invoke_with_gc_lock (do_rehash, &data);
        } else {
                /* We cannot be preempted */
-               old_table = do_rehash (&data);
+               do_rehash (&data);
        }
 
-       mg_free (old_table);
+#ifdef HAVE_SGEN_GC
+       if (hash->gc_type & MONO_HASH_KEY_GC)
+               mono_gc_deregister_root ((char*)old_keys);
+       if (hash->gc_type & MONO_HASH_VALUE_GC)
+               mono_gc_deregister_root ((char*)old_values);
+#endif
+       mg_free (old_keys);
+       mg_free (old_values);
 }
 
 guint
 mono_g_hash_table_size (MonoGHashTable *hash)
 {
        g_return_val_if_fail (hash != NULL, 0);
-       
+
        return hash->in_use;
 }
 
@@ -236,7 +268,7 @@ gpointer
 mono_g_hash_table_lookup (MonoGHashTable *hash, gconstpointer key)
 {
        gpointer orig_key, value;
-       
+
        if (mono_g_hash_table_lookup_extended (hash, key, &orig_key, &value))
                return value;
        else
@@ -246,22 +278,18 @@ mono_g_hash_table_lookup (MonoGHashTable *hash, gconstpointer key)
 gboolean
 mono_g_hash_table_lookup_extended (MonoGHashTable *hash, gconstpointer key, gpointer *orig_key, gpointer *value)
 {
-       GEqualFunc equal;
-       Slot *s;
-       guint hashcode;
-       
+       int slot;
+
        g_return_val_if_fail (hash != NULL, FALSE);
-       equal = hash->key_equal_func;
-
-       hashcode = ((*hash->hash_func) (key)) % hash->table_size;
-       
-       for (s = hash->table [hashcode]; s != NULL; s = s->next){
-               if ((*equal)(s->key, key)){
-                       *orig_key = s->key;
-                       *value = s->value;
-                       return TRUE;
-               }
+
+       slot = mono_g_hash_table_find_slot (hash, key);
+
+       if (hash->keys [slot]) {
+               *orig_key = hash->keys [slot];
+               *value = hash->values [slot];
+               return TRUE;
        }
+
        return FALSE;
 }
 
@@ -269,15 +297,13 @@ void
 mono_g_hash_table_foreach (MonoGHashTable *hash, GHFunc func, gpointer user_data)
 {
        int i;
-       
+
        g_return_if_fail (hash != NULL);
        g_return_if_fail (func != NULL);
 
-       for (i = 0; i < hash->table_size; i++){
-               Slot *s;
-
-               for (s = hash->table [i]; s != NULL; s = s->next)
-                       (*func)(s->key, s->value, user_data);
+       for (i = 0; i < hash->table_size; i++) {
+               if (hash->keys [i])
+                       (*func)(hash->keys [i], hash->values [i], user_data);
        }
 }
 
@@ -285,16 +311,13 @@ gpointer
 mono_g_hash_table_find (MonoGHashTable *hash, GHRFunc predicate, gpointer user_data)
 {
        int i;
-       
+
        g_return_val_if_fail (hash != NULL, NULL);
        g_return_val_if_fail (predicate != NULL, NULL);
 
-       for (i = 0; i < hash->table_size; i++){
-               Slot *s;
-
-               for (s = hash->table [i]; s != NULL; s = s->next)
-                       if ((*predicate)(s->key, s->value, user_data))
-                               return s->value;
+       for (i = 0; i < hash->table_size; i++) {
+               if (hash->keys [i] && (*predicate)(hash->keys [i], hash->values [i], user_data))
+                       return hash->values [i];
        }
        return NULL;
 }
@@ -302,32 +325,53 @@ mono_g_hash_table_find (MonoGHashTable *hash, GHRFunc predicate, gpointer user_d
 gboolean
 mono_g_hash_table_remove (MonoGHashTable *hash, gconstpointer key)
 {
-       GEqualFunc equal;
-       Slot *s, *last;
-       guint hashcode;
-       
+       int slot, last_clear_slot;
+
        g_return_val_if_fail (hash != NULL, FALSE);
-       equal = hash->key_equal_func;
-
-       hashcode = ((*hash->hash_func)(key)) % hash->table_size;
-       last = NULL;
-       for (s = hash->table [hashcode]; s != NULL; s = s->next){
-               if ((*equal)(s->key, key)){
-                       if (hash->key_destroy_func != NULL)
-                               (*hash->key_destroy_func)(s->key);
-                       if (hash->value_destroy_func != NULL)
-                               (*hash->value_destroy_func)(s->value);
-                       if (last == NULL)
-                               hash->table [hashcode] = s->next;
-                       else
-                               last->next = s->next;
-                       free_slot (hash, s);
-                       hash->in_use--;
-                       return TRUE;
+       slot = mono_g_hash_table_find_slot (hash, key);
+
+       if (!hash->keys [slot])
+               return FALSE;
+
+       if (hash->key_destroy_func)
+               (*hash->key_destroy_func)(hash->keys [slot]);
+       hash->keys [slot] = NULL;
+       if (hash->value_destroy_func)
+               (*hash->value_destroy_func)(hash->values [slot]);
+       hash->values [slot] = NULL;
+       hash->in_use--;
+
+       /*
+        * When we insert in the hashtable, if the required position is occupied we
+        * consecutively try out following positions. In order to be able to find
+        * if a key exists or not in the array (without traversing the entire hash)
+        * we maintain the constraint that there can be no free slots between two
+        * entries that are hashed to the same position. This means that, at search
+        * time, when we encounter a free slot we can stop looking for collissions.
+        * Similarly, at remove time, we need to shift all following slots to their
+        * normal slot, until we reach an empty slot.
+        */
+       last_clear_slot = slot;
+       slot = (slot + 1) % hash->table_size;
+       while (hash->keys [slot]) {
+               guint hashcode = ((*hash->hash_func)(hash->keys [slot])) % hash->table_size;
+               /*
+                * We try to move the current element to last_clear_slot, but only if
+                * it brings it closer to its normal position (hashcode)
+                */
+               if ((last_clear_slot < slot && (hashcode > slot || hashcode <= last_clear_slot)) ||
+                               (last_clear_slot > slot && (hashcode > slot && hashcode <= last_clear_slot))) {
+                       mono_g_hash_table_key_store (hash, last_clear_slot, hash->keys [slot]);
+                       mono_g_hash_table_value_store (hash, last_clear_slot, hash->values [slot]);
+                       hash->keys [slot] = NULL;
+                       hash->values [slot] = NULL;
+                       last_clear_slot = slot;
                }
-               last = s;
+               slot++;
+               if (slot == hash->table_size)
+                       slot = 0;
        }
-       return FALSE;
+       return TRUE;
 }
 
 guint
@@ -335,40 +379,19 @@ mono_g_hash_table_foreach_remove (MonoGHashTable *hash, GHRFunc func, gpointer u
 {
        int i;
        int count = 0;
-       
+
        g_return_val_if_fail (hash != NULL, 0);
        g_return_val_if_fail (func != NULL, 0);
 
-       for (i = 0; i < hash->table_size; i++){
-               Slot *s, *last;
-
-               last = NULL;
-               for (s = hash->table [i]; s != NULL; ){
-                       if ((*func)(s->key, s->value, user_data)){
-                               Slot *n;
-
-                               if (hash->key_destroy_func != NULL)
-                                       (*hash->key_destroy_func)(s->key);
-                               if (hash->value_destroy_func != NULL)
-                                       (*hash->value_destroy_func)(s->value);
-                               if (last == NULL){
-                                       hash->table [i] = s->next;
-                                       n = s->next;
-                               } else  {
-                                       last->next = s->next;
-                                       n = last->next;
-                               }
-                               free_slot (hash, s);
-                               hash->in_use--;
-                               count++;
-                               s = n;
-                       } else {
-                               last = s;
-                               s = s->next;
-                       }
+       for (i = 0; i < hash->table_size; i++) {
+               if (hash->keys [i] && (*func)(hash->keys [i], hash->values [i], user_data)) {
+                       mono_g_hash_table_remove (hash, hash->keys [i]);
+                       count++;
+                       /* Retry current slot in case the removal shifted elements */
+                       i--;
                }
        }
-       if (count > 0)
+       if (hash->in_use < hash->table_size * HASH_TABLE_MIN_LOAD_FACTOR)
                rehash (hash);
        return count;
 }
@@ -377,27 +400,26 @@ void
 mono_g_hash_table_destroy (MonoGHashTable *hash)
 {
        int i;
-       
+
        g_return_if_fail (hash != NULL);
 
 #ifdef HAVE_SGEN_GC
-       mono_gc_deregister_root ((char*)hash);
+       if (hash->gc_type & MONO_HASH_KEY_GC)
+               mono_gc_deregister_root ((char*)hash->keys);
+       if (hash->gc_type & MONO_HASH_VALUE_GC)
+               mono_gc_deregister_root ((char*)hash->values);
 #endif
 
-       for (i = 0; i < hash->table_size; i++){
-               Slot *s, *next;
-
-               for (s = hash->table [i]; s != NULL; s = next){
-                       next = s->next;
-                       
-                       if (hash->key_destroy_func != NULL)
-                               (*hash->key_destroy_func)(s->key);
-                       if (hash->value_destroy_func != NULL)
-                               (*hash->value_destroy_func)(s->value);
-                       free_slot (hash, s);
+       for (i = 0; i < hash->table_size; i++) {
+               if (hash->keys [i]) {
+                       if (hash->key_destroy_func)
+                               (*hash->key_destroy_func)(hash->keys [i]);
+                       if (hash->value_destroy_func)
+                               (*hash->value_destroy_func)(hash->values [i]);
                }
        }
-       mg_free (hash->table);
+       mg_free (hash->keys);
+       mg_free (hash->values);
 #ifdef HAVE_SGEN_GC
        mg_free (hash);
 #else
@@ -408,36 +430,28 @@ mono_g_hash_table_destroy (MonoGHashTable *hash)
 static void
 mono_g_hash_table_insert_replace (MonoGHashTable *hash, gpointer key, gpointer value, gboolean replace)
 {
-       guint hashcode;
-       Slot *s;
-       GEqualFunc equal;
-       
+       int slot;
        g_return_if_fail (hash != NULL);
 
-       equal = hash->key_equal_func;
-       if (hash->in_use >= hash->threshold)
+       if (hash->in_use > (hash->table_size * HASH_TABLE_MAX_LOAD_FACTOR))
                rehash (hash);
 
-       hashcode = ((*hash->hash_func) (key)) % hash->table_size;
-       for (s = hash->table [hashcode]; s != NULL; s = s->next){
-               if ((*equal) (s->key, key)){
-                       if (replace){
-                               if (hash->key_destroy_func != NULL)
-                                       (*hash->key_destroy_func)(s->key);
-                               s->key = (MonoObject *)key;
-                       }
-                       if (hash->value_destroy_func != NULL)
-                               (*hash->value_destroy_func) (s->value);
-                       s->value = (MonoObject *)value;
-                       return;
+       slot = mono_g_hash_table_find_slot (hash, key);
+
+       if (hash->keys [slot]) {
+               if (replace) {
+                       if (hash->key_destroy_func)
+                               (*hash->key_destroy_func)(hash->keys [slot]);
+                       mono_g_hash_table_key_store (hash, slot, (MonoObject*)key);
                }
+               if (hash->value_destroy_func)
+                       (*hash->value_destroy_func) (hash->values [slot]);
+               mono_g_hash_table_value_store (hash, slot, (MonoObject*)value);
+       } else {
+               mono_g_hash_table_key_store (hash, slot, (MonoObject*)key);
+               mono_g_hash_table_value_store (hash, slot, (MonoObject*)value);
+               hash->in_use++;
        }
-       s = new_slot (hash);
-       s->key = (MonoObject *)key;
-       s->value = (MonoObject *)value;
-       s->next = hash->table [hashcode];
-       hash->table [hashcode] = s;
-       hash->in_use++;
 }
 
 void
@@ -453,56 +467,28 @@ mono_g_hash_table_replace(MonoGHashTable *h, gpointer k, gpointer v)
 }
 
 void
-mono_g_hash_table_print_stats (MonoGHashTable *table)
+mono_g_hash_table_print_stats (MonoGHashTable *hash)
 {
-       int i, chain_size, max_chain_size;
-       Slot *node;
-
-       max_chain_size = 0;
-       for (i = 0; i < table->table_size; i++) {
-               chain_size = 0;
-               for (node = table->table [i]; node; node = node->next)
-                       chain_size ++;
-               max_chain_size = MAX(max_chain_size, chain_size);
-       }
-
-       printf ("Size: %d Table Size: %d Max Chain Length: %d\n", table->in_use, table->table_size, max_chain_size);
-}
-
-#ifdef HAVE_SGEN_GC
-
-/* GC marker function */
-static void
-mono_g_hash_mark (void *addr, MonoGCMarkFunc mark_func, void *gc_data)
-{
-       MonoGHashTable *table = (MonoGHashTable*)addr;
-       Slot *node;
-       int i;
-
-       if (table->gc_type == MONO_HASH_KEY_GC) {
-               for (i = 0; i < table->table_size; i++) {
-                       for (node = table->table [i]; node; node = node->next) {
-                               if (node->key)
-                                       mark_func (&node->key, gc_data);
-                       }
-               }
-       } else if (table->gc_type == MONO_HASH_VALUE_GC) {
-               for (i = 0; i < table->table_size; i++) {
-                       for (node = table->table [i]; node; node = node->next) {
-                               if (node->value)
-                                       mark_func (&node->value, gc_data);
-                       }
+       int i = 0, chain_size = 0, max_chain_size = 0;
+       gboolean wrapped_around = FALSE;
+
+       while (TRUE) {
+               if (hash->keys [i]) {
+                       chain_size++;
+               } else {
+                       max_chain_size = MAX(max_chain_size, chain_size);
+                       chain_size = 0;
+                       if (wrapped_around)
+                               break;
                }
-       } else if (table->gc_type == MONO_HASH_KEY_VALUE_GC) {
-               for (i = 0; i < table->table_size; i++) {
-                       for (node = table->table [i]; node; node = node->next) {
-                               if (node->key)
-                                       mark_func (&node->key, gc_data);
-                               if (node->value)
-                                       mark_func (&node->value, gc_data);
-                       }
+
+               if (i == (hash->table_size - 1)) {
+                       wrapped_around = TRUE;
+                       i = 0;
+               } else {
+                       i++;
                }
        }
+       /* Rehash to a size that can fit the current elements */
+       printf ("Size: %d Table Size: %d Max Chain Length: %d\n", hash->in_use, hash->table_size, max_chain_size);
 }
-       
-#endif
index 60c3328a238782269a18de0e1c9bf04ddef6aa52..dca17694f8eab15a9ae3022b6d49ba112046aa49 100644 (file)
@@ -21,6 +21,8 @@ typedef enum {
        MONO_HASH_KEY_VALUE_GC = MONO_HASH_KEY_GC | MONO_HASH_VALUE_GC,
 } MonoGHashGCType;
 
+extern int mono_g_hash_table_max_chain_length;
+
 typedef struct _MonoGHashTable MonoGHashTable;
 
 MONO_API MonoGHashTable *mono_g_hash_table_new_type (GHashFunc hash_func, GEqualFunc key_equal_func, MonoGHashGCType type, MonoGCRootSource source, const char *msg);
index 9ea87bd844c51a3efaf775a8b159251b1271fc2f..4ee7dd7c9c4f9ea7f327c0ffe7d81a5dcb3e1107 100644 (file)
@@ -164,6 +164,12 @@ mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits)
        return NULL;
 }
 
+void*
+mono_gc_make_vector_descr (void)
+{
+       return NULL;
+}
+
 void*
 mono_gc_make_root_descr_all_refs (int numbits)
 {
index fbcce02c18cb15aab9c083847680fe611bdc3d6f..43843be4a5a676a9f8f34808588688bbbf81f150 100644 (file)
@@ -165,7 +165,10 @@ reflected_equal (gconstpointer a, gconstpointer b)
 guint
 reflected_hash (gconstpointer a) {
        const ReflectedEntry *ea = (const ReflectedEntry *)a;
-       return mono_aligned_addr_hash (ea->item);
+       /* Combine hashes for item and refclass. Identical to boost's hash_combine */
+       guint seed = mono_aligned_addr_hash (ea->item) + 0x9e3779b9;
+       seed ^= mono_aligned_addr_hash (ea->refclass) + 0x9e3779b9 + (seed << 6) + (seed >> 2);
+       return seed;
 }
 
 
index e8dd50b13d7be09050d60feaf0c89b399961beec..1964c55b064373fa05d69c01e5e3221f3cd6e8c3 100644 (file)
@@ -1573,67 +1573,6 @@ sgen_has_managed_allocator (void)
        return FALSE;
 }
 
-/*
- * Cardtable scanning
- */
-
-#define MWORD_MASK (sizeof (mword) - 1)
-
-static inline int
-find_card_offset (mword card)
-{
-/*XXX Use assembly as this generates some pretty bad code */
-#if defined(__i386__) && defined(__GNUC__)
-       return  (__builtin_ffs (card) - 1) / 8;
-#elif defined(__x86_64__) && defined(__GNUC__)
-       return (__builtin_ffsll (card) - 1) / 8;
-#elif defined(__s390x__)
-       return (__builtin_ffsll (GUINT64_TO_LE(card)) - 1) / 8;
-#else
-       int i;
-       guint8 *ptr = (guint8 *) &card;
-       for (i = 0; i < sizeof (mword); ++i) {
-               if (ptr[i])
-                       return i;
-       }
-       return 0;
-#endif
-}
-
-static guint8*
-find_next_card (guint8 *card_data, guint8 *end)
-{
-       mword *cards, *cards_end;
-       mword card;
-
-       while ((((mword)card_data) & MWORD_MASK) && card_data < end) {
-               if (*card_data)
-                       return card_data;
-               ++card_data;
-       }
-
-       if (card_data == end)
-               return end;
-
-       cards = (mword*)card_data;
-       cards_end = (mword*)((mword)end & ~MWORD_MASK);
-       while (cards < cards_end) {
-               card = *cards;
-               if (card)
-                       return (guint8*)cards + find_card_offset (card);
-               ++cards;
-       }
-
-       card_data = (guint8*)cards_end;
-       while (card_data < end) {
-               if (*card_data)
-                       return card_data;
-               ++card_data;
-       }
-
-       return end;
-}
-
 #define ARRAY_OBJ_INDEX(ptr,array,elem_size) (((char*)(ptr) - ((char*)(array) + G_STRUCT_OFFSET (MonoArray, vector))) / (elem_size))
 
 gboolean
@@ -1690,8 +1629,8 @@ sgen_client_cardtable_scan_object (GCObject *obj, guint8 *cards, ScanCopyContext
 LOOP_HEAD:
 #endif
 
-               card_data = find_next_card (card_data, card_data_end);
-               for (; card_data < card_data_end; card_data = find_next_card (card_data + 1, card_data_end)) {
+               card_data = sgen_find_next_card (card_data, card_data_end);
+               for (; card_data < card_data_end; card_data = sgen_find_next_card (card_data + 1, card_data_end)) {
                        size_t index;
                        size_t idx = (card_data - card_base) + extra_idx;
                        char *start = (char*)(obj_start + idx * CARD_SIZE_IN_BYTES);
@@ -2007,6 +1946,15 @@ precisely_report_roots_from (GCRootReport *report, void** start_root, void** end
                }
                break;
        }
+       case ROOT_DESC_VECTOR: {
+               void **p;
+
+               for (p = start_root; p < end_root; p++) {
+                       if (*p)
+                               add_profile_gc_root (report, *p, MONO_PROFILE_GC_ROOT_OTHER, 0);
+               }
+               break;
+       }
        case ROOT_DESC_USER: {
                MonoGCRootMarkFunc marker = (MonoGCRootMarkFunc)sgen_get_user_descriptor_func (desc);
                root_report = report;
index 618d995dceb7db96eccc7cccbdc98e1852f4cd56..4f4fa7b1559c202ec6d0ef11435e43504759831c 100644 (file)
@@ -325,7 +325,7 @@ selector_thread (gpointer data)
                return 0;
        }
 
-       states = mono_g_hash_table_new_type (g_direct_hash, g_direct_equal, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_THREAD_POOL, "i/o thread pool states table");
+       states = mono_g_hash_table_new_type (g_direct_hash, NULL, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_THREAD_POOL, "i/o thread pool states table");
 
        while (!mono_runtime_is_shutting_down ()) {
                gint i, j;
index 8f120de8683fd6b93dba923a01a2ff6686dabca4..ed1b7a14a7f3f502ef5708be026901355408022f 100644 (file)
@@ -998,7 +998,7 @@ mono_debugger_agent_init (void)
        /* Needed by the hash_table_new_type () call below */
        mono_gc_base_init ();
 
-       thread_to_tls = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_KEY_GC, MONO_ROOT_SOURCE_DEBUGGER, "thread-to-tls table");
+       thread_to_tls = mono_g_hash_table_new_type ((GHashFunc)mono_object_hash, NULL, MONO_HASH_KEY_GC, MONO_ROOT_SOURCE_DEBUGGER, "thread-to-tls table");
 
        tid_to_thread = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_VALUE_GC, MONO_ROOT_SOURCE_DEBUGGER, "tid-to-thread table");
 
@@ -1939,7 +1939,7 @@ objrefs_init (void)
 {
        objrefs = g_hash_table_new_full (NULL, NULL, NULL, free_objref);
        obj_to_objref = g_hash_table_new (NULL, NULL);
-       suspended_objs = mono_g_hash_table_new_type (NULL, NULL, MONO_HASH_KEY_GC, MONO_ROOT_SOURCE_DEBUGGER, "suspended objects table");
+       suspended_objs = mono_g_hash_table_new_type ((GHashFunc)mono_object_hash, NULL, MONO_HASH_KEY_GC, MONO_ROOT_SOURCE_DEBUGGER, "suspended objects table");
 }
 
 static void
index 62039f7267901a805e94c8e1fb79c4c7c72a9dca..dc9b091bf6f95262b3dd0bec4a1903c88576e3d7 100644 (file)
@@ -93,6 +93,9 @@ MonoGCDescriptor mono_gc_make_descr_for_array (int vector, gsize *elem_bitmap, i
 /* simple interface for data structures needed in the runtime */
 MonoGCDescriptor mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits);
 
+/* Return a root descriptor for a vector with repeating refs bitmap */
+MonoGCDescriptor mono_gc_make_vector_descr (void);
+
 /* Return a root descriptor for a root with all refs */
 MonoGCDescriptor mono_gc_make_root_descr_all_refs (int numbits);
 
index cf89aedad4f5f7e10c46216141c0bc81ae4d8a9a..0138669a78897f120a97561e8f96b22edb5cfa57 100644 (file)
@@ -412,6 +412,7 @@ sgen_card_table_clear_cards (void)
        /*XXX we could do this in 2 ways. using mincore or iterating over all sections/los objects */
        sgen_major_collector_iterate_block_ranges (clear_cards);
        sgen_los_iterate_live_block_ranges (clear_cards);
+       sgen_wbroots_iterate_live_block_ranges (clear_cards);
 }
 
 static void
@@ -433,6 +434,7 @@ sgen_card_table_scan_remsets (ScanCopyContext ctx)
        /*First we copy*/
        sgen_major_collector_iterate_block_ranges (move_cards_to_shadow_table);
        sgen_los_iterate_live_block_ranges (move_cards_to_shadow_table);
+       sgen_wbroots_iterate_live_block_ranges (move_cards_to_shadow_table);
 
        /*Then we clear*/
        sgen_card_table_clear_cards ();
@@ -446,6 +448,8 @@ sgen_card_table_scan_remsets (ScanCopyContext ctx)
        SGEN_TV_GETTIME (atv);
        last_los_scan_time = SGEN_TV_ELAPSED (btv, atv);
        los_card_scan_time += last_los_scan_time;
+
+       sgen_wbroots_scan_card_table (ctx);
 }
 
 guint8*
@@ -488,6 +492,67 @@ sgen_card_table_dump_obj_card (GCObject *object, size_t size, void *dummy)
 }
 #endif
 
+/*
+ * Cardtable scanning
+ */
+
+#define MWORD_MASK (sizeof (mword) - 1)
+
+static inline int
+find_card_offset (mword card)
+{
+/*XXX Use assembly as this generates some pretty bad code */
+#if (defined(__i386__) || defined(__arm__)) && defined(__GNUC__)
+       return  (__builtin_ffs (card) - 1) / 8;
+#elif (defined(__x86_64__) || defined(__aarch64__)) && defined(__GNUC__)
+       return (__builtin_ffsll (card) - 1) / 8;
+#elif defined(__s390x__)
+       return (__builtin_ffsll (GUINT64_TO_LE(card)) - 1) / 8;
+#else
+       int i;
+       guint8 *ptr = (guint8 *) &card;
+       for (i = 0; i < sizeof (mword); ++i) {
+               if (ptr[i])
+                       return i;
+       }
+       return 0;
+#endif
+}
+
+guint8*
+sgen_find_next_card (guint8 *card_data, guint8 *end)
+{
+       mword *cards, *cards_end;
+       mword card;
+
+       while ((((mword)card_data) & MWORD_MASK) && card_data < end) {
+               if (*card_data)
+                       return card_data;
+               ++card_data;
+       }
+
+       if (card_data == end)
+               return end;
+
+       cards = (mword*)card_data;
+       cards_end = (mword*)((mword)end & ~MWORD_MASK);
+       while (cards < cards_end) {
+               card = *cards;
+               if (card)
+                       return (guint8*)cards + find_card_offset (card);
+               ++cards;
+       }
+
+       card_data = (guint8*)cards_end;
+       while (card_data < end) {
+               if (*card_data)
+                       return card_data;
+               ++card_data;
+       }
+
+       return end;
+}
+
 void
 sgen_cardtable_scan_object (GCObject *obj, mword block_obj_size, guint8 *cards, ScanCopyContext ctx)
 {
index 059fb77fa64925d61f73ff1311c1f7b979b7343e..a4fa1e32b6e91b2be1b3f281c21172bdbed6744c 100644 (file)
@@ -9,6 +9,7 @@
 
 /*WARNING: This function returns the number of cards regardless of overflow in case of overlapping cards.*/
 mword sgen_card_table_number_of_cards_in_range (mword address, mword size);
+guint8* sgen_find_next_card (guint8 *card_data, guint8 *end);
 
 void sgen_card_table_reset_region (mword start, mword end);
 void* sgen_card_table_align_pointer (void *ptr);
index 195894f8cbf1eecfa6997df325edc00fd9caf643..a78fb3dad57e7b8d3d3d31671ba54a5d24a13f05 100644 (file)
@@ -804,6 +804,15 @@ scan_roots_for_specific_ref (GCObject *key, int root_type)
                        }
                        break;
                }
+               case ROOT_DESC_VECTOR: {
+                       void **p;
+
+                       for (p = start_root; p < (void**)root->end_root; p++) {
+                               if (*p)
+                                       check_root_obj_specific_ref (root, key, (GCObject *)*p);
+                       }
+                       break;
+               }
                case ROOT_DESC_USER: {
                        SgenUserRootMarkFunc marker = sgen_get_user_descriptor_func (desc);
                        marker (start_root, check_root_obj_specific_ref_from_marker, NULL);
@@ -908,6 +917,15 @@ sgen_scan_for_registered_roots_in_domain (MonoDomain *domain, int root_type)
                        }
                        break;
                }
+               case ROOT_DESC_VECTOR: {
+                       void **p;
+
+                       for (p = start_root; p < (void**)root->end_root; p++) {
+                               if (*p)
+                                       check_obj_not_in_domain ((MonoObject **)*p);
+                       }
+                       break;
+               }
                case ROOT_DESC_USER: {
                        SgenUserRootMarkFunc marker = sgen_get_user_descriptor_func (desc);
                        marker (start_root, check_obj_not_in_domain_callback, NULL);
index 248b07b8f50fff935da561c90488a52af682ac17..f358c9da42977d736172a2d3fe15b8798ecf6970 100644 (file)
@@ -275,6 +275,12 @@ mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits)
        }
 }
 
+SgenDescriptor
+mono_gc_make_vector_descr (void)
+{
+       return MAKE_ROOT_DESC (ROOT_DESC_VECTOR, 0);
+}
+
 SgenDescriptor
 mono_gc_make_root_descr_all_refs (int numbits)
 {
index 54e1b7681fbe3fbb48a3c5385888b8b0d3567922..e072ca45d3267c1e21108f9eaafd7d33c0a62767 100644 (file)
@@ -114,6 +114,7 @@ enum {
        ROOT_DESC_BITMAP,
        ROOT_DESC_RUN_LEN, 
        ROOT_DESC_COMPLEX,
+       ROOT_DESC_VECTOR,
        ROOT_DESC_USER,
        ROOT_DESC_TYPE_MASK = 0x7,
        ROOT_DESC_TYPE_SHIFT = 3,
index 7c02172c6ee188b91fd9ded6a42c49a6d24d70a7..ec27de4224b9520a93998439738af18de6bbf08d 100644 (file)
@@ -858,6 +858,7 @@ static void
 precisely_scan_objects_from (void** start_root, void** end_root, char* n_start, char *n_end, SgenDescriptor desc, ScanCopyContext ctx)
 {
        CopyOrMarkObjectFunc copy_func = ctx.ops->copy_or_mark_object;
+       ScanPtrFieldFunc scan_field_func = ctx.ops->scan_ptr_field;
        SgenGrayQueue *queue = ctx.queue;
 
        switch (desc & ROOT_DESC_TYPE_MASK) {
@@ -892,6 +893,15 @@ precisely_scan_objects_from (void** start_root, void** end_root, char* n_start,
                }
                break;
        }
+       case ROOT_DESC_VECTOR: {
+               void **p;
+
+               for (p = start_root; p < end_root; p++) {
+                       if (*p)
+                               scan_field_func (NULL, (GCObject**)p, queue);
+               }
+               break;
+       }
        case ROOT_DESC_USER: {
                SgenUserRootMarkFunc marker = sgen_get_user_descriptor_func (desc);
                marker (start_root, single_arg_user_copy_or_mark, &ctx);
@@ -1481,13 +1491,16 @@ enqueue_scan_from_roots_jobs (SgenGrayQueue *gc_thread_gray_queue, char *heap_st
        scrrj->root_type = ROOT_TYPE_NORMAL;
        sgen_workers_enqueue_job (&scrrj->scan_job.job, enqueue);
 
-       scrrj = (ScanFromRegisteredRootsJob*)sgen_thread_pool_job_alloc ("scan from registered roots wbarrier", job_scan_from_registered_roots, sizeof (ScanFromRegisteredRootsJob));
-       scrrj->scan_job.ops = ops;
-       scrrj->scan_job.gc_thread_gray_queue = gc_thread_gray_queue;
-       scrrj->heap_start = heap_start;
-       scrrj->heap_end = heap_end;
-       scrrj->root_type = ROOT_TYPE_WBARRIER;
-       sgen_workers_enqueue_job (&scrrj->scan_job.job, enqueue);
+       if (current_collection_generation == GENERATION_OLD) {
+               /* During minors we scan the cardtable for these roots instead */
+               scrrj = (ScanFromRegisteredRootsJob*)sgen_thread_pool_job_alloc ("scan from registered roots wbarrier", job_scan_from_registered_roots, sizeof (ScanFromRegisteredRootsJob));
+               scrrj->scan_job.ops = ops;
+               scrrj->scan_job.gc_thread_gray_queue = gc_thread_gray_queue;
+               scrrj->heap_start = heap_start;
+               scrrj->heap_end = heap_end;
+               scrrj->root_type = ROOT_TYPE_WBARRIER;
+               sgen_workers_enqueue_job (&scrrj->scan_job.job, enqueue);
+       }
 
        /* Threads */
 
@@ -2599,6 +2612,94 @@ sgen_deregister_root (char* addr)
        UNLOCK_GC;
 }
 
+void
+sgen_wbroots_iterate_live_block_ranges (sgen_cardtable_block_callback cb)
+{
+       void **start_root;
+       RootRecord *root;
+       SGEN_HASH_TABLE_FOREACH (&roots_hash [ROOT_TYPE_WBARRIER], void **, start_root, RootRecord *, root) {
+               cb ((mword)start_root, (mword)root->end_root - (mword)start_root);
+       } SGEN_HASH_TABLE_FOREACH_END;
+}
+
+/* Root equivalent of sgen_client_cardtable_scan_object */
+static void
+sgen_wbroot_scan_card_table (void** start_root, mword size,  ScanCopyContext ctx)
+{
+       ScanPtrFieldFunc scan_field_func = ctx.ops->scan_ptr_field;
+       guint8 *card_data = sgen_card_table_get_card_scan_address ((mword)start_root);
+       guint8 *card_base = card_data;
+       mword card_count = sgen_card_table_number_of_cards_in_range ((mword)start_root, size);
+       guint8 *card_data_end = card_data + card_count;
+       mword extra_idx = 0;
+       char *obj_start = sgen_card_table_align_pointer (start_root);
+       char *obj_end = (char*)start_root + size;
+#ifdef SGEN_HAVE_OVERLAPPING_CARDS
+       guint8 *overflow_scan_end = NULL;
+#endif
+
+#ifdef SGEN_HAVE_OVERLAPPING_CARDS
+       /*Check for overflow and if so, setup to scan in two steps*/
+       if (card_data_end >= SGEN_SHADOW_CARDTABLE_END) {
+               overflow_scan_end = sgen_shadow_cardtable + (card_data_end - SGEN_SHADOW_CARDTABLE_END);
+               card_data_end = SGEN_SHADOW_CARDTABLE_END;
+       }
+
+LOOP_HEAD:
+#endif
+
+       card_data = sgen_find_next_card (card_data, card_data_end);
+
+       for (; card_data < card_data_end; card_data = sgen_find_next_card (card_data + 1, card_data_end)) {
+               size_t idx = (card_data - card_base) + extra_idx;
+               char *start = (char*)(obj_start + idx * CARD_SIZE_IN_BYTES);
+               char *card_end = start + CARD_SIZE_IN_BYTES;
+               char *elem = start, *first_elem = start;
+
+               /*
+                * Don't clean first and last card on 32bit systems since they
+                * may also be part from other roots.
+                */
+               if (card_data != card_base && card_data != (card_data_end - 1))
+                       sgen_card_table_prepare_card_for_scanning (card_data);
+
+               card_end = MIN (card_end, obj_end);
+
+               if (elem < (char*)start_root)
+                       first_elem = elem = (char*)start_root;
+
+               for (; elem < card_end; elem += SIZEOF_VOID_P) {
+                       if (*(GCObject**)elem)
+                               scan_field_func (NULL, (GCObject**)elem, ctx.queue);
+               }
+
+               binary_protocol_card_scan (first_elem, elem - first_elem);
+       }
+
+#ifdef SGEN_HAVE_OVERLAPPING_CARDS
+       if (overflow_scan_end) {
+               extra_idx = card_data - card_base;
+               card_base = card_data = sgen_shadow_cardtable;
+               card_data_end = overflow_scan_end;
+               overflow_scan_end = NULL;
+               goto LOOP_HEAD;
+       }
+#endif
+}
+
+void
+sgen_wbroots_scan_card_table (ScanCopyContext ctx)
+{
+       void **start_root;
+       RootRecord *root;
+
+       SGEN_HASH_TABLE_FOREACH (&roots_hash [ROOT_TYPE_WBARRIER], void **, start_root, RootRecord *, root) {
+               SGEN_ASSERT (0, (root->root_desc & ROOT_DESC_TYPE_MASK) == ROOT_DESC_VECTOR, "Unsupported root type");
+
+               sgen_wbroot_scan_card_table (start_root, (mword)root->end_root - (mword)start_root, ctx);
+       } SGEN_HASH_TABLE_FOREACH_END;
+}
+
 /*
  * ######################################################################
  * ########  Thread handling (stop/start code)
index ba7aee729406a55f2ae6bde264d7219e9e349620..a89a5471dd729c563d09721fcd4a5bd9ccdadf68 100644 (file)
@@ -832,6 +832,9 @@ void sgen_finalize_if (SgenObjectPredicateFunc predicate, void *user_data);
 void sgen_remove_finalizers_if (SgenObjectPredicateFunc predicate, void *user_data, int generation);
 void sgen_set_suspend_finalizers (void);
 
+void sgen_wbroots_iterate_live_block_ranges (sgen_cardtable_block_callback cb);
+void sgen_wbroots_scan_card_table (ScanCopyContext ctx);
+
 void sgen_register_disappearing_link (GCObject *obj, void **link, gboolean track, gboolean in_gc);
 
 GCObject* sgen_weak_link_get (void **link_addr);
index 6eb4d266fdc16d423a5ef48398c1cb7dec3e2a59..98d8917593cd385d6f77c5bdfed4facb5e96ef63 100644 (file)
@@ -240,7 +240,7 @@ SCAN_OBJECT_FUNCTION_NAME (GCObject *full_object, SgenDescriptor desc, SgenGrayQ
                GCObject *__old = *(ptr);                               \
                binary_protocol_scan_process_reference ((full_object), (ptr), __old); \
                if (__old && !sgen_ptr_in_nursery (__old)) {            \
-                       if (G_UNLIKELY (!sgen_ptr_in_nursery (ptr) &&   \
+                       if (G_UNLIKELY (full_object && !sgen_ptr_in_nursery (ptr) && \
                                        sgen_safe_object_is_small (__old, sgen_obj_get_descriptor (__old) & DESC_TYPE_MASK) && \
                                        major_block_is_evacuating (MS_BLOCK_FOR_OBJ (__old)))) { \
                                mark_mod_union_card ((full_object), (void**)(ptr), __old); \
@@ -249,7 +249,7 @@ SCAN_OBJECT_FUNCTION_NAME (GCObject *full_object, SgenDescriptor desc, SgenGrayQ
                                COPY_OR_MARK_FUNCTION_NAME ((ptr), __old, queue); \
                        }                                               \
                } else {                                                \
-                       if (G_UNLIKELY (sgen_ptr_in_nursery (__old) && !sgen_ptr_in_nursery ((ptr)) && !sgen_cement_is_forced (__old))) \
+                       if (G_UNLIKELY (full_object && sgen_ptr_in_nursery (__old) && !sgen_ptr_in_nursery ((ptr)) && !sgen_cement_is_forced (__old))) \
                                mark_mod_union_card ((full_object), (void**)(ptr), __old); \
                        }                                               \
                } while (0)
@@ -261,7 +261,7 @@ SCAN_OBJECT_FUNCTION_NAME (GCObject *full_object, SgenDescriptor desc, SgenGrayQ
                        PREFETCH_READ (__old);                  \
                        COPY_OR_MARK_FUNCTION_NAME ((ptr), __old, queue); \
                } else {                                                \
-                       if (G_UNLIKELY (sgen_ptr_in_nursery (__old) && !sgen_ptr_in_nursery ((ptr)) && !sgen_cement_is_forced (__old))) \
+                       if (G_UNLIKELY (full_object && sgen_ptr_in_nursery (__old) && !sgen_ptr_in_nursery ((ptr)) && !sgen_cement_is_forced (__old))) \
                                mark_mod_union_card ((full_object), (void**)(ptr), __old); \
                        }                                               \
                } while (0)
@@ -310,6 +310,12 @@ SCAN_VTYPE_FUNCTION_NAME (GCObject *full_object, char *start, SgenDescriptor des
 static void
 SCAN_PTR_FIELD_FUNCTION_NAME (GCObject *full_object, GCObject **ptr, SgenGrayQueue *queue)
 {
+       /*
+        * full_object is NULL if we scan unmanaged memory. This means we can't mark
+        * mod unions for it, so these types of roots currently don't have support
+        * for the concurrent collector (aka they need to be scanned as normal roots
+        * both in the start and finishing pause)
+        */
        HANDLE_PTR (ptr, NULL);
 }
 #endif
index b280749a46a3dd8f9d045cd6de5e6ae7ee4a7e16..5c4ec06a9ebda9b21afd80477086a42fe303ba00 100644 (file)
@@ -2809,6 +2809,7 @@ sgen_marksweep_init_internal (SgenMajorCollector *collector, gboolean is_concurr
 
        collector->major_ops_serial.copy_or_mark_object = major_copy_or_mark_object_canonical;
        collector->major_ops_serial.scan_object = major_scan_object_with_evacuation;
+       collector->major_ops_serial.scan_ptr_field = major_scan_ptr_field_with_evacuation;
        collector->major_ops_serial.drain_gray_stack = drain_gray_stack;
        if (is_concurrent) {
                collector->major_ops_concurrent_start.copy_or_mark_object = major_copy_or_mark_object_concurrent_canonical;
index 9b92493191ed1a08bad915c7ab7df8ecd6a5fcb5..9f5fd6addb19608c19acb1a7549eecf7000af369 100644 (file)
@@ -114,7 +114,7 @@ mono_conc_hashtable_new (GHashFunc hash_func, GEqualFunc key_equal_func)
 {
        MonoConcurrentHashTable *res = g_new0 (MonoConcurrentHashTable, 1);
        res->hash_func = hash_func ? hash_func : g_direct_hash;
-       res->equal_func = key_equal_func ? key_equal_func : g_direct_equal;
+       res->equal_func = key_equal_func;
        // res->equal_func = g_direct_equal;
        res->table = conc_table_new (INITIAL_SIZE);
        res->element_count = 0;