#include "metadata/threads.h"
#include "metadata/sgen-gc.h"
#include "metadata/sgen-cardtable.h"
+#include "metadata/sgen-protocol.h"
#include "metadata/sgen-archdep.h"
+#include "metadata/sgen-bridge.h"
#include "metadata/mono-gc.h"
#include "metadata/method-builder.h"
#include "metadata/profiler-private.h"
*/
static int gc_initialized = 0;
-/* If set, do a minor collection before every allocation */
-static gboolean collect_before_allocs = FALSE;
+/* If set, do a minor collection before every X allocation */
+static guint32 collect_before_allocs = 0;
/* If set, do a heap consistency check before each minor collection */
static gboolean consistency_check_at_minor_collection = FALSE;
/* If set, check that there are no references to the domain left at domain unload */
/* If not null, dump the heap after each collection into this file */
static FILE *heap_dump_file = NULL;
/* If set, mark stacks conservatively, even if precise marking is possible */
-static gboolean conservative_stack_mark = TRUE;
+static gboolean conservative_stack_mark = FALSE;
/* If set, do a plausibility check on the scan_starts before and after
each collection */
static gboolean do_scan_starts_check = FALSE;
static int stat_wbarrier_object_copy = 0;
#endif
+static long long stat_pinned_objects = 0;
+
static long long time_minor_pre_collection_fragment_clear = 0;
static long long time_minor_pinning = 0;
static long long time_minor_scan_remsets = 0;
static void update_current_thread_stack (void *start);
static void finalize_in_range (CopyOrMarkObjectFunc copy_func, char *start, char *end, int generation, GrayQueue *queue);
static void add_or_remove_disappearing_link (MonoObject *obj, void **link, gboolean track, int generation);
-static void null_link_in_range (CopyOrMarkObjectFunc copy_func, char *start, char *end, int generation, GrayQueue *queue);
+static void null_link_in_range (CopyOrMarkObjectFunc copy_func, char *start, char *end, int generation, gboolean before_finalization, GrayQueue *queue);
static void null_links_for_domain (MonoDomain *domain, int generation);
static gboolean search_fragment_for_size (size_t size);
static int search_fragment_for_size_range (size_t desired_size, size_t minimum_size);
static void clear_remsets (void);
static void clear_tlabs (void);
static void sort_addresses (void **array, int size);
-static void drain_gray_stack (GrayQueue *queue);
+static gboolean drain_gray_stack (GrayQueue *queue, int max_objs);
static void finish_gray_stack (char *start_addr, char *end_addr, int generation, GrayQueue *queue);
static gboolean need_major_collection (mword space_needed);
static void major_collection (const char *reason);
SgenMajorCollector major_collector;
-#include "sgen-protocol.c"
#include "sgen-pinning.c"
#include "sgen-pinning-stats.c"
#include "sgen-gray.c"
obj = start;
}
- size = ALIGN_UP (safe_object_get_size (obj));
+ size = ALIGN_UP (safe_object_get_size ((MonoObject*)obj));
callback (obj, size, data);
* frequently after each object is copied, to achieve better locality and cache
* usage.
*/
-static void
-drain_gray_stack (GrayQueue *queue)
+static gboolean
+drain_gray_stack (GrayQueue *queue, int max_objs)
{
char *obj;
for (;;) {
GRAY_OBJECT_DEQUEUE (queue, obj);
if (!obj)
- break;
+ return TRUE;
DEBUG (9, fprintf (gc_debug_file, "Precise gray object scan %p (%s)\n", obj, safe_name (obj)));
major_collector.minor_scan_object (obj, queue);
}
} else {
+ int i;
+
if (major_collector.is_parallel && queue == &workers_distribute_gray_queue)
- return;
+ return TRUE;
- for (;;) {
- GRAY_OBJECT_DEQUEUE (queue, obj);
- if (!obj)
- break;
- DEBUG (9, fprintf (gc_debug_file, "Precise gray object scan %p (%s)\n", obj, safe_name (obj)));
- major_collector.major_scan_object (obj, queue);
- }
+ do {
+ for (i = 0; i != max_objs; ++i) {
+ GRAY_OBJECT_DEQUEUE (queue, obj);
+ if (!obj)
+ return TRUE;
+ DEBUG (9, fprintf (gc_debug_file, "Precise gray object scan %p (%s)\n", obj, safe_name (obj)));
+ major_collector.major_scan_object (obj, queue);
+ }
+ } while (max_objs < 0);
+ return FALSE;
}
}
add_profile_gc_root (&report, definitely_pinned [idx], MONO_PROFILE_GC_ROOT_PINNING, 0);
notify_gc_roots (&report);
}
+ stat_pinned_objects += count;
return count;
}
pin_stage_ptr ((void*)addr);
if (heap_dump_file)
pin_stats_register_address ((char*)addr, pin_type);
- DEBUG (6, if (count) fprintf (gc_debug_file, "Pinning address %p\n", (void*)addr));
+ DEBUG (6, if (count) fprintf (gc_debug_file, "Pinning address %p from %p\n", (void*)addr, start));
count++;
}
start++;
if ((desc & 1) && *start_root) {
copy_func (start_root, queue);
DEBUG (9, fprintf (gc_debug_file, "Overwrote root at %p with %p\n", start_root, *start_root));
- drain_gray_stack (queue);
+ drain_gray_stack (queue, -1);
}
desc >>= 1;
start_root++;
if ((bmap & 1) && *objptr) {
copy_func (objptr, queue);
DEBUG (9, fprintf (gc_debug_file, "Overwrote root at %p with %p\n", objptr, *objptr));
- drain_gray_stack (queue);
+ drain_gray_stack (queue, -1);
}
bmap >>= 1;
++objptr;
return nursery_start;
}
+gboolean
+mono_gc_precise_stack_mark_enabled (void)
+{
+ return !conservative_stack_mark;
+}
+
+FILE *
+mono_gc_get_logfile (void)
+{
+ return mono_sgen_get_logfile ();
+}
+
static void
report_finalizer_roots_list (FinalizeEntry *list)
{
}
}
+static MonoObject **finalized_array = NULL;
+static int finalized_array_capacity = 0;
+static int finalized_array_entries = 0;
+
+static void
+bridge_register_finalized_object (MonoObject *object)
+{
+ if (!finalized_array)
+ return;
+
+ if (finalized_array_entries >= finalized_array_capacity) {
+ MonoObject **new_array;
+ g_assert (finalized_array_entries == finalized_array_capacity);
+ finalized_array_capacity *= 2;
+ new_array = mono_sgen_alloc_internal_dynamic (sizeof (MonoObject*) * finalized_array_capacity, INTERNAL_MEM_BRIDGE_DATA);
+ memcpy (new_array, finalized_array, sizeof (MonoObject*) * finalized_array_entries);
+ mono_sgen_free_internal_dynamic (finalized_array, sizeof (MonoObject*) * finalized_array_entries, INTERNAL_MEM_BRIDGE_DATA);
+ finalized_array = new_array;
+ }
+ finalized_array [finalized_array_entries++] = object;
+}
+
static void
finish_gray_stack (char *start_addr, char *end_addr, int generation, GrayQueue *queue)
{
TV_DECLARE (btv);
int fin_ready;
int ephemeron_rounds = 0;
+ int num_loops;
CopyOrMarkObjectFunc copy_func = current_collection_generation == GENERATION_NURSERY ? major_collector.copy_object : major_collector.copy_or_mark_object;
/*
* To achieve better cache locality and cache usage, we drain the gray stack
* frequently, after each object is copied, and just finish the work here.
*/
- drain_gray_stack (queue);
+ drain_gray_stack (queue, -1);
TV_GETTIME (atv);
DEBUG (2, fprintf (gc_debug_file, "%s generation done\n", generation_name (generation)));
+
+ /*
+ We must clear weak links that don't track resurrection before processing object ready for
+ finalization so they can be cleared before that.
+ */
+ null_link_in_range (copy_func, start_addr, end_addr, generation, TRUE, queue);
+ if (generation == GENERATION_OLD)
+ null_link_in_range (copy_func, start_addr, end_addr, GENERATION_NURSERY, TRUE, queue);
+
+ if (finalized_array == NULL && mono_sgen_need_bridge_processing ()) {
+ finalized_array_capacity = 32;
+ finalized_array = mono_sgen_alloc_internal_dynamic (sizeof (MonoObject*) * finalized_array_capacity, INTERNAL_MEM_BRIDGE_DATA);
+ }
+ finalized_array_entries = 0;
+
/* walk the finalization queue and move also the objects that need to be
* finalized: use the finalized objects as new roots so the objects they depend
* on are also not reclaimed. As with the roots above, only objects in the nursery
* We need a loop here, since objects ready for finalizers may reference other objects
* that are fin-ready. Speedup with a flag?
*/
+ num_loops = 0;
do {
/*
* Walk the ephemeron tables marking all values with reachable keys. This must be completely done
int done_with_ephemerons = 0;
do {
done_with_ephemerons = mark_ephemerons_in_range (copy_func, start_addr, end_addr, queue);
- drain_gray_stack (queue);
+ drain_gray_stack (queue, -1);
++ephemeron_rounds;
} while (!done_with_ephemerons);
if (generation == GENERATION_OLD)
finalize_in_range (copy_func, nursery_start, nursery_real_end, GENERATION_NURSERY, queue);
+ if (fin_ready != num_ready_finalizers) {
+ ++num_loops;
+ if (finalized_array != NULL)
+ mono_sgen_bridge_processing (finalized_array_entries, finalized_array);
+ }
+
/* drain the new stack that might have been created */
DEBUG (6, fprintf (gc_debug_file, "Precise scan of gray area post fin\n"));
- drain_gray_stack (queue);
+ drain_gray_stack (queue, -1);
} while (fin_ready != num_ready_finalizers);
+ if (mono_sgen_need_bridge_processing ())
+ g_assert (num_loops <= 1);
+
/*
* Clear ephemeron pairs with unreachable keys.
* We pass the copy func so we can figure out if an array was promoted or not.
*/
g_assert (gray_object_queue_is_empty (queue));
for (;;) {
- null_link_in_range (copy_func, start_addr, end_addr, generation, queue);
+ null_link_in_range (copy_func, start_addr, end_addr, generation, FALSE, queue);
if (generation == GENERATION_OLD)
- null_link_in_range (copy_func, start_addr, end_addr, GENERATION_NURSERY, queue);
+ null_link_in_range (copy_func, start_addr, end_addr, GENERATION_NURSERY, FALSE, queue);
if (gray_object_queue_is_empty (queue))
break;
- drain_gray_stack (queue);
+ drain_gray_stack (queue, -1);
}
g_assert (gray_object_queue_is_empty (queue));
mono_counters_register ("Major sweep", MONO_COUNTER_GC | MONO_COUNTER_LONG, &time_major_sweep);
mono_counters_register ("Major fragment creation", MONO_COUNTER_GC | MONO_COUNTER_LONG, &time_major_fragment_creation);
+ mono_counters_register ("Number of pinned objects", MONO_COUNTER_GC | MONO_COUNTER_LONG, &stat_pinned_objects);
#ifdef HEAVY_STATISTICS
mono_counters_register ("WBarrier set field", MONO_COUNTER_GC | MONO_COUNTER_INT, &stat_wbarrier_set_field);
inited = TRUE;
}
+static gboolean need_calculate_minor_collection_allowance;
+
+static int last_collection_old_num_major_sections;
+static mword last_collection_los_memory_usage = 0;
+static mword last_collection_old_los_memory_usage;
+static mword last_collection_los_memory_alloced;
+
+static void
+reset_minor_collection_allowance (void)
+{
+ need_calculate_minor_collection_allowance = TRUE;
+}
+
+static void
+try_calculate_minor_collection_allowance (gboolean overwrite)
+{
+ int num_major_sections, num_major_sections_saved, save_target, allowance_target;
+ mword los_memory_saved;
+
+ if (overwrite)
+ g_assert (need_calculate_minor_collection_allowance);
+
+ if (!need_calculate_minor_collection_allowance)
+ return;
+
+ if (!*major_collector.have_swept) {
+ if (overwrite)
+ minor_collection_allowance = MIN_MINOR_COLLECTION_ALLOWANCE;
+ return;
+ }
+
+ num_major_sections = major_collector.get_num_major_sections ();
+
+ num_major_sections_saved = MAX (last_collection_old_num_major_sections - num_major_sections, 0);
+ los_memory_saved = MAX (last_collection_old_los_memory_usage - last_collection_los_memory_usage, 1);
+
+ save_target = ((num_major_sections * major_collector.section_size) + los_memory_saved) / 2;
+
+ /*
+ * We aim to allow the allocation of as many sections as is
+ * necessary to reclaim save_target sections in the next
+ * collection. We assume the collection pattern won't change.
+ * In the last cycle, we had num_major_sections_saved for
+ * minor_collection_sections_alloced. Assuming things won't
+ * change, this must be the same ratio as save_target for
+ * allowance_target, i.e.
+ *
+ * num_major_sections_saved save_target
+ * --------------------------------- == ----------------
+ * minor_collection_sections_alloced allowance_target
+ *
+ * hence:
+ */
+ allowance_target = (mword)((double)save_target * (double)(minor_collection_sections_alloced * major_collector.section_size + last_collection_los_memory_alloced) / (double)(num_major_sections_saved * major_collector.section_size + los_memory_saved));
+
+ minor_collection_allowance = MAX (MIN (allowance_target, num_major_sections * major_collector.section_size + los_memory_usage), MIN_MINOR_COLLECTION_ALLOWANCE);
+
+ if (major_collector.have_computed_minor_collection_allowance)
+ major_collector.have_computed_minor_collection_allowance ();
+
+ need_calculate_minor_collection_allowance = FALSE;
+}
+
static gboolean
need_major_collection (mword space_needed)
{
- mword los_alloced = los_memory_usage - MIN (last_los_memory_usage, los_memory_usage);
+ mword los_alloced = los_memory_usage - MIN (last_collection_los_memory_usage, los_memory_usage);
return (space_needed > available_free_space ()) ||
minor_collection_sections_alloced * major_collector.section_size + los_alloced > minor_collection_allowance;
}
major_collector.start_nursery_collection ();
+ try_calculate_minor_collection_allowance (FALSE);
+
gray_object_queue_init (&gray_queue, mono_sgen_get_unmanaged_allocator ());
num_minor_gcs++;
time_minor_scan_card_table += TV_ELAPSED_MS (atv, btv);
}
- drain_gray_stack (&gray_queue);
+ drain_gray_stack (&gray_queue, -1);
if (mono_profiler_get_events () & MONO_PROFILE_GC_ROOTS)
report_registered_roots ();
*/
char *heap_start = NULL;
char *heap_end = (char*)-1;
- int old_num_major_sections = major_collector.get_num_major_sections ();
- int num_major_sections, num_major_sections_saved, save_target, allowance_target;
int old_next_pin_slot;
- mword los_memory_saved, los_memory_alloced, old_los_memory_usage;
mono_perfcounters->gc_collections1++;
+ last_collection_old_num_major_sections = major_collector.get_num_major_sections ();
+
/*
* A domain could have been freed, resulting in
- * los_memory_usage being less than last_los_memory_usage.
+ * los_memory_usage being less than last_collection_los_memory_usage.
*/
- los_memory_alloced = los_memory_usage - MIN (last_los_memory_usage, los_memory_usage);
- old_los_memory_usage = los_memory_usage;
+ last_collection_los_memory_alloced = los_memory_usage - MIN (last_collection_los_memory_usage, los_memory_usage);
+ last_collection_old_los_memory_usage = los_memory_usage;
objects_pinned = 0;
//count_ref_nonref_objs ();
if (major_collector.start_major_collection)
major_collector.start_major_collection ();
+ *major_collector.have_swept = FALSE;
+ reset_minor_collection_allowance ();
+
if (xdomain_checks)
check_for_xdomain_refs ();
major_collector.init_to_space ();
- workers_start_all_workers (1);
+ workers_start_all_workers ();
if (mono_profiler_get_events () & MONO_PROFILE_GC_ROOTS)
report_registered_roots ();
if (major_collector.is_parallel) {
while (!gray_object_queue_is_empty (WORKERS_DISTRIBUTE_GRAY_QUEUE)) {
workers_distribute_gray_queue_sections ();
- usleep (2000);
+ usleep (1000);
}
}
- workers_change_num_working (-1);
workers_join ();
if (major_collector.is_parallel)
TV_GETTIME (atv);
time_major_finish_gray_stack += TV_ELAPSED_MS (btv, atv);
+ /*
+ * The (single-threaded) finalization code might have done
+ * some copying/marking so we can only reset the GC thread's
+ * worker data here instead of earlier when we joined the
+ * workers.
+ */
+ if (major_collector.reset_worker_data)
+ major_collector.reset_worker_data (workers_gc_thread_data.major_collector_data);
+
if (objects_pinned) {
/*This is slow, but we just OOM'd*/
mono_sgen_pin_queue_clear_discarded_entries (nursery_section, old_next_pin_slot);
g_assert (gray_object_queue_is_empty (&gray_queue));
- num_major_sections = major_collector.get_num_major_sections ();
-
- num_major_sections_saved = MAX (old_num_major_sections - num_major_sections, 0);
- los_memory_saved = MAX (old_los_memory_usage - los_memory_usage, 1);
-
- save_target = ((num_major_sections * major_collector.section_size) + los_memory_saved) / 2;
- /*
- * We aim to allow the allocation of as many sections as is
- * necessary to reclaim save_target sections in the next
- * collection. We assume the collection pattern won't change.
- * In the last cycle, we had num_major_sections_saved for
- * minor_collection_sections_alloced. Assuming things won't
- * change, this must be the same ratio as save_target for
- * allowance_target, i.e.
- *
- * num_major_sections_saved save_target
- * --------------------------------- == ----------------
- * minor_collection_sections_alloced allowance_target
- *
- * hence:
- */
- allowance_target = (mword)((double)save_target * (double)(minor_collection_sections_alloced * major_collector.section_size + los_memory_alloced) / (double)(num_major_sections_saved * major_collector.section_size + los_memory_saved));
-
- minor_collection_allowance = MAX (MIN (allowance_target, num_major_sections * major_collector.section_size + los_memory_usage), MIN_MINOR_COLLECTION_ALLOWANCE);
+ try_calculate_minor_collection_allowance (TRUE);
minor_collection_sections_alloced = 0;
- last_los_memory_usage = los_memory_usage;
+ last_collection_los_memory_usage = los_memory_usage;
major_collector.finish_major_collection ();
mono_profiler_gc_event (MONO_GC_EVENT_END, 1);
}
- degraded_mode += size;
return major_collector.alloc_degraded (vtable, size);
}
g_assert (vtable->gc_descr);
if (G_UNLIKELY (collect_before_allocs)) {
- if (nursery_section) {
+ static int alloc_count;
+
+ InterlockedIncrement (&alloc_count);
+ if (((alloc_count % collect_before_allocs) == 0) && nursery_section) {
mono_profiler_gc_event (MONO_GC_EVENT_START, 0);
stop_world (0);
collect_nursery (0);
restart_world (0);
mono_profiler_gc_event (MONO_GC_EVENT_END, 0);
- if (!degraded_mode && !search_fragment_for_size (size)) {
+ if (!degraded_mode && !search_fragment_for_size (size) && size <= MAX_SMALL_OBJ_SIZE) {
// FIXME:
g_assert_not_reached ();
}
p = mono_sgen_los_alloc_large_inner (vtable, size);
} else {
DEBUG (9, g_assert (vtable->klass->inited));
- p = major_collector.alloc_small_pinned_obj (size, vtable->klass->has_references);
+ p = major_collector.alloc_small_pinned_obj (size, SGEN_VTABLE_HAS_REFERENCES (vtable));
}
if (G_LIKELY (p)) {
DEBUG (6, fprintf (gc_debug_file, "Allocated pinned object %p, vtable: %p (%s), size: %zd\n", p, vtable, vtable->klass->name, size));
num_ready_finalizers++;
hash_table->num_registered--;
queue_finalization_entry (entry);
+ bridge_register_finalized_object ((MonoObject*)copy);
/* Make it survive */
from = entry->object;
entry->object = copy;
return !object_is_fin_ready (object) || major_collector.is_object_live (object);
}
+gboolean
+mono_sgen_object_is_live (void *obj)
+{
+ if (ptr_in_nursery (obj))
+ return object_is_pinned (obj);
+ if (current_collection_generation == GENERATION_NURSERY)
+ return FALSE;
+ return major_collector.is_object_live (obj);
+}
+
/* LOCKING: requires that the GC lock is held */
static void
null_ephemerons_for_domain (MonoDomain *domain)
/* LOCKING: requires that the GC lock is held */
static void
-null_link_in_range (CopyOrMarkObjectFunc copy_func, char *start, char *end, int generation, GrayQueue *queue)
+null_link_in_range (CopyOrMarkObjectFunc copy_func, char *start, char *end, int generation, gboolean before_finalization, GrayQueue *queue)
{
DisappearingLinkHashTable *hash = get_dislink_hash_table (generation);
DisappearingLink **disappearing_link_hash = hash->table;
for (i = 0; i < disappearing_link_hash_size; ++i) {
prev = NULL;
for (entry = disappearing_link_hash [i]; entry;) {
- char *object = DISLINK_OBJECT (entry);
+ char *object;
+ gboolean track = DISLINK_TRACK (entry);
+ if (track == before_finalization) {
+ prev = entry;
+ entry = entry->next;
+ continue;
+ }
+
+ object = DISLINK_OBJECT (entry);
+
if (object >= start && object < end && !major_collector.is_object_live (object)) {
- gboolean track = DISLINK_TRACK (entry);
if (!track && object_is_fin_ready (object)) {
void **p = entry->link;
DisappearingLink *old;
void*
mono_gc_scan_object (void *obj)
{
- g_assert_not_reached ();
if (current_collection_generation == GENERATION_NURSERY)
major_collector.copy_object (&obj, &gray_queue);
else
static void
find_pinning_ref_from_thread (char *obj, size_t size)
{
- int i;
+ int i, j;
SgenThreadInfo *info;
char *endobj = obj + size;
start++;
}
- /* FIXME: check info->stopped_regs */
+ for (j = 0; j < ARCH_NUM_REGS; ++j) {
+ mword w = (mword)info->stopped_regs [j];
+
+ if (w >= (mword)obj && w < (mword)obj + size)
+ DEBUG (0, fprintf (gc_debug_file, "Object %p referenced in saved reg %d of thread %p (id %p)\n", obj, j, info, (gpointer)info->id));
+ }
}
}
}
} else {
prev->next = p->next;
}
+
+ if (gc_callbacks.thread_detach_func) {
+ gc_callbacks.thread_detach_func (p->runtime_data);
+ p->runtime_data = NULL;
+ }
+
if (p->remset) {
if (freed_thread_remsets) {
for (rset = p->remset; rset->next; rset = rset->next)
static void
unregister_thread (void *k)
{
- g_assert (!mono_domain_get ());
+ /* If a delegate is passed to native code and invoked on a thread we dont
+ * know about, the jit will register it with mono_jit_thead_attach, but
+ * we have no way of knowing when that thread goes away. SGen has a TSD
+ * so we assume that if the domain is still registered, we can detach
+ * the thread
+ */
+ if (mono_domain_get ())
+ mono_thread_detach (mono_thread_current ());
+
LOCK_GC;
unregister_current_thread ();
UNLOCK_GC;
LOCK_GC;
init_stats ();
info = mono_sgen_thread_info_lookup (ARCH_GET_THREAD ());
- if (info == NULL)
+ if (info == NULL) {
info = gc_register_current_thread (baseptr);
+ } else {
+ /* The main thread might get registered before callbacks are set */
+ if (gc_callbacks.thread_attach_func && !info->runtime_data)
+ info->runtime_data = gc_callbacks.thread_attach_func ();
+ }
UNLOCK_GC;
/* Need a better place to initialize this */
return info != NULL;
}
+/*
+ * mono_gc_set_stack_end:
+ *
+ * Set the end of the current threads stack to STACK_END. The stack space between
+ * STACK_END and the real end of the threads stack will not be scanned during collections.
+ */
+void
+mono_gc_set_stack_end (void *stack_end)
+{
+ SgenThreadInfo *info;
+
+ LOCK_GC;
+ info = mono_sgen_thread_info_lookup (ARCH_GET_THREAD ());
+ if (info) {
+ g_assert (stack_end < info->stack_end);
+ info->stack_end = stack_end;
+ }
+ UNLOCK_GC;
+}
+
#if USE_PTHREAD_INTERCEPT
typedef struct {
sgen_card_table_mark_range ((mword)dest, size);
} else {
rs = REMEMBERED_SET;
- if (ptr_in_nursery (dest) || ptr_on_stack (dest) || !klass->has_references) {
+ if (ptr_in_nursery (dest) || ptr_on_stack (dest) || !SGEN_CLASS_HAS_REFERENCES (klass)) {
UNLOCK_GC;
return;
}
DEBUG (1, fprintf (gc_debug_file, "Heap consistency check done.\n"));
-#ifdef SGEN_BINARY_PROTOCOL
- if (!binary_protocol_file)
-#endif
+ if (!binary_protocol_is_enabled ())
g_assert (!missing_remsets);
}
char *major_collector_opt = NULL;
struct sigaction sinfo;
glong max_heap = 0;
-
-#ifdef PLATFORM_ANDROID
- g_assert_not_reached ();
-#endif
+ int num_workers;
/* the gc_initialized guard seems to imply this method is
idempotent, but LOCK_INIT(gc_mutex) might not be. It's
return;
}
pagesize = mono_pagesize ();
- gc_debug_file = stderr;
+ gc_debug_file = stdout;
LOCK_INIT (interruption_mutex);
LOCK_INIT (global_remset_mutex);
mono_sgen_marksweep_fixed_init (&major_collector);
} else if (!major_collector_opt || !strcmp (major_collector_opt, "marksweep-par")) {
mono_sgen_marksweep_par_init (&major_collector);
- workers_init (mono_cpu_count ());
} else if (!major_collector_opt || !strcmp (major_collector_opt, "marksweep-fixed-par")) {
mono_sgen_marksweep_fixed_par_init (&major_collector);
- workers_init (mono_cpu_count ());
} else if (!strcmp (major_collector_opt, "copying")) {
mono_sgen_copying_init (&major_collector);
} else {
use_cardtable = FALSE;
#endif
+ num_workers = mono_cpu_count ();
+ g_assert (num_workers > 0);
+ if (num_workers > 16)
+ num_workers = 16;
+
+ /* Keep this the default for now */
+ conservative_stack_mark = TRUE;
+
if (opts) {
for (ptr = opts; *ptr; ++ptr) {
char *opt = *ptr;
}
continue;
}
+ if (g_str_has_prefix (opt, "workers=")) {
+ long val;
+ char *endptr;
+ if (!major_collector.is_parallel) {
+ fprintf (stderr, "The workers= option can only be used for parallel collectors.");
+ exit (1);
+ }
+ opt = strchr (opt, '=') + 1;
+ val = strtol (opt, &endptr, 10);
+ if (!*opt || *endptr) {
+ fprintf (stderr, "Cannot parse the workers= option value.");
+ exit (1);
+ }
+ if (val <= 0 || val > 16) {
+ fprintf (stderr, "The number of workers must be in the range 1 to 16.");
+ exit (1);
+ }
+ num_workers = (int)val;
+ continue;
+ }
+ if (g_str_has_prefix (opt, "stack-mark=")) {
+ opt = strchr (opt, '=') + 1;
+ if (!strcmp (opt, "precise")) {
+ conservative_stack_mark = FALSE;
+ } else if (!strcmp (opt, "conservative")) {
+ conservative_stack_mark = TRUE;
+ } else {
+ fprintf (stderr, "Invalid value '%s' for stack-mark= option, possible values are: 'precise', 'conservative'.\n", opt);
+ exit (1);
+ }
+ continue;
+ }
#ifdef USER_CONFIG
if (g_str_has_prefix (opt, "nursery-size=")) {
long val;
fprintf (stderr, " nursery-size=N (where N is an integer, possibly with a k, m or a g suffix)\n");
fprintf (stderr, " major=COLLECTOR (where COLLECTOR is `marksweep', `marksweep-par' or `copying')\n");
fprintf (stderr, " wbarrier=WBARRIER (where WBARRIER is `remset' or `cardtable')\n");
+ fprintf (stderr, " stack-mark=MARK-METHOD (where MARK-METHOD is 'precise' or 'conservative')\n");
if (major_collector.print_gc_param_usage)
major_collector.print_gc_param_usage ();
exit (1);
g_strfreev (opts);
}
+ if (major_collector.is_parallel)
+ workers_init (num_workers);
+
if (major_collector_opt)
g_free (major_collector_opt);
g_free (rf);
}
} else if (!strcmp (opt, "collect-before-allocs")) {
- collect_before_allocs = TRUE;
+ collect_before_allocs = 1;
+ } else if (g_str_has_prefix (opt, "collect-before-allocs=")) {
+ char *arg = strchr (opt, '=') + 1;
+ collect_before_allocs = atoi (arg);
} else if (!strcmp (opt, "check-at-minor-collections")) {
consistency_check_at_minor_collection = TRUE;
nursery_clear_policy = CLEAR_AT_GC;
xdomain_checks = TRUE;
} else if (!strcmp (opt, "clear-at-gc")) {
nursery_clear_policy = CLEAR_AT_GC;
- } else if (!strcmp (opt, "conservative-stack-mark")) {
- conservative_stack_mark = TRUE;
+ } else if (!strcmp (opt, "clear-nursery-at-gc")) {
+ nursery_clear_policy = CLEAR_AT_GC;
} else if (!strcmp (opt, "check-scan-starts")) {
do_scan_starts_check = TRUE;
} else if (g_str_has_prefix (opt, "heap-dump=")) {
#ifdef SGEN_BINARY_PROTOCOL
} else if (g_str_has_prefix (opt, "binary-protocol=")) {
char *filename = strchr (opt, '=') + 1;
- binary_protocol_file = fopen (filename, "w");
+ binary_protocol_init (filename);
#endif
} else {
fprintf (stderr, "Invalid format for the MONO_GC_DEBUG env variable: '%s'\n", env);
fprintf (stderr, "The format is: MONO_GC_DEBUG=[l[:filename]|<option>]+ where l is a debug level 0-9.\n");
- fprintf (stderr, "Valid options are: collect-before-allocs, check-at-minor-collections, xdomain-checks, clear-at-gc.\n");
+ fprintf (stderr, "Valid options are: collect-before-allocs[=<n>], check-at-minor-collections, xdomain-checks, clear-at-gc.\n");
exit (1);
}
}
g_strfreev (opts);
}
+ if (major_collector.post_param_init)
+ major_collector.post_param_init ();
+
suspend_ack_semaphore_ptr = &suspend_ack_semaphore;
MONO_SEM_INIT (&suspend_ack_semaphore, 0);
mono_mb_emit_i4 ((mb), (offset)); \
} while (0)
#else
+
+/*
+ * CEE_MONO_TLS requires the tls offset, not the key, so the code below only works on darwin,
+ * where the two are the same.
+ */
+#ifdef __APPLE__
#define EMIT_TLS_ACCESS(mb,member,dummy) do { \
mono_mb_emit_byte ((mb), MONO_CUSTOM_PREFIX); \
mono_mb_emit_byte ((mb), CEE_MONO_TLS); \
mono_mb_emit_byte ((mb), CEE_ADD); \
mono_mb_emit_byte ((mb), CEE_LDIND_I); \
} while (0)
+#else
+#define EMIT_TLS_ACCESS(mb,member,dummy) do { g_error ("sgen is not supported when using --with-tls=pthread.\n"); } while (0)
+#endif
+
#endif
#ifdef MANAGED_ALLOCATION
return NULL;
if (collect_before_allocs)
return NULL;
- g_assert (!klass->has_finalize && !klass->marshalbyref);
+ g_assert (!mono_class_has_finalizer (klass) && !klass->marshalbyref);
return mono_gc_get_managed_allocator_by_type (ATYPE_VECTOR);
#else
va_end (ap);
}
+FILE*
+mono_sgen_get_logfile (void)
+{
+ return gc_debug_file;
+}
+
+#ifdef HOST_WIN32
+BOOL APIENTRY mono_gc_dllmain (HMODULE module_handle, DWORD reason, LPVOID reserved)
+{
+ return TRUE;
+}
+#endif
+
#endif /* HAVE_SGEN_GC */