// tiny_hotheap_v2_box.h - TinyHotHeap v2 skeleton (Step1: types & stubs only) // 役割: // - TinyHotHeap v2 の型と API を先行定義するが、現行経路には配線しない。 // - HAKMEM_TINY_HOTHEAP_V2 / HAKMEM_TINY_HOTHEAP_CLASSES で将来の A/B に備える。 // メモ (Phase35): // - 現状の v2 は C7-only でも v1 より遅く、mixed では大きな回帰が確認されている。 // - 研究用/実験用フラグを明示的に立てたときだけ使用し、デフォルトは OFF とする。 #pragma once #include #include #ifndef TINY_HOTHEAP_MAX_CLASSES #define TINY_HOTHEAP_MAX_CLASSES 8 // とりあえず全クラス分確保(後で mask で限定) #endif struct TinySlabMeta; struct SuperSlab; struct tiny_heap_page_t; // from tiny_heap_box.h (v1 page型) typedef struct tiny_hotheap_page_v2 { void* freelist; uint16_t used; uint16_t capacity; uint16_t slab_idx; uint16_t flags; // future use (HOT/PARTIAL/FULL) void* base; struct TinySlabMeta* meta; // Superslab slab meta(Cold 側は v1 が保持) struct SuperSlab* ss; // Owning Superslab(Cold 側は v1 に委譲) struct tiny_heap_page_t* lease_page; // v1 側の page 構造体(freelist/used は lease_page と同期させる) struct tiny_hotheap_page_v2* next; } tiny_hotheap_page_v2; typedef struct tiny_hotheap_class_v2 { tiny_hotheap_page_v2* current_page; tiny_hotheap_page_v2* partial_pages; tiny_hotheap_page_v2* full_pages; uint16_t stride; uint16_t max_partial_pages; // 空ページを保持する上限(C7 専用で 1〜2 を想定) uint16_t partial_count; // いま握っている partial の枚数 tiny_hotheap_page_v2 storage_page; // C7 専用の 1 枚だけをまず保持(Phase36: reuse when空き) } tiny_hotheap_class_v2; typedef struct tiny_hotheap_ctx_v2 { tiny_hotheap_class_v2 cls[TINY_HOTHEAP_MAX_CLASSES]; } tiny_hotheap_ctx_v2; // TLS state (定義は core/hakmem_tiny.c) extern __thread tiny_hotheap_ctx_v2* g_tiny_hotheap_ctx_v2; // API (Step1: まだ中身はダミー) tiny_hotheap_ctx_v2* tiny_hotheap_v2_tls_get(void); void* tiny_hotheap_v2_alloc(uint8_t class_idx); void tiny_hotheap_v2_free(uint8_t class_idx, void* p, void* meta); void tiny_hotheap_v2_record_route_fallback(uint8_t class_idx); void tiny_hotheap_v2_record_free_fallback(uint8_t class_idx); typedef struct tiny_hotheap_v2_stats_snapshot { uint64_t route_hits; uint64_t alloc_calls; uint64_t alloc_fast; uint64_t alloc_lease; uint64_t alloc_refill; uint64_t alloc_fallback_v1; uint64_t alloc_route_fb; uint64_t free_calls; uint64_t free_fast; uint64_t free_fallback_v1; uint64_t cold_refill_fail; uint64_t cold_retire_calls; uint64_t retire_calls_v2; uint64_t prepare_calls; uint64_t prepare_with_current_null; uint64_t prepare_from_partial; uint64_t free_made_current; uint64_t page_retired; uint64_t partial_pushes; uint64_t partial_pops; uint64_t partial_peak; uint64_t refill_with_current; uint64_t refill_with_partial; } tiny_hotheap_v2_stats_snapshot_t; void tiny_hotheap_v2_debug_snapshot(tiny_hotheap_v2_stats_snapshot_t* out); static inline void tiny_hotheap_v2_page_reset(tiny_hotheap_page_v2* page) { if (!page) return; page->freelist = NULL; page->used = 0; page->capacity = 0; page->slab_idx = 0; page->flags = 0; page->base = NULL; page->meta = NULL; page->ss = NULL; page->lease_page = NULL; page->next = NULL; }