Merge pull request #463 from strawd/concurrent-requests
[mono.git] / mono / metadata / sgen-tarjan-bridge.c
index fec1d697ca27c4e3eaf92fef781b2356351a0bae..9537c0710bee73f26bb018c8df30d9f349825e4d 100644 (file)
 
 #include <stdlib.h>
 
-#include "sgen-gc.h"
-#include "sgen-bridge.h"
-#include "sgen-hash-table.h"
-#include "sgen-qsort.h"
+#include "sgen/sgen-gc.h"
+#include "sgen-bridge-internal.h"
+#include "sgen/sgen-hash-table.h"
+#include "sgen/sgen-qsort.h"
 #include "tabledefs.h"
 #include "utils/mono-logger-internal.h"
-#include "utils/mono-time.h"
-#include "utils/mono-compiler.h"
-
 
 typedef struct {
        int size;
@@ -67,14 +64,6 @@ typedef struct {
 
 /* private */
 
-static void
-dyn_array_init (DynArray *da)
-{
-       da->size = 0;
-       da->capacity = 0;
-       da->data = NULL;
-}
-
 static void
 dyn_array_uninit (DynArray *da, int elem_size)
 {
@@ -121,12 +110,6 @@ dyn_array_add (DynArray *da, int elem_size)
 
 /* ptr */
 
-static void
-dyn_array_ptr_init (DynPtrArray *da)
-{
-       dyn_array_init (&da->array);
-}
-
 static void
 dyn_array_ptr_uninit (DynPtrArray *da)
 {
@@ -248,7 +231,7 @@ typedef struct {
 
 
 typedef struct {
-       MonoObject *obj; //XXX this can be eliminated.
+       GCObject *obj; //XXX this can be eliminated.
        mword lock_word;
 
        ColorData *color;
@@ -390,10 +373,10 @@ retry:
 static void
 free_color_buckets (void)
 {
-       color_data_count = 0;
-
        ColorBucket *cur, *tmp;
 
+       color_data_count = 0;
+
        for (cur = root_color_bucket; cur; cur = tmp) {
                ColorData *cd;
                for (cd = &cur->data [0]; cd < cur->next_data; ++cd) {
@@ -408,7 +391,7 @@ free_color_buckets (void)
 
 
 static ScanData*
-create_data (MonoObject *obj)
+create_data (GCObject *obj)
 {
        mword *o = (mword*)obj;
        ScanData *res = alloc_object_data ();
@@ -424,7 +407,7 @@ create_data (MonoObject *obj)
 }
 
 static ScanData*
-find_data (MonoObject *obj)
+find_data (GCObject *obj)
 {
        ScanData *a = NULL;
        mword *o = (mword*)obj;
@@ -449,10 +432,10 @@ clear_after_processing (void)
        }
 }
 
-static MonoObject*
-bridge_object_forward (MonoObject *obj)
+static GCObject*
+bridge_object_forward (GCObject *obj)
 {
-       MonoObject *fwd;
+       GCObject *fwd;
        mword *o = (mword*)obj;
        if ((o [0] & SGEN_VTABLE_BITS_MASK) == SGEN_VTABLE_BITS_MASK)
                return obj;
@@ -461,22 +444,23 @@ bridge_object_forward (MonoObject *obj)
        return fwd ? fwd : obj;
 }
 
+#ifdef DUMP_GRAPH
 static const char*
-safe_name_bridge (MonoObject *obj)
+safe_name_bridge (GCObject *obj)
 {
-       MonoVTable *vt = (MonoVTable*)SGEN_LOAD_VTABLE (obj);
+       GCVTable vt = SGEN_LOAD_VTABLE (obj);
        return vt->klass->name;
 }
 
 static ScanData*
-find_or_create_data (MonoObject *obj)
+find_or_create_data (GCObject *obj)
 {
        ScanData *entry = find_data (obj);
        if (!entry)
                entry = create_data (obj);
        return entry;
 }
-
+#endif
 
 //----------
 typedef struct {
@@ -502,7 +486,7 @@ static HashEntry merge_cache [COLOR_CACHE_SIZE][ELEMENTS_PER_BUCKET];
 static int
 mix_hash (size_t hash)
 {
-       return ((hash * 215497) >> 16) ^ (hash * 1823231) + hash;
+       return (int)(((hash * 215497) >> 16) ^ ((hash * 1823231) + hash));
 }
 
 static void
@@ -599,15 +583,15 @@ new_color (gboolean force_new)
 
 
 static void
-register_bridge_object (MonoObject *obj)
+register_bridge_object (GCObject *obj)
 {
        create_data (obj)->is_bridge = TRUE;
 }
 
 static gboolean
-is_opaque_object (MonoObject *obj)
+is_opaque_object (GCObject *obj)
 {
-       MonoVTable *vt = (MonoVTable*)SGEN_LOAD_VTABLE (obj);
+       MonoVTable *vt = SGEN_LOAD_VTABLE (obj);
        if ((vt->gc_bits & SGEN_GC_BIT_BRIDGE_OPAQUE_OBJECT) == SGEN_GC_BIT_BRIDGE_OPAQUE_OBJECT) {
                SGEN_LOG (6, "ignoring %s\n", vt->klass->name);
                ++ignored_objects;
@@ -617,7 +601,7 @@ is_opaque_object (MonoObject *obj)
 }
 
 static void
-push_object (MonoObject *obj)
+push_object (GCObject *obj)
 {
        ScanData *data;
        obj = bridge_object_forward (obj);
@@ -665,26 +649,27 @@ push_object (MonoObject *obj)
 
 #undef HANDLE_PTR
 #define HANDLE_PTR(ptr,obj)    do {                                    \
-               MonoObject *dst = (MonoObject*)*(ptr);                  \
+               GCObject *dst = (GCObject*)*(ptr);                      \
                if (dst) push_object (dst);                     \
        } while (0)
 
 static void
 push_all (ScanData *data)
 {
-       MonoObject *obj = data->obj;
+       GCObject *obj = data->obj;
        char *start = (char*)obj;
+       mword desc = sgen_obj_get_descriptor_safe (obj);
 
 #if DUMP_GRAPH
        printf ("**scanning %p %s\n", obj, safe_name_bridge (obj));
 #endif
 
-       #include "sgen-scan-object.h"
+       #include "sgen/sgen-scan-object.h"
 }
 
 
 static void
-compute_low_index (ScanData *data, MonoObject *obj)
+compute_low_index (ScanData *data, GCObject *obj)
 {
        ScanData *other;
        ColorData *cd;
@@ -716,17 +701,18 @@ compute_low_index (ScanData *data, MonoObject *obj)
 
 #undef HANDLE_PTR
 #define HANDLE_PTR(ptr,obj)    do {                                    \
-               MonoObject *dst = (MonoObject*)*(ptr);                  \
+               GCObject *dst = (GCObject*)*(ptr);                      \
                if (dst) compute_low_index (data, dst);                         \
        } while (0)
 
 static void
 compute_low (ScanData *data)
 {
-       MonoObject *obj = data->obj;
+       GCObject *obj = data->obj;
        char *start = (char*)obj;
+       mword desc = sgen_obj_get_descriptor_safe (obj);
 
-       #include "sgen-scan-object.h"
+       #include "sgen/sgen-scan-object.h"
 }
 
 static ColorData*
@@ -883,7 +869,7 @@ dfs (void)
 }
 
 static void
-register_finalized_object (MonoObject *obj)
+register_finalized_object (GCObject *obj)
 {
        g_assert (sgen_need_bridge_processing ());
        dyn_array_ptr_push (&registered_bridges, obj);
@@ -908,6 +894,7 @@ cleanup (void)
        num_colors_with_bridges = 0;
 }
 
+#ifdef DUMP_GRAPH
 static void
 dump_color_table (const char *why, gboolean do_index)
 {
@@ -928,7 +915,7 @@ dump_color_table (const char *why, gboolean do_index)
                        if (dyn_array_ptr_size (&cd->bridges)) {
                                printf (" bridges: ");
                                for (j = 0; j < dyn_array_ptr_size (&cd->bridges); ++j) {
-                                       MonoObject *obj = dyn_array_ptr_get (&cd->bridges, j);
+                                       GCObject *obj = dyn_array_ptr_get (&cd->bridges, j);
                                        ScanData *data = find_or_create_data (obj);
                                        printf ("%d ", data->index);
                                }
@@ -938,6 +925,7 @@ dump_color_table (const char *why, gboolean do_index)
        }
 
 }
+#endif
 
 static gint64
 step_timer (gint64 *timer)
@@ -1036,16 +1024,6 @@ reset_xrefs (ColorData *color)
        }
 }
 
-static mono_bool
-is_bridge_object_alive (MonoObject *obj, void *data)
-{
-       SgenHashTable *table = data;
-       unsigned char *value = sgen_hash_table_lookup (table, obj);
-       if (!value)
-               return TRUE;
-       return *value;
-}
-
 static void
 processing_build_callback_data (int generation)
 {
@@ -1186,7 +1164,7 @@ processing_after_callback (int generation)
 }
 
 static void
-describe_pointer (MonoObject *obj)
+describe_pointer (GCObject *obj)
 {
        // HashEntry *entry;
        int i;