Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/mono.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVlad Brezae <brezaevlad@gmail.com>2017-02-28 15:30:18 +0300
committerGitHub <noreply@github.com>2017-02-28 15:30:18 +0300
commitd899b02874a476290f6e8cd54d40e0eaba2ecf04 (patch)
tree5f361ab655b8361268628c680b96aa65df0a78bc
parent2a239b5205f9a73b9c800f079fc008d78b6446a3 (diff)
parentea9d8f02a99c19d1194e74bfaf9e5e55ef7ff72d (diff)
Merge pull request #4381 from BrzVlad/feature-generational-hash
[sgen] Generational MonoGHashTable
-rw-r--r--mono/metadata/boehm-gc.c6
-rw-r--r--mono/metadata/domain.c2
-rw-r--r--mono/metadata/metadata.c3
-rw-r--r--mono/metadata/mono-hash.c470
-rw-r--r--mono/metadata/mono-hash.h2
-rw-r--r--mono/metadata/null-gc.c6
-rw-r--r--mono/metadata/reflection.c5
-rw-r--r--mono/metadata/sgen-mono.c74
-rw-r--r--mono/metadata/threadpool-io.c2
-rw-r--r--mono/mini/debugger-agent.c4
-rw-r--r--mono/sgen/gc-internal-agnostic.h3
-rw-r--r--mono/sgen/sgen-cardtable.c65
-rw-r--r--mono/sgen/sgen-cardtable.h1
-rw-r--r--mono/sgen/sgen-debug.c18
-rw-r--r--mono/sgen/sgen-descriptor.c6
-rw-r--r--mono/sgen/sgen-descriptor.h1
-rw-r--r--mono/sgen/sgen-gc.c115
-rw-r--r--mono/sgen/sgen-gc.h3
-rw-r--r--mono/sgen/sgen-marksweep-drain-gray-stack.h12
-rw-r--r--mono/sgen/sgen-marksweep.c1
-rw-r--r--mono/utils/mono-conc-hashtable.c2
21 files changed, 480 insertions, 321 deletions
diff --git a/mono/metadata/boehm-gc.c b/mono/metadata/boehm-gc.c
index dcfd310f649..f0fa3579f72 100644
--- a/mono/metadata/boehm-gc.c
+++ b/mono/metadata/boehm-gc.c
@@ -618,6 +618,12 @@ mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits)
}
void*
+mono_gc_make_vector_descr (void)
+{
+ return NULL;
+}
+
+void*
mono_gc_make_root_descr_all_refs (int numbits)
{
return NULL;
diff --git a/mono/metadata/domain.c b/mono/metadata/domain.c
index 810d4119791..0785369e0c6 100644
--- a/mono/metadata/domain.c
+++ b/mono/metadata/domain.c
@@ -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);
diff --git a/mono/metadata/metadata.c b/mono/metadata/metadata.c
index 7ef3b74c5eb..545b917177b 100644
--- a/mono/metadata/metadata.c
+++ b/mono/metadata/metadata.c
@@ -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;
}
/*
diff --git a/mono/metadata/mono-hash.c b/mono/metadata/mono-hash.c
index 00f7afab0cc..9c6cdb44101 100644
--- a/mono/metadata/mono-hash.c
+++ b/mono/metadata/mono-hash.c
@@ -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)))
@@ -44,49 +46,20 @@
#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
diff --git a/mono/metadata/mono-hash.h b/mono/metadata/mono-hash.h
index 60c3328a238..dca17694f8e 100644
--- a/mono/metadata/mono-hash.h
+++ b/mono/metadata/mono-hash.h
@@ -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);
diff --git a/mono/metadata/null-gc.c b/mono/metadata/null-gc.c
index 9ea87bd844c..4ee7dd7c9c4 100644
--- a/mono/metadata/null-gc.c
+++ b/mono/metadata/null-gc.c
@@ -165,6 +165,12 @@ mono_gc_make_descr_from_bitmap (gsize *bitmap, int numbits)
}
void*
+mono_gc_make_vector_descr (void)
+{
+ return NULL;
+}
+
+void*
mono_gc_make_root_descr_all_refs (int numbits)
{
return NULL;
diff --git a/mono/metadata/reflection.c b/mono/metadata/reflection.c
index fbcce02c18c..43843be4a5a 100644
--- a/mono/metadata/reflection.c
+++ b/mono/metadata/reflection.c
@@ -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;
}
diff --git a/mono/metadata/sgen-mono.c b/mono/metadata/sgen-mono.c
index e8dd50b13d7..1964c55b064 100644
--- a/mono/metadata/sgen-mono.c
+++ b/mono/metadata/sgen-mono.c
@@ -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;
diff --git a/mono/metadata/threadpool-io.c b/mono/metadata/threadpool-io.c
index 618d995dceb..4f4fa7b1559 100644
--- a/mono/metadata/threadpool-io.c
+++ b/mono/metadata/threadpool-io.c
@@ -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;
diff --git a/mono/mini/debugger-agent.c b/mono/mini/debugger-agent.c
index 8f120de8683..ed1b7a14a7f 100644
--- a/mono/mini/debugger-agent.c
+++ b/mono/mini/debugger-agent.c
@@ -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
diff --git a/mono/sgen/gc-internal-agnostic.h b/mono/sgen/gc-internal-agnostic.h
index 62039f72679..dc9b091bf6f 100644
--- a/mono/sgen/gc-internal-agnostic.h
+++ b/mono/sgen/gc-internal-agnostic.h
@@ -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);
diff --git a/mono/sgen/sgen-cardtable.c b/mono/sgen/sgen-cardtable.c
index cf89aedad4f..0138669a788 100644
--- a/mono/sgen/sgen-cardtable.c
+++ b/mono/sgen/sgen-cardtable.c
@@ -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)
{
diff --git a/mono/sgen/sgen-cardtable.h b/mono/sgen/sgen-cardtable.h
index 059fb77fa64..a4fa1e32b6e 100644
--- a/mono/sgen/sgen-cardtable.h
+++ b/mono/sgen/sgen-cardtable.h
@@ -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);
diff --git a/mono/sgen/sgen-debug.c b/mono/sgen/sgen-debug.c
index 195894f8cbf..a78fb3dad57 100644
--- a/mono/sgen/sgen-debug.c
+++ b/mono/sgen/sgen-debug.c
@@ -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);
diff --git a/mono/sgen/sgen-descriptor.c b/mono/sgen/sgen-descriptor.c
index 248b07b8f50..f358c9da429 100644
--- a/mono/sgen/sgen-descriptor.c
+++ b/mono/sgen/sgen-descriptor.c
@@ -276,6 +276,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)
{
gsize *gc_bitmap;
diff --git a/mono/sgen/sgen-descriptor.h b/mono/sgen/sgen-descriptor.h
index 54e1b7681fb..e072ca45d32 100644
--- a/mono/sgen/sgen-descriptor.h
+++ b/mono/sgen/sgen-descriptor.h
@@ -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,
diff --git a/mono/sgen/sgen-gc.c b/mono/sgen/sgen-gc.c
index 7c02172c6ee..ec27de4224b 100644
--- a/mono/sgen/sgen-gc.c
+++ b/mono/sgen/sgen-gc.c
@@ -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)
diff --git a/mono/sgen/sgen-gc.h b/mono/sgen/sgen-gc.h
index ba7aee72940..a89a5471dd7 100644
--- a/mono/sgen/sgen-gc.h
+++ b/mono/sgen/sgen-gc.h
@@ -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);
diff --git a/mono/sgen/sgen-marksweep-drain-gray-stack.h b/mono/sgen/sgen-marksweep-drain-gray-stack.h
index 6eb4d266fdc..98d8917593c 100644
--- a/mono/sgen/sgen-marksweep-drain-gray-stack.h
+++ b/mono/sgen/sgen-marksweep-drain-gray-stack.h
@@ -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
diff --git a/mono/sgen/sgen-marksweep.c b/mono/sgen/sgen-marksweep.c
index b280749a46a..5c4ec06a9eb 100644
--- a/mono/sgen/sgen-marksweep.c
+++ b/mono/sgen/sgen-marksweep.c
@@ -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;
diff --git a/mono/utils/mono-conc-hashtable.c b/mono/utils/mono-conc-hashtable.c
index 9b92493191e..9f5fd6addb1 100644
--- a/mono/utils/mono-conc-hashtable.c
+++ b/mono/utils/mono-conc-hashtable.c
@@ -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;