Merge pull request #2216 from akoeplinger/fix-array-sort
[mono.git] / mono / metadata / sgen-tarjan-bridge.c
index 5c6525e9ec71723050687a7e8e4c0fd577d140c5..910fa9bf1fc582de56b904463ba62d72d95be964 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;
@@ -182,28 +179,28 @@ enable_accounting (void)
 }
 
 static MonoGCBridgeObjectKind
-class_kind (MonoClass *class)
+class_kind (MonoClass *klass)
 {
-       MonoGCBridgeObjectKind res = bridge_callbacks.bridge_class_kind (class);
+       MonoGCBridgeObjectKind res = bridge_callbacks.bridge_class_kind (klass);
 
        /* If it's a bridge, nothing we can do about it. */
        if (res == GC_BRIDGE_TRANSPARENT_BRIDGE_CLASS || res == GC_BRIDGE_OPAQUE_BRIDGE_CLASS)
                return res;
 
        /* Non bridge classes with no pointers will never point to a bridge, so we can savely ignore them. */
-       if (!class->has_references) {
-               SGEN_LOG (6, "class %s is opaque\n", class->name);
+       if (!klass->has_references) {
+               SGEN_LOG (6, "class %s is opaque\n", klass->name);
                return GC_BRIDGE_OPAQUE_CLASS;
        }
 
        /* Some arrays can be ignored */
-       if (class->rank == 1) {
-               MonoClass *elem_class = class->element_class;
+       if (klass->rank == 1) {
+               MonoClass *elem_class = klass->element_class;
 
                /* FIXME the bridge check can be quite expensive, cache it at the class level. */
                /* An array of a sealed type that is not a bridge will never get to a bridge */
                if ((elem_class->flags & TYPE_ATTRIBUTE_SEALED) && !elem_class->has_references && !bridge_callbacks.bridge_class_kind (elem_class)) {
-                       SGEN_LOG (6, "class %s is opaque\n", class->name);
+                       SGEN_LOG (6, "class %s is opaque\n", klass->name);
                        return GC_BRIDGE_OPAQUE_CLASS;
                }
        }
@@ -234,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;
@@ -394,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 ();
@@ -410,7 +407,7 @@ create_data (MonoObject *obj)
 }
 
 static ScanData*
-find_data (MonoObject *obj)
+find_data (GCObject *obj)
 {
        ScanData *a = NULL;
        mword *o = (mword*)obj;
@@ -435,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;
@@ -449,14 +446,14 @@ bridge_object_forward (MonoObject *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)
@@ -586,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;
@@ -604,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);
@@ -652,27 +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 (start);
+       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;
@@ -704,18 +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 (start);
+       mword desc = sgen_obj_get_descriptor_safe (obj);
 
-       #include "sgen-scan-object.h"
+       #include "sgen/sgen-scan-object.h"
 }
 
 static ColorData*
@@ -872,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);
@@ -918,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);
                                }
@@ -1167,7 +1164,7 @@ processing_after_callback (int generation)
 }
 
 static void
-describe_pointer (MonoObject *obj)
+describe_pointer (GCObject *obj)
 {
        // HashEntry *entry;
        int i;