Skip to content

Commit

Permalink
Add --gc-params and --gc-debug command line options
Browse files Browse the repository at this point in the history
  • Loading branch information
joncham committed Oct 7, 2016
1 parent cb17a4f commit 3f234cb
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 4 deletions.
10 changes: 10 additions & 0 deletions mono/metadata/boehm-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1369,6 +1369,16 @@ mono_gc_get_logfile (void)
return NULL;
}

void
mono_gc_params_set (const char* options)
{
}

void
mono_gc_debug_set (const char* options)
{
}

void
mono_gc_conservatively_scan_area (void *start, void *end)
{
Expand Down
10 changes: 10 additions & 0 deletions mono/metadata/null-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,16 @@ mono_gc_get_logfile (void)
return NULL;
}

void
mono_gc_params_set (const char* options)
{
}

void
mono_gc_debug_set (const char* options)
{
}

void
mono_gc_conservatively_scan_area (void *start, void *end)
{
Expand Down
8 changes: 8 additions & 0 deletions mono/mini/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -1434,6 +1434,10 @@ mono_jit_parse_options (int argc, char * argv[])

if (!mono_debugger_insert_breakpoint (argv [++i], FALSE))
fprintf (stderr, "Error: invalid method name '%s'\n", argv [i]);
} else if (strncmp (argv[i], "--gc-params=", 12) == 0) {
mono_gc_params_set (argv[i] + 12);
} else if (strncmp (argv[i], "--gc-debug=", 11) == 0) {
mono_gc_debug_set (argv[i] + 11);
} else if (strcmp (argv [i], "--llvm") == 0) {
#ifndef MONO_ARCH_LLVM_SUPPORTED
fprintf (stderr, "Mono Warning: --llvm not supported on this platform.\n");
Expand Down Expand Up @@ -1679,6 +1683,10 @@ mono_main (int argc, char* argv[])
switch_gc (argv, "sgen");
} else if (strcmp (argv [i], "--gc=boehm") == 0) {
switch_gc (argv, "boehm");
} else if (strncmp (argv[i], "--gc-params=", 12) == 0) {
mono_gc_params_set (argv[i] + 12);
} else if (strncmp (argv[i], "--gc-debug=", 11) == 0) {
mono_gc_debug_set (argv[i] + 11);
}
#ifdef TARGET_OSX
else if (strcmp (argv [i], "--arch=32") == 0) {
Expand Down
5 changes: 5 additions & 0 deletions mono/sgen/gc-internal-agnostic.h
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,9 @@ void mono_gc_memmove_aligned (void *dest, const void *src, size_t size);

FILE *mono_gc_get_logfile (void);

/* equivalent to options set via MONO_GC_PARAMS */
void mono_gc_params_set (const char* options);
/* equivalent to options set via MONO_GC_DEBUG */
void mono_gc_debug_set (const char* options);

#endif
44 changes: 40 additions & 4 deletions mono/sgen/sgen-gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,8 @@ static SGEN_TV_DECLARE (time_major_conc_collection_end);

int gc_debug_level = 0;
FILE* gc_debug_file;
static char* gc_params_options;
static char* gc_debug_options;

/*
void
Expand Down Expand Up @@ -990,6 +992,24 @@ mono_gc_get_logfile (void)
return gc_debug_file;
}

void
mono_gc_params_set (const char* options)
{
if (gc_params_options)
g_free (gc_params_options);

gc_params_options = g_strdup (options);
}

void
mono_gc_debug_set (const char* options)
{
if (gc_debug_options)
g_free (gc_debug_options);

gc_debug_options = g_strdup (options);
}

static void
scan_finalizer_entries (SgenPointerQueue *fin_queue, ScanCopyContext ctx)
{
Expand Down Expand Up @@ -2735,6 +2755,8 @@ sgen_gc_init (void)
char **opts, **ptr;
char *major_collector_opt = NULL;
char *minor_collector_opt = NULL;
char *params_opts = NULL;
char *debug_opts = NULL;
size_t max_heap = 0;
size_t soft_limit = 0;
int result;
Expand Down Expand Up @@ -2772,8 +2794,12 @@ sgen_gc_init (void)

mono_coop_mutex_init (&sgen_interruption_mutex);

if ((env = g_getenv (MONO_GC_PARAMS_NAME))) {
opts = g_strsplit (env, ",", -1);
if ((env = g_getenv (MONO_GC_PARAMS_NAME)) || gc_params_options) {
params_opts = g_strdup_printf ("%s,%s", gc_params_options ? gc_params_options : "", env ? env : "");
}

if (params_opts) {
opts = g_strsplit (params_opts, ",", -1);
for (ptr = opts; *ptr; ++ptr) {
char *opt = *ptr;
if (g_str_has_prefix (opt, "major=")) {
Expand Down Expand Up @@ -2975,15 +3001,22 @@ sgen_gc_init (void)
if (minor_collector_opt)
g_free (minor_collector_opt);

if (params_opts)
g_free (params_opts);

alloc_nursery ();

sgen_pinning_init ();
sgen_cement_init (cement_enabled);

if ((env = g_getenv (MONO_GC_DEBUG_NAME))) {
if ((env = g_getenv (MONO_GC_DEBUG_NAME)) || gc_debug_options) {
debug_opts = g_strdup_printf ("%s,%s", gc_debug_options ? gc_debug_options : "", env ? env : "");
}

if (debug_opts) {
gboolean usage_printed = FALSE;

opts = g_strsplit (env, ",", -1);
opts = g_strsplit (debug_opts, ",", -1);
for (ptr = opts; ptr && *ptr; ptr ++) {
char *opt = *ptr;
if (!strcmp (opt, ""))
Expand Down Expand Up @@ -3114,6 +3147,9 @@ sgen_gc_init (void)
g_strfreev (opts);
}

if (debug_opts)
g_free (debug_opts);

if (check_mark_bits_after_major_collection)
nursery_clear_policy = CLEAR_AT_GC;

Expand Down

0 comments on commit 3f234cb

Please sign in to comment.