X-Git-Url: https://git.llucax.com/software/dgc/cdgc.git/blobdiff_plain/8183938bc0141793deae76c17ea182b2774fd0df..HEAD:/rt/gc/cdgc/opts.d diff --git a/rt/gc/cdgc/opts.d b/rt/gc/cdgc/opts.d index 5f93cd0..01ac964 100644 --- a/rt/gc/cdgc/opts.d +++ b/rt/gc/cdgc/opts.d @@ -33,9 +33,12 @@ module rt.gc.cdgc.opts; +//debug = PRINTF; + import cstdlib = tango.stdc.stdlib; import cstring = tango.stdc.string; import cerrno = tango.stdc.errno; +debug (PRINTF) import tango.stdc.stdio: printf; private: @@ -52,9 +55,14 @@ struct Options char[MAX_OPT_LEN] collect_stats_file = ""; bool sentinel = false; bool mem_stomp = false; - bool conservative = false; + version (D_HavePointerMap) + bool conservative = false; + else + bool conservative = true; bool fork = true; bool eager_alloc = true; + bool early_collect = false; + uint min_free = 5; // percent of the heap (0-100) size_t prealloc_psize = 0; size_t prealloc_npools = 0; } @@ -62,6 +70,22 @@ struct Options package Options options; +debug (PRINTF) +void print_options() +{ + int b(bool v) { return v; } + with (options) + printf("rt.gc.cdgc.opts: verbose=%u, log_file='%s', " + "malloc_stats_file='%s', collect_stats_file='%s', sentinel=%d, " + "mem_stomp=%d, conservative=%d, fork=%d, eager_alloc=%d, " + "early_collect=%d, min_free=%u, prealloc_psize=%lu, " + "prealloc_npools=%lu\n", verbose, log_file.ptr, + malloc_stats_file.ptr, collect_stats_file.ptr, b(sentinel), + b(mem_stomp), b(conservative), b(fork), b(eager_alloc), + b(early_collect), min_free, prealloc_psize, prealloc_npools); +} + + bool cstr_eq(char* s1, char* s2) { return cstring.strcmp(s1, s2) == 0; @@ -101,6 +125,16 @@ void parse_prealloc(char* value) } +void parse_min_free(char* value) +{ + char* end; + long free = cstdlib.strtol(value, &end, 10); + if (*end != '\0' || end == value || cerrno.errno || free < 0 || free > 100) + return; + options.min_free = free; +} + + void process_option(char* opt_name, char* opt_value) { if (cstr_eq(opt_name, "verbose")) @@ -121,6 +155,10 @@ void process_option(char* opt_name, char* opt_value) options.fork = parse_bool(opt_value); else if (cstr_eq(opt_name, "eager_alloc")) options.eager_alloc = parse_bool(opt_value); + else if (cstr_eq(opt_name, "early_collect")) + options.early_collect = parse_bool(opt_value); + else if (cstr_eq(opt_name, "min_free")) + parse_min_free(opt_value); else if (cstr_eq(opt_name, "pre_alloc")) parse_prealloc(opt_value); } @@ -134,8 +172,10 @@ package void parse(char* opts_string) opt_value[0] = '\0'; char* curr = opt_name.ptr; size_t i = 0; - if (opts_string is null) + if (opts_string is null) { + debug (PRINTF) printf("rt.gc.cdgc.opts: no options overriden\n"); return; + } for (; *opts_string != '\0'; opts_string++) { char c = *opts_string; @@ -170,6 +210,7 @@ package void parse(char* opts_string) i--; curr[i] = '\0'; process_option(opt_name.ptr, opt_value.ptr); + debug (PRINTF) print_options(); } @@ -183,8 +224,10 @@ unittest assert (conservative == false); assert (fork == true); assert (eager_alloc == true); + assert (early_collect == false); assert (prealloc_psize == 0); assert (prealloc_npools == 0); + assert (min_free == 5); } parse("mem_stomp"); with (options) { @@ -195,8 +238,10 @@ unittest assert (conservative == false); assert (fork == true); assert (eager_alloc == true); + assert (early_collect == false); assert (prealloc_psize == 0); assert (prealloc_npools == 0); + assert (min_free == 5); } parse("mem_stomp=0:verbose=2:conservative:fork=0:eager_alloc=0"); with (options) { @@ -207,8 +252,10 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 0); assert (prealloc_npools == 0); + assert (min_free == 5); } parse("log_file=12345 67890:verbose=1:sentinel=4:mem_stomp=1"); with (options) { @@ -219,10 +266,12 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 0); assert (prealloc_npools == 0); + assert (min_free == 5); } - parse("pre_alloc"); + parse("pre_alloc:min_free=30:early_collect"); with (options) { assert (verbose == 1); assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); @@ -231,10 +280,12 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == true); assert (prealloc_psize == 0); assert (prealloc_npools == 0); + assert (min_free == 30); } - parse("pre_alloc=1"); + parse("pre_alloc=1:early_collect=0"); with (options) { assert (verbose == 1); assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); @@ -243,10 +294,12 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 1 * 1024 * 1024); assert (prealloc_npools == 1); + assert (min_free == 30); } - parse("pre_alloc=5a"); + parse("pre_alloc=5a:min_free=101"); with (options) { assert (verbose == 1); assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); @@ -255,10 +308,12 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 1 * 1024 * 1024); assert (prealloc_npools == 1); + assert (min_free == 30); } - parse("pre_alloc=5x"); + parse("pre_alloc=5x:min_free=-1"); with (options) { assert (verbose == 1); assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); @@ -267,10 +322,12 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 1 * 1024 * 1024); assert (prealloc_npools == 1); + assert (min_free == 30); } - parse("pre_alloc=09x010"); + parse("pre_alloc=09x010:min_free=10a"); with (options) { assert (verbose == 1); assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); @@ -279,10 +336,12 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 9 * 1024 * 1024); assert (prealloc_npools == 10); + assert (min_free == 30); } - parse("pre_alloc=5x2"); + parse("pre_alloc=5x2:min_free=1.0"); with (options) { assert (verbose == 1); assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); @@ -291,10 +350,12 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 5 * 1024 * 1024); assert (prealloc_npools == 2); + assert (min_free == 30); } - parse("pre_alloc=9x5x"); + parse("pre_alloc=9x5x:min_free=-1"); with (options) { assert (verbose == 1); assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); @@ -303,10 +364,12 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 5 * 1024 * 1024); assert (prealloc_npools == 2); + assert (min_free == 30); } - parse("pre_alloc=9x-5"); + parse("pre_alloc=9x-5:min_free=0"); with (options) { assert (verbose == 1); assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); @@ -315,10 +378,12 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 5 * 1024 * 1024); assert (prealloc_npools == 2); + assert (min_free == 0); } - parse("pre_alloc=0x3x0x4"); + parse("pre_alloc=0x3x0x4:min_free=100"); with (options) { assert (verbose == 1); assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); @@ -327,8 +392,10 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 5 * 1024 * 1024); assert (prealloc_npools == 2); + assert (min_free == 100); } parse(null); with (options) { @@ -339,8 +406,10 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 5 * 1024 * 1024); assert (prealloc_npools == 2); + assert (min_free == 100); } parse(""); with (options) { @@ -351,8 +420,10 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 5 * 1024 * 1024); assert (prealloc_npools == 2); + assert (min_free == 100); } parse(":"); with (options) { @@ -363,8 +434,10 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 5 * 1024 * 1024); assert (prealloc_npools == 2); + assert (min_free == 100); } parse("::::"); with (options) { @@ -375,8 +448,10 @@ unittest assert (conservative == true); assert (fork == false); assert (eager_alloc == false); + assert (early_collect == false); assert (prealloc_psize == 5 * 1024 * 1024); assert (prealloc_npools == 2); + assert (min_free == 100); } }