[sgen] Remove obsolete check in #ifdef.
[mono.git] / mono / metadata / sgen-toggleref.c
index 10f263affe5e992b90b066a37a8c18886804d855..4709ccfeef6cd3a9cd19dd1bb175019594916f08 100644 (file)
@@ -90,12 +90,13 @@ sgen_process_togglerefs (void)
                w);
 }
 
-void
-sgen_scan_togglerefs (CopyOrMarkObjectFunc copy_func, char *start, char *end, SgenGrayQueue *queue)
+void sgen_mark_togglerefs (char *start, char *end, ScanCopyContext ctx)
 {
+       CopyOrMarkObjectFunc copy_func = ctx.copy_func;
+       SgenGrayQueue *queue = ctx.queue;
        int i;
 
-       SGEN_LOG (4, "Scanning ToggleRefs %d", toggleref_array_size);
+       SGEN_LOG (4, "Marking ToggleRefs %d", toggleref_array_size);
 
        for (i = 0; i < toggleref_array_size; ++i) {
                if (toggleref_array [i].strong_ref) {
@@ -104,7 +105,21 @@ sgen_scan_togglerefs (CopyOrMarkObjectFunc copy_func, char *start, char *end, Sg
                                SGEN_LOG (6, "\tcopying strong slot %d", i);
                                copy_func (&toggleref_array [i].strong_ref, queue);
                        }
-               } else if (toggleref_array [i].weak_ref) {
+               }
+       }
+       sgen_drain_gray_stack (-1, ctx);
+}
+
+void sgen_clear_togglerefs (char *start, char *end, ScanCopyContext ctx)
+{
+       CopyOrMarkObjectFunc copy_func = ctx.copy_func;
+       SgenGrayQueue *queue = ctx.queue;
+       int i;
+
+       SGEN_LOG (4, "Clearing ToggleRefs %d", toggleref_array_size);
+
+       for (i = 0; i < toggleref_array_size; ++i) {
+               if (toggleref_array [i].weak_ref) {
                        char *object = toggleref_array [i].weak_ref;
 
                        if (object >= start && object < end) {
@@ -118,6 +133,7 @@ sgen_scan_togglerefs (CopyOrMarkObjectFunc copy_func, char *start, char *end, Sg
                        }
                }
        }
+       sgen_drain_gray_stack (-1, ctx);
 }
 
 static void
@@ -134,7 +150,7 @@ ensure_toggleref_capacity (int capacity)
                MonoGCToggleRef *tmp;
                int old_capacity = toggleref_array_capacity;
                while (toggleref_array_capacity < toggleref_array_size + capacity)
-                       toggleref_array_size *= 2;
+                       toggleref_array_capacity *= 2;
 
                tmp = sgen_alloc_internal_dynamic (
                        toggleref_array_capacity * sizeof (MonoGCToggleRef),
@@ -189,4 +205,26 @@ mono_gc_toggleref_register_callback (MonoToggleRefStatus (*proccess_toggleref) (
        toggleref_callback = proccess_toggleref;
 }
 
+static MonoToggleRefStatus
+test_toggleref_callback (MonoObject *obj)
+{
+       static MonoClassField *mono_toggleref_test_field;
+       int status = MONO_TOGGLE_REF_DROP;
+
+       if (!mono_toggleref_test_field) {
+               mono_toggleref_test_field = mono_class_get_field_from_name (mono_object_get_class (obj), "__test");
+               g_assert (mono_toggleref_test_field);
+       }
+
+       mono_field_get_value (obj, mono_toggleref_test_field, &status);
+       printf ("toggleref-cb obj %d\n", status);
+       return status;
+}
+
+void
+sgen_register_test_toggleref_callback (void)
+{
+       toggleref_callback = test_toggleref_callback;
+}
+
 #endif