X-Git-Url: https://git.llucax.com/software/dgc/cdgc.git/blobdiff_plain/b28fd72842fc9ce935bed74f7b2ba79f9cc59711..fcae2848ff5191cadae251c0a1c5ce3ea66a02b8:/rt/gc/cdgc/opts.d diff --git a/rt/gc/cdgc/opts.d b/rt/gc/cdgc/opts.d index 728119f..5f93cd0 100644 --- a/rt/gc/cdgc/opts.d +++ b/rt/gc/cdgc/opts.d @@ -35,6 +35,7 @@ module rt.gc.cdgc.opts; import cstdlib = tango.stdc.stdlib; import cstring = tango.stdc.string; +import cerrno = tango.stdc.errno; private: @@ -53,6 +54,9 @@ struct Options bool mem_stomp = false; bool conservative = false; bool fork = true; + bool eager_alloc = true; + size_t prealloc_psize = 0; + size_t prealloc_npools = 0; } package Options options; @@ -72,6 +76,31 @@ bool parse_bool(char* value) } +void parse_prealloc(char* value) +{ + char* end; + cerrno.errno = 0; + long size = cstdlib.strtol(value, &end, 10); + if (end == value || cerrno.errno) // error parsing + return; + size *= 1024 * 1024; // size is supposed to be in MiB + long npools = 1; + if (*end == 'x') { // number of pools specified + char* start = end + 1; + npools = cstdlib.strtol(start, &end, 10); + if (*end != '\0' || end == start || cerrno.errno) // error parsing + return; + } + else if (*end != '\0') { // don't accept trailing garbage + return; + } + if (size > 0 && npools > 0) { + options.prealloc_psize = size; + options.prealloc_npools = npools; + } +} + + void process_option(char* opt_name, char* opt_value) { if (cstr_eq(opt_name, "verbose")) @@ -88,8 +117,12 @@ void process_option(char* opt_name, char* opt_value) options.mem_stomp = parse_bool(opt_value); else if (cstr_eq(opt_name, "conservative")) options.conservative = parse_bool(opt_value); - else if (cstr_eq(opt_name, "no_fork")) - options.fork = !parse_bool(opt_value); + else if (cstr_eq(opt_name, "fork")) + 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, "pre_alloc")) + parse_prealloc(opt_value); } @@ -149,6 +182,9 @@ unittest assert (mem_stomp == false); assert (conservative == false); assert (fork == true); + assert (eager_alloc == true); + assert (prealloc_psize == 0); + assert (prealloc_npools == 0); } parse("mem_stomp"); with (options) { @@ -158,8 +194,11 @@ unittest assert (mem_stomp == true); assert (conservative == false); assert (fork == true); + assert (eager_alloc == true); + assert (prealloc_psize == 0); + assert (prealloc_npools == 0); } - parse("mem_stomp=0:verbose=2:conservative:no_fork=10"); + parse("mem_stomp=0:verbose=2:conservative:fork=0:eager_alloc=0"); with (options) { assert (verbose == 2); assert (log_file[0] == '\0'); @@ -167,6 +206,9 @@ unittest assert (mem_stomp == false); assert (conservative == true); assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 0); + assert (prealloc_npools == 0); } parse("log_file=12345 67890:verbose=1:sentinel=4:mem_stomp=1"); with (options) { @@ -176,6 +218,117 @@ unittest assert (mem_stomp == true); assert (conservative == true); assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 0); + assert (prealloc_npools == 0); + } + parse("pre_alloc"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 0); + assert (prealloc_npools == 0); + } + parse("pre_alloc=1"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 1 * 1024 * 1024); + assert (prealloc_npools == 1); + } + parse("pre_alloc=5a"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 1 * 1024 * 1024); + assert (prealloc_npools == 1); + } + parse("pre_alloc=5x"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 1 * 1024 * 1024); + assert (prealloc_npools == 1); + } + parse("pre_alloc=09x010"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 9 * 1024 * 1024); + assert (prealloc_npools == 10); + } + parse("pre_alloc=5x2"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 5 * 1024 * 1024); + assert (prealloc_npools == 2); + } + parse("pre_alloc=9x5x"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 5 * 1024 * 1024); + assert (prealloc_npools == 2); + } + parse("pre_alloc=9x-5"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 5 * 1024 * 1024); + assert (prealloc_npools == 2); + } + parse("pre_alloc=0x3x0x4"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 5 * 1024 * 1024); + assert (prealloc_npools == 2); } parse(null); with (options) { @@ -185,6 +338,45 @@ unittest assert (mem_stomp == true); assert (conservative == true); assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 5 * 1024 * 1024); + assert (prealloc_npools == 2); + } + parse(""); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 5 * 1024 * 1024); + assert (prealloc_npools == 2); + } + parse(":"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 5 * 1024 * 1024); + assert (prealloc_npools == 2); + } + parse("::::"); + with (options) { + assert (verbose == 1); + assert (cstring.strcmp(log_file.ptr, "12345 67890".ptr) == 0); + assert (sentinel == true); + assert (mem_stomp == true); + assert (conservative == true); + assert (fork == false); + assert (eager_alloc == false); + assert (prealloc_psize == 5 * 1024 * 1024); + assert (prealloc_npools == 2); } }