AutoEnvironment.cpp [plain text]
#include <errno.h>
#include "AutoDefs.h"
#include "AutoEnvironment.h"
#include "auto_impl_utilities.h"
namespace Auto {
uint32_t Environment::read_long(const char *var, uint32_t default_value, const char *msg) {
uint32_t result = default_value;
const char *s = getenv(var);
if (s) {
uint32_t parsed = strtol(s, NULL, 10);
if (parsed != 0 || errno != EINVAL) {
result = parsed;
if (result != default_value)
malloc_printf("%s: %s = \"%s\" in environment. %s\n", auto_prelude(), var, s, msg ?: "");
}
}
return result;
}
bool Environment::read_bool(const char *var, bool default_value, const char *msg) {
bool result = default_value;
const char *s = getenv(var);
if (s) {
if (strlen(s) == 0)
result = true;
else if (strcasecmp(s, "yes") == 0 || strcasecmp(s, "true") == 0 || strcmp(s, "1") == 0)
result = true;
else if (strcasecmp(s, "no") == 0 || strcasecmp(s, "false") == 0 || strcmp(s, "0") == 0)
result = false;
if (result != default_value)
malloc_printf("%s: %s = \"%s\" in environment. %s\n", auto_prelude(), var, s, msg ?: "");
}
return result;
}
#if defined(DEBUG)
bool Environment::clear_all_new; bool Environment::dirty_all_new; bool Environment::unsafe_scan; bool Environment::print_stats; bool Environment::print_scan_stats; bool Environment::print_allocs; uint32_t Environment::local_allocations_size_limit; #endif
bool Environment::guard_pages; bool Environment::dirty_all_deleted; bool Environment::enable_monitor; bool Environment::use_exact_scanning; bool Environment::thread_collections; bool Environment::log_reference_counting; uint32_t Environment::exhaustive_collection_limit; bool Environment::resurrection_is_fatal;
void Environment::initialize() {
#if defined(DEBUG)
clear_all_new = read_bool("AUTO_CLEAR_ALL_NEW", false);
dirty_all_new = read_bool("AUTO_DIRTY_ALL_NEW", false);
unsafe_scan = read_bool("AUTO_UNSAFE_SCAN", false);
print_stats = read_bool("AUTO_PRINT_STATS", false);
print_scan_stats = read_bool("AUTO_SCAN_PRINT_STATS", false);
local_allocations_size_limit = read_long("AUTO_THREAD_LOCAL_BLOCK_LIMIT", 2000);
#endif
guard_pages = read_bool("AUTO_USE_GUARDS", false, "Guard pages are enabled. Application will be slower and use more memory. Buffer overruns in the Auto zone will be caught.");
dirty_all_deleted = read_bool("AUTO_DIRTY_ALL_DELETED", false, "Deleted objects will be dirtied by the collector (similar to MallocScribble).") || read_long("MallocScribble", false, "Deleted objects will be dirtied by the collector.");
enable_monitor = read_bool("AUTO_ENABLE_MONITOR", false);
use_exact_scanning = read_bool("AUTO_USE_EXACT_SCANNING", true, "Exact scanning disabled. Additional references may be found.");
thread_collections = read_bool("AUTO_USE_TLC", true, "Thread local collector [TLC] disabled.");
log_reference_counting = read_bool("AUTO_REFERENCE_COUNT_LOGGING", false, "Reference count logging enabled.");
exhaustive_collection_limit = read_long("AUTO_EXHAUSTIVE_COLLECTION_LIMIT", 8);
resurrection_is_fatal = read_bool("AUTO_RESURRECTION_ABORT", true, "Resurrections errors will not be treated as fatal. This may lead to heap inconsistencies and crashes, possibly long after the resurrection occurs.");
}
};