[threadpool] Remove assertion on RequestWorkerThread failure (#4167)
[mono.git] / mono / sgen / sgen-descriptor.c
index b30ab4334bc84338e9d65132da2b88df04911a43..248b07b8f50fff935da561c90488a52af682ac17 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "mono/sgen/sgen-gc.h"
 #include "mono/sgen/gc-internal-agnostic.h"
+#include "mono/sgen/sgen-array-list.h"
 
 #define MAX_USER_DESCRIPTORS 16
 
@@ -40,9 +41,7 @@
 #define ALIGN_TO(val,align) ((((guint64)val) + ((align) - 1)) & ~((align) - 1))
 
 
-static gsize* complex_descriptors = NULL;
-static int complex_descriptors_size = 0;
-static int complex_descriptors_next = 0;
+static SgenArrayList complex_descriptors = SGEN_ARRAY_LIST_INIT (NULL, NULL, NULL, INTERNAL_MEM_COMPLEX_DESCRIPTORS);
 static SgenUserRootMarkFunc user_descriptors [MAX_USER_DESCRIPTORS];
 static int user_descriptors_next = 0;
 static SgenDescriptor all_ref_root_descrs [32];
@@ -56,6 +55,8 @@ static int
 alloc_complex_descriptor (gsize *bitmap, int numbits)
 {
        int nwords, res, i;
+       volatile gpointer *slot;
+       gsize *descriptor;
 
        SGEN_ASSERT (0, sizeof (gsize) == sizeof (mword), "We expect gsize and mword to have same size");
 
@@ -63,38 +64,41 @@ alloc_complex_descriptor (gsize *bitmap, int numbits)
        nwords = numbits / GC_BITS_PER_WORD + 1;
 
        sgen_gc_lock ();
-       res = complex_descriptors_next;
        /* linear search, so we don't have duplicates with domain load/unload
         * this should not be performance critical or we'd have bigger issues
         * (the number and size of complex descriptors should be small).
         */
-       for (i = 0; i < complex_descriptors_next; ) {
-               if (complex_descriptors [i] == nwords) {
+       SGEN_ARRAY_LIST_FOREACH_SLOT (&complex_descriptors, slot) {
+               gsize first_word = *(gsize*)slot;
+               if (first_word == 0) {
+                       /* Unused slots should be 0 so we simply skip them */
+                       continue;
+               } else if (first_word == nwords) {
                        int j, found = TRUE;
                        for (j = 0; j < nwords - 1; ++j) {
-                               if (complex_descriptors [i + 1 + j] != bitmap [j]) {
+                               if (((gsize*)slot) [j + 1] != bitmap [j]) {
                                        found = FALSE;
                                        break;
                                }
                        }
                        if (found) {
                                sgen_gc_unlock ();
-                               return i;
+                               return __index;
                        }
                }
-               i += (int)complex_descriptors [i];
-       }
-       if (complex_descriptors_next + nwords > complex_descriptors_size) {
-               int new_size = complex_descriptors_size * 2 + nwords;
-               complex_descriptors = (gsize *)g_realloc (complex_descriptors, new_size * sizeof (gsize));
-               complex_descriptors_size = new_size;
-       }
-       SGEN_LOG (6, "Complex descriptor %d, size: %d (total desc memory: %d)", res, nwords, complex_descriptors_size);
-       complex_descriptors_next += nwords;
-       complex_descriptors [res] = nwords;
+               /* Skip the bitmap words */
+               __index += (guint32)(first_word - 1);
+               __offset += (guint32)(first_word - 1);
+       } SGEN_ARRAY_LIST_END_FOREACH_SLOT;
+
+       res = sgen_array_list_alloc_block (&complex_descriptors, nwords);
+
+       SGEN_LOG (6, "Complex descriptor %d, size: %d (total desc memory: %d)", res, nwords, complex_descriptors.capacity);
+       descriptor = (gsize*)sgen_array_list_get_slot (&complex_descriptors, res);
+       descriptor [0] = nwords;
        for (i = 0; i < nwords - 1; ++i) {
-               complex_descriptors [res + 1 + i] = bitmap [i];
-               SGEN_LOG (6, "\tvalue: %p", (void*)complex_descriptors [res + 1 + i]);
+               descriptor [1 + i] = bitmap [i];
+               SGEN_LOG (6, "\tvalue: %p", (void*)descriptor [1 + i]);
        }
        sgen_gc_unlock ();
        return res;
@@ -103,7 +107,7 @@ alloc_complex_descriptor (gsize *bitmap, int numbits)
 gsize*
 sgen_get_complex_descriptor (SgenDescriptor desc)
 {
-       return complex_descriptors + (desc >> LOW_TYPE_BITS);
+       return (gsize*) sgen_array_list_get_slot (&complex_descriptors, desc >> LOW_TYPE_BITS);
 }
 
 /*
@@ -313,7 +317,7 @@ sgen_make_user_root_descriptor (SgenUserRootMarkFunc marker)
 void*
 sgen_get_complex_descriptor_bitmap (SgenDescriptor desc)
 {
-       return complex_descriptors + (desc >> ROOT_DESC_TYPE_SHIFT);
+       return (void*) sgen_array_list_get_slot (&complex_descriptors, desc >> ROOT_DESC_TYPE_SHIFT);
 }
 
 SgenUserRootMarkFunc