patch-quiet now works in systems with 'gsed'
[mono.git] / mono / metadata / sgen-major-copying.c
index d5409dbba8eef75c560e1cc6d8c88e43fbaec0ab..ce007aa8e39f2cabef9fb46df5775683cfe9c8b5 100644 (file)
@@ -53,8 +53,7 @@
 
 #include "metadata/sgen-gc.h"
 #include "metadata/sgen-protocol.h"
-
-#define DEBUG(l,x)
+#include "metadata/mono-gc.h"
 
 #define MAJOR_SECTION_SIZE             SGEN_PINNED_CHUNK_SIZE
 #define BLOCK_FOR_OBJECT(o)            SGEN_PINNED_CHUNK_FOR_PTR ((o))
@@ -68,6 +67,8 @@ static GCMemSection *section_list = NULL;
 
 static SgenInternalAllocator pinned_allocator;
 
+static gboolean have_swept;
+
 /*
  * used when moving the objects
  */
@@ -89,6 +90,20 @@ static long stat_major_copy_object_failed_large_pinned = 0;
 static long stat_major_copy_object_failed_to_space = 0;
 #endif
 
+static void*
+major_alloc_heap (mword nursery_size, mword nursery_align, int the_nursery_bits)
+{
+       if (nursery_align)
+               nursery_start = mono_sgen_alloc_os_memory_aligned (nursery_size, nursery_align, TRUE);
+       else
+               nursery_start = mono_sgen_alloc_os_memory (nursery_size, TRUE);
+
+       nursery_end = nursery_start + nursery_size;
+       nursery_bits = the_nursery_bits;
+
+       return nursery_start;
+}
+
 static gboolean
 obj_is_from_pinned_alloc (char *p)
 {
@@ -116,7 +131,7 @@ alloc_major_section (void)
        section->size = MAJOR_SECTION_SIZE - SGEN_SIZEOF_GC_MEM_SECTION;
        section->end_data = section->data + section->size;
        mono_sgen_update_heap_boundaries ((mword)section->data, (mword)section->end_data);
-       DEBUG (3, fprintf (gc_debug_file, "New major heap section: (%p-%p), total: %zd\n", section->data, section->end_data, total_alloc));
+       DEBUG (3, fprintf (gc_debug_file, "New major heap section: (%p-%p), total: %jd\n", section->data, section->end_data, mono_gc_get_heap_size ()));
        scan_starts = (section->size + SGEN_SCAN_START_SIZE - 1) / SGEN_SCAN_START_SIZE;
        section->scan_starts = mono_sgen_alloc_internal_dynamic (sizeof (char*) * scan_starts, INTERNAL_MEM_SCAN_STARTS);
        section->num_scan_start = scan_starts;
@@ -339,7 +354,7 @@ major_copy_or_mark_object (void **obj_slot, SgenGrayQueue *queue)
        if (G_UNLIKELY (objsize > SGEN_MAX_SMALL_OBJ_SIZE || obj_is_from_pinned_alloc (obj))) {
                if (SGEN_OBJECT_IS_PINNED (obj))
                        return;
-               DEBUG (9, fprintf (gc_debug_file, " (marked LOS/Pinned %p (%s), size: %zd)\n", obj, safe_name (obj), objsize));
+               DEBUG (9, fprintf (gc_debug_file, " (marked LOS/Pinned %p (%s), size: %zd)\n", obj, mono_sgen_safe_name (obj), objsize));
                binary_protocol_pin (obj, (gpointer)SGEN_LOAD_VTABLE (obj), mono_sgen_safe_object_get_size ((MonoObject*)obj));
                SGEN_PIN_OBJECT (obj);
                GRAY_OBJECT_ENQUEUE (queue, obj);
@@ -413,9 +428,9 @@ sweep_pinned_objects_callback (char *ptr, size_t size, void *data)
 {
        if (SGEN_OBJECT_IS_PINNED (ptr)) {
                SGEN_UNPIN_OBJECT (ptr);
-               DEBUG (6, fprintf (gc_debug_file, "Unmarked pinned object %p (%s)\n", ptr, safe_name (ptr)));
+               DEBUG (6, fprintf (gc_debug_file, "Unmarked pinned object %p (%s)\n", ptr, mono_sgen_safe_name (ptr)));
        } else {
-               DEBUG (6, fprintf (gc_debug_file, "Freeing unmarked pinned object %p (%s)\n", ptr, safe_name (ptr)));
+               DEBUG (6, fprintf (gc_debug_file, "Freeing unmarked pinned object %p (%s)\n", ptr, mono_sgen_safe_name (ptr)));
                free_pinned_object (ptr, size);
        }
 }
@@ -432,7 +447,7 @@ major_iterate_objects (gboolean non_pinned, gboolean pinned, IterateObjectCallba
        if (non_pinned) {
                GCMemSection *section;
                for (section = section_list; section; section = section->block.next)
-                       mono_sgen_scan_area_with_callback (section->data, section->end_data, callback, data);
+                       mono_sgen_scan_area_with_callback (section->data, section->end_data, callback, data, FALSE);
        }
        if (pinned)
                mono_sgen_internal_scan_objects (&pinned_allocator, callback, data);
@@ -452,7 +467,7 @@ pin_pinned_object_callback (void *addr, size_t slot_size, SgenGrayQueue *queue)
                mono_sgen_pin_stats_register_object ((char*) addr, mono_sgen_safe_object_get_size ((MonoObject*) addr));
        SGEN_PIN_OBJECT (addr);
        GRAY_OBJECT_ENQUEUE (queue, addr);
-       DEBUG (6, fprintf (gc_debug_file, "Marked pinned object %p (%s) from roots\n", addr, safe_name (addr)));
+       DEBUG (6, fprintf (gc_debug_file, "Marked pinned object %p (%s) from roots\n", addr, mono_sgen_safe_name (addr)));
 }
 
 static void
@@ -491,15 +506,19 @@ major_sweep (void)
        /* unpin objects from the pinned chunks and free the unmarked ones */
        sweep_pinned_objects ();
 
+       mono_sgen_internal_update_heap_boundaries (&pinned_allocator);
+
        /* free the unused sections */
        prev_section = NULL;
        for (section = section_list; section;) {
+               GCMemSection *this_section = section;
+
                /* to_space doesn't need handling here */
                if (section->is_to_space) {
                        section->is_to_space = FALSE;
                        prev_section = section;
                        section = section->block.next;
-                       continue;
+                       goto update;
                }
                /* no pinning object, so the section is free */
                if (!section->pin_queue_num_entries) {
@@ -519,7 +538,12 @@ major_sweep (void)
                }
                prev_section = section;
                section = section->block.next;
+
+       update:
+               mono_sgen_update_heap_boundaries ((mword)this_section->data, (mword)this_section->data + this_section->size);
        }
+
+       have_swept = TRUE;
 }
 
 static void
@@ -616,12 +640,8 @@ get_num_major_sections (void)
 }
 
 void
