diff --git a/core/hakmem_tiny.c b/core/hakmem_tiny.c index 6201d3d3..68ab89ac 100644 --- a/core/hakmem_tiny.c +++ b/core/hakmem_tiny.c @@ -9,6 +9,7 @@ #include "hakmem_tiny_magazine.h" #include "hakmem_tiny_integrity.h" // PRIORITY 1-4: Corruption detection #include "box/tiny_next_ptr_box.h" // Box API: next pointer read/write +#include "hakmem_env_cache.h" // Priority-2: ENV cache // Phase 1 modules (must come AFTER hakmem_tiny.h for TinyPool definition) #include "hakmem_tiny_batch_refill.h" // Phase 1: Batch refill/spill for mini-magazine #include "hakmem_tiny_stats.h" // Phase 1: Batched statistics (replaces XOR RNG) @@ -580,8 +581,8 @@ extern __thread int g_tls_in_wrapper; // Tiny Heap v2 stats dump (opt-in) void tiny_heap_v2_print_stats(void) { - const char* env = getenv("HAKMEM_TINY_HEAP_V2_STATS"); - if (!(env && *env && *env != '0')) return; + // Priority-2: Use cached ENV + if (!HAK_ENV_TINY_HEAP_V2_STATS()) return; fprintf(stderr, "\n[HeapV2] TLS magazine stats (per class, thread-local)\n"); for (int cls = 0; cls < TINY_NUM_CLASSES; cls++) { @@ -608,8 +609,8 @@ static void tiny_heap_v2_stats_atexit(void) { _Atomic uint64_t g_tiny_alloc_ge1024[TINY_NUM_CLASSES] = {0}; static void tiny_alloc_1024_diag_atexit(void) __attribute__((destructor)); static void tiny_alloc_1024_diag_atexit(void) { - const char* env = getenv("HAKMEM_TINY_ALLOC_1024_METRIC"); - if (!(env && *env && *env != '0')) return; + // Priority-2: Use cached ENV + if (!HAK_ENV_TINY_ALLOC_1024_METRIC()) return; fprintf(stderr, "\n[ALLOC_GE1024] per-class counts (size>=1024)\n"); for (int cls = 0; cls < TINY_NUM_CLASSES; cls++) { uint64_t v = atomic_load_explicit(&g_tiny_alloc_ge1024[cls], memory_order_relaxed); @@ -626,8 +627,8 @@ extern _Atomic uint64_t g_tls_sll_invalid_push[TINY_NUM_CLASSES]; static void tiny_tls_sll_diag_atexit(void) __attribute__((destructor)); static void tiny_tls_sll_diag_atexit(void) { #if !HAKMEM_BUILD_RELEASE - const char* env = getenv("HAKMEM_TINY_SLL_DIAG"); - if (!(env && *env && *env != '0')) return; + // Priority-2: Use cached ENV + if (!HAK_ENV_TINY_SLL_DIAG()) return; fprintf(stderr, "\n[TLS_SLL_DIAG] invalid head/push counts per class\n"); for (int cls = 0; cls < TINY_NUM_CLASSES; cls++) { uint64_t ih = atomic_load_explicit(&g_tls_sll_invalid_head[cls], memory_order_relaxed);