|
|
a6aeeb7a4e
|
Phase 1 Refactoring Complete: Box-based Logic Consolidation ✅
Summary:
- Task 1.1 ✅: Created tiny_layout_box.h for centralized class/header definitions
- Task 1.2 ✅: Updated tiny_nextptr.h to use layout Box (bitmasking optimization)
- Task 1.3 ✅: Enhanced ptr_conversion_box.h with Phantom Types support
- Task 1.4 ✅: Implemented test_phantom.c for Debug-mode type checking
Verification Results (by Task Agent):
- Box Pattern Compliance: ⭐⭐⭐⭐⭐ (5/5) - MISSION/DESIGN documented
- Type Safety: ⭐⭐⭐⭐⭐ (5/5) - Phantom Types working as designed
- Test Coverage: ⭐⭐⭐☆☆ (3/5) - Compile-time tests OK, runtime tests planned
- Performance: 0 bytes, 0 cycles overhead in Release build
- Build Status: ✅ Success (526KB libhakmem.so, zero warnings)
Key Achievements:
1. Single Source of Truth principle fully implemented
2. Circular dependency eliminated (layout→header→nextptr→conversion)
3. Release build: 100% inlining, zero overhead
4. Debug build: Full type checking with Phantom Types
5. HAK_RET_ALLOC macro migrated to Box API
Known Issues (unrelated to Phase 1):
- TLS_SLL_HDR_RESET from sh8bench (existing, will be resolved in Phase 2)
Next Steps:
- Phase 2 readiness: ✅ READY
- Recommended: Create migration guide + runtime test suite
- Alignment guarantee will be addressed in Phase 2 (Headerless layout)
🤖 Generated with Claude Code + Gemini (implementation) + Task Agent (verification)
Co-Authored-By: Gemini <gemini@example.com>
Co-Authored-By: Claude <noreply@anthropic.com>
|
2025-12-03 11:38:11 +09:00 |
|
|
|
6e2552e654
|
Bugfix: Add Header Box and fix Class 0/7 header handling (crash rate -50%)
Root Cause Analysis:
- tls_sll_box.h had hardcoded `class_idx != 7` checks
- This incorrectly assumed only C7 uses offset=0
- But C0 (8B) also uses offset=0 (header overwritten by next pointer)
- Result: C0 blocks had corrupted headers in TLS SLL → crash
Architecture Fix: Header Box (Single Source of Truth)
- Created core/box/tiny_header_box.h
- Encapsulates "which classes preserve headers" logic
- Delegates to tiny_nextptr.h (0x7E bitmask: C0=0, C1-C6=1, C7=0)
- API:
* tiny_class_preserves_header() - C1-C6 only
* tiny_header_write_if_preserved() - Conditional write
* tiny_header_validate() - Conditional validation
* tiny_header_write_for_alloc() - Unconditional (alloc path)
Bug Fixes (6 locations):
- tls_sll_box.h:366 - push header restore (C1-C6 only; skip C0/C7)
- tls_sll_box.h:560 - pop header validate (C1-C6 only; skip C0/C7)
- tls_sll_box.h:700 - splice header restore head (C1-C6 only)
- tls_sll_box.h:722 - splice header restore next (C1-C6 only)
- carve_push_box.c:198 - freelist→TLS SLL header restore
- hakmem_tiny_free.inc:78 - drain freelist header restore
Impact:
- Before: 23.8% crash rate (bench_random_mixed_hakmem)
- After: 12% crash rate
- Improvement: 49.6% reduction in crashes
- Test: 88/100 runs successful (vs 76/100 before)
Design Principles:
- Eliminates hardcoded class_idx checks (class_idx != 7)
- Single Source of Truth (tiny_nextptr.h → Header Box)
- Type-safe API prevents future bugs
- Future: Add lint to forbid direct header manipulation
Remaining Work:
- 12% crash rate still exists (likely different root cause)
- Next: Investigate with core dump analysis
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
2025-11-29 07:57:49 +09:00 |
|