-mono_sgen_copying_init (SgenMajorCollector *collector, int the_nursery_bits, char *the_nursery_start, char *the_nursery_end)
+mono_sgen_copying_init (SgenMajorCollector *collector)
 {
-       nursery_bits = the_nursery_bits;
-       nursery_start = the_nursery_start;
-       nursery_end = the_nursery_end;
-
 #ifdef HEAVY_STATISTICS
        mono_counters_register ("# major copy_object() failed forwarded", MONO_COUNTER_GC | MONO_COUNTER_LONG, &stat_major_copy_object_failed_forwarded);
        mono_counters_register ("# major copy_object() failed pinned", MONO_COUNTER_GC | MONO_COUNTER_LONG, &stat_major_copy_object_failed_pinned);
@@ -630,7 +650,12 @@ mono_sgen_copying_init (SgenMajorCollector *collector, int the_nursery_bits, cha
 #endif
 
        collector->section_size = MAJOR_SECTION_SIZE;
+       collector->supports_cardtable = FALSE;
+       collector->is_parallel = FALSE;
+
+       collector->have_swept = &have_swept;
 
+       collector->alloc_heap = major_alloc_heap;
        collector->is_object_live = major_is_object_live;
        collector->alloc_small_pinned_obj = major_alloc_small_pinned_obj;
        collector->alloc_degraded = major_alloc_degraded;
@@ -653,6 +678,8 @@ mono_sgen_copying_init (SgenMajorCollector *collector, int the_nursery_bits, cha
        collector->obj_is_from_pinned_alloc = obj_is_from_pinned_alloc;
        collector->report_pinned_memory_usage = major_report_pinned_memory_usage;
        collector->get_num_major_sections = get_num_major_sections;
+       collector->handle_gc_param = NULL;
+       collector->print_gc_param_usage = NULL;
 
        FILL_COLLECTOR_COPY_OBJECT (collector);
        FILL_COLLECTOR_SCAN_OBJECT (collector);