Priority-2 ENV Cache: hakmem_tiny.c (3箇所置換)

【置換ファイル】
- 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 <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-12-02 20:54:03 +09:00
parent 183b106733
commit f0e77a000e

View File

@ -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);