From f0e77a000e76e8e130ea97583978641766b4495e Mon Sep 17 00:00:00 2001 From: "Moe Charm (CI)" Date: Tue, 2 Dec 2025 20:54:03 +0900 Subject: [PATCH] =?UTF-8?q?Priority-2=20ENV=20Cache:=20hakmem=5Ftiny.c=20(?= =?UTF-8?q?3=E7=AE=87=E6=89=80=E7=BD=AE=E6=8F=9B)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【置換ファイル】 - core/hakmem_tiny.c (3箇所 → ENV Cache) 【変更詳細】 1. tiny_heap_v2_print_stats(): - getenv("HAKMEM_TINY_HEAP_V2_STATS") → HAK_ENV_TINY_HEAP_V2_STATS() 2. tiny_alloc_1024_diag_atexit(): - getenv("HAKMEM_TINY_ALLOC_1024_METRIC") → HAK_ENV_TINY_ALLOC_1024_METRIC() 3. tiny_tls_sll_diag_atexit(): - getenv("HAKMEM_TINY_SLL_DIAG") → HAK_ENV_TINY_SLL_DIAG() - #include "hakmem_env_cache.h" 追加 【効果】 - 診断系atexit()関数からgetenv()呼び出しを排除 - 既存ENV変数を利用 (新規追加なし、カウント: 46変数維持) 【テスト】 ✅ make shared → 成功 ✅ /tmp/test_mixed3_final → PASSED 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- core/hakmem_tiny.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) 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);