Phase v4-mid-0: Small-object v4 型・IF 足場(箱化モジュール化)

- SmallHeapCtx/SmallPageMeta/SmallClassHeap typedef alias 追加
- SmallSegment struct (base/num_pages/owner_tid/magic) を smallsegment_v4_box.h に定義
- SmallColdIface_v4 direct function prototypes (refill/retire/remote_push/drain)
- smallobject_hotbox_v4.c の internal/public API 分離(small_segment_v4_internal)
- direct function stubs 実装(SmallColdIfaceV4 delegate 形式)
- ENV OFF デフォルト(ENABLED=0/CLASSES=0)で既存挙動 100% 不変
- ビルド成功・sanity 確認(mixed/C6-heavy、segv/assert なし)
- CURRENT_TASK.md に Phase v4-mid-0 記録

🤖 Generated with Claude Code

Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
Moe Charm (CI)
2025-12-10 23:23:07 +09:00
parent 2a13478dc7
commit 52c65da783
6 changed files with 214 additions and 17 deletions

View File

@ -19,13 +19,14 @@
// TLS context
static __thread small_heap_ctx_v4 g_ctx_v4;
typedef struct small_segment_v4 {
// Internal segment structure (internal use only, not exposed via public box API)
typedef struct small_segment_v4_internal {
int class_idx;
size_t segment_size;
tiny_heap_ctx_t* tiny_ctx;
} small_segment_v4;
} small_segment_v4_internal;
static __thread small_segment_v4 g_segments_v4[SMALLOBJECT_NUM_CLASSES];
static __thread small_segment_v4_internal g_segments_v4[SMALLOBJECT_NUM_CLASSES];
small_heap_ctx_v4* small_heap_ctx_v4_get(void) {
return &g_ctx_v4;
@ -54,7 +55,7 @@ static size_t smallsegment_v4_default_size(void) {
small_segment_v4* smallsegment_v4_acquire(int class_idx) {
if (!v4_class_supported(class_idx)) return NULL;
small_segment_v4* seg = &g_segments_v4[class_idx];
small_segment_v4_internal* seg = &g_segments_v4[class_idx];
seg->class_idx = class_idx;
if (!seg->segment_size) {
seg->segment_size = smallsegment_v4_default_size();
@ -62,27 +63,29 @@ small_segment_v4* smallsegment_v4_acquire(int class_idx) {
if (!seg->tiny_ctx) {
seg->tiny_ctx = tiny_heap_ctx_for_thread();
}
return seg;
return (small_segment_v4*)seg;
}
void* smallsegment_v4_alloc_page(small_segment_v4* seg, int class_idx) {
if (!seg || !v4_class_supported(class_idx)) return NULL;
if (!seg->tiny_ctx) {
seg->tiny_ctx = tiny_heap_ctx_for_thread();
// Internal use only: cast to internal type to access tiny_ctx
small_segment_v4_internal* int_seg = (small_segment_v4_internal*)seg;
if (!int_seg->tiny_ctx) {
int_seg->tiny_ctx = tiny_heap_ctx_for_thread();
}
tiny_heap_ctx_t* tctx = seg->tiny_ctx ? seg->tiny_ctx : tiny_heap_ctx_for_thread();
tiny_heap_ctx_t* tctx = int_seg->tiny_ctx ? int_seg->tiny_ctx : tiny_heap_ctx_for_thread();
if (!tctx) return NULL;
tiny_heap_page_t* lease = tiny_heap_prepare_page(tctx, class_idx);
if (!lease) return NULL;
seg->tiny_ctx = tctx;
int_seg->tiny_ctx = tctx;
return v4_page_from_lease(lease, class_idx, seg);
}
void smallsegment_v4_release_if_empty(small_segment_v4* seg, void* page_ptr, int class_idx) {
small_page_v4* page = (small_page_v4*)page_ptr;
if (!page || !v4_class_supported(class_idx)) return;
tiny_heap_ctx_t* tctx = (seg && seg->tiny_ctx) ? seg->tiny_ctx : tiny_heap_ctx_for_thread();
tiny_heap_ctx_t* tctx = tiny_heap_ctx_for_thread();
tiny_heap_page_t* lease = (tiny_heap_page_t*)page->slab_ref;
if (tctx && lease) {
tiny_heap_page_becomes_empty(tctx, class_idx, lease);
@ -256,6 +259,40 @@ const SmallColdIfaceV4* small_cold_iface_v4_get(void) {
return &g_cold_iface_v4;
}
// Direct function stubs (phase v4-mid-0: delegates to iface)
small_page_v4* small_cold_v4_refill_page(small_heap_ctx_v4* ctx, uint32_t class_idx) {
const SmallColdIfaceV4* iface = small_cold_iface_v4_get();
if (!iface || !iface->refill_page) return NULL;
return iface->refill_page(ctx, class_idx);
}
void small_cold_v4_retire_page(small_heap_ctx_v4* ctx, small_page_v4* page) {
const SmallColdIfaceV4* iface = small_cold_iface_v4_get();
if (!iface || !iface->retire_page || !page) return;
iface->retire_page(ctx, (uint32_t)page->class_idx, page);
}
bool small_cold_v4_remote_push(small_page_v4* page, void* ptr, uint32_t tid) {
const SmallColdIfaceV4* iface = small_cold_iface_v4_get();
if (!iface || !iface->remote_push) return false;
return iface->remote_push(page, ptr, tid);
}
void small_cold_v4_remote_drain(small_heap_ctx_v4* ctx) {
const SmallColdIfaceV4* iface = small_cold_iface_v4_get();
if (!iface || !iface->remote_drain) return;
iface->remote_drain(ctx);
}
// Stub accessor for smallsegment_v4_page_meta_of
small_page_v4* smallsegment_v4_page_meta_of(small_segment_v4* seg, void* ptr) {
// Phase v4-mid-0: stub only, will be implemented in later phase
// For now, return NULL (unimplemented)
(void)seg;
(void)ptr;
return NULL;
}
// -----------------------------------------------------------------------------
// alloc/free
// -----------------------------------------------------------------------------