[dtrace] GC heap allocation probes for SGen.
[mono.git] / mono / metadata / sgen-major-copying.c
index 6b8cad2d00767288ed235bc071c69797987468a7..d1737a6b787b6630f0779dcdf7499eafc1463e90 100644 (file)
@@ -57,6 +57,7 @@
 #include "metadata/mono-gc.h"
 #include "metadata/object-internals.h"
 #include "metadata/profiler-private.h"
+#include "metadata/sgen-memory-governor.h"
 
 #define MAJOR_SECTION_SIZE             SGEN_PINNED_CHUNK_SIZE
 #define BLOCK_FOR_OBJECT(o)            SGEN_PINNED_CHUNK_FOR_PTR ((o))
@@ -97,9 +98,9 @@ static void*
 major_alloc_heap (mword nursery_size, mword nursery_align, int the_nursery_bits)
 {
        if (nursery_align)
-               nursery_start = sgen_alloc_os_memory_aligned (nursery_size, nursery_align, TRUE);
+               nursery_start = sgen_alloc_os_memory_aligned (nursery_size, nursery_align, TRUE, TRUE, "nursery");
        else
-               nursery_start = sgen_alloc_os_memory (nursery_size, TRUE);
+               nursery_start = sgen_alloc_os_memory (nursery_size, TRUE, TRUE, "nursery");
 
        nursery_end = nursery_start + nursery_size;
        nursery_bits = the_nursery_bits;
@@ -128,15 +129,15 @@ alloc_major_section (void)
        GCMemSection *section;
        int scan_starts;
 
-       section = sgen_alloc_os_memory_aligned (MAJOR_SECTION_SIZE, MAJOR_SECTION_SIZE, TRUE);
+       section = sgen_alloc_os_memory_aligned (MAJOR_SECTION_SIZE, MAJOR_SECTION_SIZE, TRUE, TRUE, "major heap section");
        section->next_data = section->data = (char*)section + SGEN_SIZEOF_GC_MEM_SECTION;
        g_assert (!((mword)section->data & 7));
        section->size = MAJOR_SECTION_SIZE - SGEN_SIZEOF_GC_MEM_SECTION;
        section->end_data = section->data + section->size;
        sgen_update_heap_boundaries ((mword)section->data, (mword)section->end_data);
-       DEBUG (3, fprintf (gc_debug_file, "New major heap section: (%p-%p), total: %ld\n", section->data, section->end_data, mono_gc_get_heap_size ()));
+       DEBUG (3, fprintf (gc_debug_file, "New major heap section: (%p-%p), total: %lld\n", section->data, section->end_data, (long long int)mono_gc_get_heap_size ()));
        scan_starts = (section->size + SGEN_SCAN_START_SIZE - 1) / SGEN_SCAN_START_SIZE;
-       section->scan_starts = sgen_alloc_internal_dynamic (sizeof (char*) * scan_starts, INTERNAL_MEM_SCAN_STARTS);
+       section->scan_starts = sgen_alloc_internal_dynamic (sizeof (char*) * scan_starts, INTERNAL_MEM_SCAN_STARTS, TRUE);
        section->num_scan_start = scan_starts;
        section->block.role = MEMORY_ROLE_GEN1;
        section->is_to_space = TRUE;
@@ -156,7 +157,7 @@ free_major_section (GCMemSection *section)
        DEBUG (3, fprintf (gc_debug_file, "Freed major section %p (%p-%p)\n", section, section->data, section->end_data));
        sgen_free_internal_dynamic (section->scan_starts,
                        (section->size + SGEN_SCAN_START_SIZE - 1) / SGEN_SCAN_START_SIZE * sizeof (char*), INTERNAL_MEM_SCAN_STARTS);
-       sgen_free_os_memory (section, MAJOR_SECTION_SIZE);
+       sgen_free_os_memory (section, MAJOR_SECTION_SIZE, TRUE);
 
        --num_major_sections;
 }
@@ -279,7 +280,11 @@ major_alloc_degraded (MonoVTable *vtable, size_t size)
        return p;
 }
 
-#define pin_major_object       sgen_pin_object
+static inline void
+pin_major_object (char *obj, SgenGrayQueue *queue)
+{
+       sgen_pin_object (obj, queue);
+}
 
 #include "sgen-major-copy-object.h"
 
@@ -310,8 +315,8 @@ major_copy_or_mark_object (void **obj_slot, SgenGrayQueue *queue)
         *
         * Before we can copy the object we must make sure that we are
         * allowed to, i.e. that the object not pinned, not already
-        * forwarded and doesn't belong to the LOS, a pinned chunk, or
-        * a to-space section.
+        * forwarded, not in the nursery To Space and doesn't belong
+        * to the LOS, a pinned chunk, or a to-space section.
         *
         * We are usually called for to-space objects (5) when we have
         * two remset entries for the same reference.  The first entry
@@ -336,6 +341,7 @@ major_copy_or_mark_object (void **obj_slot, SgenGrayQueue *queue)
        }
 
        if (ptr_in_nursery (obj)) {
+               /* A To Space object is already on its final destination for the current collection. */
                if (sgen_nursery_is_to_space (obj))
                        return;
                goto copy;
@@ -362,7 +368,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, sgen_safe_name (obj), objsize));
+               DEBUG (9, fprintf (gc_debug_file, " (marked LOS/Pinned %p (%s), size: %td)\n", obj, sgen_safe_name (obj), objsize));
                binary_protocol_pin (obj, (gpointer)SGEN_LOAD_VTABLE (obj), sgen_safe_object_get_size ((MonoObject*)obj));
                SGEN_PIN_OBJECT (obj);
                GRAY_OBJECT_ENQUEUE (queue, obj);
@@ -673,6 +679,7 @@ sgen_copying_init (SgenMajorCollector *collector)
        collector->free_non_pinned_object = major_free_non_pinned_object;
        collector->find_pin_queue_start_ends = major_find_pin_queue_start_ends;
        collector->pin_objects = major_pin_objects;
+       collector->pin_major_object = pin_major_object;
        collector->init_to_space = major_init_to_space;
        collector->sweep = major_sweep;
        collector->check_scan_starts = major_check_scan_starts;
@@ -689,8 +696,7 @@ sgen_copying_init (SgenMajorCollector *collector)
        collector->print_gc_param_usage = NULL;
 
        collector->major_ops.copy_or_mark_object = major_copy_or_mark_object;
-       FILL_COLLECTOR_COPY_OBJECT (collector);
-       FILL_COLLECTOR_SCAN_OBJECT (collector);
+       collector->major_ops.scan_object = major_scan_object;
 }
 
 #endif